private ModuleReference Fix(ModuleReference moduleRef) { ModuleReference nmr = repack.TargetAssemblyMainModule.ModuleReferences.First(x => x.Name == moduleRef.Name); if (nmr == null) throw new NullReferenceException("referenced module not found: \"" + moduleRef.Name + "\"."); return nmr; }
public MethodDefinition GetExternalMethod (MethodReference mr) { string library = GetSymbolLibrary (mr.Name); if (library != null) { List<MethodDefinition> methods = null; if (externalMethods.ContainsKey (mr.Name)) { methods = externalMethods [mr.Name]; foreach (MethodDefinition method in methods) { if (CompareMethodSignatures (mr, method)) { return method; } } } else { methods = new List<MethodDefinition> (); externalMethods [mr.Name] = methods; } if (! referredLibraries.ContainsKey (library)) { referredLibraries [library] = new ModuleReference (library); } MethodDefinition md = CreateExternalMethod (mr, library, referredLibraries [library]); methods.Add (md); return md; } else { return null; } }
public static void EnsureWellName(ModuleReference r) { if (r.mWellName != null) return; r.mWellName = r.Name; if (!IGNORE_WELLNAMING) { TryFormatName("MDL_", ref r.mWellName, ""); } }
MethodDefinition CreateExternalMethod (MethodReference mr, string library, ModuleReference referredLibrary) { MethodDefinition md = new MethodDefinition(mr.Name, MethodAttributes.PInvokeImpl | MethodAttributes.HideBySig | MethodAttributes.Private | MethodAttributes.Static, mr.ReturnType.ReturnType); foreach (ParameterDefinition pd in mr.Parameters) { md.Parameters.Add (pd); } md.PInvokeInfo = new PInvokeInfo(md, PInvokeAttributes.CharSetAnsi | PInvokeAttributes.CallConvCdecl, md.Name, referredLibrary); return md; }
public virtual TypeDefinition Resolve(TypeReference type) { if (type == null) { throw new ArgumentNullException("type"); } type = type.GetElementType(); IMetadataScope scope = type.Scope; if (scope == null) { return(null); } switch (scope.MetadataScopeType) { case MetadataScopeType.AssemblyNameReference: { AssemblyDefinition assemblyDefinition = this.assembly_resolver.Resolve((AssemblyNameReference)scope); if (assemblyDefinition == null) { return(null); } return(MetadataResolver.GetType(assemblyDefinition.MainModule, type)); } case MetadataScopeType.ModuleReference: { Collection <ModuleDefinition> modules = type.Module.Assembly.Modules; ModuleReference moduleReference = (ModuleReference)scope; for (int i = 0; i < modules.Count; i++) { ModuleDefinition item = modules[i]; if (item.Name == moduleReference.Name) { return(MetadataResolver.GetType(item, type)); } } break; } case MetadataScopeType.ModuleDefinition: { return(MetadataResolver.GetType((ModuleDefinition)scope, type)); } } throw new NotSupportedException(); }
public override void VisitModuleReferenceCollection(ModuleReferenceCollection modules) { if (!m_tHeap.HasTable(ModuleRefTable.RId)) { return; } ModuleRefTable mrTable = m_tableReader.GetModuleRefTable(); for (int i = 0; i < mrTable.Rows.Count; i++) { ModuleRefRow mrRow = mrTable [i]; ModuleReference mod = new ModuleReference(ReadString(mrRow.Name)); mod.MetadataToken = MetadataToken.FromMetadataRow(TokenType.ModuleRef, i); modules.Add(mod); } }
public TypeDefinition Resolve(TypeReference type) { type = type.GetOriginalType(); if (type is TypeDefinition) { return((TypeDefinition)type); } AssemblyNameReference reference = type.Scope as AssemblyNameReference; if (reference != null) { AssemblyDefinition assembly = AssemblyResolver.Resolve(reference); if (assembly == null) { return(null); } return(Resolve(assembly.MainModule, type)); } ModuleDefinition module = type.Scope as ModuleDefinition; if (module != null) { return(Resolve(module, type)); } ModuleReference mod_reference = type.Scope as ModuleReference; if (mod_reference != null) { foreach (ModuleDefinition netmodule in type.Module.Assembly.Modules) { if (netmodule.Name == mod_reference.Name) { return(Resolve(netmodule, type)); } } } throw new NotImplementedException(); }
private static void AddGetProcAddress(TypeDefinition type) { var module = type.Module; MethodDefinition getProcAddressDef = new MethodDefinition("GetProcAddress", MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig, module.TypeSystem.IntPtr); getProcAddressDef.IsPInvokeImpl = true; var kernel32ref = module.ModuleReferences.FirstOrDefault(mr => mr.Name.Equals("kernel32.dll", StringComparison.OrdinalIgnoreCase)); if (kernel32ref == null) { kernel32ref = new ModuleReference("kernel32.dll"); module.ModuleReferences.Add(kernel32ref); } getProcAddressDef.IsPreserveSig = true; getProcAddressDef.PInvokeInfo = new PInvokeInfo(PInvokeAttributes.CallConvWinapi | PInvokeAttributes.NoMangle | PInvokeAttributes.CharSetAnsi | PInvokeAttributes.SupportsLastError, "GetProcAddress", kernel32ref); getProcAddressDef.IsIL = false; getProcAddressDef.Parameters.Add(new ParameterDefinition("hModule", ParameterAttributes.None, module.TypeSystem.IntPtr)); getProcAddressDef.Parameters.Add(new ParameterDefinition("lpProcName", ParameterAttributes.None, module.TypeSystem.String)); type.Methods.Add(getProcAddressDef); }
public virtual TypeDefinition Resolve(TypeReference type) { Mixin.CheckType(type); type = type.GetElementType(); IMetadataScope scope = type.Scope; if (scope == null) { return(null); } switch (scope.MetadataScopeType) { case MetadataScopeType.AssemblyNameReference: { AssemblyDefinition assemblyDefinition = assembly_resolver.Resolve((AssemblyNameReference)scope); if (assemblyDefinition == null) { return(null); } return(GetType(assemblyDefinition.MainModule, type)); } case MetadataScopeType.ModuleDefinition: return(GetType((ModuleDefinition)scope, type)); case MetadataScopeType.ModuleReference: { Collection <ModuleDefinition> modules = type.Module.Assembly.Modules; ModuleReference moduleReference = (ModuleReference)scope; for (int i = 0; i < modules.Count; i++) { ModuleDefinition moduleDefinition = modules[i]; if (moduleDefinition.Name == moduleReference.Name) { return(GetType(moduleDefinition, type)); } } break; } } throw new NotSupportedException(); }
public void Remove(ModuleReference value) { List.Remove(value); }
public DependencyGraph( ModuleReference module, IEqualityComparer<ModuleReference> moduleComparer) : base(module, moduleComparer) { }
public override void VisitModuleReference (ModuleReference module) { ModuleRefTable mrTable = m_tableWriter.GetModuleRefTable (); ModuleRefRow mrRow = m_rowWriter.CreateModuleRefRow ( m_mdWriter.AddString (module.Name)); mrTable.Rows.Add (mrRow); }
/// <summary> /// Checks if the operand calls a native library, via PInvoke. /// </summary> /// <param name="operand">The operand in question.</param> /// <returns>True if the operand is a PInvoke, otherwise false.</returns> static bool IsPInvoke(object operand, out ModuleReference nativeLib) { nativeLib = null; // try to cast operand to method definition and check for PInvoke var mdef = operand as MethodDefinition; if (mdef != null) { if (mdef.IsPInvokeImpl) { logger.Debug("Is PInvoke? {0}", true); if (mdef.PInvokeInfo != null) { nativeLib = mdef.PInvokeInfo.Module; logger.Debug("Native library: {0}", nativeLib.Name); } return true; } } return false; }
public uint GetRidFor(ModuleReference modRef) { return (uint) m_mod.ModuleReferences.IndexOf (modRef) + 1; }
public void Remove (ModuleReference value) { List.Remove (value); }
public int IndexOf (ModuleReference value) { return List.IndexOf (value); }
public PInvokeInfo(PInvokeAttributes attributes, string entryPoint, ModuleReference module) { this.attributes = (ushort)attributes; this.entry_point = entryPoint; this.module = module; }
public static Reflector.CodeModel.IModuleReference Cecil2Reflector(ModuleReference mr, ModuleDefinition md) { Reflector.CodeModel.IModule m = Cecil2Reflector(md); if (m == null) return null; string mrName = mr.Name; foreach (Reflector.CodeModel.IModuleReference mrTmp in m.ModuleReferences) { if (mrTmp.Name == mrName) return mrTmp; } return null; }
public ModuleReferenceTreeNode(ModuleReference r) { if (r == null) throw new ArgumentNullException("r"); this.r = r; }
private static bool IsAny(ModuleReference module, params ModuleDefinition[] others) { bool result = module != null && others.Any(other => other.Name == module.Name); return result; }
public virtual void VisitModuleReference(ModuleReference module) { }
private MethodReference MakeCtorAndReference(ModuleDefinition targetModule, ModuleDefinition moduleWithAttributeType) { // optimization - trygettypereference does not work in case of in memory reference... //TypeReference existingAttributeReference; //if (targetModule.TryGetTypeReference (_attributeNamespace + "." + _attributeName, out existingAttributeReference)) // return (MethodReference) targetModule.GetMemberReferences ().Single (mr => mr.DeclaringType == existingAttributeReference); var attributeCtorDefinition = GetCustomAttributeCtor (moduleWithAttributeType); if (targetModule == moduleWithAttributeType) return attributeCtorDefinition; var moduleReference = new ModuleReference (moduleWithAttributeType.Name); if (!targetModule.ModuleReferences.Contains (moduleReference)) targetModule.ModuleReferences.Add (moduleReference); var ctorReference = targetModule.Import (attributeCtorDefinition); return ctorReference; }
private ModuleReference ModuleReferenceFor(string name) { foreach (var reference in _module_definition.ModuleReferences) if (reference.Name == name) return reference; var module = new ModuleReference(name); _module_definition.ModuleReferences.Add(module); return module; }
public int IndexOf(ModuleReference value) { return(m_items.IndexOf(value)); }
public bool Contains (ModuleReference value) { return List.Contains (value); }
internal Module ResolveModule(ModuleReference reference) { return GetModule(reference.Name); }
public void Insert (int index, ModuleReference value) { List.Insert (index, value); }
public static ModuleReference addModuleReference(ModuleDefinition module, ModuleReference modRef) { foreach (var modModRef in module.ModuleReferences) { if (modModRef.Name == modRef.Name) return modModRef; } var newModRef = new ModuleReference(modRef.Name); module.ModuleReferences.Add(newModRef); return newModRef; }
public ModuleReference convert(ModuleReference modRef) { foreach (var modModRef in module.ModuleReferences) { if (modModRef.Name == modRef.Name) return modModRef; } var newModRef = new ModuleReference(modRef.Name); module.ModuleReferences.Add(newModRef); return newModRef; }
public static string GetNetmoduleName(ModuleReference module) { if (module.Name.EndsWith(".netmodule")) { return module.Name.Substring(0, module.Name.Length - ".netmodule".Length); } else { return module.Name; } }
public override void VisitModuleReferenceCollection (ModuleReferenceCollection modules) { if (!m_tHeap.HasTable (ModuleRefTable.RId)) return; ModuleRefTable mrTable = m_tableReader.GetModuleRefTable (); for (int i = 0; i < mrTable.Rows.Count; i++) { ModuleRefRow mrRow = mrTable [i]; ModuleReference mod = new ModuleReference (ReadString (mrRow.Name)); mod.MetadataToken = MetadataToken.FromMetadataRow (TokenType.ModuleRef, i); modules.Add (mod); } }
protected virtual void ProcessModuleReference(ModuleReference moduleRef) { }
public override void VisitModuleReference (ModuleReference module) { string name = module.Name; name = name.ToLower (); if (!BaseAssemblyResolver.OnMono ()) { if (!name.EndsWith (".dll")) name += ".dll"; } if (!ModuleReferencesContains (target.MainModule.ModuleReferences, name)) { module.Name = name; target.MainModule.ModuleReferences.Add (module); } }
public void Add(ModuleReference value) { List.Add(value); }
public int IndexOf(ModuleReference value) { return(List.IndexOf(value)); }
public bool Contains(ModuleReference value) { return(m_items.Contains(value)); }
public bool Contains(ModuleReference value) { return(List.Contains(value)); }
public static bool isReferenceToModule(ModuleReference moduleReference, IMetadataScope scope) { switch (scope.MetadataScopeType) { case MetadataScopeType.AssemblyNameReference: var asmRef = (AssemblyNameReference)scope; var module = moduleReference as ModuleDefinition; return module != null && module.Assembly != null && module.Assembly.Name.FullName == asmRef.FullName; case MetadataScopeType.ModuleDefinition: return moduleReference == scope; case MetadataScopeType.ModuleReference: return moduleReference.Name == ((ModuleReference)scope).Name; default: throw new ApplicationException("Unknown MetadataScopeType"); } }
public void Insert(int index, ModuleReference value) { List.Insert(index, value); }
public void Add (ModuleReference value) { List.Add (value); }
ModuleReference GetModuleReference (ModuleReferenceCollection members, ModuleReference module) { string name = module.Name; name = name.ToLower (); if (!BaseAssemblyResolver.OnMono ()) { if (!name.EndsWith (".dll")) name += ".dll"; } foreach (ModuleReference mr in members) { if (mr.Name == name) return mr; } return null; }
public ModuleReferenceEventArgs(ModuleReference item) { m_item = item; }
public virtual void VisitModuleReference (ModuleReference module) { }
public void Remove(ModuleReference value) { if (OnModuleReferenceRemoved != null && this.Contains (value)) OnModuleReferenceRemoved (this, new ModuleReferenceEventArgs (value)); m_items.Remove (value); }