Skip to content

Instantly share code, notes, and snippets.

@LeryLee
Forked from zergtant/unwxapkg2.py
Created January 4, 2018 14:06
Show Gist options
  • Save LeryLee/d4b625e673c085da3f682ac2bcaf8d08 to your computer and use it in GitHub Desktop.
Save LeryLee/d4b625e673c085da3f682ac2bcaf8d08 to your computer and use it in GitHub Desktop.

Revisions

  1. @zergtant zergtant revised this gist Jan 3, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion unwxapkg3.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/python

    # usage python unwxapkg.py filename

    # python3版本
    import sys, os
    import struct

  2. @zergtant zergtant revised this gist Jan 3, 2018. 2 changed files with 85 additions and 0 deletions.
    File renamed without changes.
    85 changes: 85 additions & 0 deletions unwxapkg3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    #!/usr/bin/python

    # usage python unwxapkg.py filename

    import sys, os
    import struct


    class WxapkgFile:
    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)

    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.decode('utf-8') + ' at Offset = ' + str(data.offset))

    fileList.append(data)

    #save files
    #print(name)
    print(fileList)
    for d in fileList:
    path = root + '/' + name + '_'
    file_ = path + d.name.decode('utf-8')

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

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

    print ('writeFile = ' + file_)

    f.close()
  3. @thedreamwork thedreamwork created this gist May 11, 2017.
    82 changes: 82 additions & 0 deletions unwxapkg.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    #!/usr/bin/python

    # usage python unwxapkg.py filename

    import sys,os
    import struct

    class WxapkgFile:
    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)

    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()