Skip to content

Instantly share code, notes, and snippets.

@4ft35t
Forked from Integ/unwxapkg.py
Created April 3, 2019 07:26
Show Gist options
  • Save 4ft35t/b2215423c75d678c8f00d5c88b02d96b to your computer and use it in GitHub Desktop.
Save 4ft35t/b2215423c75d678c8f00d5c88b02d96b to your computer and use it in GitHub Desktop.

Revisions

  1. @Integ Integ revised this gist Jan 2, 2018. 1 changed file with 70 additions and 78 deletions.
    148 changes: 70 additions & 78 deletions unwxapkg.py
    Original file line number Diff line number Diff line change
    @@ -1,85 +1,77 @@
    #!/usr/bin/env python2

    # lrdcq
    # usage python2 unwxapkg.py filename

    # coding: utf-8
    # py2 origin author lrdcq
    # usage python3 unwxapkg.py filename

    __author__ = 'Integ: https://github.com./integ'

    import sys, os
    import struct

    class WxapkgFile(object):
    nameLen = 0
    name = ""
    offset = 0
    size = 0

    class WxapkgFile(object):
    nameLen = 0
    name = ""
    offset = 0
    size = 0

    if len(sys.argv) < 2:
    print 'usage: unwxapkg.py filename'
    exit()

    print('usage: unwxapkg.py filename [output_dir]')
    exit()

    with open(sys.argv[1], "rb") as f:

    root = os.path.dirname(os.path.realpath(f.name))
    name = os.path.basename(f.name) + '_dir'

    if len(sys.argv) > 2:
    name = sys.argv[2]

    #read header

    firstMark = struct.unpack('B', f.read(1))[0]
    print 'first header mark = ' + str(firstMark)

    info1 = struct.unpack('>L', f.read(4))[0]
    print 'info1 = ' + str(info1)

    indexInfoLength = struct.unpack('>L', f.read(4))[0]
    print 'indexInfoLength = ' + str(indexInfoLength)

    bodyInfoLength = struct.unpack('>L', f.read(4))[0]
    print 'bodyInfoLength = ' + str(bodyInfoLength)

    lastMark = struct.unpack('B', f.read(1))[0]
    print 'last header mark = ' + str(lastMark)

    if firstMark != 0xBE or lastMark != 0xED:
    print 'its not a wxapkg file!!!!!'
    exit()

    fileCount = struct.unpack('>L', f.read(4))[0]
    print 'fileCount = ' + str(fileCount)

    #read index

    fileList = []

    for i in range(fileCount):

    data = WxapkgFile()
    data.nameLen = struct.unpack('>L', f.read(4))[0]
    data.name = f.read(data.nameLen)
    data.offset = struct.unpack('>L', f.read(4))[0]
    data.size = struct.unpack('>L', f.read(4))[0]

    print 'readFile = ' + data.name + ' at Offset = ' + str(data.offset)

    fileList.append(data)

    #save files

    for d in fileList:
    d.name = '/' + name + d.name
    path = root + os.path.dirname(d.name)

    if not os.path.exists(path):
    os.makedirs(path)

    w = open(root + d.name, 'w')
    f.seek(d.offset)
    w.write(f.read(d.size))
    w.close()

    print 'writeFile = ' + root + d.name

    f.close()
    root = os.path.dirname(os.path.realpath(f.name))
    name = os.path.basename(f.name) + '_dir'
    if len(sys.argv) > 2:
    name = sys.argv[2]

    #read header
    firstMark = struct.unpack('B', f.read(1))[0]
    print('first header mark = {}'.format(firstMark))

    info1 = struct.unpack('>L', f.read(4))[0]
    print('info1 = {}'.format(info1))

    indexInfoLength = struct.unpack('>L', f.read(4))[0]
    print('indexInfoLength = {}'.format(indexInfoLength))

    bodyInfoLength = struct.unpack('>L', f.read(4))[0]
    print('bodyInfoLength = {}'.format(bodyInfoLength))

    lastMark = struct.unpack('B', f.read(1))[0]
    print('last header mark = {}'.format(lastMark))

    if firstMark != 0xBE or lastMark != 0xED:
    print('its not a wxapkg file!!!!!')
    f.close()
    exit()

    fileCount = struct.unpack('>L', f.read(4))[0]
    print('fileCount = {}'.format(fileCount))

    #read index
    fileList = []
    for i in range(fileCount):
    data = WxapkgFile()
    data.nameLen = struct.unpack('>L', f.read(4))[0]
    data.name = f.read(data.nameLen)
    data.offset = struct.unpack('>L', f.read(4))[0]
    data.size = struct.unpack('>L', f.read(4))[0]
    print('readFile = {} at Offset = {}'.format(str(data.name, encoding = "utf-8"), data.offset))

    fileList.append(data)

    #save files
    for d in fileList:
    d.name = '/' + name + str(d.name, encoding = "utf-8")
    path = root + os.path.dirname(d.name)

    if not os.path.exists(path):
    os.makedirs(path)

    w = open(root + d.name, 'wb')
    f.seek(d.offset)
    w.write(f.read(d.size))
    w.close()

    print('writeFile = {}{}'.format(root, d.name))

    f.close()
  2. @feix feix revised this gist Jan 1, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions unwxapkg.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/usr/bin/env python2

    # lrdcq
    # usage python2 unwxapkg.py filename

    import sys, os
  3. @feix feix created this gist Dec 31, 2017.
    84 changes: 84 additions & 0 deletions unwxapkg.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    #!/usr/bin/env python2

    # usage python2 unwxapkg.py filename

    import sys, os
    import struct

    class WxapkgFile(object):
    nameLen = 0
    name = ""
    offset = 0
    size = 0


    if len(sys.argv) < 2:
    print 'usage: unwxapkg.py filename'
    exit()


    with open(sys.argv[1], "rb") as f:

    root = os.path.dirname(os.path.realpath(f.name))
    name = os.path.basename(f.name) + '_dir'

    if len(sys.argv) > 2:
    name = sys.argv[2]

    #read header

    firstMark = struct.unpack('B', f.read(1))[0]
    print 'first header mark = ' + str(firstMark)

    info1 = struct.unpack('>L', f.read(4))[0]
    print 'info1 = ' + str(info1)

    indexInfoLength = struct.unpack('>L', f.read(4))[0]
    print 'indexInfoLength = ' + str(indexInfoLength)

    bodyInfoLength = struct.unpack('>L', f.read(4))[0]
    print 'bodyInfoLength = ' + str(bodyInfoLength)

    lastMark = struct.unpack('B', f.read(1))[0]
    print 'last header mark = ' + str(lastMark)

    if firstMark != 0xBE or lastMark != 0xED:
    print 'its not a wxapkg file!!!!!'
    exit()

    fileCount = struct.unpack('>L', f.read(4))[0]
    print 'fileCount = ' + str(fileCount)

    #read index

    fileList = []

    for i in range(fileCount):

    data = WxapkgFile()
    data.nameLen = struct.unpack('>L', f.read(4))[0]
    data.name = f.read(data.nameLen)
    data.offset = struct.unpack('>L', f.read(4))[0]
    data.size = struct.unpack('>L', f.read(4))[0]

    print 'readFile = ' + data.name + ' at Offset = ' + str(data.offset)

    fileList.append(data)

    #save files

    for d in fileList:
    d.name = '/' + name + d.name
    path = root + os.path.dirname(d.name)

    if not os.path.exists(path):
    os.makedirs(path)

    w = open(root + d.name, 'w')
    f.seek(d.offset)
    w.write(f.read(d.size))
    w.close()

    print 'writeFile = ' + root + d.name

    f.close()