public void NextOp(int addr, VM.OpCode op) { LogOp _op = new LogOp(addr, op); curScript.ops.Add(_op); curOp = _op; if (op == VM.OpCode.RET || op == VM.OpCode.TAILCALL) { if (curScript.parent != null) { curScript = curScript.parent; } } }
public void LoadScript(string hash) { if (script == null) { script = new LogScript(hash); curScript = script; } else { curOp.subScript = new LogScript(hash); curOp.subScript.parent = curScript; curScript = curOp.subScript; } }
//public MyJson.JsonNode_Object ToJson() //{ // MyJson.JsonNode_Object script = new MyJson.JsonNode_Object(); // script.SetDictValue("hash", this.hash); // MyJson.JsonNode_Array array = new MyJson.JsonNode_Array(); // script.SetDictValue("ops", array); // foreach (var op in ops) // { // array.Add(op.ToJson()); // } // return script; //} public static LogScript FromJson(MyJson.JsonNode_Object json) { var hash = json["hash"].AsString(); LogScript script = new LogScript(hash); var array = json["ops"].AsList(); foreach (var op in array) { script.ops.Add(LogOp.FromJson(op as MyJson.JsonNode_Object)); var ss = script.ops.Last().subScript; if (ss != null) { ss.parent = script; } } return(script); }
//public void LoadScript(string hash) //{ // if (script == null) // { // script = new LogScript(hash); // curScript = script; // } // else // { // curOp.subScript = new LogScript(hash); // curOp.subScript.parent = curScript; // curScript = curOp.subScript; // } //} //public void NextOp(int addr, VM.OpCode op) //{ // LogOp _op = new LogOp(addr, op); // curScript.ops.Add(_op); // curOp = _op; // if (op == VM.OpCode.RET || op == VM.OpCode.TAILCALL) // { // curScript = curScript.parent; // } //} //public void OPStackRecord(Op[] records) //{ // curOp.stack = records; //} //public void OpResult(StackItem item) //{ // curOp.opresult = item; //} //public void Error(string info) //{ // this.error = info; //} //public void Finish(VMState state) //{ // this.state = state; //} //public void Save(string filename) //{ // var path = System.IO.Path.GetDirectoryName(filename); // if (System.IO.Directory.Exists(path) == false) // System.IO.Directory.CreateDirectory(path); // System.IO.File.Delete(filename + ".json"); // System.IO.File.Delete(filename); // var json = new MyJson.JsonNode_Object(); // json.SetDictValue("script", script.ToJson()); // if (string.IsNullOrEmpty(error) == false) // json.SetDictValue("error", error); // json.SetDictValue("VMState", state.ToString()); // StringBuilder sb = new StringBuilder(); // json.ConvertToStringWithFormat(sb, 0); // System.IO.File.WriteAllText(filename + ".json", sb.ToString()); // var compressor = new SevenZip.SevenZipCompressor(); // compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2; // compressor.CompressionLevel = SevenZip.CompressionLevel.Fast; // compressor.FastCompression = true; // //compressor.path = path; // compressor.CompressFiles(filename, System.IO.Path.GetFullPath(filename + ".json")); // System.IO.File.Delete(filename + ".json"); //} public static FullLog FromJson(MyJson.JsonNode_Object json) { FullLog fulllog = new FullLog(); if (json.ContainsKey("error")) { fulllog.error = json["error"].AsString(); } if (json.ContainsKey("VMState")) { var state = json["VMState"].AsString(); fulllog.state = (VMState)Enum.Parse(typeof(VMState), state); } if (json.ContainsKey("script")) { fulllog.script = LogScript.FromJson(json["script"] as MyJson.JsonNode_Object); } return(fulllog); }
//public static MyJson.JsonNode_Object StatkItemToJson(StackItem item) //{ // //MyJson.JsonNode_Object json = new MyJson.JsonNode_Object(); // //var type = item.GetType().Name; // //if (type == "InteropInterface") // //{ // // json.SetDictValue(type, item.GetInterface<VM.IInteropInterface>().GetType().Name); // //} // //else if (type == "Boolean") // //{ // // json.SetDictValue(type, item.GetBoolean().ToString()); // //} // //else if (type == "ByteArray") // //{ // // json.SetDictValue(type, item.GetByteArray().ToHexString()); // //} // //else if (type == "Integer") // //{ // // json.SetDictValue(type, item.GetBigInteger().ToString()); // //} // //else if (item.IsArray || item.IsStruct) // //{ // // MyJson.JsonNode_Array array = new MyJson.JsonNode_Array(); // // json.SetDictValue(type, array); // // foreach (var i in item.GetArray()) // // { // // array.Add(StatkItemToJson(i)); // // } // //} // //return json; //} //public MyJson.JsonNode_Object ToJson() //{ // MyJson.JsonNode_Object _op = new MyJson.JsonNode_Object(); // _op.SetDictValue("addr", addr); // _op.SetDictValue("op", op.ToString()); // if (this.stack != null) // { // MyJson.JsonNode_Array array = new MyJson.JsonNode_Array(); // _op.SetDictValue("stack", array); // foreach (var r in stack) // { // if (r.ind > 0) // { // array.AddArrayValue(r.type.ToString() + "|" + r.ind); // } // else // { // array.AddArrayValue(r.type.ToString()); // } // } // } // if (opresult != null) // { // _op.SetDictValue("result", StatkItemToJson(opresult)); // } // if (subScript != null) // { // _op.SetDictValue("subscript", subScript.ToJson()); // } // return _op; //} public static LogOp FromJson(MyJson.JsonNode_Object json) { var opstr = json["op"].AsString(); var addr = json["addr"].AsInt(); var op = (VM.OpCode)Enum.Parse(typeof(VM.OpCode), opstr); LogOp _op = new LogOp(addr, op); if (json.ContainsKey("stack")) { var array = json["stack"].AsList(); _op.stack = new Op[array.Count]; for (var i = 0; i < array.Count; i++) { var str = array[i].AsString(); var ind = -1; if (str.Contains('|')) { var strs = str.Split('|'); ind = int.Parse(strs[1]); str = strs[0]; } var type = (OpType)Enum.Parse(typeof(OpType), str); _op.stack[i] = new Op(type, ind); } } if (json.ContainsKey("param")) { _op.param = Neo.Debug.DebugTool.HexString2Bytes(json["param"].AsString()); } if (json.ContainsKey("result")) { _op.opresult = StackItem.FromJson(json["result"] as MyJson.JsonNode_Object); } if (json.ContainsKey("subscript")) { _op.subScript = LogScript.FromJson(json["subscript"] as MyJson.JsonNode_Object); } return(_op); }
public void LoadScript(string hash) { if (script == null) { script = new LogScript(hash); curScript = script; } else { if (curOp == null) { return; } if (curOp.op == VM.OpCode.CALL) { return; } curOp.subScript = new LogScript(hash); curOp.subScript.parent = curScript; curScript = curOp.subScript; } }