public NeoModule Convert(ILModule _in, ConvOption option = null) { this.inModule = _in; this.outModule = new NeoModule(this.logger) { option = option ?? ConvOption.Default }; foreach (var t in _in.mapType) { if (t.Key.Contains("<")) { continue; //skip system type } if (t.Key.Contains("_API_")) { continue; // skip api } if (t.Key.Contains(".My.")) { continue; //vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue; // skip the code generated by event } if (m.Value.method.Is_ctor()) { continue; } if (m.Value.method.Is_cctor()) { //if cctor contains sth can not be as a const value. // then need 1.record these cctor's code. // 2.insert them to main function CctorSubVM.Parse(m.Value, this.outModule); continue; } NeoMethod nm = new NeoMethod(m.Value); this.methodLink[m.Value] = nm; outModule.mapMethods[nm.name] = nm; } foreach (var e in t.Value.fields) { if (e.Value.isEvent) { NeoEvent ae = new NeoEvent(e.Value); outModule.mapEvents[ae.name] = ae; } else if (e.Value.field.IsStatic) { var _fieldindex = outModule.mapFields.Count; var field = new NeoField(e.Key, e.Value.type, _fieldindex); outModule.mapFields[e.Value.field.FullName] = field; } } } var keys = new List <string>(_in.mapType.Keys); foreach (var key in keys) { var value = _in.mapType[key]; if (key.Contains("<")) { continue; // skip system typee } if (key.Contains("_API_")) { continue; // skip api } if (key.Contains(".My.")) { continue; //vb system } foreach (var m in value.methods) { if (m.Value.method == null) { continue; } if (m.Value.method.Is_cctor()) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue; // skip the code generated by event } var nm = this.methodLink[m.Value]; //try { nm.returntype = m.Value.returntype; try { var type = m.Value.method.ReturnType.Resolve(); foreach (var i in type.Interfaces) { if (i.InterfaceType.Name == "IApiInterface") { nm.returntype = "IInteropInterface"; } } } catch { } foreach (var src in m.Value.paramtypes) { nm.paramtypes.Add(new NeoParam(src.name, src.type)); } if (IsAppCall(m.Value.method, out byte[] outcall))
public NeoModule Convert(ILModule _in, ConvOption option = null) { //logger.Log("beginConvert."); this.inModule = _in; this.outModule = new NeoModule(this.logger); this.outModule.option = option == null ? ConvOption.Default : option; foreach (var t in _in.mapType) { if (t.Key.Contains("<")) { continue;//系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } NeoMethod nm = new NeoMethod(); if (m.Key.Contains(".cctor")) { CctorSubVM.Parse(m.Value, this.outModule); continue; } if (m.Value.method.IsConstructor) { continue; } nm._namespace = m.Value.method.DeclaringType.FullName; nm.name = m.Value.method.FullName; nm.displayName = m.Value.method.Name; Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes; foreach (var attr in ca) { if (attr.AttributeType.Name == "DisplayNameAttribute") { nm.displayName = (string)attr.ConstructorArguments[0].Value; } } nm.inSmartContract = m.Value.method.DeclaringType.BaseType.Name == "SmartContract"; nm.isPublic = m.Value.method.IsPublic; this.methodLink[m.Value] = nm; outModule.mapMethods[nm.name] = nm; } foreach (var e in t.Value.fields) { if (e.Value.isEvent) { NeoEvent ae = new NeoEvent(); ae._namespace = e.Value.field.DeclaringType.FullName; ae.name = ae._namespace + "::" + e.Key; ae.displayName = e.Value.displayName; ae.returntype = e.Value.returntype; ae.paramtypes = e.Value.paramtypes; outModule.mapEvents[ae.name] = ae; } } } var keys = new List <string>(_in.mapType.Keys); foreach (var key in keys) { var value = _in.mapType[key]; if (key.Contains("<")) { continue;//系统的,不要 } if (key.Contains("_API_")) { continue; //api的,不要 } if (key.Contains(".My.")) { continue;//vb system } foreach (var m in value.methods) { if (m.Value.method == null) { continue; } if (m.Key.Contains(".cctor")) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } var nm = this.methodLink[m.Value]; //try { nm.returntype = m.Value.returntype; try { var type = m.Value.method.ReturnType.Resolve(); foreach (var i in type.Interfaces) { if (i.InterfaceType.Name == "IApiInterface") { nm.returntype = "IInteropInterface"; } } } catch (Exception err) { } foreach (var src in m.Value.paramtypes) { nm.paramtypes.Add(new NeoParam(src.name, src.type)); } byte[] outcall; string name; if (IsAppCall(m.Value.method, out outcall)) { continue; } if (IsNonCall(m.Value.method)) { continue; } if (IsOpCall(m.Value.method, out name)) { continue; } if (IsSysCall(m.Value.method, out name)) { continue; } 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("::Main(")) { NeoMethod m = outModule.mapMethods[key]; if (m.inSmartContract) { foreach (var l in this.methodLink) { if (l.Value == m) { if (mainmethod != "") { throw new Exception("Have too mush EntryPoint,Check it."); } mainmethod = key; } } } } } if (mainmethod == "") { throw new Exception("Can't find EntryPoint,Check it."); } else { //单一默认入口 logger.Log("Find entrypoint:" + mainmethod); } outModule.mainMethod = mainmethod; this.LinkCode(mainmethod); //this.findFirstFunc();//得找到第一个函数 //然后给每个method 分配一个func addr //还需要对所有的call 做一次地址转换 //this.outModule.Build(); return(outModule); }
public AntsModule Convert(ILModule _in) { //logger.Log("beginConvert."); this.outModule = new AntsModule(this.logger); foreach (var t in _in.mapType) { if (t.Key[0] == '<') { continue; //系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } AntsMethod nm = new AntsMethod(); if (m.Key == ".cctor") { CctorSubVM.Parse(m.Value, this.outModule); continue; } if (m.Value.method.IsConstructor) { continue; } nm._namespace = m.Value.method.DeclaringType.FullName; nm.name = m.Value.method.FullName; nm.isPublic = m.Value.method.IsPublic; this.methodLink[m.Value] = nm; outModule.mapMethods[nm.name] = nm; } } foreach (var t in _in.mapType) { if (t.Key[0] == '<') { continue; //系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Key == ".cctor") { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } var nm = this.methodLink[m.Value]; //try { nm.returntype = m.Value.returntype; foreach (var src in m.Value.paramtypes) { nm.paramtypes.Add(new AntsParam(src.name, src.type)); } byte[] outcall; string name; if (IsAppCall(m.Value.method, out outcall)) { continue; } if (IsNonCall(m.Value.method)) { continue; } if (IsOpCall(m.Value.method, out name)) { continue; } if (IsSysCall(m.Value.method, out name)) { continue; } 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("::Main(")) { var m = outModule.mapMethods[key]; foreach (var l in this.methodLink) { if (l.Value == m) { var srcm = l.Key.method; if (srcm.DeclaringType.BaseType.Name == "SmartContract") { logger.Log("找到函数入口点:" + key); if (mainmethod != "") { throw new Exception("拥有多个函数入口点,请检查"); } mainmethod = key; } } } } } if (mainmethod == "") { throw new Exception("找不到入口函数,请检查"); } outModule.mainMethod = mainmethod; //得找到第一个函数 this.LinkCode(mainmethod); //this.findFirstFunc();//得找到第一个函数 //然后给每个method 分配一个func addr //还需要对所有的call 做一次地址转换 //this.outModule.Build(); return(outModule); }
public AntsModule Convert(ILModule _in) { //logger.Log("beginConvert."); this.outModule = new AntsModule(this.logger); foreach (var t in _in.mapType) { if (t.Key[0] == '<') { continue; //系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } AntsMethod nm = new AntsMethod(); if (m.Key == ".cctor") { CctorSubVM.Parse(m.Value, this.outModule); continue; } if (m.Value.method.IsConstructor) { continue; } nm._namespace = m.Value.method.DeclaringType.FullName; nm.name = m.Value.method.FullName; nm.displayName = m.Value.method.Name; Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes; foreach (var attr in ca) { if (attr.AttributeType.Name == "DisplayNameAttribute") { nm.displayName = (string)attr.ConstructorArguments[0].Value; } } nm.isPublic = m.Value.method.IsPublic; this.methodLink[m.Value] = nm; outModule.mapMethods[nm.name] = nm; } foreach (var e in t.Value.fields) { if (e.Value.isEvent) { AntsEvent ae = new AntsEvent(); ae._namespace = e.Value.field.DeclaringType.FullName; ae.name = ae._namespace + "::" + e.Key; ae.displayName = e.Value.displayName; ae.returntype = e.Value.returntype; ae.paramtypes = e.Value.paramtypes; outModule.mapEvents[ae.name] = ae; } } } Dictionary <byte, string> spmains = new Dictionary <byte, string>(); foreach (var t in _in.mapType) { if (t.Key[0] == '<') { continue; //系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Key == ".cctor") { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } var nm = this.methodLink[m.Value]; byte entryid; if (IsEntryCall(m.Value.method, out entryid)) { spmains[entryid] = nm.name; logger.Log("找到函数入口点:[" + entryid + "]" + nm.name); } //try { nm.returntype = m.Value.returntype; foreach (var src in m.Value.paramtypes) { nm.paramtypes.Add(new AntsParam(src.name, src.type)); } byte[] outcall; string name; if (IsAppCall(m.Value.method, out outcall)) { continue; } if (IsNonCall(m.Value.method)) { continue; } if (IsOpCall(m.Value.method, out name)) { continue; } if (IsSysCall(m.Value.method, out name)) { continue; } 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("::Main(")) { AntsMethod m = outModule.mapMethods[key]; foreach (var l in this.methodLink) { if (l.Value == m) { var srcm = l.Key.method; if (srcm.DeclaringType.BaseType.Name == "SmartContract") { if (mainmethod != "") { throw new Exception("拥有多个函数入口点,请检查"); } mainmethod = key; } } } } } if (mainmethod == "" && spmains.Count == 0) { throw new Exception("找不到入口函数,请检查"); } else if (mainmethod != "" && spmains.Count > 0) { throw new Exception("同时拥有指定入口函数和默认入口函数,请检查"); } else if (mainmethod != "") { //单一默认入口 logger.Log("找到函数入口点:" + mainmethod); } else if (spmains.Count > 0) //拥有条件入口的情况 { mainmethod = this.CreateJmpMain(spmains); } outModule.mainMethod = mainmethod; this.LinkCode(mainmethod); //this.findFirstFunc();//得找到第一个函数 //然后给每个method 分配一个func addr //还需要对所有的call 做一次地址转换 //this.outModule.Build(); return(outModule); }
public AntsModule Convert(ILModule _in) { //logger.Log("beginConvert."); this.outModule = new AntsModule(this.logger); foreach (var t in _in.mapType) { if (t.Key[0] == '<') { continue; //系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue; //vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } AntsMethod nm = new AntsMethod(); nm.name = m.Value.method.FullName; this.methodLink[m.Value] = nm; outModule.mapMethods[nm.name] = nm; } } foreach (var t in _in.mapType) { if (t.Key[0] == '<') { continue; //系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { 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.method; if (srcm.DeclaringType.BaseType.Name == "VerificationCode" && srcm.ReturnType.FullName == "System.Boolean") { logger.Log("找到函数入口点:" + key); if (mainmethod != "") { throw new Exception("拥有多个函数入口点,请检查"); } mainmethod = key; } } } } if (key.Contains("::Main(")) { var m = outModule.mapMethods[key]; foreach (var l in this.methodLink) { if (l.Value == m) { var srcm = l.Key.method; if (srcm.DeclaringType.BaseType.Name == "FunctionCode") { logger.Log("找到函数入口点:" + key); if (mainmethod != "") { throw new Exception("拥有多个函数入口点,请检查"); } mainmethod = key; } } } } } if (mainmethod == "") { throw new Exception("找不到入口函数,请检查"); } outModule.mainMethod = mainmethod; //得找到第一个函数 this.LinkCode(mainmethod); //this.findFirstFunc();//得找到第一个函数 //然后给每个method 分配一个func addr //还需要对所有的call 做一次地址转换 //this.outModule.Build(); return(outModule); }
public NeoModule Convert(ILModule _in, ConvOption option = null) { this.inModule = _in; //logger.Log("beginConvert."); this.outModule = new NeoModule(this.logger) { option = option ?? ConvOption.Default }; foreach (var t in _in.mapType) { if (t.Key.Contains("<")) { continue;//系统的,不要 } if (t.Key.Contains("_API_")) { continue; //api的,不要 } if (t.Key.Contains(".My.")) { continue;//vb system } foreach (var m in t.Value.methods) { if (m.Value.method == null) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } NeoMethod nm = new NeoMethod(); if (m.Key.Contains(".cctor")) { CctorSubVM.Parse(m.Value, this.outModule); continue; } if (m.Value.method.IsConstructor) { continue; } nm._namespace = m.Value.method.DeclaringType.FullName; nm.name = m.Value.method.FullName; nm.displayName = m.Value.method.Name; Mono.Collections.Generic.Collection <Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes; foreach (var attr in ca) { if (attr.AttributeType.Name == "DisplayNameAttribute") { nm.displayName = (string)attr.ConstructorArguments[0].Value; } } nm.inSmartContract = m.Value.method.DeclaringType.BaseType.Name == "SmartContract"; nm.isPublic = m.Value.method.IsPublic; this.methodLink[m.Value] = nm; outModule.mapMethods[nm.name] = nm; } foreach (var e in t.Value.fields) { if (e.Value.isEvent) { NeoEvent ae = new NeoEvent { _namespace = e.Value.field.DeclaringType.FullName, name = e.Value.field.DeclaringType.FullName + "::" + e.Key, displayName = e.Value.displayName, returntype = e.Value.returntype, paramtypes = e.Value.paramtypes }; outModule.mapEvents[ae.name] = ae; } else if (e.Value.field.IsStatic) { var _fieldindex = outModule.mapFields.Count; var field = new NeoField(e.Key, e.Value.type, _fieldindex); outModule.mapFields[e.Value.field.FullName] = field; } } } var keys = new List <string>(_in.mapType.Keys); foreach (var key in keys) { var value = _in.mapType[key]; if (key.Contains("<")) { continue;//系统的,不要 } if (key.Contains("_API_")) { continue; //api的,不要 } if (key.Contains(".My.")) { continue;//vb system } foreach (var m in value.methods) { if (m.Value.method == null) { continue; } if (m.Key.Contains(".cctor")) { continue; } if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn) { continue;//event 自动生成的代码,不要 } var nm = this.methodLink[m.Value]; //try { nm.returntype = m.Value.returntype; try { var type = m.Value.method.ReturnType.Resolve(); foreach (var i in type.Interfaces) { if (i.InterfaceType.Name == "IApiInterface") { nm.returntype = "IInteropInterface"; } } } catch { } foreach (var src in m.Value.paramtypes) { nm.paramtypes.Add(new NeoParam(src.name, src.type)); } if (IsAppCall(m.Value.method, out byte[] outcall))