Use the methods dict

This commit is contained in:
de4dot 2011-12-31 16:15:38 +01:00
parent 99d4e2a770
commit 99350b456d
2 changed files with 16 additions and 16 deletions

View File

@ -115,7 +115,7 @@ namespace de4dot.code {
}
class StaticStringDecrypter : StringDecrypter {
Dictionary<MethodReferenceAndDeclaringTypeKey, Func<MethodDefinition, object[], string>> stringDecrypters = new Dictionary<MethodReferenceAndDeclaringTypeKey, Func<MethodDefinition, object[], string>>();
MethodDefinitionAndDeclaringTypeDict<Func<MethodDefinition, object[], string>> stringDecrypters = new MethodDefinitionAndDeclaringTypeDict<Func<MethodDefinition, object[], string>>();
public bool HasHandlers {
get { return stringDecrypters.Count != 0; }
@ -124,35 +124,35 @@ namespace de4dot.code {
public IEnumerable<MethodDefinition> Methods {
get {
var list = new List<MethodDefinition>(stringDecrypters.Count);
foreach (var key in stringDecrypters.Keys)
list.Add((MethodDefinition)key.MethodReference);
foreach (var method in stringDecrypters.getKeys())
list.Add(method);
return list;
}
}
class MyCallResult : CallResult {
public MethodReferenceAndDeclaringTypeKey methodKey;
public MethodReference methodReference;
public MyCallResult(Block block, int callEndIndex, MethodReference method)
: base(block, callEndIndex) {
this.methodKey = new MethodReferenceAndDeclaringTypeKey(method);
this.methodReference = method;
}
}
public void add(MethodDefinition method, Func<MethodDefinition, object[], string> handler) {
if (method != null)
stringDecrypters[new MethodReferenceAndDeclaringTypeKey(method)] = handler;
stringDecrypters.add(method, handler);
}
protected override void inlineAllCalls() {
foreach (var tmp in callResults) {
var callResult = (MyCallResult)tmp;
var handler = stringDecrypters[callResult.methodKey];
callResult.returnValue = handler((MethodDefinition)callResult.methodKey.MethodReference, callResult.args);
var handler = stringDecrypters.find(callResult.methodReference);
callResult.returnValue = handler((MethodDefinition)callResult.methodReference, callResult.args);
}
}
protected override CallResult createCallResult(MethodReference method, Block block, int callInstrIndex) {
if (!stringDecrypters.ContainsKey(new MethodReferenceAndDeclaringTypeKey(method)))
if (stringDecrypters.find(method) == null)
return null;
return new MyCallResult(block, callInstrIndex, method);
}

View File

@ -24,13 +24,13 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.dotNET_Reactor.v4 {
class BoolValueInliner : MethodReturnValueInliner {
Dictionary<MethodReferenceAndDeclaringTypeKey, Func<MethodDefinition, object[], bool>> boolDecrypters = new Dictionary<MethodReferenceAndDeclaringTypeKey, Func<MethodDefinition, object[], bool>>();
MethodDefinitionAndDeclaringTypeDict<Func<MethodDefinition, object[], bool>> boolDecrypters = new MethodDefinitionAndDeclaringTypeDict<Func<MethodDefinition, object[], bool>>();
class MyCallResult : CallResult {
public MethodReferenceAndDeclaringTypeKey methodKey;
public MethodReference methodReference;
public MyCallResult(Block block, int callEndIndex, MethodReference method)
: base(block, callEndIndex) {
this.methodKey = new MethodReferenceAndDeclaringTypeKey(method);
this.methodReference = method;
}
}
@ -40,7 +40,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v4 {
public void add(MethodDefinition method, Func<MethodDefinition, object[], bool> handler) {
if (method != null)
boolDecrypters[new MethodReferenceAndDeclaringTypeKey(method)] = handler;
boolDecrypters.add(method, handler);
}
protected override void inlineReturnValues(IList<CallResult> callResults) {
@ -56,13 +56,13 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v4 {
protected override void inlineAllCalls() {
foreach (var tmp in callResults) {
var callResult = (MyCallResult)tmp;
var handler = boolDecrypters[callResult.methodKey];
callResult.returnValue = handler((MethodDefinition)callResult.methodKey.MethodReference, callResult.args);
var handler = boolDecrypters.find(callResult.methodReference);
callResult.returnValue = handler((MethodDefinition)callResult.methodReference, callResult.args);
}
}
protected override CallResult createCallResult(MethodReference method, Block block, int callInstrIndex) {
if (!boolDecrypters.ContainsKey(new MethodReferenceAndDeclaringTypeKey(method)))
if (boolDecrypters.find(method) == null)
return null;
return new MyCallResult(block, callInstrIndex, method);
}