def track_ioctls(ioctls):
    global ioctl_tracker
    for addr, ioctl_code in ioctls:
        ioctl_tracker.add_ioctl(addr, ioctl_code)
        define = ioctl_decoder.get_define(ioctl_code)
        make_comment(addr, define)
    ioctl_tracker.print_table(ioctls)
def decode_all_ioctls():
    """Attempts to locate all the IOCTLs in a function and decode them all"""

    global ioctl_tracker
    ioctls = find_all_ioctls()
    for addr, ioctl_code in ioctls:
        define = ioctl_decoder.get_define(ioctl_code)
        make_comment(addr, define)
    ioctl_tracker.print_table(ioctls)
 def activate(self, ctx):
     pos = idc.ScreenEA()
     # Get current comment for this instruction and remove the C define from it, if present
     comment = idc.Comment(pos)
     code = get_operand_value(pos)
     define = ioctl_decoder.get_define(code)
     comment = comment.replace(define, "")
     idc.MakeComm(pos, comment)
     # Remove the ioctl from the valid list and add it to the invalid list to avoid 'find_all_ioctls' accidently re-indexing it.
     ioctl_tracker.remove_ioctl(pos)
예제 #4
0
def get_all_defines():
    """Returns the C defines for all ICOTL codes which have been marked during the current session"""

    global ioctl_tracker
    defines = []
    for inst in ioctl_tracker.ioctl_locs:
        value = get_operand_value(inst)
        define = ioctl_decoder.get_define(value)
        defines.append(define)
    return defines
def get_position_and_translate():
    """
    Gets the current selected address and decodes the second parameter to the instruction if it exists/is an immediate
    then adds the C define for the code as a comment and prints a summary table of all decoded IOCTL codes.
    """

    pos = idc.ScreenEA()
    if idc.GetOpType(pos, 1) != 5:   # Check the second operand to the instruction is an immediate
        return
    ioctl_tracker.add_ioctl(pos)
    value = get_operand_value(pos)
    define = ioctl_decoder.get_define(value)
    make_comment(pos, define)
    # Print summary table each time a new IOCTL code is decoded
    ioctls = []
    for inst in ioctl_tracker.ioctl_locs:
        value = get_operand_value(inst)
        ioctls.append((inst, value))
    ioctl_tracker.print_table(ioctls)
예제 #6
0
def get_all_defines():
    """Returns the C defines for all ICOTL codes which have been marked during the current session"""

    global ioctl_tracker
    defines = []
    for (addr, value) in ioctl_tracker.ioctls:
        function = ioctl_decoder.get_function(value)
        device_name, device_code = ioctl_decoder.get_device(value)
        method_name, method_code = ioctl_decoder.get_method(value)
        access_name, access_code = ioctl_decoder.get_access(value)
        define = ioctl_decoder.get_define(value)
        defines.append([
            "0x%X" % (addr, ),
            "0x%X" % (function, ),
            "%s (0x%X)" % (device_name, device_code),
            "%s (0x%X)" % (method_name, method_code),
            "%s (0x%X)" % (access_name, access_code), define
        ])
    return defines