private void Type3_Backward(byte[] pSrc, byte[] pDest, uint size, byte key) { int[] array = new int[] { 1, 3, 2, 3, 1, 5, 4, 2, 1, 4, 2, 8, 4, 2, 6, 8, 2, 6, 4 }; int num = array.Length; uint num2 = 2821468417u + (uint)key; int num3 = 4; int num4 = (int)(size / (uint)num3); int num5 = (int)(size % (uint)num3); uint num6 = 0u; int num7; if (num5 != 0) { num7 = num4 + 1; } else { num7 = num4; } uint[] array2 = new uint[num7]; Buffer.BlockCopy(pSrc, 0, array2, 0, pSrc.Length); int num8 = num4 - 1; while (-1 < num8) { int num9 = array[num8 % num]; int num10 = (num8 + num9) % num4; NEncrypt.Swap(ref array2[num8], ref array2[num10]); num8--; } pDest = pSrc; for (int i = 0; i < num4; i++) { uint num11 = (uint)((ulong)num2 + (ulong)((long)(i * (int)key)) + (ulong)num6); num6 = array2[i]; array2[i] += num11; } Buffer.BlockCopy(array2, 0, pDest, 0, (int)size); }
private void Type3_Forward(byte[] pSrc, byte[] pDest, uint size, byte key) { int[] array = new int[] { 1, 3, 2, 3, 1, 5, 4, 2, 1, 4, 2, 8, 4, 2, 6, 8, 2, 6, 4 }; int num = array.Length; uint num2 = 2821468417u + (uint)key; int num3 = 4; int num4 = (int)(size / (uint)num3); int num5 = (int)(size % 4u); uint num6 = 0u; int num7; if (num5 == 0) { num7 = num4; } else { num7 = num4 + 1; } uint[] array2 = new uint[num7]; Buffer.BlockCopy(pSrc, 0, array2, 0, (int)size); for (int i = 0; i < num4; i++) { uint num8 = (uint)((ulong)num2 + (ulong)((long)(i * (int)key)) + (ulong)num6); array2[i] -= num8; num6 = array2[i]; } for (int j = 0; j < num4; j++) { int num9 = array[j % num]; int num10 = (j + num9) % num4; NEncrypt.Swap(ref array2[j], ref array2[num10]); } Buffer.BlockCopy(array2, 0, pDest, 24, (int)size); }
public static bool IsForwarded(Stream stream, NEncrypt.enc_type eType) { bool result = NEncrypt.__isforwarded(stream, eType); if (stream.CanSeek) { stream.Position = 0L; } return(result); }
public static bool ProcessFile(string filename, char key = ' ', NEncrypt.PT pt = NEncrypt.PT.PT_AUTO) { bool result = false; NEncrypt.enc_type enc_type = NEncrypt.enc_type.ENC_NONE; if (pt == NEncrypt.PT.PT_DEC || pt == NEncrypt.PT.PT_AUTO) { enc_type = NEncrypt.IsForwarded(filename); if (enc_type != NEncrypt.enc_type.ENC_NONE) { return(NEncrypt.DecryptFile(filename, enc_type, key, null)); } } if (pt == NEncrypt.PT.PT_ENC || pt == NEncrypt.PT.PT_AUTO) { string extension = Path.GetExtension(filename); if (extension.Equals(".ntx") || extension.Equals(".ndt")) { enc_type = NEncrypt.enc_type.ENC_DEFAULT; } else if (extension.Equals(".nif")) { enc_type = NEncrypt.enc_type.ENC_NIF; } else if (extension.Equals(".dds")) { enc_type = NEncrypt.enc_type.ENC_DDS; } else if (extension.Equals(".tga")) { enc_type = NEncrypt.enc_type.ENC_TGA; } bool flag = true; if (enc_type == NEncrypt.enc_type.ENC_NONE) { if (pt == NEncrypt.PT.PT_AUTO) { if (flag) { enc_type = NEncrypt.enc_type.ENC_DEFAULT; } } else { flag = true; enc_type = NEncrypt.enc_type.ENC_DEFAULT; } } if (flag) { result = (NEncrypt.IsForwarded(filename, enc_type) || NEncrypt.EncryptFile(filename, enc_type, key, null)); } } return(result); }
public static NEncrypt.enc_type IsForwarded(byte[] pBuffer, uint nBufSize) { for (NEncrypt.enc_type enc_type = NEncrypt.enc_type.ENC_DEFAULT; enc_type < NEncrypt.enc_type.ENC_END; enc_type++) { if (NEncrypt.IsForwarded(pBuffer, nBufSize, enc_type)) { return(enc_type); } } return(NEncrypt.enc_type.ENC_NONE); }
public static NEncrypt.enc_type IsForwarded(Stream stream) { for (NEncrypt.enc_type enc_type = NEncrypt.enc_type.ENC_DEFAULT; enc_type < NEncrypt.enc_type.ENC_END; enc_type++) { if (NEncrypt.IsForwarded(stream, enc_type)) { return(enc_type); } } return(NEncrypt.enc_type.ENC_NONE); }
public static NEncrypt.enc_type IsForwarded(string filename) { for (NEncrypt.enc_type enc_type = NEncrypt.enc_type.ENC_DEFAULT; enc_type < NEncrypt.enc_type.ENC_END; enc_type++) { if (NEncrypt.IsForwarded(filename, enc_type)) { return(enc_type); } } return(NEncrypt.enc_type.ENC_NONE); }
public static bool CheckCrypt(string filename) { uint fileSize = NEncrypt.GetFileSize(filename); byte[] array = File.ReadAllBytes(filename); int num = array.Length; return(num >= 24 && NEncrypt.Decrypt(new NEncrypt.enc_args(NEncrypt.enc_type.ENC_DEFAULT, array, fileSize, null, false) { uiSrcFileSize = fileSize }, ' ')); }
public static bool IsForwarded(string filename, NEncrypt.enc_type eType) { if (!NEncrypt.IsExistFile(filename)) { return(false); } FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); bool result = NEncrypt.__isforwarded(fileStream, eType); fileStream.Close(); return(result); }
private static bool Enc_Dec_File(string filename, NEncrypt.enc_type eType, NEncrypt.process_type _process_type, char key, string newfilename) { StreamReader streamReader = new StreamReader(new FileStream(filename, FileMode.Open)); int num = (int)streamReader.BaseStream.Length; streamReader.Close(); byte[] array = new byte[num]; NEncrypt.enc_args enc_args = new NEncrypt.enc_args(eType, array, (uint)array.Length, null, false); BinaryReader binaryReader = new BinaryReader(new FileStream(filename, FileMode.Open)); enc_args.pSrcBuf = binaryReader.ReadBytes(num); enc_args.nSrcSize = (uint)num; binaryReader.Close(); enc_args.uiSrcFileSize = (uint)num; bool flag = false; if (_process_type != NEncrypt.process_type.process_enc_type) { if (_process_type == NEncrypt.process_type.process_dec_type) { flag = NEncrypt.Decrypt(enc_args, key); } } else { flag = NEncrypt.Encrypt(enc_args, key); } if (!flag) { return(false); } DateTime lastWriteTime = File.GetLastWriteTime(filename); BinaryWriter binaryWriter = new BinaryWriter(new FileStream(filename, FileMode.Create)); binaryWriter.Write(enc_args.pOutBuf); binaryWriter.Close(); File.SetLastWriteTime(filename, lastWriteTime); return(true); }
private static bool EncryptFile(string filename, NEncrypt.enc_type eType, char key, string newfilename = null) { return(NEncrypt.Enc_Dec_File(filename, eType, NEncrypt.process_type.process_enc_type, key, newfilename)); }