__author__ = 'Andy'
import struct
class UnzipDEX():

    def Init_dexHeader(self):
        self.dexcontent = open(r"d:\sample_tx\9.09\e7fea6a5abdaf57b131d6e1fb30a7e49\classes.dex", 'rb').read()
        #   (
        #     self.header_magic,
        #     self.header_checksum,
        #     self.header_signature,
        #     self.header_fileSize,
        #     self.header_headerSize,
        #     self.header_endianTag,
        #     self.header_linkSize,
        #     self.header_linkOff,
        #     self.header_mapOff,
        #     self.header_stringIdsSize,
        #     self.header_stringIdsOff,
        #     self.header_typeIdsSize,
        #     self.header_typeIdsOff,
        #     self.header_protoIdsSize,
        #     self.header_protoIdsOff,
        #     self.header_fieldIdsSize,
        #     self.header_fieldIdsOff,
        #     self.header_methodIdsSize,
        #     self.header_methodIdsOff,
        #     self.header_classDefsSize,
        #     self.header_classDefsOff,
        #     self.header_dataSize,
        #     self.header_dataOff
        # ) = struct.unpack("<8si20s20i", self.dexcontent[0:112])
        stname = struct.unpack("8c4b20s20i", self.dexcontent[0:112])
        #stname = struct.pack('!BQ', self.dexcontent[0:112])
        print stname


    def MMM(self):
        infile = file(r"d:\sample_tx\9.09\e7fea6a5abdaf57b131d6e1fb30a7e49\classes.dex", "rb")
        outfile = file(r"d:\sample_tx\9.09\e7fea6a5abdaf57b131d6e1fb30a7e49\result.txt", "wb")
        infile.seek(0, 1)
        byte = infile.read(8)
        hexstr =  "%s" % byte.encode('hex')
        print hexstr
        #infile.seek(4, 1)
        byte = infile.read(4)
        hexstr =  "%s" % byte.encode('hex')
        # mystr=list(hexstr)
        # mystr.reverse()
        # mystr="".join(mystr)
        print hexstr
        # while True:
        #     byte = infile.read(8)
        #     if byte == '':
        #         break
        #     else:
        #         hexstr =  "%s" % byte.encode('hex')
        #         #decnum = int(hexstr, 16)
        #         outfile.write(hexstr)
        #     #print byte, hexstr, decnum
        infile.close()
        outfile.close()


if __name__ == "__main__":
    obj = UnzipDEX()
    #obj.Init_dexHeader()
    obj.MMM()

