void BuildNeon(byte[] dll, byte[] pdb, NeonResult result)
        {
            NeonResult nr = result;

            Neo.Compiler.MSIL.ModuleConverter convert = new Neo.Compiler.MSIL.ModuleConverter(nr);
            Neo.Compiler.MSIL.ILModule        module  = new Neo.Compiler.MSIL.ILModule();
            System.IO.MemoryStream            ms      = new System.IO.MemoryStream(dll);
            System.IO.MemoryStream            mspdb   = new System.IO.MemoryStream(pdb);
            module.LoadModule(ms, mspdb);
            var mod = convert.Convert(module);
            var avm = mod.Build();

            nr.avm = avm;
            var abijson = vmtool.FuncExport.Export(mod, avm);

            nr.hash = abijson["hash"].AsString();
            nr.abi  = abijson.ToString();
            {//gen debug info
                Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array();
                foreach (var m in convert.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"))
                            {
                                infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString());
                            }
                        }
                    }
                }
                nr.map = arr.ToString();
            }
        }
示例#2
0
        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);
        }
        public static bool BuildNeon(System.IO.Stream ms, System.IO.Stream mspdb, List <string> errinfo)
        {
            string OutPath = "";

            //loaddll
            Neo.Compiler.MSIL.ILModule module = null;
            //try
            {
                module = new Neo.Compiler.MSIL.ILModule();
                module.LoadModule(ms, mspdb);
            }
            //catch (Exception err)
            //{
            //    errinfo.Add("LoadDll error:" + err.Message);
            //    return false;
            //}
            //convert
            Neo.Compiler.MSIL.ModuleConverter converter = null;
            try
            {
                converter = new Neo.Compiler.MSIL.ModuleConverter(new Logger(errinfo));
                converter.Convert(module);
            }
            catch (Exception err)
            {
                errinfo.Add("Convert error:" + err.Message);
                return(false);
            }
            //gen debug info
            string debuginfo = null;

            try
            {
                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());
                            }
                        }
                    }
                }
                debuginfo = arr.ToString();
            }
            catch (Exception err)
            {
                errinfo.Add("GenDebugInfo error:" + err.Message);
                return(false);
            }
            //save
            try
            {
                var bytes   = converter.outModule.Build(); //avm
                var hashstr = CalcScriptHashString(bytes); //hash

                System.IO.File.WriteAllBytes(System.IO.Path.Combine(OutPath, hashstr + ".avm"), bytes);
                System.IO.File.WriteAllText(System.IO.Path.Combine(OutPath, hashstr + ".debug.json"), debuginfo, Encoding.UTF8);
                //System.IO.File.Copy(System.IO.Path.Combine(BuildPath, "Contract" + ".cs"),
                //    System.IO.Path.Combine(OutPath, hashstr + ".cs"));
                return(true);
            }
            catch (Exception err)
            {
                errinfo.Add("Save error:" + err.Message);
                return(false);
            }
        }