Skip to content

[jnimarshalmethod-gen] Fix type resolution crash #706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions tools/jnimarshalmethod-gen/TypeMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class TypeMover
AssemblyDefinition Destination { get; }
string DestinationPath { get; }
Dictionary<string, System.Reflection.Emit.TypeBuilder> Types { get; }
DirectoryAssemblyResolver Resolver { get; }

MethodReference consoleWriteLine;
TypeDefinitionCache cache;
Expand All @@ -25,10 +26,11 @@ public TypeMover (AssemblyDefinition source, AssemblyDefinition destination, str
Destination = destination;
DestinationPath = destinationPath;
Types = types;
Resolver = resolver;
this.cache = cache;

if (App.Debug) {
consoleWriteLine = GetSingleParameterMethod (resolver, Destination.MainModule, "mscorlib", "System.Console", "WriteLine", "System.String");
consoleWriteLine = GetSingleParameterMethod (Destination.MainModule, "mscorlib", "System.Console", "WriteLine", "System.String");
if (consoleWriteLine == null) {
App.Warning ("Unable to find System.Console::WriteLine method. Disabling debug injection");
App.Debug = false;
Expand Down Expand Up @@ -399,6 +401,15 @@ bool AnalyzeAndImprove (Mono.Collections.Generic.Collection<Instruction> instruc
return false;

delegateType = module.GetType (delegateTypeName);
if (delegateType == null) {
var t = Type.GetType (delegateTypeName);
if (t == null)
return false;

delegateType = GetType (t.Assembly.GetName ().ToString (), delegateTypeName);
if (delegateType == null)
return false;
}

skipCount = 11;
customDelegate = true;
Expand Down Expand Up @@ -515,16 +526,18 @@ MethodDefinition Duplicate (MethodDefinition src, ModuleDefinition module, TypeD
return md;
}

MethodReference GetSingleParameterMethod (DirectoryAssemblyResolver resolver, ModuleDefinition module, string assemblyName, string typeName, string methodName, string parameterTypeName)
TypeDefinition GetType (string assemblyName, string typeName)
{
var assembly = resolver.Resolve (assemblyName);
var assembly = Resolver.Resolve (assemblyName);
if (assembly == null)
return null;

var typeTD = assembly.MainModule.GetType (typeName);
if (typeTD == null)
return null;
return assembly.MainModule.GetType (typeName);
}

MethodReference GetSingleParameterMethod (ModuleDefinition module, string assemblyName, string typeName, string methodName, string parameterTypeName)
{
var typeTD = GetType (assemblyName, typeName);
foreach (var md in typeTD.Methods)
if (md.Name == methodName && md.HasParameters && md.Parameters.Count == 1 && md.Parameters [0].ParameterType.FullName == parameterTypeName)
return GetUpdatedMethod (md, module);
Expand Down