Add a fix for when type.Scope is null

This commit is contained in:
de4dot 2012-08-31 00:24:42 +02:00
parent 26e4aa4e1d
commit 13a5fd8ff0
4 changed files with 9 additions and 2 deletions

View File

@ -146,7 +146,7 @@ namespace AssemblyData.methodsrewriter {
var asmRef = DotNetUtils.getAssemblyNameReference(b);
var asmName = a.Assembly.GetName();
if (asmRef.Name != asmName.Name)
if (asmRef == null || asmRef.Name != asmName.Name)
return false;
return compareTypes(a.DeclaringType, b.DeclaringType);

View File

@ -926,6 +926,9 @@ namespace de4dot.blocks {
public static AssemblyNameReference getAssemblyNameReference(TypeReference type) {
var scope = type.Scope;
if (scope == null)
return null;
if (scope is ModuleDefinition) {
var moduleDefinition = (ModuleDefinition)scope;
return moduleDefinition.Assembly.Name;
@ -946,7 +949,7 @@ namespace de4dot.blocks {
public static string getFullAssemblyName(TypeReference type) {
var asmRef = getAssemblyNameReference(type);
return asmRef.FullName;
return asmRef == null ? null : asmRef.FullName;
}
public static bool isAssembly(IMetadataScope scope, string assemblySimpleName) {

View File

@ -56,6 +56,8 @@ namespace de4dot.code {
ExternalAssembly load(TypeReference type) {
var asmFullName = DotNetUtils.getFullAssemblyName(type);
if (asmFullName == null)
return null;
ExternalAssembly asm;
if (assemblies.TryGetValue(asmFullName, out asm))
return asm;

View File

@ -390,6 +390,8 @@ namespace de4dot.code.renamer.asmmodules {
// Returns null if it's a non-loaded module/assembly
IEnumerable<Module> findModules(TypeReference type) {
var scope = type.Scope;
if (scope == null)
return null;
if (scope is AssemblyNameReference)
return findModules((AssemblyNameReference)scope);