Esempio n. 1
0
        private void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            Log("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(config, outputDir);
            Log("Done!");
            if (config.GenerateStruct)
            {
                Log("Generate struct...");
                try
                {
                    var scriptGenerator = new StructGenerator(executor);
                    scriptGenerator.WriteScript(outputDir);
                    Log("Done!");
                }
                catch
                {
                    Log("There was an error trying to generate struct. Skipped", Color.Orange);
                }
            }
            if (config.GenerateDummyDll)
            {
                Log("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
                Log("Done!");
                Directory.SetCurrentDirectory(realPath); //Fix read-only directory permission
            }
        }
Esempio n. 2
0
        public static bool PerformDump(string gameAssemblyPath, string metadataDatPath, string outputDirectoryPath,
                                       Config config, Action <string> reportProgressAction)
        {
            Init(gameAssemblyPath, metadataDatPath, config, reportProgressAction, out var metadata, out var il2Cpp);

            reportProgressAction("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            reportProgressAction("Done!");
            if (config.GenerateStruct)
            {
                decompiler.Decompile(config, outputDirectoryPath, reportProgressAction);
                reportProgressAction("Generate struct...");
                var scriptGenerator = new StructGenerator(executor);
                scriptGenerator.WriteScript(outputDirectoryPath);
                reportProgressAction("Done!");
            }
            if (config.GenerateDummyDll)
            {
                reportProgressAction("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDirectoryPath, config.DummyDllAddToken);
                reportProgressAction("Done!");
            }

            return(true);
        }
Esempio n. 3
0
        private static void ParseEngineApi()
        {
            StreamReader sr =
                new StreamReader("engineApi.xml");
            string content = sr.ReadToEnd();

            sr.Close();

            EngineApi engineApi = EngineApiParser.Parse(content);

            Console.WriteLine(engineApi.Enums.Count);
            Console.WriteLine(engineApi.Structs.Count);
            Console.WriteLine(engineApi.Functions.Count);
            Console.WriteLine(engineApi.Classes.Count);

            foreach (EngineStruct engineStruct in engineApi.Structs)
            {
                if (engineStruct.Fields.Count < 1)
                {
                    Console.WriteLine("No fields defined in struct: " + engineStruct.Name);
                }
            }

            // Careful!!! Don't choose the wrong directory or it might get deleted..
            string outputDirectory = "../t3dsharp/T3DSharpFramework/Generated";

            if (Directory.Exists(outputDirectory))
            {
                Directory.Delete(outputDirectory, true);
            }

            engineApi.Enums
            .ForEach(e => e.Docs = DotNetXmlDocGenerator.Generate(EngineApiDocStringParser.Parse(e.Docs)).Trim());

            engineApi.Structs
            .ForEach(s => s.Docs = DotNetXmlDocGenerator.Generate(EngineApiDocStringParser.Parse(s.Docs)).Trim());

            engineApi.Functions
            .ForEach(f => f.Docs = DotNetXmlDocGenerator.Generate(EngineApiDocStringParser.Parse(f.Docs)).Trim());

            engineApi.Classes
            .ForEach(c => c.Docs = DotNetXmlDocGenerator.Generate(EngineApiDocStringParser.Parse(c.Docs)).Trim());

            engineApi.Classes
            .ForEach(c => c.Methods.ForEach(m => m.Docs = DotNetXmlDocGenerator.Generate(EngineApiDocStringParser.Parse(m.Docs)).Trim()));

            engineApi.Classes
            .ForEach(c => c.Properties.ForEach(p => p.Docs = DotNetXmlDocGenerator.Generate(EngineApiDocStringParser.Parse(p.Docs)).Trim()));

            EnumGenerator.GenerateFor(outputDirectory, engineApi, engineApi.Enums);
            StructGenerator.GenerateFor(outputDirectory, engineApi, engineApi.Structs);
            FunctionGenerator.GenerateFor(outputDirectory, engineApi, engineApi.Functions);
            ClassGenerator.GenerateFor(outputDirectory, engineApi, engineApi.Classes);
            PrimitiveSizesGenerator.GenerateFor(outputDirectory, engineApi, engineApi.Primitives);
            Console.WriteLine("Finished code generation.");
        }
Esempio n. 4
0
 /// <summary>
 /// A list with all the generators
 /// </summary>
 /// <param name="context">The context</param>
 public AllGenerators(WalkerContext context)
 {
     AddAssignment              = new AssignmentGenerator(context, AssignmentType.Add);
     AddressOfExpression        = new AddressOfExpressionGenerator(context);
     ArgumentList               = new ArgumentListGenerator(context);
     ArrayCreationExpression    = new ArrayCreationExpressionGenerator(context);
     ArrayInitializerExpression = new ArrayInitializerGenerator(context);
     BinaryAndAssignment        = new AssignmentGenerator(context, AssignmentType.BinaryAnd);
     BinaryOrAssignment         = new AssignmentGenerator(context, AssignmentType.BinaryOr);
     Block          = new BlockGenerator(context);
     CastExpression = new CastExpressionGenerator(context);
     ConditionalAccessExpression = new ConditionalAccessExpressionGenerator(context);
     ClassCode           = new ClassCodeGenerator(context);
     DelegateDeclaration = new DelegateDeclarationGenerator(context);
     DoStatement         = new DoStatementGenerator(context);
     DivideAssignment    = new AssignmentGenerator(context, AssignmentType.Divide);
     ElementAccess       = new ElementAccessGenerator(context);
     Enum = new EnumGenerator(context);
     ExclusiveOrAssignment         = new AssignmentGenerator(context, AssignmentType.ExclusiveOr);
     Expression                    = new ExpressionGenerator(context);
     ExpressionStatement           = new ExpressionStatementGenerator(context);
     FixedStatement                = new FixedStatementGenerator(context);
     ForStatement                  = new ForStatementGenerator(context);
     GotoStatement                 = new GotoStatementGenerator(context);
     IfStatement                   = new IfStatementGenerator(context);
     Invocation                    = new InvocationGenerator(context);
     Interface                     = new InterfaceGenerator(context);
     IdentifierName                = new IdentifierNameGenerator(context);
     LabeledStatement              = new LabeledStatementGenerator(context);
     LeftShiftAssignment           = new AssignmentGenerator(context, AssignmentType.LeftShift);
     LocalDeclaration              = new LocalDeclarationGenerator(context);
     MethodDeclaration             = new MethodGenerator(context);
     ModuloAssignment              = new AssignmentGenerator(context, AssignmentType.Modulo);
     MultiplyAssignment            = new AssignmentGenerator(context, AssignmentType.Multiply);
     ObjectCreationExpression      = new ObjectCreationExpressionGenerator(context);
     PreIncrementExpression        = new PrePostExpressionGenerator(context, ExpressionType.PreIncrement);
     PreDecrementExpression        = new PrePostExpressionGenerator(context, ExpressionType.PreDecrement);
     PostIncrementExpression       = new PrePostExpressionGenerator(context, ExpressionType.PostIncrement);
     PostDecrementExpression       = new PrePostExpressionGenerator(context, ExpressionType.PostDecrement);
     PointerMemberAccessExpression = new PointerMemberAccessGenerator(context);
     Property             = new PropertyGenerator(context);
     ReturnStatement      = new ReturnStatementGenerator(context);
     RightShiftAssignment = new AssignmentGenerator(context, AssignmentType.RightShift);
     SimpleAssignment     = new SimpleAssignmentGenerator(context);
     SimpleMemberAccess   = new SimpleMemberAccessGenerator(context);
     SizeOfExpression     = new SizeofExpressionGenerator(context);
     Struct = new StructGenerator(context);
     SubstractAssignment = new AssignmentGenerator(context, AssignmentType.Substract);
     SwitchStatement     = new SwitchStatementGenerator(context);
     checkedStatement    = new checkedStatementGenerator(context);
     Variable            = new VariableGenerator(context);
     WhileStatement      = new WhileStatementGenerator(context);
 }
Esempio n. 5
0
        protected override TypeGenerator OnGenerateType(ref string output, NamespaceGenerator @namespace)
        {
            var @struct = StructGenerator.Struct(RootAccessModifier.Public, StructModifier.None, Data.title.LegalMemberName());

            if (Data.definedEvent)
            {
                @struct.ImplementInterface(typeof(IDefinedEvent));
            }
            if (Data.inspectable)
            {
                @struct.AddAttribute(AttributeGenerator.Attribute <InspectableAttribute>());
            }
            if (Data.serialized)
            {
                @struct.AddAttribute(AttributeGenerator.Attribute <SerializableAttribute>());
            }
            if (Data.includeInSettings)
            {
                @struct.AddAttribute(AttributeGenerator.Attribute <IncludeInSettingsAttribute>().AddParameter(true));
            }

            for (int i = 0; i < Data.variables.Count; i++)
            {
                if (!string.IsNullOrEmpty(Data.variables[i].name) && Data.variables[i].type != null)
                {
                    var field = FieldGenerator.Field(AccessModifier.Public, FieldModifier.None, Data.variables[i].type, Data.variables[i].name);
                    if (Data.serialized)
                    {
                        if (Data.variables[i].inspectable)
                        {
                            field.AddAttribute(AttributeGenerator.Attribute <InspectableAttribute>());
                        }
                        if (!Data.variables[i].serialized)
                        {
                            field.AddAttribute(AttributeGenerator.Attribute <NonSerializedAttribute>());
                        }
                    }
                    @struct.AddField(field);
                }
            }

            if (@namespace != null)
            {
                @namespace.AddStruct(@struct);
            }

            return(@struct);
        }
Esempio n. 6
0
        private static void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            Console.WriteLine("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(config, outputDir);
            Console.WriteLine("Done!");
            if (config.GenerateStruct)
            {
                Console.WriteLine("Generate struct...");
                var scriptGenerator = new StructGenerator(executor);
                scriptGenerator.WriteScript(outputDir);
                Console.WriteLine("Done!");
            }
            if (config.GenerateDummyDll)
            {
                Console.WriteLine("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
                Console.WriteLine("Done!");
            }
        }
Esempio n. 7
0
    public void TestGenerateStructWithPublicFields()
    {
        var gen       = new CodeUnitGenerator("TestCodeGen");
        var structGen = new StructGenerator("TestComponent")
                        .SetIsSealed(false);

        var field = new FieldGenerator(typeof(int), "MyField", true);

        structGen.AddField(field);
        var field2 = new FieldGenerator(typeof(int), "MyField2", true);

        structGen.AddField(field2);
        gen.AddType(structGen);
        var ccu = gen.GenerateCompileUnit();

        var output = StringCompiler.CompileToString(ccu);

        Assert.IsTrue(output.Contains("struct"));
        Assert.IsTrue(output.Contains("MyField"));
        Assert.IsTrue(output.Contains("MyField2"));
        Debug.Log(output);
    }
Esempio n. 8
0
        private void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            WriteOutput("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(_config, outputDir, 1);
            WriteOutput("Done!");
            if (_config.GenerateStruct)
            {
                WriteOutput("Generate struct...");
                var scriptGenerator = new StructGenerator(executor);
                scriptGenerator.WriteScript(outputDir, 1);
                WriteOutput("Done!");
            }
            if (_config.GenerateDummyDll)
            {
                WriteOutput("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDir, _config.DummyDllAddToken);
                WriteOutput("Done!");
                Directory.SetCurrentDirectory(realPath); //Fix read-only directory permission
            }
        }
Esempio n. 9
0
        public override string Generate(int indent)
        {
            if (decorated != null)
            {
                var output = string.Empty;
                NamespaceGenerator @namespace = NamespaceGenerator.Namespace(string.Empty);
                if (string.IsNullOrEmpty(Data.title))
                {
                    return(output);
                }

                if (!string.IsNullOrEmpty(Data.category))
                {
                    @namespace = NamespaceGenerator.Namespace(Data.category);
                }

                TypeGenerator   type       = OnGenerateType(ref output, @namespace);
                ClassGenerator  classType  = type as ClassGenerator;
                StructGenerator structType = type as StructGenerator;

                if (Data.lastCompiledName != Data.GetFullTypeName() && !string.IsNullOrEmpty(Data.lastCompiledName))
                {
                    if (classType != null)
                    {
                        classType.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName));
                    }
                    if (structType != null)
                    {
                        structType.AddAttribute(AttributeGenerator.Attribute <RenamedFromAttribute>().AddParameter(Data.lastCompiledName));
                    }
                }

                return(@namespace.Generate(indent));
            }

            return(string.Empty);
        }