Merge branch 'master' into goliath

This commit is contained in:
de4dot 2011-12-29 14:18:21 +01:00
commit d344c05404
3 changed files with 43 additions and 4 deletions

View File

@ -86,10 +86,34 @@ namespace de4dot.code.renamer {
prepareRenameMemberDefinitions(scopes);
renameMemberDefinitions();
renameMemberReferences();
removeUselessOverrides(scopes);
renameResources();
modules.cleanUp();
}
void removeUselessOverrides(MethodNameScopes scopes) {
foreach (var scope in scopes.getAllScopes()) {
foreach (var method in scope.Methods) {
if (!method.Owner.HasModule)
continue;
if (!method.isPublic())
continue;
var overrides = method.MethodDefinition.Overrides;
for (int i = 0; i < overrides.Count; i++) {
var overrideMethod = overrides[i];
if (method.MethodDefinition.Name != overrideMethod.Name)
continue;
Log.v("Removed useless override from method {0} ({1:X8}), override: {2:X8}",
method.MethodDefinition,
method.MethodDefinition.MetadataToken.ToInt32(),
overrideMethod.MetadataToken.ToInt32());
overrides.RemoveAt(i);
i--;
}
}
}
}
void renameTypeDefinitions() {
Log.v("Renaming obfuscated type definitions");

View File

@ -88,7 +88,7 @@ namespace de4dot.code.renamer {
if (type.TypeDefinition.IsNested)
newNamespace = "";
else if (!checker.isValidNamespaceName(oldNamespace))
newNamespace = state.createNamespace(oldNamespace);
newNamespace = state.createNamespace(this.type.TypeDefinition, oldNamespace);
}
string origClassName = null;

View File

@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using Mono.Cecil;
namespace de4dot.code.renamer {
class TypeRenamerState {
@ -44,11 +45,25 @@ namespace de4dot.code.renamer {
return existingNames.getName(oldName, new NameCreator2(newName));
}
public string createNamespace(string ns) {
public string createNamespace(TypeDefinition type, string ns) {
string newName;
if (namespaceToNewName.TryGetValue(ns, out newName))
string asmFullName;
if (type.Module.Assembly != null)
asmFullName = type.Module.Assembly.FullName;
else
asmFullName = "<no assembly>";
// Make sure that two namespaces with the same names in different modules aren't renamed
// to the same name.
var key = string.Format(" [{0}] [{1}] [{2}] [{3}] ",
type.Module.FullyQualifiedName,
asmFullName,
type.Module.Name,
ns);
if (namespaceToNewName.TryGetValue(key, out newName))
return newName;
return namespaceToNewName[ns] = createNamespaceName.create();
return namespaceToNewName[key] = createNamespaceName.create();
}
}
}