Exemplo n.º 1
0
 public PyRep Process(byte[] data)
 {
     if (data == null)
     {
         return(null);
     }
     if (data[0] == ZlibMarker)
     {
         data = Zlib.Decompress(data);
     }
     return(Process(new BinaryReader(new MemoryStream(data), Encoding.ASCII)));
 }
Exemplo n.º 2
0
 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);
             }
         }
     }
 }
Exemplo n.º 3
0
        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;
                }
            }
        }