コード例 #1
0
        public static byte[] Convert(string classfilename, ILogger logger = null)
        {
            var moduleJVMPackage = new JavaModule();

            moduleJVMPackage.LoadClass("go.class");
            moduleJVMPackage.LoadJar("AntShares.SmartContract.Framework.jar");

            var converter = new ModuleConverter(logger);
            //有异常的话在 convert 函数中会直接throw 出来
            var antmodule = converter.Convert(moduleJVMPackage);

            return(antmodule.Build());
        }
コード例 #2
0
        public AntsModule Convert(JavaModule _in)
        {
            this.srcModule = _in;
            //logger.Log("beginConvert.");
            this.outModule = new AntsModule(this.logger);
            foreach (var c in _in.classes.Values)
            {
                if (c.skip)
                {
                    continue;
                }
                foreach (var m in c.methods)
                {
                    if (m.Value.skip)
                    {
                        continue;
                    }
                    if (m.Key[0] == '<')
                    {
                        continue;                 //系統函數不要
                    }
                    AntsMethod nm = new AntsMethod();
                    nm.name = c.classfile.Name + "::" + m.Key;
                    this.methodLink[m.Value]      = nm;
                    outModule.mapMethods[nm.name] = nm;
                }
            }

            foreach (var c in _in.classes.Values)
            {
                if (c.skip)
                {
                    continue;
                }
                foreach (var m in c.methods)
                {
                    if (m.Value.skip)
                    {
                        continue;
                    }
                    if (m.Key[0] == '<')
                    {
                        continue;                 //系統函數不要
                    }
                    var nm = this.methodLink[m.Value];
                    //try
                    {
                        this.ConvertMethod(m.Value, nm);
                    }
                    //catch (Exception err)
                    //{
                    //    logger.Log("error:" + err.Message);
                    //}
                }
            }
            //转换完了,做个link,全部拼到一起
            string mainmethod = "";

            foreach (var key in outModule.mapMethods.Keys)
            {
                if (key.Contains("Verify"))
                {
                    var m = outModule.mapMethods[key];
                    foreach (var l in this.methodLink)
                    {
                        if (l.Value == m)
                        {
                            var srcm = l.Key;
                            if (srcm.DeclaringType.superClass == "VerificationCode" && srcm.returnType == "System.Boolean")
                            {
                                logger.Log("找到函数入口点:" + key);
                                if (mainmethod != "")
                                {
                                    throw new Exception("拥有多个函数入口点,请检查");
                                }
                                mainmethod = key;
                            }
                        }
                    }
                }
                var name = key.Substring(key.IndexOf("::") + 2);
                if (name == ("Main"))
                {
                    var m = outModule.mapMethods[key];
                    foreach (var l in this.methodLink)
                    {
                        if (l.Value == m)
                        {
                            var srcm = l.Key;
                            if (srcm.DeclaringType.superClass == "AntShares.SmartContract.Framework.FunctionCode")
                            {
                                logger.Log("找到函数入口点:" + key);
                                if (mainmethod != "")
                                {
                                    throw new Exception("拥有多个函数入口点,请检查");
                                }
                                mainmethod = key;
                            }
                        }
                    }
                }
            }
            if (mainmethod == "")
            {
                throw new Exception("找不到入口函数,请检查");
            }
            //得找到第一个函数
            this.LinkCode(mainmethod);
            //this.findFirstFunc();//得找到第一个函数
            //然后给每个method 分配一个func addr
            //还需要对所有的call 做一次地址转换

            //this.outModule.Build();
            return(outModule);
        }