fwunpack.py 文件源码

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

项目:binaryanalysis 作者: armijnhemel 项目源码 文件源码
def searchUnpackKnownBzip2(filename, tempdir=None, scanenv={}, debug=False):
    ## first check if the file actually could be a valid gzip file
    bzip2file = open(filename, 'rb')
    bzip2file.seek(0)
    bzip2header = bzip2file.read(3)
    bzip2file.close()
    if bzip2header != fsmagic.fsmagic['bz2']:
        return ([], [], [], {})

    ## then try unpacking it.
    res = searchUnpackBzip2(filename, tempdir, [], {'bz2': [0]}, scanenv, debug)
    (diroffsets, blacklist, newtags, hints) = res

    failed = False
    ## there were results, so check if they were successful
    if diroffsets != []:
        if len(diroffsets) != 1:
            failed = True
        else:
            (dirpath, startoffset, endoffset) = diroffsets[0]
            if startoffset != 0 or endoffset != os.stat(filename).st_size:
                failed = True

        if failed:
            for i in diroffsets:
                (dirpath, startoffset, endoffset) = i
                try:
                    shutil.rmtree(dirpath)
                except:
                    pass
            return ([], [], [], {})
        else:
            return (diroffsets, blacklist, newtags, hints)
    return ([], [], [], {})

## search and unpack bzip2 compressed files
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号