Add a fix for when type.Scope is null
This commit is contained in:
parent
26e4aa4e1d
commit
13a5fd8ff0
|
@ -146,7 +146,7 @@ namespace AssemblyData.methodsrewriter {
|
||||||
|
|
||||||
var asmRef = DotNetUtils.getAssemblyNameReference(b);
|
var asmRef = DotNetUtils.getAssemblyNameReference(b);
|
||||||
var asmName = a.Assembly.GetName();
|
var asmName = a.Assembly.GetName();
|
||||||
if (asmRef.Name != asmName.Name)
|
if (asmRef == null || asmRef.Name != asmName.Name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return compareTypes(a.DeclaringType, b.DeclaringType);
|
return compareTypes(a.DeclaringType, b.DeclaringType);
|
||||||
|
|
|
@ -926,6 +926,9 @@ namespace de4dot.blocks {
|
||||||
|
|
||||||
public static AssemblyNameReference getAssemblyNameReference(TypeReference type) {
|
public static AssemblyNameReference getAssemblyNameReference(TypeReference type) {
|
||||||
var scope = type.Scope;
|
var scope = type.Scope;
|
||||||
|
if (scope == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (scope is ModuleDefinition) {
|
if (scope is ModuleDefinition) {
|
||||||
var moduleDefinition = (ModuleDefinition)scope;
|
var moduleDefinition = (ModuleDefinition)scope;
|
||||||
return moduleDefinition.Assembly.Name;
|
return moduleDefinition.Assembly.Name;
|
||||||
|
@ -946,7 +949,7 @@ namespace de4dot.blocks {
|
||||||
|
|
||||||
public static string getFullAssemblyName(TypeReference type) {
|
public static string getFullAssemblyName(TypeReference type) {
|
||||||
var asmRef = getAssemblyNameReference(type);
|
var asmRef = getAssemblyNameReference(type);
|
||||||
return asmRef.FullName;
|
return asmRef == null ? null : asmRef.FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool isAssembly(IMetadataScope scope, string assemblySimpleName) {
|
public static bool isAssembly(IMetadataScope scope, string assemblySimpleName) {
|
||||||
|
|
|
@ -56,6 +56,8 @@ namespace de4dot.code {
|
||||||
|
|
||||||
ExternalAssembly load(TypeReference type) {
|
ExternalAssembly load(TypeReference type) {
|
||||||
var asmFullName = DotNetUtils.getFullAssemblyName(type);
|
var asmFullName = DotNetUtils.getFullAssemblyName(type);
|
||||||
|
if (asmFullName == null)
|
||||||
|
return null;
|
||||||
ExternalAssembly asm;
|
ExternalAssembly asm;
|
||||||
if (assemblies.TryGetValue(asmFullName, out asm))
|
if (assemblies.TryGetValue(asmFullName, out asm))
|
||||||
return asm;
|
return asm;
|
||||||
|
|
|
@ -390,6 +390,8 @@ namespace de4dot.code.renamer.asmmodules {
|
||||||
// Returns null if it's a non-loaded module/assembly
|
// Returns null if it's a non-loaded module/assembly
|
||||||
IEnumerable<Module> findModules(TypeReference type) {
|
IEnumerable<Module> findModules(TypeReference type) {
|
||||||
var scope = type.Scope;
|
var scope = type.Scope;
|
||||||
|
if (scope == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (scope is AssemblyNameReference)
|
if (scope is AssemblyNameReference)
|
||||||
return findModules((AssemblyNameReference)scope);
|
return findModules((AssemblyNameReference)scope);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user