Move method to Utils.cs

This commit is contained in:
de4dot 2012-06-03 16:07:05 +02:00
parent d2ec4e2969
commit e75386d0f9
2 changed files with 22 additions and 7 deletions

View File

@ -232,5 +232,22 @@ namespace de4dot.code {
return fileData;
}
}
public static uint readEncodedUInt32(BinaryReader reader) {
uint val = 0;
int bits = 0;
for (int i = 0; i < 5; i++) {
byte b = reader.ReadByte();
val |= (uint)(b & 0x7F) << bits;
if ((b & 0x80) == 0)
return val;
bits += 7;
}
throw new ApplicationException("Invalid encoded int32");
}
public static int readEncodedInt32(BinaryReader reader) {
return (int)readEncodedUInt32(reader);
}
}
}

View File

@ -154,14 +154,12 @@ namespace de4dot.code.resources {
}
static uint readUInt32(BinaryReader reader) {
uint val = 0;
for (int i = 0; i < 5; i++) {
byte b = reader.ReadByte();
val |= b;
if ((b & 0x80) == 0)
return val;
try {
return Utils.readEncodedUInt32(reader);
}
catch {
throw new ResourceReaderException("Invalid encoded int32");
}
throw new ResourceReaderException("Invalid encoded int32");
}
bool checkReaders() {