Beispiel #1
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());
        }
Beispiel #2
0
 public abstract void Compile(Instruction i, AsmBuilder ab, List <string> Offsets, MethodDefinition md);