예제 #1
0
파일: insn.py 프로젝트: jkoppel/Revitalize
 def to_masm(self):
     if self.verbatim:
         return "\t%s" % (idaapi.tag_remove(
             idaapi.generate_disasm_line(self.ea)))
     else:
         return "\t%s  %s" % (idaapi.ua_mnem(self.ea), ", ".join(
             map(lambda e: e.to_masm(), self.ops)))
예제 #2
0
def instruction(ea):
    insn = idaapi.generate_disasm_line(ea)
    unformatted = idaapi.tag_remove(insn)
    nocomment = unformatted[:unformatted.rfind(';')]
    return reduce(
        lambda t, x: t + (('' if t.endswith(' ') else ' ')
                          if x == ' ' else x), nocomment, '')
예제 #3
0
def disasm(ea, count=1):
    res = []
    while count > 0:
        insn = idaapi.generate_disasm_line(ea)
        unformatted = idaapi.tag_remove(insn)
        nocomment = unformatted[:unformatted.rfind(';')] if ';' in unformatted else unformatted
        res.append( '{:x}: {:s}'.format(ea, reduce(lambda t,x: t + (('' if t.endswith(' ') else ' ') if x == ' ' else x), nocomment, '')) )
        ea = next(ea)
        count -= 1
    return '\n'.join(res)
예제 #4
0
    def getInsn(self, ea):
        mnem = idaapi.generate_disasm_line(ea).split(' ', 1)[0][2:-2]

        ops = []
        for i in range(6):
            op = idc.GetOpnd(ea, i)
            if not op:
                break

            ops.append(op)

        return mnem, tuple(ops), idautils.CodeRefsFrom(ea, True)
예제 #5
0
파일: IDA.py 프로젝트: daeken/daebrain
 def getInsn(self, ea):
     mnem = idaapi.generate_disasm_line(ea).split(' ', 1)[0][2:-2]
     
     ops = []
     for i in range(6):
         op = idc.GetOpnd(ea, i)
         if not op:
             break
         
         ops.append(op)
     
     return mnem, tuple(ops), idautils.CodeRefsFrom(ea, True)
예제 #6
0
 def __init__(self, ea):
     self.ea = ea
     self.columns = []
     if not isCode(GetFlags(ea)):
         MakeCode(ea)
     t = idaapi.generate_disasm_line(ea)
     if t:
         line = idaapi.tag_remove(t)
     else:
         line = ""
     self.columns.append ("%08X" % ea)
     n = SegName(ea)
     self.columns.append (n)
     self.columns.append (line)
예제 #7
0
 def __init__(self, ea):
     self.ea = ea
     if not isCode(GetFlags(ea)):
         MakeCode(ea)
     t = idaapi.generate_disasm_line(ea)
     if t:
         line = idaapi.tag_remove(t)
     else:
         line = ""
     func = GetFunctionName(ea)
     self.display = hex(ea) + ": "
     if func:
         self.display += func + ": "
     else:
         n = SegName(ea)
         if n: self.display += n + ": "
     self.display += line
예제 #8
0
 def __init__(self, ea):
     self.ea = ea
     if not isCode(GetFlags(ea)):
         MakeCode(ea)
     t = idaapi.generate_disasm_line(ea)
     if t:
         line = idaapi.tag_remove(t)
     else:
         line = ""
     func = GetFunctionName(ea)
     self.display = hex(ea) + ": "
     if func:
         self.display += func + ": "
     else:
         n = SegName(ea)
         if n: self.display += n + ": "
     self.display += line
예제 #9
0
def startarm():
	curEA = idc.ScreenEA()
	isCont = 1
	while isCont:
		t = idaapi.generate_disasm_line(curEA)
		if t:
			line = idaapi.tag_remove(t)
		else:
			line = ""
		str = AskStr(line,"Address :"+hex(curEA)+"\nInstruction")
		if str:
			try:
				arm(curEA,str)
				curEA = curEA + 4
			except InputError as e:
				print e.msg
		else:
			isCont = 0
예제 #10
0
 def __init__(self, ea):
     self.ea = ea
     if not is_code(get_flags(ea)):
         create_insn(ea)
     t = idaapi.generate_disasm_line(ea)
     if t:
         line = idaapi.tag_remove(t)
     else:
         line = ""
     func = get_func_name(ea)
     self.display = ""
     if func:
         self.display += func + ": "
     else:
         n = get_segm_name(ea)
         if n:
           self.display += n + ": "
     self.display += line
