Example #1
0
def readObjectFromFile(filename):    
    file = open(filename,'r')
    
    xstream=XStream(DomDriver()) 
    object=xstream.fromXML(file.read())
    
    file.close()
    
    return object
Example #2
0
    def execute(self, data):
        if not self.is_jython:
            print '[!] This module can only be used in jython!'
            return data

        # Creating XStream object and creating Java object from XML structure
        xs = XStream()
        serial = xs.fromXML(data)

        # writing created Java object to and serializing it with ObjectOutputStream
        bos = io.ByteArrayOutputStream()
        oos = io.ObjectOutputStream(bos)
        oos.writeObject(serial)

        # I had a problem with signed vs. unsigned bytes, hence the & 0xff
        return "".join([chr(x & 0xff) for x in bos.toByteArray().tolist()])
Example #3
0
    def serializeData(self):
        """
        Serialize data, put the result inside self.output
        """
        self.output = '\xAC\xED\x00\x05'

        for type_, data in self.input:
            print type_
            print data
            print len(data)

            if type_ == 'object':

                # Create XStream object and create Java object from the XML structure
                xs = XStream()
                serialized = xs.fromXML(data)

                # Serialize created object with ObjectOutputStream
                bos = io.ByteArrayOutputStream()
                oos = io.ObjectOutputStream(bos)
                oos.writeObject(serialized)

                self.output += bos.toByteArray()[4:]

            elif type_ == 'block':

                # TC_BLOCKDATA = (byte)0x77
                if len(data) <= 0xff:
                    self.output += '\x77'
                    self.output += struct.pack('<B',
                                               len(data))  # length on 1 byte

                # TC_BLOCKDATALONG = (byte)0x7A
                else:
                    self.output += '\x7A'
                    self.output += struct.pack(
                        '>I', len(data))  # length on 4 bytes (big endian)

                self.output += ''.join(
                    list(map(lambda x: chr(int(x, 16)), data)))