public void CompileModule(ModuleDefinition md) { ab.Comment("Module: " + md.FullyQualifiedName); ab.Line(); foreach (var i in md.Types) { CompileType(i); } }
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(); }
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()); }