Ejemplo n.º 1
0
        public static void AutoCompile(Instruction i, AsmBuilder ab, List <string> Offsets, MethodDefinition md)
        {
            ab.Comment(i.ToString().Replace("\r\n", "\n").Replace("\n", ""));
            bool Found = false;

            if (Offsets.Contains(Utils.SafeName(md.FullName) + i.ToString().Split(':')[0]))
            {
                ab.Label(Utils.SafeName(md.FullName) + i.ToString().Split(':')[0]);
            }

            foreach (var z in Opcodes)
            {
                if (z.OP.Contains(i.OpCode))
                {
                    z.Compile(i, ab, Offsets, md);
                    Found = true;
                    break;
                }
            }
            if (!Found)
            {
                Console.WriteLine("Missing opcode: " + i.ToString());
            }

            ab.Line();
        }
Ejemplo n.º 2
0
        public void CompileMethod(MethodDefinition md, Type plug = null)
        {
            if (plug != null)
            {
                ab.Comment("Pluging: " + md.Name + " for " + plug.Name);
                //System.Char System.String::get_Chars(System.Int32)
                //System.Char_System.String__get_CharsSystem.Int32
            }
            ab.Comment("Method: " + md.FullName);
            ab.Line();



            ab.Label(Utils.SafeName(md.FullName));

            ab.Line();

            /*  for (int i = 0; i < md.Parameters.Count; i++)
             * {
             *    var z = md.Parameters[i];
             *    ab.Pop("eax");
             *    ab.Mov("[ebp + " + (4 + (i * 4)) + "]", "eax");
             * }*/
            ab.Line();


            ab.Push("ebp");
            ab.Mov("ebp", "esp");
            // ab.Sub("esp", (md.Body.MaxStackSize * 4).ToString());
            ab.Push("edi");
            ab.Push("esi");



            var Offsets = new List <string>();

            foreach (var i in md.Body.Instructions)
            {
                BuildOffsets(i, ref Offsets, md);
            }

            foreach (var i in md.Body.Instructions)
            {
                IOpcode.AutoCompile(i, ab, Offsets, md);
            }
        }
Ejemplo n.º 3
0
        public void Compile(string inFile, string outFile)
        {
            PlugIndex.Clear();
            ConstantIndex.Clear();
            IOpcode.BuildOpcodeIndex();

            var lst = new List <AssemblyDefinition>();

            if (!File.Exists(inFile))
            {
                Console.WriteLine("The file \"" + inFile + "\" does not exist.");
                return;
            }

            ab = new AsmBuilder();
            lst.Add(AssemblyDefinition.ReadAssembly("i2a.Bace.dll"));
            var asm = AssemblyDefinition.ReadAssembly(inFile);


            foreach (var z in asm.Modules)
            {
                for (int i = 1; i < z.AssemblyReferences.Count; i++)
                {
                    var refs = asm.MainModule.AssemblyReferences[i];
                    lst.Add(AssemblyDefinition.ReadAssembly(Path.Combine(new FileInfo(inFile).Directory.FullName, refs.Name + ".dll")));
                }
            }

            foreach (var i in asm.Modules)
            {
                foreach (var z in i.Types)
                {
                    var att = z.CustomAttributes.Where((x) => { return(x.AttributeType.FullName == typeof(Import).FullName); });
                    if (att.Count() != 0)
                    {
                        var str = att.First().ConstructorArguments[0].Value.ToString();
                        lst.Add(AssemblyDefinition.ReadAssembly(Path.Combine(new FileInfo(inFile).Directory.FullName, str)));
                    }
                }
            }

            lst.Add(asm);
            ab.Global("kmain");
            ab.Label("kmain");

            foreach (var i in lst)
            {
                ScanAssembly(i);
            }

            ab.Jmp(Utils.SafeName(asm.EntryPoint.FullName));
            ab.Ret();
            ab.Line();
            ab.Line();


            foreach (var z in lst)
            {
                foreach (var i in z.Modules)
                {
                    CompileModule(i);
                }
            }

            File.WriteAllText(outFile, ab.ToString());
        }