public override void dump(PrettyPrinter printer) { printer.addLine("[PyDict " + Dictionary.Count + " kvp]" + PrettyPrinter.PrintRawData(this)); printer.indentLevel++; foreach (var kvp in Dictionary) { printer.addLine("Key:"); printer.addItem(kvp.Key); if (kvp.Value == null) { printer.addLine("Value: <nullptr>"); } else { printer.addLine("Value:"); printer.addItem(kvp.Value); } } printer.indentLevel--; }
public override string dump(string prefix) { StringBuilder builder = new StringBuilder(); builder.AppendLine(prefix + "[PyBuffer " + Data.Length + " bytes]" + PrettyPrinter.PrintRawData(this)); if (Data[0] == Unmarshal.HeaderByte || Data[0] == Unmarshal.ZlibMarker) { string pfx1 = prefix + PrettyPrinter.Spacer; Unmarshal un = new Unmarshal(); PyRep rep = un.Process(Data); if (rep != null) { if (Data[0] == Unmarshal.ZlibMarker) { builder.AppendLine("<compressed-data>"); } builder.AppendLine(pfx1 + rep.dump(pfx1)); } } return(builder.ToString()); }
public override string dump(string prefix) { StringBuilder builder = new StringBuilder(); string pfx1 = prefix + PrettyPrinter.Spacer; string pfx2 = pfx1 + PrettyPrinter.Spacer + PrettyPrinter.Spacer; builder.AppendLine("[PyDict " + Dictionary.Count + " kvp]" + PrettyPrinter.PrintRawData(this)); foreach (var kvp in Dictionary) { PrettyPrinter.Print(builder, pfx1 + "Key:", kvp.Key); if (kvp.Value == null) { builder.AppendLine(pfx1 + "==Value: <nullptr>"); } else { builder.AppendLine(pfx1 + "==Value:" + kvp.Value.dump(pfx2).TrimEnd('\r', '\n')); } } return(builder.ToString()); }
public override void dump(PrettyPrinter printer) { printer.addLine("[PyBuffer " + Data.Length + " bytes]" + PrettyPrinter.PrintRawData(this)); if (Data != null && (Data[0] == Unmarshal.HeaderByte || Data[0] == Unmarshal.ZlibMarker || Data[0] == 0x63)) { byte[] d = Data; if (d[0] == Unmarshal.ZlibMarker) { d = Zlib.Decompress(d); } if (d != null && (d[0] == Unmarshal.PythonMarker || d[0] == 0x63) && printer.decompilePython && d.Length > 60) { // We have a python file. Bytecode code = new Bytecode(); if (code.load(d, d[0] == 0x63)) { Python.PrettyPrinter pp = new Python.PrettyPrinter(); pp.indentLevel = printer.indentLevel + 1; pp.indent = printer.indent; code.dump(pp); printer.addLine(pp.dump); } } else if (d != null && d[0] == Unmarshal.HeaderByte) { Unmarshal un = new Unmarshal(); PyRep rep = un.Process(d); if (rep != null) { if (Data[0] == Unmarshal.ZlibMarker) { printer.addLine("<compressed-data>"); } printer.addItem(rep); } } } }
public override void dump(PrettyPrinter printer) { printer.addLine("[PyObjectEx " + (IsType2 ? "Type2" : "Normal") + "]" + PrettyPrinter.PrintRawData(this)); printer.indentLevel++; printer.addLine("Header:"); printer.addItem(Header); printer.addLine("List:"); foreach (var item in List) { printer.addItem(item); } printer.addLine("Dictionary:"); foreach (var kvp in Dictionary) { printer.indentLevel++; printer.addLine("Key:"); printer.addItem(kvp.Key); printer.addLine("Value:"); printer.addItem(kvp.Value); printer.indentLevel--; } printer.indentLevel--; }
public override string dump(string prefix) { string pfx1 = prefix + PrettyPrinter.Spacer; string pfx2 = pfx1 + PrettyPrinter.Spacer; string pfx3 = pfx2 + PrettyPrinter.Spacer + PrettyPrinter.Spacer; StringBuilder builder = new StringBuilder(); builder.AppendLine("[PyObjectEx " + (IsType2 ? "Type2" : "Normal") + "]" + PrettyPrinter.PrintRawData(this)); builder.AppendLine(pfx1 + "Header:"); PrettyPrinter.Print(builder, pfx2, Header); builder.AppendLine(pfx1 + "List:"); foreach (var item in List) { PrettyPrinter.Print(builder, pfx2, item); } builder.AppendLine(pfx1 + "Dictionary:"); foreach (var kvp in Dictionary) { PrettyPrinter.Print(builder, pfx2 + "Key:", kvp.Key); builder.AppendLine(pfx2 + "==Value:" + kvp.Value.dump(pfx3).TrimEnd('\r', '\n')); //PrettyPrinter.Print(builder, pfx2 + "==Value:", kvp.Value); } return(builder.ToString()); }
public override void dump(PrettyPrinter printer) { printer.addLine("[PyInt " + Value + "]"); }
public override void dump(PrettyPrinter printer) { printer.addLine("[PyChecksumedStream Checksum: " + Checksum + "]"); printer.addItem(Data); }
public override void dump(PrettyPrinter printer) { string name = "Unknown"; if (opCode == MarshalOpcode.StringEmpty) { name = "PyStringEmpty"; } else if (opCode == MarshalOpcode.StringChar) { name = "PyStringChar"; } else if (opCode == MarshalOpcode.WStringUTF8) { name = "PyWStringUTF8"; } else if (opCode == MarshalOpcode.WStringUCS2Char) { name = "PyWStringUCS2Char"; } else if (opCode == MarshalOpcode.WStringEmpty) { name = "PyWStringEmpty"; } else if (opCode == MarshalOpcode.WStringUCS2) { name = "PyWStringUCS2"; } else if (opCode == MarshalOpcode.StringShort) { name = "PyString"; } else if (opCode == MarshalOpcode.StringLong) { name = "PyString"; } else if (opCode == MarshalOpcode.StringTable) { name = "PyStringTable[" + tableIndex.ToString() + "]"; } bool printed = false; if (Raw.Length > 0 && (Raw[0] == (byte)Unmarshal.ZlibMarker || Raw[0] == (byte)Unmarshal.HeaderByte || Raw[0] == Unmarshal.PythonMarker || Raw[0] == 0x63)) { // We have serialized python data, decode and display it. byte[] d = Raw; if (d[0] == Unmarshal.ZlibMarker) { d = Zlib.Decompress(d); } if (d != null && (d[0] == Unmarshal.PythonMarker || d[0] == 0x63) && printer.decompilePython && d.Length > 60) { // We have a python file. Bytecode code = new Bytecode(); if (code.load(d, d[0] == 0x63)) { printer.addLine("[" + name); Python.PrettyPrinter pp = new Python.PrettyPrinter(); pp.indent = printer.indent; pp.indentLevel = printer.indentLevel + 1; code.dump(pp); printer.addLine(pp.dump); printer.addLine("]"); printed = true; } } else if (d != null && d[0] == Unmarshal.HeaderByte) { Unmarshal un = new Unmarshal(); un.analizeInput = decodedAnalized; PyRep obj = un.Process(d); if (obj != null) { string sType = "<serialized>"; if (Raw[0] == Unmarshal.ZlibMarker) { sType = "<serialized-compressed>"; } printer.addLine("[" + name + " " + sType); printer.addItem(obj); printer.addLine("]"); printed = true; } } } if (!printed) { if (!PrettyPrinter.containsBinary(Raw)) { printer.addLine("[" + name + " \"" + Value + "\"]"); } else { printer.addLine("[" + name + " \"" + Value + "\""); printer.indentLevel += 2; printer.addLine("<binary len=" + Value.Length + "> hex=\"" + PrettyPrinter.ByteArrayToString(Raw) + "\"]"); printer.indentLevel -= 2; } } }
public override void dump(PrettyPrinter printer) { printer.addLine(PrettyPrinter.PrintRawData(this)); }
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); }
public override void dump(PrettyPrinter printer) { printer.addLine("[PySubStruct]"); printer.addItem(Definition); }
public override void dump(PrettyPrinter printer) { printer.addLine("[PyNone]"); }
public override string dump(string prefix) { return("[PyToken " + Token + "]" + PrettyPrinter.PrintRawData(this)); }
public abstract void dump(PrettyPrinter printer);
public override void dump(PrettyPrinter printer) { printer.addLine("[PyToken " + Token + "]" + PrettyPrinter.PrintRawData(this)); }
public override string dump(string prefix) { if (Raw.Length > 0 && (Raw[0] == (byte)Unmarshal.ZlibMarker || Raw[0] == (byte)Unmarshal.HeaderByte)) { // We have serialized python data, decode and display it. string pfx1 = prefix + PrettyPrinter.Spacer; try { Unmarshal un = new Unmarshal(); PyRep obj = un.Process(Raw); if (obj != null) { string sType = "<serialized>"; if (Raw[0] == Unmarshal.ZlibMarker) { sType = "<serialized-compressed>"; } return("[PyString " + sType + Environment.NewLine + pfx1 + obj.dump(pfx1) + Environment.NewLine + prefix + "]"); } } catch (Exception) { } } if (!PrettyPrinter.containsBinary(Raw)) { return("[PyString \"" + Value + "\"]"); } else { return("[PyString \"" + Value + "\"" + Environment.NewLine + prefix + " <binary len=" + Value.Length + "> hex=\"" + PrettyPrinter.ByteArrayToString(Raw) + "\"]"); } }
public override string dump(string prefix) { return(PrettyPrinter.PrintRawData(this)); }
public override void dump(PrettyPrinter printer) { printer.addLine("[PyObject Name: " + Name + "]" + PrettyPrinter.PrintRawData(this)); printer.addItem(Arguments); }