fwunpack.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:binaryanalysis 作者: armijnhemel 项目源码 文件源码
def searchUnpackLzip(filename, tempdir=None, blacklist=[], offsets={}, scanenv={}, debug=False):
    hints = {}
    if not 'lzip' in offsets:
        return ([], blacklist, [], hints)
    if offsets['lzip'] == []:
        return ([], blacklist, [], hints)
    filesize = os.stat(filename).st_size
    if filesize < 5:
        return ([], blacklist, [], hints)
    diroffsets = []
    tags = []
    counter = 1
    for offset in offsets['lzip']:
        blacklistoffset = extractor.inblacklist(offset, blacklist)
        if blacklistoffset != None:
            continue
        ## sanity check, only versions 0 or 1 are supported
        lzipfile = open(filename, 'rb')
        lzipfile.seek(offset+4)
        lzipversion = lzipfile.read(1)
        lzipfile.close()
        if struct.unpack('<B', lzipversion)[0] > 1:
            continue
        tmpdir = dirsetup(tempdir, filename, "lzip", counter)
        (res, lzipsize) = unpackLzip(filename, offset, tmpdir)
        if res != None:
            diroffsets.append((res, offset, lzipsize))
            blacklist.append((offset, offset+lzipsize))
            counter = counter + 1
            if offset == 0 and lzipsize == filesize:
                tags.append("compressed")
                tags.append("lzip")
        else:
            ## cleanup
            os.rmdir(tmpdir)
    return (diroffsets, blacklist, tags, hints)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号