Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Fix AntiTamper compatibility with mixed mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Jan 7, 2015
1 parent 4f83c6a commit 2f10e00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Confuser.Protections/AntiTamper/JITMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,18 @@ void EncryptSection(ModuleWriterBase writer) {
stream.Position += 2 + optSize;

uint encLoc = 0, encSize = 0;
int origSects = -1;
if (writer is NativeModuleWriter && writer.Module is ModuleDefMD)
origSects = ((ModuleDefMD)writer.Module).MetaData.PEImage.ImageSectionHeaders.Count;
for (int i = 0; i < sections; i++) {
uint nameHash = reader.ReadUInt32() * reader.ReadUInt32();
uint nameHash;
if (origSects > 0) {
origSects--;
stream.Write(new byte[8], 0, 8);
nameHash = 0;
}
else
nameHash = reader.ReadUInt32() * reader.ReadUInt32();
stream.Position += 8;
if (nameHash == name1 * name2) {
encSize = reader.ReadUInt32();
Expand All @@ -256,6 +266,8 @@ void EncryptSection(ModuleWriterBase writer) {
uint sectLoc = reader.ReadUInt32();
Hash(stream, reader, sectLoc, sectSize);
}
else
stream.Position += 8;
stream.Position += 16;
}

Expand Down
14 changes: 13 additions & 1 deletion Confuser.Protections/AntiTamper/NormalMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,18 @@ void EncryptSection(ModuleWriterBase writer) {
stream.Position += 2 + optSize;

uint encLoc = 0, encSize = 0;
int origSects = -1;
if (writer is NativeModuleWriter && writer.Module is ModuleDefMD)
origSects = ((ModuleDefMD)writer.Module).MetaData.PEImage.ImageSectionHeaders.Count;
for (int i = 0; i < sections; i++) {
uint nameHash = reader.ReadUInt32() * reader.ReadUInt32();
uint nameHash;
if (origSects > 0) {
origSects--;
stream.Write(new byte[8], 0, 8);
nameHash = 0;
}
else
nameHash = reader.ReadUInt32() * reader.ReadUInt32();
stream.Position += 8;
if (nameHash == name1 * name2) {
encSize = reader.ReadUInt32();
Expand All @@ -197,6 +207,8 @@ void EncryptSection(ModuleWriterBase writer) {
uint sectLoc = reader.ReadUInt32();
Hash(stream, reader, sectLoc, sectSize);
}
else
stream.Position += 8;
stream.Position += 16;
}

Expand Down

0 comments on commit 2f10e00

Please sign in to comment.