Move reading variable length int32 code to DeobUtils

This commit is contained in:
de4dot 2012-02-12 16:54:48 +01:00
parent 67efd5e7e7
commit 3e3be639e5
4 changed files with 15 additions and 35 deletions

View File

@ -470,15 +470,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
}
public int readVariableLengthInt32() {
byte b = reader.ReadByte();
if ((b & 0x80) == 0)
return b;
if ((b & 0x40) == 0)
return (((int)b & 0x3F) << 8) + reader.ReadByte();
return (((int)b & 0x3F) << 24) +
((int)reader.ReadByte() << 16) +
((int)reader.ReadByte() << 8) +
reader.ReadByte();
return DeobUtils.readVariableLengthInt32(reader);
}
int getMetadataOffset() {

View File

@ -92,19 +92,7 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
}
public string decrypt(int index) {
int len;
byte b = decryptedData[index++];
if ((b & 0x80) == 0)
len = b;
else if ((b & 0x40) == 0)
len = ((b & 0x3F) << 8) + decryptedData[index++];
else {
len = ((b & 0x3F) << 24) +
((int)decryptedData[index++] << 16) +
((int)decryptedData[index++] << 8) +
decryptedData[index++];
}
int len = DeobUtils.readVariableLengthInt32(decryptedData, ref index);
return Encoding.Unicode.GetString(decryptedData, index, len);
}

View File

@ -163,6 +163,18 @@ namespace de4dot.code.deobfuscators {
reader.ReadByte();
}
public static int readVariableLengthInt32(byte[] data, ref int index) {
byte b = data[index++];
if ((b & 0x80) == 0)
return b;
if ((b & 0x40) == 0)
return (((int)b & 0x3F) << 8) + data[index++];
return (((int)b & 0x3F) << 24) +
((int)data[index++] << 16) +
((int)data[index++] << 8) +
data[index++];
}
public static bool hasInteger(MethodDefinition method, uint value) {
return hasInteger(method, (int)value);
}

View File

@ -54,19 +54,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
throw new ApplicationException("Can't decrypt strings since decryptedData is null");
int index = id - (token & 0x00FFFFFF) - stringOffset;
int len;
byte b = decryptedData[index++];
if ((b & 0x80) == 0)
len = b;
else if ((b & 0x40) == 0)
len = ((b & 0x3F) << 8) + decryptedData[index++];
else {
len = ((b & 0x1F) << 24) +
((int)decryptedData[index++] << 16) +
((int)decryptedData[index++] << 8) +
decryptedData[index++];
}
int len = DeobUtils.readVariableLengthInt32(decryptedData, ref index);
switch (StringDecrypterInfo.DecrypterVersion) {
case StringDecrypterVersion.V1: