Example #1
0
def _load_file(filename, ea, size, offset=0):
    path = os.path.abspath(filename)
    li = idaapi.open_linput(path, False)
    if not li:
        raise Exception, 'Unable to create loader_input_t : %s' % path
    res = idaapi.file2base(li, offset, ea, ea + size, True)
    idaapi.close_linput(li)
    return res
Example #2
0
def _load_file(filename, ea, size, offset=0):
    path = os.path.abspath(filename)
    li = idaapi.open_linput(path, False)
    if not li:
        raise Exception, 'Unable to create loader_input_t : %s'% path
    res = idaapi.file2base(li, offset, ea, ea+size, True)
    idaapi.close_linput(li)
    return res
Example #3
0
def _load_file(filename, ea, size, offset=0):
    path = os.path.abspath(filename)
    li = idaapi.open_linput(path, False)
    if not li:
        raise IOError("{:s}.load_file({!r}, {:x}, {:#x}) : Unable to create loader_input_t : {:s}".format(__name__, filename, ea, size, path))
    res = idaapi.file2base(li, offset, ea, ea+size, True)
    idaapi.close_linput(li)
    return res
Example #4
0
def __load_file(filename, ea, size, offset=0):
    path = os.path.abspath(filename)
    res = idaapi.open_linput(path, False)
    if not res:
        raise E.DisassemblerError(
            "{:s}.load_file({!r}, {:#x}, {:+#x}) : Unable to create loader_input_t from path \"{:s}\"."
            .format(__name__, filename, ea, size, path))
    ok = idaapi.file2base(res, offset, ea, ea + size, False)
    idaapi.close_linput(res)
    return ok
Example #5
0
def __load_file(filename, ea, size, offset=0):
    path = os.path.abspath(filename)

    # use IDA to open up the file contents
    # XXX: does IDA support unicode file paths?
    res = idaapi.open_linput(path, False)
    if not res:
        raise E.DisassemblerError(u"{:s}.load_file({!r}, {:#x}, {:+#x}) : Unable to create an `idaapi.loader_input_t` from path \"{:s}\".".format(__name__, filename, ea, size, path))

    # now we can write the file into the specified address as a segment
    ok = idaapi.file2base(res, offset, ea, ea+size, False)
    idaapi.close_linput(res)
    return ok
def __load_file(filename, ea, size, offset=0):
    path = os.path.abspath(filename)

    # use IDA to open up the file contents
    # XXX: does IDA support unicode file paths?
    res = idaapi.open_linput(path, False)
    if not res:
        raise E.DisassemblerError(
            u"{:s}.load_file({!r}, {:#x}, {:+#x}) : Unable to create an `idaapi.loader_input_t` from path \"{:s}\"."
            .format(__name__, filename, ea, size, path))

    # now we can write the file into the specified address as a segment
    ok = idaapi.file2base(res, offset, ea, ea + size, False)
    idaapi.close_linput(res)
    return ok
def map_metadata(file, addr):
    flags = 0
    flags |= 0x0001  # NEF_SEGS
    size = os.stat(file).st_size

    li = idaapi.open_linput(file, False)

    #print('li = %s' % str(li))

    rc = idaapi.load_binary_file(file, li, flags, 0, 0, addr, size)

    #print('rc = %d' % rc)

    names = [
        'stringLiteral',
        'stringLiteralData',
        'strings',
        'events',
        'properties',
        'methods',
        'parameterDefaultValues',
        'fieldDefaultValues',
        'fieldAndParameterDefaultValueData',
        'fieldMarshaledSizes',
        'parameters',
        'fields',
        'genericParameters',
        'genericParameterConstraints',
        'genericContainers',
        'nestedTypes',
        'interfaces',
        'vtableMethods',
        'interfaceOffsets',
        'typeDefinitions',
        'rgctxEntries',
        'images',
        'assemblies',
        'metadataUsageLists',
        'metadataUsagePairs',
        'fieldRefs',
        'referencedAssemblies',
        'attributesInfo',
        'attributeTypes',
    ]

    baseaddr = addr

    idc.MakeDword(addr + 0)
    idc.MakeNameEx(addr + 0, 'META_Sig', idc.SN_NOWARN | idc.SN_AUTO)
    idc.MakeDword(addr + 4)
    idc.MakeNameEx(addr + 0, 'META_Version', idc.SN_NOWARN | idc.SN_AUTO)

    for i in range(len(names)):
        descaddr = baseaddr + 8 + i * 8

        idc.MakeStruct(descaddr, 'OffsetAndCount')
        idc.MakeNameEx(descaddr, 'META_%sDesc' % names[i],
                       idc.SN_NOWARN | idc.SN_AUTO)

        dataaddr = baseaddr + idc.Dword(descaddr + 0)
        datasize = idc.Dword(descaddr + 4)

        idc.MakeNameEx(dataaddr, 'META_%s' % names[i],
                       idc.SN_NOWARN | idc.SN_AUTO)

    # string literal
    descaddr = idc.LocByName('META_stringLiteralDesc')
    size1 = idc.Dword(descaddr + 4)
    addr1 = idc.LocByName('META_stringLiteral')
    addr1end = addr1 + size1
    addr2 = idc.LocByName('META_stringLiteralData')

    #print('addr1: %X' % (addr1))
    #print('addr2: %X' % (addr2))

    while addr1 < addr1end:
        strsize = idc.Dword(addr1 + 0)
        stroff = idc.Dword(addr1 + 4)

        #print('%X - %X' % (addr2 + stroff, addr2 + stroff + strsize))

        idc.MakeStr(addr2 + stroff, addr2 + stroff + strsize)

        addr1 += 8

    idc.Jump(baseaddr)