Example #1
0
        public TypeRewriteContext(AssemblyRewriteContext assemblyContext, TypeDefinition originalType, TypeDefinition newType)
        {
            AssemblyContext = assemblyContext ?? throw new ArgumentNullException(nameof(assemblyContext));
            OriginalType    = originalType;
            NewType         = newType ?? throw new ArgumentNullException(nameof(newType));

            if (OriginalType == null)
            {
                return;
            }

            OriginalNameWasObfuscated = OriginalType.Name != NewType.Name;
            if (OriginalNameWasObfuscated)
            {
                NewType.CustomAttributes.Add(new CustomAttribute(assemblyContext.Imports.ObfuscatedNameAttributeCtor)
                {
                    ConstructorArguments = { new CustomAttributeArgument(assemblyContext.Imports.String, originalType.FullName) }
                });
            }

            if (!OriginalType.IsValueType)
            {
                ComputedTypeSpecifics = TypeSpecifics.ReferenceType;
            }
            else if (OriginalType.IsEnum)
            {
                ComputedTypeSpecifics = TypeSpecifics.BlittableStruct;
            }
            else if (OriginalType.HasGenericParameters)
            {
                ComputedTypeSpecifics = TypeSpecifics.NonBlittableStruct; // not reference type, covered by first if
            }
        }
Example #2
0
        public RewriteGlobalContext(string mscorlibPath, IEnumerable <string> sourceAssemblyPaths)
        {
            var metadataResolver = new MetadataResolver(myAssemblyResolver);

            var mscorlib = AssemblyDefinition.ReadAssembly(mscorlibPath);

            TargetTypeSystemHandler.Init(mscorlib);

            myAssemblyResolver.Register(mscorlib);

            foreach (var sourceAssemblyPath in sourceAssemblyPaths)
            {
                var assemblyName = Path.GetFileNameWithoutExtension(sourceAssemblyPath);
                if (assemblyName == "Il2CppDummyDll")
                {
                    continue;
                }

                var sourceAssembly = AssemblyDefinition.ReadAssembly(File.OpenRead(sourceAssemblyPath), new ReaderParameters(ReadingMode.Immediate)
                {
                    MetadataResolver = metadataResolver
                });
                myAssemblyResolver.Register(sourceAssembly);
                var newAssembly = AssemblyDefinition.CreateAssembly(
                    new AssemblyNameDefinition(sourceAssembly.Name.Name.UnSystemify(), sourceAssembly.Name.Version),
                    sourceAssembly.MainModule.Name.UnSystemify(), sourceAssembly.MainModule.Kind);

                var assemblyRewriteContext = new AssemblyRewriteContext(this, sourceAssembly, newAssembly);
                myAssemblies[assemblyName]        = assemblyRewriteContext;
                myAssembliesByOld[sourceAssembly] = assemblyRewriteContext;
            }
        }
Example #3
0
        public TypeRewriteContext(AssemblyRewriteContext assemblyContext, TypeDefinition originalType, TypeDefinition newType)
        {
            AssemblyContext = assemblyContext ?? throw new ArgumentNullException(nameof(assemblyContext));
            OriginalType    = originalType;
            NewType         = newType ?? throw new ArgumentNullException(nameof(newType));

            if (OriginalType == null)
            {
                return;
            }

            OriginalNameWasObfuscated = OriginalType.Name != NewType.Name;
            if (!OriginalType.IsValueType)
            {
                ComputedTypeSpecifics = TypeSpecifics.ReferenceType;
            }
            else if (OriginalType.IsEnum)
            {
                ComputedTypeSpecifics = TypeSpecifics.BlittableStruct;
            }
        }
 public TypeRewriteContext(AssemblyRewriteContext assemblyContext, TypeDefinition originalType, TypeDefinition newType)
 {
     AssemblyContext = assemblyContext ?? throw new ArgumentNullException(nameof(assemblyContext));
     OriginalType    = originalType ?? throw new ArgumentNullException(nameof(originalType));
     NewType         = newType ?? throw new ArgumentNullException(nameof(newType));
 }