Skip to content

Commit

Permalink
Fix code since CilBody/HasCilBody were renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Nov 6, 2012
1 parent 3ed2dae commit ac171e3
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 94 deletions.
2 changes: 1 addition & 1 deletion AssemblyData/methodsrewriter/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void initInstrToIndex() {

void initLocals() {
locals = new List<LocalBuilder>();
foreach (var local in methodInfo.methodDef.CilBody.LocalList)
foreach (var local in methodInfo.methodDef.Body.LocalList)
locals.Add(ilg.DeclareLocal(Resolver.getRtType(local.Type), local.Type.IsPinned));
tempObjLocal = ilg.DeclareLocal(typeof(object));
tempObjArrayLocal = ilg.DeclareLocal(typeof(object[]));
Expand Down
2 changes: 1 addition & 1 deletion AssemblyData/methodsrewriter/MMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MMethod(MethodBase methodBase, MethodDef methodDefinition) {
}

public bool hasInstructions() {
return methodDef.CilBody != null && methodDef.CilBody.Instructions.Count != 0;
return methodDef.Body != null && methodDef.Body.Instructions.Count != 0;
}

public override string ToString() {
Expand Down
2 changes: 1 addition & 1 deletion blocks/Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Blocks(MethodDef method) {
}

public void updateBlocks() {
var body = method.CilBody;
var body = method.Body;
locals = body.LocalList;
methodBlocks = new InstructionListParser(body.Instructions, body.ExceptionHandlers).parse();
}
Expand Down
32 changes: 16 additions & 16 deletions blocks/DotNetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public static MethodDef getModuleTypeCctor(ModuleDef module) {
}

public static bool isEmpty(MethodDef method) {
if (method.CilBody == null)
if (method.Body == null)
return false;
foreach (var instr in method.CilBody.Instructions) {
foreach (var instr in method.Body.Instructions) {
var code = instr.OpCode.Code;
if (code != Code.Nop && code != Code.Ret)
return false;
Expand All @@ -171,10 +171,10 @@ public static bool isEmpty(MethodDef method) {
}

public static bool isEmptyObfuscated(MethodDef method) {
if (method.CilBody == null)
if (method.Body == null)
return false;
int index = 0;
var instr = getInstruction(method.CilBody.Instructions, ref index);
var instr = getInstruction(method.Body.Instructions, ref index);
if (instr == null || instr.OpCode.Code != Code.Ret)
return false;

Expand Down Expand Up @@ -467,8 +467,8 @@ public static IList<string> getCodeStrings(MethodDefinition method) {

public static IList<string> getCodeStrings(MethodDef method) {
var strings = new List<string>();
if (method != null && method.CilBody != null) {
foreach (var instr in method.CilBody.Instructions) {
if (method != null && method.Body != null) {
foreach (var instr in method.Body.Instructions) {
if (instr.OpCode.Code == Code.Ldstr)
strings.Add((string)instr.Operand);
}
Expand Down Expand Up @@ -604,14 +604,14 @@ static Instruction getInstruction(IList<Instruction> instructions, IDictionary<I
#endif

public static void copyBody(MethodDef method, out IList<Instruction> instructions, out IList<ExceptionHandler> exceptionHandlers) {
if (method == null || !method.HasCilBody) {
if (method == null || !method.HasBody) {
instructions = new List<Instruction>();
exceptionHandlers = new List<ExceptionHandler>();
return;
}

var oldInstrs = method.CilBody.Instructions;
var oldExHandlers = method.CilBody.ExceptionHandlers;
var oldInstrs = method.Body.Instructions;
var oldExHandlers = method.Body.ExceptionHandlers;
instructions = new List<Instruction>(oldInstrs.Count);
exceptionHandlers = new List<ExceptionHandler>(oldExHandlers.Count);
var oldToIndex = Utils.createObjectToIndexDictionary(oldInstrs);
Expand Down Expand Up @@ -669,15 +669,15 @@ public static void restoreBody(MethodDefinition method, IEnumerable<Instruction>
#endif

public static void restoreBody(MethodDef method, IEnumerable<Instruction> instructions, IEnumerable<ExceptionHandler> exceptionHandlers) {
if (method == null || method.CilBody == null)
if (method == null || method.Body == null)
return;

var bodyInstrs = method.CilBody.Instructions;
var bodyInstrs = method.Body.Instructions;
bodyInstrs.Clear();
foreach (var instr in instructions)
bodyInstrs.Add(instr);

var bodyExceptionHandlers = method.CilBody.ExceptionHandlers;
var bodyExceptionHandlers = method.Body.ExceptionHandlers;
bodyExceptionHandlers.Clear();
foreach (var eh in exceptionHandlers)
bodyExceptionHandlers.Add(eh);
Expand All @@ -696,17 +696,17 @@ public static void copyBodyFromTo(MethodDef fromMethod, MethodDef toMethod) {
}

static void copyLocalsFromTo(MethodDef fromMethod, MethodDef toMethod) {
var fromBody = fromMethod.CilBody;
var toBody = toMethod.CilBody;
var fromBody = fromMethod.Body;
var toBody = toMethod.Body;

toBody.LocalList.Clear();
foreach (var local in fromBody.LocalList)
toBody.LocalList.Add(new Local(local.Type));
}

static void updateInstructionOperands(MethodDef fromMethod, MethodDef toMethod) {
var fromBody = fromMethod.CilBody;
var toBody = toMethod.CilBody;
var fromBody = fromMethod.Body;
var toBody = toMethod.Body;

toBody.InitLocals = fromBody.InitLocals;
toBody.MaxStack = fromBody.MaxStack;
Expand Down
2 changes: 1 addition & 1 deletion blocks/cflow/CachedCflowDeobfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MethodDef deobfuscate(MethodDef method) {
if (deobfuscated.TryGetValue(method, out deobfuscatedMethod))
return deobfuscatedMethod;

if (method.CilBody == null || method.CilBody.Instructions.Count == 0) {
if (method.Body == null || method.Body.Instructions.Count == 0) {
deobfuscated[method] = method;
return method;
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/cflow/CflowDeobfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void deobfuscate(MethodDef method) {
}

static bool hasNonEmptyBody(MethodDef method) {
return method.CilBody != null && method.CilBody.Instructions.Count > 0;
return method.Body != null && method.Body.Instructions.Count > 0;
}

void deobfuscate(MethodDef method, Action<Blocks> handler) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/cflow/InstructionEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void init(Blocks blocks) {

public void init(MethodDef method) {
this.parameterDefs = method.Parameters;
this.localDefs = method.CilBody.LocalList;
this.localDefs = method.Body.LocalList;
valueStack.init();
protectedStackValues.Clear();

Expand Down
2 changes: 1 addition & 1 deletion blocks/cflow/MethodCallInliner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool inlineMethod(Instruction callInstr, int instrIndex) {

if (!canInline(methodToInline))
return false;
var body = methodToInline.CilBody;
var body = methodToInline.Body;
if (body == null)
return false;

Expand Down
4 changes: 2 additions & 2 deletions blocks/cflow/MethodCallInlinerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected InstructionPatcher tryInlineOtherMethod(int patchIndex, MethodDef meth
if (instr.GetParameterIndex() != loadIndex)
return null;
loadIndex++;
instr = DotNetUtils.getInstruction(methodToInline.CilBody.Instructions, ref instrIndex);
instr = DotNetUtils.getInstruction(methodToInline.Body.Instructions, ref instrIndex);
}
if (instr == null || loadIndex != methodArgsCount - popLastArgs)
return null;
Expand Down Expand Up @@ -187,7 +187,7 @@ protected InstructionPatcher tryInlineOtherMethod(int patchIndex, MethodDef meth
}

protected virtual bool isReturn(MethodDef methodToInline, int instrIndex) {
var instr = DotNetUtils.getInstruction(methodToInline.CilBody.Instructions, ref instrIndex);
var instr = DotNetUtils.getInstruction(methodToInline.Body.Instructions, ref instrIndex);
return instr != null && instr.OpCode.Code == Code.Ret;
}

Expand Down
4 changes: 2 additions & 2 deletions de4dot.code/MethodReturnValueInliner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public int decrypt(MethodDef method, List<Block> allBlocks) {

bool getLocalVariableValue(Local variable, out object value) {
if (variableValues == null)
variableValues = new VariableValues(theMethod.CilBody.LocalList, allBlocks);
variableValues = new VariableValues(theMethod.Body.LocalList, allBlocks);
var val = variableValues.getValue(variable);
if (!val.isValid()) {
value = null;
Expand Down Expand Up @@ -342,7 +342,7 @@ bool getArg(IMethod method, Block block, ref object arg, ref int instrIndex) {
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
getLocalVariableValue(instr.Instruction.GetLocal(theMethod.CilBody.LocalList), out arg);
getLocalVariableValue(instr.Instruction.GetLocal(theMethod.Body.LocalList), out arg);
break;

case Code.Ldfld:
Expand Down
10 changes: 5 additions & 5 deletions de4dot.code/ObfuscatedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ void deobfuscateMethods() {
catch (Exception ex) {
if (!canLoadMethodBody(method)) {
Log.v("Invalid method body. {0:X8}", method.MDToken.ToInt32());
method.CilBody = new CilBody();
method.Body = new CilBody();
}
else {
Log.w("Could not deobfuscate method {0:X8}. Hello, E.T.: {1}", // E.T. = exception type
Expand All @@ -568,7 +568,7 @@ void deobfuscateMethods() {

static bool canLoadMethodBody(MethodDef method) {
try {
var body = method.CilBody;
var body = method.Body;
return true;
}
catch {
Expand All @@ -582,7 +582,7 @@ void deobfuscate(MethodDef method, BlocksCflowDeobfuscator cflowDeobfuscator, Me

var blocks = new Blocks(method);
int numRemovedLocals = 0;
int oldNumInstructions = method.CilBody.Instructions.Count;
int oldNumInstructions = method.Body.Instructions.Count;

deob.deobfuscateMethodBegin(blocks);
if (options.ControlFlowDeobfuscation) {
Expand Down Expand Up @@ -611,7 +611,7 @@ void deobfuscate(MethodDef method, BlocksCflowDeobfuscator cflowDeobfuscator, Me

if (numRemovedLocals > 0)
Log.v("Removed {0} unused local(s)", numRemovedLocals);
int numRemovedInstructions = oldNumInstructions - method.CilBody.Instructions.Count;
int numRemovedInstructions = oldNumInstructions - method.Body.Instructions.Count;
if (numRemovedInstructions > 0)
Log.v("Removed {0} dead instruction(s)", numRemovedInstructions);

Expand All @@ -625,7 +625,7 @@ void deobfuscate(MethodDef method, BlocksCflowDeobfuscator cflowDeobfuscator, Me
}

bool hasNonEmptyBody(MethodDef method) {
return method.HasCilBody && method.CilBody.Instructions.Count > 0;
return method.HasBody && method.Body.Instructions.Count > 0;
}

void deobfuscateStrings(Blocks blocks) {
Expand Down
6 changes: 3 additions & 3 deletions de4dot.code/deobfuscators/ArrayFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static List<byte[]> getArrays(MethodDef method) {

public static List<byte[]> getArrays(MethodDef method, IType arrayElementType) {
var arrays = new List<byte[]>();
var instrs = method.CilBody.Instructions;
var instrs = method.Body.Instructions;
for (int i = 0; i < instrs.Count; i++) {
IType type;
var ary = getArray(instrs, ref i, out type);
Expand Down Expand Up @@ -135,7 +135,7 @@ public static Value[] getInitializedArray(int arraySize, MethodDef method, ref i
var theArray = new UnknownValue();
emulator.push(theArray);

var instructions = method.CilBody.Instructions;
var instructions = method.Body.Instructions;
int i;
for (i = newarrIndex + 1; i < instructions.Count; i++) {
var instr = instructions[i];
Expand Down Expand Up @@ -194,7 +194,7 @@ static int findNewarr(MethodDef method, int arraySize) {
}

public static bool findNewarr(MethodDef method, ref int i, out int size) {
var instructions = method.CilBody.Instructions;
var instructions = method.Body.Instructions;
for (; i < instructions.Count; i++) {
var instr = instructions[i];
if (instr.OpCode.Code != Code.Newarr || i < 1)
Expand Down
4 changes: 2 additions & 2 deletions de4dot.code/deobfuscators/ConstantsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public ConstantsReader(IList<Instr> instrs, bool emulateConvInstrs)
}

public ConstantsReader(MethodDef method)
: this(method.CilBody.Instructions) {
this.locals = method.CilBody.LocalList;
: this(method.Body.Instructions) {
this.locals = method.Body.LocalList;
}

public ConstantsReader(IList<Instr> instrs, IList<Local> locals)
Expand Down
8 changes: 4 additions & 4 deletions de4dot.code/deobfuscators/DeobUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ public static bool hasInteger(MethodDef method, int value) {
}

public static int indexOfLdci4Instruction(MethodDef method, int value) {
if (method == null || method.CilBody == null)
if (method == null || method.Body == null)
return -1;
var instrs = method.CilBody.Instructions;
var instrs = method.Body.Instructions;
for (int i = 0; i < instrs.Count; i++) {
var instr = instrs[i];
if (!instr.IsLdcI4())
Expand Down Expand Up @@ -249,9 +249,9 @@ public static IEnumerable<MethodDef> getInitCctors(ModuleDef module, int maxCcto

public static List<MethodDef> getAllResolveHandlers(MethodDef method) {
var list = new List<MethodDef>();
if (method == null || method.CilBody == null)
if (method == null || method.Body == null)
return list;
foreach (var instr in method.CilBody.Instructions) {
foreach (var instr in method.Body.Instructions) {
if (instr.OpCode.Code != Code.Ldftn && instr.OpCode.Code != Code.Ldvirtftn)
continue;
var handler = instr.Operand as MethodDef;
Expand Down
18 changes: 9 additions & 9 deletions de4dot.code/deobfuscators/DeobfuscatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ protected void setInitLocals() {
foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (isFatHeader(method))
method.CilBody.InitLocals = true;
method.Body.InitLocals = true;
}
}
}

static bool isFatHeader(MethodDef method) {
if (method == null || method.CilBody == null)
if (method == null || method.Body == null)
return false;
var body = method.CilBody;
var body = method.Body;
if (body.InitLocals || body.MaxStack > 8)
return true;
if (body.LocalList.Count > 0)
Expand All @@ -562,10 +562,10 @@ static bool isFatHeader(MethodDef method) {
}

static int getCodeSize(MethodDef method) {
if (method == null || method.CilBody == null)
if (method == null || method.Body == null)
return 0;
int size = 0;
foreach (var instr in method.CilBody.Instructions)
foreach (var instr in method.Body.Instructions)
size += instr.GetSize();
return size;
}
Expand All @@ -575,10 +575,10 @@ public override string ToString() {
}

protected void findPossibleNamesToRemove(MethodDef method) {
if (method == null || !method.HasCilBody)
if (method == null || !method.HasBody)
return;

foreach (var instr in method.CilBody.Instructions) {
foreach (var instr in method.Body.Instructions) {
if (instr.OpCode == OpCodes.Ldstr)
namesToPossiblyRemove.Add((string)instr.Operand);
}
Expand Down Expand Up @@ -730,14 +730,14 @@ protected bool isTypeCalled(TypeDef decrypterType) {

foreach (var type in module.GetTypes()) {
foreach (var method in type.Methods) {
if (method.CilBody == null)
if (method.Body == null)
continue;
if (decrypterMethods.exists(method))
break; // decrypter type / nested type method
if (removedMethods.exists(method))
continue;

foreach (var instr in method.CilBody.Instructions) {
foreach (var instr in method.Body.Instructions) {
switch (instr.OpCode.Code) {
case Code.Call:
case Code.Callvirt:
Expand Down
6 changes: 3 additions & 3 deletions de4dot.code/deobfuscators/InlinedMethodsFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static List<MethodDef> find(ModuleDef module) {
continue;
if (method.Name == ".cctor")
continue;
if (method.CilBody == null)
if (method.Body == null)
continue;
var instrs = method.CilBody.Instructions;
var instrs = method.Body.Instructions;
if (instrs.Count < 2)
continue;

Expand Down Expand Up @@ -100,7 +100,7 @@ public static List<MethodDef> find(ModuleDef module) {
static bool isCallMethod(MethodDef method) {
int loadIndex = 0;
int methodArgsCount = DotNetUtils.getArgsCount(method);
var instrs = method.CilBody.Instructions;
var instrs = method.Body.Instructions;
int i = 0;
for (; i < instrs.Count && i < methodArgsCount; i++) {
var instr = instrs[i];
Expand Down
2 changes: 1 addition & 1 deletion de4dot.code/deobfuscators/MethodStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static TypeSig getLoadedType(MethodDef method, IList<Instruction> instruc
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
local = pushInstr.GetLocal(method.CilBody.LocalList);
local = pushInstr.GetLocal(method.Body.LocalList);
if (local == null)
return null;
type = local.Type.RemovePinned();
Expand Down
Loading

0 comments on commit ac171e3

Please sign in to comment.