Exemplo n.º 1
0
 def __call__(self):
     py_type = [Event.encode_bytes(t) for t in self.py_type]
     if len(py_type) == 3:
         py_type = py_type[1:]
     if len(py_type) >= 2:
         ida_typeinf.apply_type(None, py_type[0], py_type[1], self.ea,
                                ida_typeinf.TINFO_DEFINITE)
def set_function_prototype(func, proto):
    """Set the prototype of a given function with the given type

    :param func: Function where we will apply the prototype
    :type func: ida_funcs.func_t
    :param proto: prototype we will apply to the given function
    :type api_type: str
    """
    t = ida_typeinf.idc_parse_decl(None, proto, 0)
    ida_typeinf.apply_type(None, t[1], t[2], func.start_ea,
                           ida_typeinf.TINFO_DEFINITE)
Exemplo n.º 3
0
 def implement(self):
     py_type = [encode_bytes(t) for t in self._type]
     if len(py_type) == 3:
         py_type = py_type[1:]
     if len(py_type) >= 2:
         ida_typeinf.apply_type(
             None,
             py_type[0],
             py_type[1],
             self._ea,
             ida_typeinf.TINFO_DEFINITE,
         )
Exemplo n.º 4
0
 def implement(self):
     if self._is_make_data:
         ea, flags, tid, len = self._type.split(":")
         ida_bytes.create_data(int(ea), int(flags), int(len), int(tid))
     else:
         py_type = [encode_bytes(t) for t in self._type]
         if len(py_type) == 3:
             py_type = py_type[1:]
         if len(py_type) >= 2:
             ida_typeinf.apply_type(
                 None,
                 py_type[0],
                 py_type[1],
                 self._ea,
                 ida_typeinf.TINFO_DEFINITE,
             )
Exemplo n.º 5
0
 def __call__(self):
     py_type = [Event.encode_bytes(t) for t in self.py_type]
     if len(py_type) == 3:
         py_type = py_type[1:]
     if len(py_type) >= 2:
         try:
             ida_typeinf.apply_type(
                 None,
                 py_type[
                     0],  # DefaultEvent(type=event, event_type=ti_changed, ea=4278195233, py_type=['\x1b\x052', ''])
                 py_type[1],
                 self.ea,
                 ida_typeinf.TINFO_DEFINITE,
             )
         except:
             raise Exception(repr(py_type))
Exemplo n.º 6
0
 def __call__(self):
     py_type = [Event.encode_bytes(t) for t in self.py_type]
     if len(py_type) == 3:
         py_type = py_type[1:]
     if len(py_type) >= 2:
         if self.name:
             r = ida_struct.get_member_by_fullname(self.name)
             if r:
                 self.ea = r[0].id
         ida_typeinf.apply_type(
             None,
             GetTypeString(py_type[0]),
             py_type[1],
             self.ea,
             ida_typeinf.TINFO_DEFINITE,
         )
def set_function_prototype(func, proto):
    t = ida_typeinf.idc_parse_decl(None, proto, 0)
    ida_typeinf.apply_type(None, t[1], t[2], func.start_ea,
                           ida_typeinf.TINFO_DEFINITE)
 def __call__(self):
     py_type = [Event.encode_bytes(t) for t in self.py_type]
     ida_typeinf.apply_type(self.ea, tuple(py_type))
Exemplo n.º 9
0
    def activate(self, ctx):
        selection = idaapi.read_selection()
        if not selection[0]:
            return 0

        start = selection[1] - 1
        stop = selection[2] + 1

        print('Parsing selection between %X -> %X' % (start, stop))

        prefix = ida_kernwin.ask_str('', 0, 'Prefix')

        if prefix is not None:
            prefix = prefix.replace('/', '::')

        while True:
            name_address = ida_bytes.next_head(start, stop)

            if name_address == idaapi.BADADDR:
                break

            name_offset = ida_bytes.get_dword(name_address)

            name = ida_bytes.get_strlit_contents(name_offset, -1, 0)

            if prefix is not None:
                name = prefix + '::' + name

            signature_address = ida_bytes.next_head(name_address, stop)

            if signature_address == idaapi.BADADDR:
                break

            signature_offset = ida_bytes.get_dword(signature_address)

            signature = ida_bytes.get_strlit_contents(signature_offset, -1, 0)

            function_address = ida_bytes.next_head(signature_address, stop)

            if function_address == idaapi.BADADDR:
                break

            function_offset = ida_bytes.get_dword(function_address)

            if function_offset % 2 != 0:
                function_offset -= 1

            try:
                c_signature = JNINativeMethodSignature(name, signature).c
            except JNINativeMethodError:
                break

            start = function_address

            parsed_decl = ida_typeinf.idc_parse_decl(None, c_signature,
                                                     ida_typeinf.PT_SIL)

            if parsed_decl is None:
                return 0

            ida_typeinf.apply_type(None, parsed_decl[1], parsed_decl[2],
                                   function_offset, 1)

            ida_name.set_name(function_offset, name, ida_name.SN_FORCE)

        return 1