Add FieldTypes class and re-use LocalTypes code
This commit is contained in:
parent
6d1cca149a
commit
fec1ec7e35
|
@ -89,7 +89,7 @@
|
||||||
<Compile Include="deobfuscators\IDeobfuscator.cs" />
|
<Compile Include="deobfuscators\IDeobfuscator.cs" />
|
||||||
<Compile Include="deobfuscators\IDeobfuscatorInfo.cs" />
|
<Compile Include="deobfuscators\IDeobfuscatorInfo.cs" />
|
||||||
<Compile Include="deobfuscators\ISimpleDeobfuscator.cs" />
|
<Compile Include="deobfuscators\ISimpleDeobfuscator.cs" />
|
||||||
<Compile Include="deobfuscators\LocalTypes.cs" />
|
<Compile Include="deobfuscators\StringCounts.cs" />
|
||||||
<Compile Include="deobfuscators\Operations.cs" />
|
<Compile Include="deobfuscators\Operations.cs" />
|
||||||
<Compile Include="deobfuscators\ProxyDelegateFinderBase.cs" />
|
<Compile Include="deobfuscators\ProxyDelegateFinderBase.cs" />
|
||||||
<Compile Include="deobfuscators\SmartAssembly\AssemblyResolver.cs" />
|
<Compile Include="deobfuscators\SmartAssembly\AssemblyResolver.cs" />
|
||||||
|
|
|
@ -23,13 +23,60 @@ using Mono.Cecil;
|
||||||
using Mono.Cecil.Cil;
|
using Mono.Cecil.Cil;
|
||||||
|
|
||||||
namespace de4dot.deobfuscators {
|
namespace de4dot.deobfuscators {
|
||||||
class LocalTypes {
|
class StringCounts {
|
||||||
Dictionary<string, int> localTypes = new Dictionary<string, int>(StringComparer.Ordinal);
|
Dictionary<string, int> strings = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||||
|
|
||||||
public IEnumerable<string> Types {
|
public IEnumerable<string> Strings {
|
||||||
get { return localTypes.Keys; }
|
get { return strings.Keys; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int NumStrings {
|
||||||
|
get { return strings.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(string s) {
|
||||||
|
int count;
|
||||||
|
strings.TryGetValue(s, out count);
|
||||||
|
strings[s] = count + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool exists(string s) {
|
||||||
|
return strings.ContainsKey(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool all(IList<string> list) {
|
||||||
|
foreach (var s in list) {
|
||||||
|
if (!exists(s))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count(string s) {
|
||||||
|
int count;
|
||||||
|
strings.TryGetValue(s, out count);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FieldTypes : StringCounts {
|
||||||
|
public FieldTypes(TypeDefinition type) {
|
||||||
|
init(type.Fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldTypes(IEnumerable<FieldDefinition> fields) {
|
||||||
|
init(fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init(IEnumerable<FieldDefinition> fields) {
|
||||||
|
if (fields == null)
|
||||||
|
return;
|
||||||
|
foreach (var field in fields)
|
||||||
|
add(field.FieldType.FullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocalTypes : StringCounts {
|
||||||
public LocalTypes(MethodDefinition method) {
|
public LocalTypes(MethodDefinition method) {
|
||||||
if (method != null && method.Body != null)
|
if (method != null && method.Body != null)
|
||||||
init(method.Body.Variables);
|
init(method.Body.Variables);
|
||||||
|
@ -42,30 +89,8 @@ namespace de4dot.deobfuscators {
|
||||||
void init(IEnumerable<VariableDefinition> locals) {
|
void init(IEnumerable<VariableDefinition> locals) {
|
||||||
if (locals == null)
|
if (locals == null)
|
||||||
return;
|
return;
|
||||||
foreach (var local in locals) {
|
foreach (var local in locals)
|
||||||
var key = local.VariableType.FullName;
|
add(local.VariableType.FullName);
|
||||||
int count;
|
|
||||||
localTypes.TryGetValue(key, out count);
|
|
||||||
localTypes[key] = count + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool exists(string typeFullName) {
|
|
||||||
return localTypes.ContainsKey(typeFullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool all(IList<string> types) {
|
|
||||||
foreach (var typeName in types) {
|
|
||||||
if (!exists(typeName))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int count(string typeFullName) {
|
|
||||||
int count;
|
|
||||||
localTypes.TryGetValue(typeFullName, out count);
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user