/* * [PyTuple 1] * [PyTuple] response * or * [PyTuple 1] * [PySubStream] * response * ------------- * response = return from PyCallable::Call(); */ public CallRsp(PyTuple payload) { if (payload == null) { throw new InvalidDataException("CallRsp: null payload."); } if (payload.Items.Count != 1) { throw new InvalidDataException("CallRsp: Invalid tuple size expected 1 got" + payload.Items.Count); } if (payload.Items[0] is PyTuple) { response = payload.Items[0]; } else { if (!(payload.Items[0] is PySubStream)) { throw new InvalidDataException("CallRsp: No PySubStreeam."); } subStream = true; PySubStream sub = payload.Items[0] as PySubStream; response = sub.Data; } }
/* * [PyTuple 3 items] * [PyInt causingMessageType] * [PyInt ErrorCode] * [PyTuple 1 items] * [PySubStream 87 bytes] * errorPayload * create with: * throw PyException(errorPayload) */ public ErrorResponse(PyTuple payload) { if (payload == null) { throw new InvalidDataException("ErrorResponse: null payload."); } if (payload.Items.Count != 3) { throw new InvalidDataException("ErrorResponse: Invalid tuple size expected 3 got" + payload.Items.Count); } causingMessageType = payload.Items[0].IntValue; errorCode = payload.Items[1].IntValue; PyTuple payloadTuple = payload.Items[2] as PyTuple; if (payloadTuple == null) { throw new InvalidDataException("ErrorResponse: Invalid type expected PyTuple got " + payload.Items[2].Type); } if (payloadTuple.Items.Count != 1) { throw new InvalidDataException("ErrorResponse: Invalid tuple size expected 1 got" + payload.Items.Count); } PySubStream sub = payloadTuple.Items[0] as PySubStream; if (sub == null) { throw new InvalidDataException("ErrorResponse: Invalid PySubStreeam."); } errorPayload = sub.Data; }
private void button1_Click(object sender, EventArgs e) { if (txtInput.Text.Length == 0) { txtOutput.Text = ""; return; } string hex = txtInput.Text.Replace(" ", "").Replace(System.Environment.NewLine, ""); try { //txtOutput.Text = hex; byte[] raw = new Byte[hex.Length / 2]; for (int i = 0; i < raw.Length; i++) { raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16); } Console.WriteLine(raw.Length + ", " + hex.Length); Unmarshal un = new Unmarshal(); //un.DebugMode = true; //PyObject obj = un.Process(BinaryReader.); PyRep obj = un.Process(raw); PrettyPrinter pp = new PrettyPrinter(); txtOutput.Text = pp.Print(obj); } catch { hex = txtInput.Text.Substring(8, txtInput.Text.Length - 8).Replace(" ", "").Replace(System.Environment.NewLine, ""); byte[] raw = new Byte[hex.Length / 2]; for (int i = 0; i < raw.Length; i++) { raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16); } Console.WriteLine(raw.Length + ", " + hex.Length); Unmarshal un = new Unmarshal(); un.DebugMode = true; // un.DebugMode = true; //PyObject obj = un.Process(BinaryReader.); PyRep obj = un.Process(raw); PrettyPrinter pp = new PrettyPrinter(); txtOutput.Text = pp.Print(obj); } /* * //txtOutput.Text = hex; * byte[] raw = new Byte[hex.Length / 2]; * for (int i = 0; i < raw.Length; i++) { * raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16); * } * Console.WriteLine(raw.Length+", "+hex.Length); * Unmarshal un = new Unmarshal(); * // un.DebugMode = true; * //PyObject obj = un.Process(BinaryReader.); * PyObject obj = un.Process(raw); * txtOutput.Text = PrettyPrinter.Print(obj); */ }
public UserError(PyTuple tuple, PyDict match) { if (match == null) { throw new InvalidDataException("UserError: No matching set found."); } if (tuple.Items.Count > 2 || tuple.Items.Count < 1) { throw new InvalidDataException("UserError: Invalid tuple size expected 1 or 2 got " + tuple.Items.Count); } PyString msgString = tuple.Items[0] as PyString; if (msgString == null) { throw new InvalidDataException("UserError: No message found."); } message = msgString.Value; if (tuple.Items.Count == 2) { dict = tuple.Items[1] as PyDict; if (dict == null) { throw new InvalidDataException("UserError: Invalid dictionary."); } } msgString = match.Get("msg") as PyString; if (msgString == null || msgString.StringValue != message) { throw new InvalidDataException("UserError: Message name mismatch."); } PyRep matchRep = match.Get("dict"); if (dict != null) { PyDict matchDict = matchRep as PyDict; if (matchDict == null) { throw new InvalidDataException("UserError: No matching dictionary."); } if (matchDict.Dictionary.Count != dict.Dictionary.Count) { throw new InvalidDataException("UserError: Dictionary size mismatch."); } //foreach(var kvp in dict.Dictionary) //{ // To-DO: compare each entry. //} } else { if (matchRep != null && !(matchRep is PyNone)) { throw new InvalidDataException("UserError: No Dictionary to match."); } } }
public NotificationStream(PyRep payload) { PyTuple sub = getZeroSubStream(payload as PyTuple, out zeroOne) as PyTuple; PyRep args = sub; if (sub != null) { if (zeroOne == 0) { args = getZeroOne(sub); } } if (args == null) { throw new InvalidDataException("NotificationStream: null args."); } notice = args; }
/* * Attempt to analyse */ public PyRep analyse(PyRep obj, string filename) { if (obj.Type == PyObjectType.ObjectData) { eveMarshal.PyObject packetData = obj as eveMarshal.PyObject; try { return(new PyPacket(packetData)); } catch (InvalidDataException e) { addText(filename + Environment.NewLine); addText("Packet Decode failed: " + e.Message + Environment.NewLine); return(obj); } } return(obj); }
/* * [PyObjectEx Normal] * Header: * [PyTuple 3 items] * [PyToken carbon.common.script.net.machoNetExceptions.WrongMachoNode] * [PyTuple 0 items] * [PyDict 1 kvp] * Key:[PyString "payload"] * ==Value:[PyInt correctNode] * List: * Dictionary: */ public WrongMachoNode(PyDict obj) { if (obj == null) { throw new InvalidDataException("WrongMachoNode: null dictionary."); } if (!obj.Contains("payload")) { throw new InvalidDataException("WrongMachoNode: Could not find key 'payload'."); } if (obj.Dictionary.Count > 1) { throw new InvalidDataException("WrongMachoNode: Too many values in dictionary."); } PyRep value = obj.Get("payload"); correctNode = value.IntValue; }
/* * [PyObjectEx Type2] * header: * [PyTuple 1] * [PyToken "carbon.common.script.sys.crowset.CIndexedRowset"] * [PyDict] * Key=header * Value=[DBRowDescriptor] * key=columnName * value=[PyString columnName] * dict: * rows * create with: DBResultToCIndexedRowset() */ public CIndexedRowset(PyDict dict, Dictionary<PyRep, PyRep> nRows) { rows = nRows; if(rows == null) { rows = new Dictionary<PyRep, PyRep>(); } descriptor = dict.Get("header") as DBRowDescriptor; if (descriptor == null) { throw new InvalidDataException("CIndexedRowSet: Invalid DBRowDescriptor."); } PyRep name = dict.Get("columnName"); if(name == null) { throw new InvalidDataException("CIndexedRowSet: Could not find index name."); } columnName = name.StringValue; }
public CallMachoBindObject(PyTuple payload) { if (payload == null) { throw new InvalidDataException("CallMachoBindObject: null payload."); } if (payload.Items.Count != 2) { throw new InvalidDataException("CallMachoBindObject: Invalid tuple size expected 2 got" + payload.Items.Count); } bindArgs = payload.Items[0]; PyTuple tupleArgs = bindArgs as PyTuple; if (tupleArgs != null && tupleArgs.Items.Count == 2 && tupleArgs.Items[0].isIntNumber && tupleArgs.Items[1].isIntNumber) { locationID = tupleArgs.Items[0].IntValue; locationGroupID = tupleArgs.Items[1].IntValue; bindArgs = null; } else if (bindArgs.isIntNumber) { characterID = bindArgs.IntValue; bindArgs = null; } PyTuple tuple = payload.Items[1] as PyTuple; if (tuple != null) { if (tuple.Items.Count != 3) { throw new InvalidDataException("CallMachoBindObject: Invalid tuple size expected 3 got" + tuple.Items.Count); } if (!(tuple.Items[0] is PyString) || !(tuple.Items[1] is PyTuple) || !(tuple.Items[2] is PyDict)) { throw new InvalidDataException("CallMachoBindObject: Invalid call structure, expected PyString, PyTuple, PyDict. Got " + tuple.Items[0].Type + ", " + tuple.Items[1].Type + "," + tuple.Items[2].Type); } callMethod = tuple.Items[0].StringValue; callTuple = tuple.Items[1] as PyTuple; callDict = tuple.Items[2] as PyDict; } }
/* * Helper functions. */ /* * [PyTuple 2] * [PyInt 0] * [PyTuple 2] * [PyInt 1] * response */ public static PyRep getZeroOne(PyTuple payload) { if (payload.Items.Count != 2) { throw new InvalidDataException("zeroOne: Invalid tuple size expected 2 got" + payload.Items.Count); } if (!payload.Items[0].isIntNumber) { throw new InvalidDataException("zeroOne: Invalid integer object got " + payload.Items[0].Type); } long zero = payload.Items[0].IntValue; if (zero != 0) { throw new InvalidDataException("zeroOne: Invalid integer value expected 0 got " + zero); } PyRep temp = payload.Items[1]; PyTuple tuple = temp as PyTuple; if (tuple == null) { throw new InvalidDataException("zeroOne: Invalid tuple got " + ((temp == null) ? "nullptr" : temp.Type.ToString())); } if (tuple.Items.Count != 2) { throw new InvalidDataException("zeroOne: Invalid tuple size expected 2 got" + tuple.Items.Count); } if (!tuple.Items[0].isIntNumber) { throw new InvalidDataException("zeroOne: Invalid integer object got " + tuple.Items[0].Type); } long one = tuple.Items[0].IntValue; if (one != 1) { throw new InvalidDataException("zeroOne: Invalid integer value expected 1 got " + one); } return(tuple.Items[1]); }
/* * [PyTuple 1] * [PyTuple 2] * [PyInt zeroOne] * [PySubStream] * response */ public static PyRep getZeroSubStream(PyTuple payload, out long zeroOne) { if (payload.Items.Count != 1) { throw new InvalidDataException("zeroSubstream: Invalid tuple size expected 1 got" + payload.Items.Count); } PyRep temp = payload.Items[0]; PyTuple tuple = temp as PyTuple; if (tuple == null) { throw new InvalidDataException("zeroSubstream: Invalid tuple got " + ((temp == null) ? "nullptr" : temp.Type.ToString())); } if (tuple.Items.Count != 2) { throw new InvalidDataException("zeroSubstream: Invalid tuple size expected 2 got" + tuple.Items.Count); } if (!tuple.Items[0].isIntNumber) { throw new InvalidDataException("zeroSubstream: Invalid integer object got " + tuple.Items[0].Type); } zeroOne = tuple.Items[0].IntValue; if (zeroOne != 0 && zeroOne != 1) { throw new InvalidDataException("zeroSubstream: Invalid integer value expected 0 got " + zeroOne); } if (!(tuple.Items[1] is PySubStream)) { throw new InvalidDataException("zeroSubstream: No PySubStreeam."); } PySubStream sub = tuple.Items[1] as PySubStream; if (sub != null) { return(sub.Data); } return(null); }
private bool process(string filename, StreamWriter singleWriter) { // Does the file exist? if (!File.Exists(filename)) { addText("File not found: " + filename); // No, fail! return(false); } byte[] data = null; using (var f = File.Open(filename, FileMode.Open)) { if (f.Length == 0) { if (singleWriter != null) { // Write the filename. singleWriter.WriteLine(Path.GetFileName(filename)); // Write the decoded file. singleWriter.WriteLine("Zero Length file."); } return(true); } data = new byte[f.Length]; f.Read(data, 0, (int)f.Length); f.Close(); } if (data == null) { // No data loaded. return(false); } // Is this a compressed file? if (data[0] == ZlibMarker) { // Yes, decompress it. data = Zlib.Decompress(data); if (data == null) { // Decompress failed. return(false); } } // Is this a proper python serial stream? if (data[0] != HeaderByte) { // No, is this a python file? If yes, ignore it but dont cause an error. if (data[0] == PythonMarker && decompilePython && !imbededPython) { try { Bytecode code = new Bytecode(); code.load(data); string outfile = null; if (code.body != null) { Python.PyString fns = code.body.filename as Python.PyString; if (fns != null) { outfile = fns.str; outfile = outfile.Replace(':', '_'); outfile = outfile.Replace('\\', '-'); outfile = outfile.Replace('/', '-'); } } if (outfile != null) { string pyd = Path.GetDirectoryName(filename); pyd += "\\py\\"; if (!Directory.Exists(pyd)) { Directory.CreateDirectory(pyd); } outfile = pyd + "\\" + outfile + ".txt"; string dump = Python.PrettyPrinter.print(code, true); File.WriteAllText(outfile, dump); } } catch (Exception e) { string err = Path.GetFileName(filename) + Environment.NewLine + "Error: " + e.ToString(); // We, had an error but should still produce some kind of notice in the output. addText(err + Environment.NewLine); if (singleWriter != null) { //// Write the filename. //singleWriter.WriteLine(Path.GetFileName(filename)); //// Write the decoded file. //singleWriter.WriteLine("Python Decoder Error."); //singleWriter.WriteLine(err); } else { //File.WriteAllText(filename + ".txt", err); } return(false); } } return(data[0] == PythonMarker); } bool decodeDone = false; try { Unmarshal un = new Unmarshal(); un.analizeInput = analizeInput; PyRep obj = un.Process(data); decodeDone = true; obj = analyse(obj, filename); eveMarshal.PrettyPrinter printer = new eveMarshal.PrettyPrinter(); printer.analizeInput = analizeInput; printer.decompilePython = decompilePython; string decoded = printer.Print(obj); if (singleWriter != null) { // Write the filename. singleWriter.WriteLine(Path.GetFileName(filename)); // Write the decoded file. singleWriter.Write(decoded); singleWriter.Flush(); } else { File.WriteAllText(filename + ".txt", decoded); } if (un.unknown.Length > 0) { addText(workingDirectory + Environment.NewLine); addText(un.unknown.ToString() + Environment.NewLine); } } catch (Exception e) { string err = Path.GetFileName(filename) + Environment.NewLine + "Error: " + e.ToString(); // We, had an error but should still produce some kind of notice in the output. addText(err + Environment.NewLine); if (singleWriter != null) { // Write the filename. singleWriter.WriteLine(Path.GetFileName(filename)); // Write the decoded file. singleWriter.WriteLine(decodeDone ? "Printer Error. " : "Decoder Error."); singleWriter.WriteLine(err); } else { File.WriteAllText(filename + ".txt", err); } return(false); } return(true); }
private bool process(string filename, StreamWriter singleWriter) { // Does the file exist? if (!File.Exists(filename)) { // No, fail! return(false); } byte[] data = null; using (var f = File.Open(filename, FileMode.Open)) { if (f.Length == 0) { if (singleWriter != null) { // Write the filename. singleWriter.WriteLine(Path.GetFileName(filename)); // Write the decoded file. singleWriter.WriteLine("Zero Length file."); } return(true); } data = new byte[f.Length]; f.Read(data, 0, (int)f.Length); f.Close(); } if (data == null) { // No data loaded. return(false); } // Is this a compressed file? if (data[0] == ZlibMarker) { // Yes, decompress it. data = Zlib.Decompress(data); if (data == null) { // Decompress failed. return(false); } } // Is this a proper python serial stream? if (data[0] != HeaderByte) { // No, is this a python file? If yes, ignore it but dont cause an error. return(data[0] == PythonMarker); } bool decodeDone = false; try { Unmarshal un = new Unmarshal(); PyRep obj = un.Process(data); decodeDone = true; obj = analyse(obj, filename); string decoded = PrettyPrinter.Print(obj); if (singleWriter != null) { // Write the filename. singleWriter.WriteLine(Path.GetFileName(filename)); // Write the decoded file. singleWriter.Write(decoded); singleWriter.Flush(); } else { File.WriteAllText(filename + ".txt", decoded); } if (un.unknown.Length > 0) { addText(workingDirectory + Environment.NewLine); addText(un.unknown.ToString() + Environment.NewLine); } } catch (Exception e) { string err = Path.GetFileName(filename) + Environment.NewLine + "Error: " + e.ToString(); // We, had an error but should still produce some kind of notice in the output. addText(err + Environment.NewLine); if (singleWriter != null) { // Write the filename. singleWriter.WriteLine(Path.GetFileName(filename)); // Write the decoded file. singleWriter.WriteLine(decodeDone ? "Printer Error. " : "Decoder Error."); singleWriter.WriteLine(err); } else { File.WriteAllText(filename + ".txt", err); } return(false); } return(true); }