private bool IsEntryPoint(Method method) { return Context.Program.EntryPoint == null && method.Name == "Main" && method.Static; }
public Class ForceResolveType(Method method) { return ForceResolveTypeCore(CreateParseTarget(method)); }
public void ParseMethodBody(Method method) { if (method.InternalCall) { // fetch internal call ast Console.WriteLine("Internal call: " + method.Name); } else if (method.PInvoke) { Console.WriteLine("PInvoke: " + method.Name); } else { Console.WriteLine("=== Method: " + method.Name + method.Signature + " ==="); method.Body = ILReader.Read(this, method.Signature, Pe.GetMethodBody(((MethodDefinition)method.SourceHandle).RelativeVirtualAddress)); } }
private void AddMethodToClass(Method m, TypeDefinitionHandle typeHandle) { int token = MetadataTokens.GetToken(typeHandle); var clazz = Context.GetClass(token); if(clazz == null) { ParseClass(typeHandle, null); clazz = Context.GetClass(token); } clazz.Methods.Add(m.Name + m.Signature, m); }
public Method ParseMethodHeader(MethodDefinitionHandle handle, bool addToQueue = true) { var method = Reader.GetMethodDefinition(handle); var name = Reader.GetString(method.Name); var signature = ILReader.ParseMethodSignature(this, Reader.GetBlobBytes(method.Signature)); var fullname = name + signature; var existing = Find(fullname, method.GetDeclaringType()); if (existing != null) return existing; var newMethod = new Method(name) { Signature = signature, SourceHandle = method, Static = method.Attributes.HasFlag(MethodAttributes.Static), InternalCall = method.ImplAttributes.HasFlag(MethodImplAttributes.InternalCall), PInvoke = method.Attributes.HasFlag(MethodAttributes.PinvokeImpl) }; AddMethodToClass(newMethod, method.GetDeclaringType()); if (IsEntryPoint(newMethod)) Context.Program.EntryPoint = newMethod; if (signature.ReturnType.HasTarget) { Console.WriteLine("!! Force resolve !!"); signature.ReturnType.Target = ForceResolveType(newMethod); } else { if (addToQueue) Context.AddTodo(CreateParseTarget(newMethod)); } return newMethod; }
/// <summary> /// Create a parse target assuming that only the body needs to be parsed /// </summary> /// <param name="m"></param> /// <returns></returns> public ParseTarget CreateParseTarget(Method m) { return new ParseTarget(this, m); }
public ParseTarget(InspectableAssembly ia, Method m) { Ia = ia; Method = m; MethodSignature = m.Signature; MethodName = m.Name; ClassName = ia.GetFullyQualifiedName( ia.Reader.GetTypeDefinition( ((MethodDefinition)m.SourceHandle).GetDeclaringType())); }