fwunpack.py 文件源码

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

项目:binaryanalysis 作者: armijnhemel 项目源码 文件源码
def searchUnpackIHex(filename, tempdir=None, blacklist=[], offsets={}, scanenv={}, debug=False):
    hints = {}
    tags = []
    diroffsets = []
    counter = 1
    filesize = os.stat(filename).st_size

    tmpdir = dirsetup(tempdir, filename, "ihex", counter)
    tmpfile = tempfile.mkstemp(dir=tmpdir)
    datafile = open(filename, 'r')
    foundend = False
    offset = 0
    for d in datafile:
        if foundend:
            os.fdopen(tmpfile[0]).close()
            datafile.close()
            os.rmdir(tmpdir)
            return (diroffsets, blacklist, tags, hints)
        b = d.strip()
        if not b.startswith(':'):
            if not b.startswith('#'):
                break
        if len(b) < 3:
            break
        bytecount = ord(b[1:3].decode('hex'))
        address = struct.unpack('>H', b[3:7].decode('hex'))
        recordtype = ord(b[7:9].decode('hex'))
        if recordtype == 1:
            foundend = True
            break
        if recordtype != 0:
            continue
        databytes = b[9:9+bytecount*2].decode('hex')
        os.write(tmpfile[0], databytes)
    os.fdopen(tmpfile[0]).close()
    datafile.close()
    diroffsets.append((tmpdir, offset, filesize))
    blacklist.append((offset, offset + filesize))
    return (diroffsets, blacklist, tags, hints)

## sometimes MP3 audio files are embedded into binary blobs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号