Exemple #1
0
 public PySubStream(byte[] data)
     : base(PyObjectType.SubStream)
 {
     RawData       = data;
     DataUnmarshal = new Unmarshal();
     Data          = DataUnmarshal.Process(data);
 }
Exemple #2
0
 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) + "\"]");
     }
 }
Exemple #3
0
        public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
        {
            uint len = source.ReadSizeEx();

            RawData       = source.ReadBytes((int)len);
            DataUnmarshal = new Unmarshal();
            Data          = DataUnmarshal.Process(RawData);
        }
Exemple #4
0
        public override void Decode(Unmarshal context, MarshalOpcode op)
        {
            uint len = context.reader.ReadSizeEx();

            RawData       = context.reader.ReadBytes((int)len);
            DataUnmarshal = new Unmarshal();
            DataUnmarshal.analizeInput = context.analizeInput;
            Data = DataUnmarshal.Process(RawData);
        }
Exemple #5
0
        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());
        }
Exemple #6
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);
             }
         }
     }
 }
Exemple #7
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;
                }
            }
        }
Exemple #8
0
        public static T Process <T>(byte[] data) where T : class
        {
            var un = new Unmarshal();

            return(un.Process(data) as T);
        }