diff --git a/de4dot.code/de4dot.code.csproj b/de4dot.code/de4dot.code.csproj
index 025b253d..be6f70f4 100644
--- a/de4dot.code/de4dot.code.csproj
+++ b/de4dot.code/de4dot.code.csproj
@@ -89,7 +89,7 @@
-
+
diff --git a/de4dot.code/deobfuscators/LocalTypes.cs b/de4dot.code/deobfuscators/StringCounts.cs
similarity index 54%
rename from de4dot.code/deobfuscators/LocalTypes.cs
rename to de4dot.code/deobfuscators/StringCounts.cs
index bfb3b783..d8cc927e 100644
--- a/de4dot.code/deobfuscators/LocalTypes.cs
+++ b/de4dot.code/deobfuscators/StringCounts.cs
@@ -23,13 +23,60 @@ using Mono.Cecil;
using Mono.Cecil.Cil;
namespace de4dot.deobfuscators {
- class LocalTypes {
- Dictionary localTypes = new Dictionary(StringComparer.Ordinal);
+ class StringCounts {
+ Dictionary strings = new Dictionary(StringComparer.Ordinal);
- public IEnumerable Types {
- get { return localTypes.Keys; }
+ public IEnumerable Strings {
+ 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 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 fields) {
+ init(fields);
+ }
+
+ void init(IEnumerable fields) {
+ if (fields == null)
+ return;
+ foreach (var field in fields)
+ add(field.FieldType.FullName);
+ }
+ }
+
+ class LocalTypes : StringCounts {
public LocalTypes(MethodDefinition method) {
if (method != null && method.Body != null)
init(method.Body.Variables);
@@ -42,30 +89,8 @@ namespace de4dot.deobfuscators {
void init(IEnumerable locals) {
if (locals == null)
return;
- foreach (var local in locals) {
- var key = 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 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;
+ foreach (var local in locals)
+ add(local.VariableType.FullName);
}
}
}