mclf_loader.py 文件源码

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

项目:mclf-ida-loader 作者: ghassani 项目源码 文件源码
def load_file(f, neflags, format):
    f.seek(0)

    magic           = f.read(4);
    version         = struct.unpack("<I", f.read(4))[0];
    flags           = struct.unpack("<I", f.read(4))[0];
    memType         = struct.unpack("<I", f.read(4))[0];
    serviceType     = struct.unpack("<I", f.read(4))[0];
    numInstances    = struct.unpack("<I", f.read(4))[0];
    uuid            = struct.unpack("<IIII", f.read(16));
    driverId        = struct.unpack("<I", f.read(4))[0];
    numThreads      = struct.unpack("<I", f.read(4))[0];
    textVA          = struct.unpack("<I", f.read(4))[0];
    textLen         = struct.unpack("<I", f.read(4))[0];
    dataVA          = struct.unpack("<I", f.read(4))[0];
    dataLen         = struct.unpack("<I", f.read(4))[0];
    bssLen          = struct.unpack("<I", f.read(4))[0];
    entry           = struct.unpack("<I", f.read(4))[0];

    f.seek(MCLF_TEXT_INFO_OFFSET)

    idaapi.set_processor_type("arm", SETPROC_ALL)

    # Set VA for .text and add the segment
    f.file2base(0, textVA, textVA + textLen, True)
    idaapi.add_segm(0, textVA, textVA + textLen, ".text", "CODE")

    # Set VA for .data and add the segment
    f.file2base(MCLF_HEADER_SIZE_V23 + textLen, dataVA, dataVA + dataLen, True)
    idaapi.add_segm(0, dataVA, dataVA + dataLen, ".data", "DATA")

    # Add BSS segment after .text and .data
    idaapi.add_segm(0, dataVA + dataLen, dataVA + dataLen + bssLen, ".bss", "BSS")

    if entry % 4 == 1: 
        #Thumb address is always +1 to set the T bit
        idaapi.add_entry(entry-1, entry-1, "_entry", 1)
        SetRegEx(entry-1, "T", 0x1, SR_user);
    else:
        idaapi.add_entry(entry, entry, "_entry", 1)
        SetRegEx(entry, "T", 0x0, SR_user);

    MakeDword(tlApiLibEntry)
    MakeName(tlApiLibEntry,"tlApiLibEntry");
    return 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号