de4dot-cex/de4dot.code/deobfuscators/Eazfuscator_NET/EfUtils.cs

96 lines
2.5 KiB
C#
Raw Normal View History

2012-02-27 19:55:37 +08:00
/*
2014-03-12 05:15:43 +08:00
Copyright (C) 2011-2014 de4dot@gmail.com
2012-02-27 19:55:37 +08:00
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;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
2012-02-27 19:55:37 +08:00
using de4dot.blocks;
namespace de4dot.code.deobfuscators.Eazfuscator_NET {
static class EfUtils {
2013-01-19 20:03:57 +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;
}
2013-01-19 20:03:57 +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) {
2013-01-19 20:03:57 +08:00
index = FindOpCodeIndex(method, index, code);
2012-04-10 09:52:18 +08:00
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
}
2013-01-19 20:03:57 +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
}
}
}