public static byte[] Convert(System.IO.Stream dllstream, Neo.Compiler.ILogger logger = null) { var module = new ILModule(); module.LoadModule(dllstream, null); if (logger == null) { logger = new DefLogger(); } var converter = new ModuleConverter(logger); //有异常的话在 convert 函数中会直接throw 出来 var antmodule = converter.Convert(module); return(antmodule.Build()); }
private static Result CompileDll(Neo.Compiler.ILogger logger, string name) { Result r = new Result(); var namepdb = name.Substring(0, name.Length - 4) + ".pdb"; if (System.IO.File.Exists(name) == false || System.IO.File.Exists(namepdb) == false) { throw new Exception("必须同时拥有dll 和 pdb 文件"); } var stream = System.IO.File.OpenRead(name); var streampdb = System.IO.File.OpenRead(namepdb); Neo.Compiler.MSIL.ILModule module = new Neo.Compiler.MSIL.ILModule(); module.LoadModule(stream, streampdb); Neo.Compiler.MSIL.ModuleConverter converter = new Neo.Compiler.MSIL.ModuleConverter(logger); converter.Convert(module); string srcfile = null; {//gen debug info Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in converter.outModule.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); if (debugcode.Contains(".cs")) { if (srcfile == null) { srcfile = debugcode; } infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } r.debuginfo = arr.ToString(); } r.srcfile = srcfile; {//gen hexscript var bytes = converter.outModule.Build(); var hashstr = CalcScriptHashString(bytes); r.avm = bytes; r.script_hash = hashstr; } return(r); }