예제 #11
0
    def _data(self):
        flow_chart = idaapi.FlowChart(idaapi.get_func(self.offset))

        nodes = {}
        for node in flow_chart:
            assembly = [
                idaapi.generate_disasm_line(ea)
                for ea in idautils.Heads(node.startEA, node.endEA)
            ]
            successive_nodes = [succ.id for succ in node.succs()]
            serialized_node = {
                'id': node.id,
                'type': node.type,
                'start': node.startEA,
                'end': node.endEA,
                'successive': successive_nodes,
                'assembly': assembly
            }
            nodes[node.id] = serialized_node

        return nodes
예제 #12
0
def disasm(ea=None, count=1, **options):
    """disassemble ``count`` instructions starting at ``ea``.

    If the keyword ``comments`` is True, then also display the comments for each line of the disassembly.
    """
    res = []
    ea = ui.current.address() if ea is None else ea
    while count > 0:
        insn = idaapi.generate_disasm_line(ea)
        unformatted = idaapi.tag_remove(insn)
        nocomment = unformatted[:unformatted.
                                rfind(';'
                                      )] if ';' in unformatted and options.get(
                                          'comments', False) else unformatted
        res.append('{:x}: {:s}'.format(
            ea,
            reduce(
                lambda t, x: t + (('' if t.endswith(' ') else ' ')
                                  if x == ' ' else x), nocomment, '')))
        ea = next(ea)
        count -= 1
    return '\n'.join(res)
예제 #13
0
def create_func_signature(start, length):
    """Return function signature in mega format."""
    if length < MIN_SIG_LENGTH:
        return

    ea = start
    end = start + length
    sig = ""
    publics = []
    refs = {}
    v = [False for _ in range(length)]

    while (ea - start < length):
        flags = idaapi.getFlags(ea)
        if idaapi.has_name(flags):
            publics.append(ea)

        ref = idaapi.get_first_dref_from(ea)
        if ref != idaapi.BADADDR:
            ref_loc = ea
            set_v_bytes(v, ref_loc - start)
            refs[ref_loc] = ref

            # Check if there is a second data location ref'd
            ref = idaapi.get_next_dref_from(ea, ref)
            if ref != idaapi.BADADDR:
                ref_loc = ea
                set_v_bytes(v, ref_loc - start)
                refs[ref_loc] = ref
        else:
            # Code ref?
            ref = idaapi.get_first_fcref_from(ea)
            if ref != idaapi.BADADDR:
                if not start <= ref < end:
                    ref_loc = ea
                    set_v_bytes(v, ref_loc - start)
                    refs[ref_loc] = ref

            # Check for r13 and rtoc
            disasm = idaapi.generate_disasm_line(ea)
            if "%r13" in disasm or "%rtoc" in disasm:
                ref_loc = ea
                set_v_bytes(v, ref_loc - start)

        ea = idaapi.next_not_tail(ea)

    line = ""
    for i in range(length):
        if v[i]:
            line += ".."
        else:
            line += "{:02X}".format(idaapi.get_byte(start + i))

    # Write publics
    found = False
    for public in sorted(publics):
        name = idaapi.get_true_name(idaapi.BADADDR, public)
        if name:
            found = True
            if is_skipped(name):
                idaapi.warning("Rename the function {} ({})!".format(
                    name, "it is on the skip list"))
                return
            else:
                line += " :{:04X} {}".format(public - start, name)

    if not found:
        idaapi.warning("The function has autogenerated name, rename it first!")

    # Write refs
    for ref_loc, ref in sorted(refs.items()):
        name = idaapi.get_true_name(idaapi.BADADDR, ref)
        if name:
            if not is_skipped(name) and ref_loc != idaapi.BADADDR:
                line += " ^{:04X} {}".format(ref_loc - start, name)

    return line
예제 #14
0
 def to_masm(self):
     if self.verbatim:
         return "\t%s" % (idaapi.tag_remove(idaapi.generate_disasm_line(self.ea)))
     else:
         return "\t%s  %s" % (idaapi.ua_mnem(self.ea), ", ".join(map(lambda e: e.to_masm(), self.ops)))
예제 #15
0
def instruction(ea):
    insn = idaapi.generate_disasm_line(ea)
    unformatted = idaapi.tag_remove(insn)
    nocomment = unformatted[:unformatted.rfind(';')]
    return reduce(lambda t,x: t + (('' if t.endswith(' ') else ' ') if x == ' ' else x), nocomment, '')