2012-02-27 19:55:37 +08:00
|
|
|
|
/*
|
|
|
|
|
Copyright (C) 2011-2012 de4dot@gmail.com
|
|
|
|
|
|
|
|
|
|
This file is part of de4dot.
|
|
|
|
|
|
|
|
|
|
de4dot is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
de4dot is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2012-11-02 22:57:11 +08:00
|
|
|
|
using dot10.DotNet;
|
|
|
|
|
using dot10.DotNet.Emit;
|
2012-02-27 19:55:37 +08:00
|
|
|
|
using de4dot.blocks;
|
|
|
|
|
|
|
|
|
|
namespace de4dot.code.deobfuscators.Eazfuscator_NET {
|
|
|
|
|
static class EfUtils {
|
2012-11-02 22:57:11 +08:00
|
|
|
|
public static int findOpCodeIndex(MethodDef method, int index, Code code) {
|
2012-04-10 09:52:18 +08:00
|
|
|
|
for (; index < method.Body.Instructions.Count; index++) {
|
|
|
|
|
var instr = method.Body.Instructions[index];
|
|
|
|
|
if (instr.OpCode.Code != code)
|
|
|
|
|
continue;
|
2012-03-17 06:22:24 +08:00
|
|
|
|
|
2012-04-10 09:52:18 +08:00
|
|
|
|
return index;
|
2012-03-17 06:22:24 +08:00
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-02 22:57:11 +08:00
|
|
|
|
public static int findOpCodeIndex(MethodDef method, int index, Code code, string operandString) {
|
2012-04-10 09:52:18 +08:00
|
|
|
|
while (index < method.Body.Instructions.Count) {
|
|
|
|
|
index = findOpCodeIndex(method, index, code);
|
|
|
|
|
if (index < 0)
|
|
|
|
|
break;
|
2012-02-27 19:55:37 +08:00
|
|
|
|
var instr = method.Body.Instructions[index];
|
2012-04-10 09:52:18 +08:00
|
|
|
|
if (instr.Operand.ToString() == operandString)
|
|
|
|
|
return index;
|
2012-02-27 19:55:37 +08:00
|
|
|
|
|
2012-04-10 09:52:18 +08:00
|
|
|
|
index++;
|
2012-02-27 19:55:37 +08:00
|
|
|
|
}
|
2012-04-10 09:52:18 +08:00
|
|
|
|
return -1;
|
2012-02-27 19:55:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-02 22:57:11 +08:00
|
|
|
|
public static Instruction getNextStore(MethodDef method, ref int index) {
|
2012-04-10 09:52:18 +08:00
|
|
|
|
for (; index < method.Body.Instructions.Count; index++) {
|
|
|
|
|
var instr = method.Body.Instructions[index];
|
2012-02-27 19:55:37 +08:00
|
|
|
|
|
|
|
|
|
switch (instr.OpCode.Code) {
|
2012-04-10 09:52:18 +08:00
|
|
|
|
case Code.Starg:
|
|
|
|
|
case Code.Starg_S:
|
2012-11-07 11:45:05 +08:00
|
|
|
|
case Code.Stelem:
|
2012-04-10 09:52:18 +08:00
|
|
|
|
case Code.Stelem_I:
|
|
|
|
|
case Code.Stelem_I1:
|
|
|
|
|
case Code.Stelem_I2:
|
|
|
|
|
case Code.Stelem_I4:
|
|
|
|
|
case Code.Stelem_I8:
|
|
|
|
|
case Code.Stelem_R4:
|
|
|
|
|
case Code.Stelem_R8:
|
|
|
|
|
case Code.Stelem_Ref:
|
|
|
|
|
case Code.Stfld:
|
|
|
|
|
case Code.Stind_I:
|
|
|
|
|
case Code.Stind_I1:
|
|
|
|
|
case Code.Stind_I2:
|
|
|
|
|
case Code.Stind_I4:
|
|
|
|
|
case Code.Stind_I8:
|
|
|
|
|
case Code.Stind_R4:
|
|
|
|
|
case Code.Stind_R8:
|
|
|
|
|
case Code.Stind_Ref:
|
|
|
|
|
case Code.Stloc:
|
|
|
|
|
case Code.Stloc_0:
|
|
|
|
|
case Code.Stloc_1:
|
|
|
|
|
case Code.Stloc_2:
|
|
|
|
|
case Code.Stloc_3:
|
|
|
|
|
case Code.Stloc_S:
|
|
|
|
|
case Code.Stobj:
|
|
|
|
|
case Code.Stsfld:
|
|
|
|
|
return instr;
|
|
|
|
|
}
|
2012-02-27 19:55:37 +08:00
|
|
|
|
|
2012-04-10 09:52:18 +08:00
|
|
|
|
if (instr.OpCode.FlowControl != FlowControl.Next)
|
2012-02-27 19:55:37 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-04-10 09:52:18 +08:00
|
|
|
|
|
|
|
|
|
return null;
|
2012-02-27 19:55:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|