public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleParameters parameters) { if (assemblyName == null) { throw new ArgumentNullException("assemblyName"); } if (moduleName == null) { throw new ArgumentNullException("moduleName"); } Mixin.CheckParameters(parameters); if (parameters.Kind == ModuleKind.NetModule) { throw new ArgumentException("kind"); } var assembly = ModuleDefinition.CreateModule(moduleName, parameters).Assembly; assembly.Name = assemblyName; return(assembly); }
public virtual AssemblyNameReference ImportReference(SR.AssemblyName name) { Mixin.CheckName(name); AssemblyNameReference reference; if (TryGetAssemblyNameReference(name, out reference)) { return(reference); } reference = new AssemblyNameReference(name.Name, name.Version) { PublicKeyToken = name.GetPublicKeyToken(), Culture = name.CultureInfo.Name, HashAlgorithm = (AssemblyHashAlgorithm)name.HashAlgorithm, }; module.AssemblyReferences.Add(reference); return(reference); }
public static ModuleDefinition CreateModule(string name, ModuleParameters parameters) { Mixin.CheckName(name); Mixin.CheckParameters(parameters); var module = new ModuleDefinition(GlobalAssemblyResolver.Instance) { Name = name, kind = parameters.Kind, Runtime = parameters.Runtime, architecture = parameters.Architecture, mvid = Guid.NewGuid(), Attributes = ModuleAttributes.ILOnly, Characteristics = (ModuleCharacteristics)0x8540, }; if (parameters.AssemblyResolver != null) { module.assembly_resolver = parameters.AssemblyResolver; } if (parameters.MetadataResolver != null) { module.metadata_resolver = parameters.MetadataResolver; } if (parameters.Kind != ModuleKind.NetModule) { var assembly = new AssemblyDefinition(); module.assembly = assembly; module.assembly.Name = CreateAssemblyName(name); assembly.main_module = module; } module.Types.Add(new TypeDefinition(string.Empty, "<Module>", TypeAttributes.NotPublic)); return(module); }
public virtual AssemblyNameReference ImportReference(AssemblyNameReference name) { Mixin.CheckName(name); if (module.TryGetAssemblyNameReference(name, out AssemblyNameReference assemblyNameReference)) { return(assemblyNameReference); } assemblyNameReference = new AssemblyNameReference(name.Name, name.Version) { Culture = name.Culture, HashAlgorithm = name.HashAlgorithm, IsRetargetable = name.IsRetargetable, IsWindowsRuntime = name.IsWindowsRuntime }; byte[] array = (!name.PublicKeyToken.IsNullOrEmpty()) ? new byte[name.PublicKeyToken.Length] : Empty <byte> .Array; if (array.Length != 0) { Buffer.BlockCopy(name.PublicKeyToken, 0, array, 0, array.Length); } assemblyNameReference.PublicKeyToken = array; module.AssemblyReferences.Add(assemblyNameReference); return(assemblyNameReference); }
TypeDefinition GetNestedType(string fullname) { var names = fullname.Split('/'); var type = GetType(names[0]); if (type == null) { return(null); } for (int i = 1; i < names.Length; i++) { var nested_type = Mixin.GetNestedType(type, names[i]); if (nested_type == null) { return(null); } type = nested_type; } return(type); }
static void AppendType(TypeReference type, StringBuilder name, bool fq_name, bool top_level) { var declaring_type = type.DeclaringType; if (declaring_type != null) { AppendType(declaring_type, name, false, top_level); name.Append('+'); } var @namespace = type.Namespace; if (!string.IsNullOrEmpty(@namespace)) { name.Append(@namespace); name.Append('.'); } name.Append(type.GetElementType().Name); if (!fq_name) { return; } if (Mixin.IsTypeSpecification(type)) { AppendTypeSpecification((TypeSpecification)type, name); } if (RequiresFullyQualifiedName(type, top_level)) { name.Append(", "); name.Append(GetScopeFullName(type)); } }
static bool AreSame(TypeReference a, TypeReference b) { if (ReferenceEquals(a, b)) { return(true); } if (a == null || b == null) { return(false); } if (a.etype != b.etype) { return(false); } if (a.IsGenericParameter) { return(AreSame((GenericParameter)a, (GenericParameter)b)); } if (Mixin.IsTypeSpecification(a)) { return(AreSame((TypeSpecification)a, (TypeSpecification)b)); } if (a.Name != b.Name || a.Namespace != b.Namespace) { return(false); } //TODO: check scope return(AreSame(a.DeclaringType, b.DeclaringType)); }
public ArrayType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Array; }
public static bool GetHasGenericParameters( IGenericParameterProvider self, ModuleDefinition module) { return(Mixin.HasImage(module) && module.Read(self, (provider, reader) => reader.HasGenericParameters(provider))); }
public virtual MethodReference ImportReference(MethodReference method, IGenericParameterProvider context) { Mixin.CheckMethod(method); return(ImportMethod(method, ImportGenericContext.For(context))); }
internal PropertyReference(string name, TypeReference propertyType) : base(name) { Mixin.CheckType(propertyType, Mixin.Argument.propertyType); property_type = propertyType; }
public virtual TypeReference ImportReference(TypeReference type, IGenericParameterProvider context) { Mixin.CheckType(type); return(ImportType(type, ImportGenericContext.For(context))); }
public virtual FieldReference ImportReference(FieldReference field, IGenericParameterProvider context) { Mixin.CheckField(field); return(ImportField(field, ImportGenericContext.For(context))); }
static Stream GetFileStream(string fileName, FileMode mode, FileAccess access, FileShare share) { Mixin.CheckFileName(fileName); return(new FileStream(fileName, mode, access, share)); }
public static bool GetHasSecurityDeclarations( ISecurityDeclarationProvider self, ModuleDefinition module) { return(Mixin.HasImage(module) && module.Read(self, (provider, reader) => reader.HasSecurityDeclarations(provider))); }
public PinnedType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = Mono.Cecil.Metadata.ElementType.Pinned; }
public CustomAttributeNamedArgument(string name, CustomAttributeArgument argument) { Mixin.CheckName(name); this.name = name; this.argument = argument; }
public SentinelType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Sentinel; }
public PointerType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Ptr; }
static Stream GetFileStream(string fileName, FileMode mode, FileAccess access, FileShare share) { Mixin.CheckFileName(fileName); return(new FileStream(uTinyRipper.FileUtils.ToLongPath(fileName), mode, access, share)); }
public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { Mixin.CheckName(name); Mixin.CheckParameters(parameters); AssemblyDefinition assemblyDefinition = SearchDirectory(name, directories, parameters); if (assemblyDefinition != null) { return(assemblyDefinition); } if (name.IsRetargetable) { name = new AssemblyNameReference(name.Name, Mixin.ZeroVersion) { PublicKeyToken = Empty <byte> .Array }; } string directoryName = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName); string[] array = on_mono ? new string[2] { directoryName, Path.Combine(directoryName, "Facades") } : new string[1] { directoryName }; if (IsZero(name.Version)) { assemblyDefinition = SearchDirectory(name, array, parameters); if (assemblyDefinition != null) { return(assemblyDefinition); } } if (name.Name == "mscorlib") { assemblyDefinition = GetCorlib(name, parameters); if (assemblyDefinition != null) { return(assemblyDefinition); } } assemblyDefinition = GetAssemblyInGac(name, parameters); if (assemblyDefinition != null) { return(assemblyDefinition); } assemblyDefinition = SearchDirectory(name, array, parameters); if (assemblyDefinition != null) { return(assemblyDefinition); } if (this.ResolveFailure != null) { assemblyDefinition = this.ResolveFailure(this, name); if (assemblyDefinition != null) { return(assemblyDefinition); } } throw new AssemblyResolutionException(name); }
public PinnedType(TypeReference type) : base(type) { Mixin.CheckType(type); base.etype = ElementType.Pinned; }
public ByReferenceType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.ByRef; }
public PinnedType(TypeReference type) : base(type) { Mixin.CheckType(type); this.etype = MD.ElementType.Pinned; }
public CustomAttributeArgument(TypeReference type, object value) { Mixin.CheckType(type); this.type = type; this.value = value; }
public RequiredModifierType(TypeReference modifierType, TypeReference type) : base(type) { Mixin.CheckModifier(modifierType, type); this.modifier_type = modifierType; base.etype = ElementType.CModReqD; }
public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { Mixin.CheckName(name); Mixin.CheckParameters(parameters); var assembly = SearchDirectory(name, directories, parameters); if (assembly != null) { return(assembly); } if (name.IsRetargetable) { // if the reference is retargetable, zero it name = new AssemblyNameReference(name.Name, Mixin.ZeroVersion) { PublicKeyToken = Empty <byte> .Array, }; } #if NET_CORE assembly = SearchTrustedPlatformAssemblies(name, parameters); if (assembly != null) { return(assembly); } #else var framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName); var framework_dirs = on_mono ? new [] { framework_dir, Path.Combine(framework_dir, "Facades") } : new [] { framework_dir }; if (IsZero(name.Version)) { assembly = SearchDirectory(name, framework_dirs, parameters); if (assembly != null) { return(assembly); } } if (name.Name == "mscorlib") { assembly = GetCorlib(name, parameters); if (assembly != null) { return(assembly); } } assembly = GetAssemblyInGac(name, parameters); if (assembly != null) { return(assembly); } assembly = SearchDirectory(name, framework_dirs, parameters); if (assembly != null) { return(assembly); } #endif if (ResolveFailure != null) { assembly = ResolveFailure(this, name); if (assembly != null) { return(assembly); } } throw new AssemblyResolutionException(name); }
public ReflectionImporter(ModuleDefinition module) { Mixin.CheckModule(module); this.module = module; }
public TypeDefinition GetType(string @namespace, string name) { Mixin.CheckName(name); return(((TypeDefinitionCollection)this.Types).GetType(@namespace ?? string.Empty, name)); }
public MetadataImporter(ModuleDefinition module) { Mixin.CheckModule(module); this.module = module; }