Some fixes
- Rename offset variables - Alloc buffer outside the loop - Read CRC32 checksum outside the loop - Get rid of a local variable
This commit is contained in:
parent
7e9e691ef3
commit
bf7c0d58d2
|
@ -169,11 +169,11 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
|
|
||||||
public static DecrypterV106 create(IBinaryReader reader) {
|
public static DecrypterV106 create(IBinaryReader reader) {
|
||||||
try {
|
try {
|
||||||
int keyXorOffs2 = (ReadByteAt(reader, 0) ^ ReadByteAt(reader, 2)) + 2;
|
int keyXorOffs7 = (ReadByteAt(reader, 0) ^ ReadByteAt(reader, 2)) + 2;
|
||||||
reader.Position = keyXorOffs2 + (ReadByteAt(reader, 1) ^ ReadByteAt(reader, keyXorOffs2));
|
reader.Position = keyXorOffs7 + (ReadByteAt(reader, 1) ^ ReadByteAt(reader, keyXorOffs7));
|
||||||
|
|
||||||
int sha1DataLen = reader.Read7BitEncodedInt32() + 0x80;
|
int sha1DataLen = reader.Read7BitEncodedInt32() + 0x80;
|
||||||
int keyXorOffs1 = (int)reader.Position;
|
int keyXorOffs6 = (int)reader.Position;
|
||||||
int encryptedOffs = (int)reader.Position + sha1DataLen;
|
int encryptedOffs = (int)reader.Position + sha1DataLen;
|
||||||
var sha1Data = reader.ReadBytes(sha1DataLen);
|
var sha1Data = reader.ReadBytes(sha1DataLen);
|
||||||
uint crc32 = CRC32.checksum(sha1Data);
|
uint crc32 = CRC32.checksum(sha1Data);
|
||||||
|
@ -184,8 +184,8 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var key0 = DeobUtils.sha1Sum(sha1Data); // 1.0.6.0
|
var key0 = DeobUtils.sha1Sum(sha1Data); // 1.0.6.0
|
||||||
var key6 = getKey(reader, key0, keyXorOffs1); // 1.0.6.6
|
var key6 = getKey(reader, key0, keyXorOffs6); // 1.0.6.6
|
||||||
var key7 = getKey(reader, key0, keyXorOffs2); // 1.0.6.7
|
var key7 = getKey(reader, key0, keyXorOffs7); // 1.0.6.7
|
||||||
return new DecrypterV106(key0, key6, key7, encryptedOffs);
|
return new DecrypterV106(key0, key6, key7, encryptedOffs);
|
||||||
}
|
}
|
||||||
catch (IOException) {
|
catch (IOException) {
|
||||||
|
@ -196,27 +196,27 @@ namespace de4dot.code.deobfuscators.ILProtector {
|
||||||
static byte[] getKey(IBinaryReader reader, byte[] sha1Sum, int offs) {
|
static byte[] getKey(IBinaryReader reader, byte[] sha1Sum, int offs) {
|
||||||
var key = (byte[])sha1Sum.Clone();
|
var key = (byte[])sha1Sum.Clone();
|
||||||
reader.Position = offs;
|
reader.Position = offs;
|
||||||
for (int i = 0; i < key.Length; i++) {
|
for (int i = 0; i < key.Length; i++)
|
||||||
byte b = reader.ReadByte();
|
key[i] ^= reader.ReadByte();
|
||||||
key[i] ^= b;
|
|
||||||
}
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte ReadByteAt(IBinaryReader reader, int offs) {
|
static byte ReadByteAt(IBinaryReader reader, int offs) {
|
||||||
reader.Position = offs;
|
reader.Position = offs;
|
||||||
byte b = reader.ReadByte();
|
return reader.ReadByte();
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] getMethodsData(EmbeddedResource resource) {
|
public override byte[] getMethodsData(EmbeddedResource resource) {
|
||||||
var reader = resource.Data;
|
var reader = resource.Data;
|
||||||
|
reader.Position = startOffset;
|
||||||
|
var decrypted = new byte[reader.Read7BitEncodedUInt32()];
|
||||||
|
uint origCrc32 = reader.ReadUInt32();
|
||||||
|
long pos = reader.Position;
|
||||||
|
|
||||||
var keys = new byte[][] { decryptionKey, decryptionKey6, decryptionKey7 };
|
var keys = new byte[][] { decryptionKey, decryptionKey6, decryptionKey7 };
|
||||||
foreach (var key in keys) {
|
foreach (var key in keys) {
|
||||||
try {
|
try {
|
||||||
reader.Position = startOffset;
|
reader.Position = pos;
|
||||||
var decrypted = new byte[reader.Read7BitEncodedUInt32()];
|
|
||||||
uint origCrc32 = reader.ReadUInt32();
|
|
||||||
decompress(decrypted, reader, key, decryptionKeyMod);
|
decompress(decrypted, reader, key, decryptionKeyMod);
|
||||||
uint crc32 = CRC32.checksum(decrypted);
|
uint crc32 = CRC32.checksum(decrypted);
|
||||||
if (crc32 == origCrc32)
|
if (crc32 == origCrc32)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user