def main():
    filename = idaapi.askfile_c(0, "pintool.log", "Trace file to load.")
    #filename = RECOVERER_PATH + "\\pintool.log"
    if filename is None:
        idaapi.msg("Aborting ...\n")

    # Get loaded binary name
    image_name = idc.GetInputFile().lower()
    idaapi.msg("Binary name %s\n" % image_name)
        
    # Get the image base
    image_base = idaapi.get_imagebase()
    idaapi.msg("Binary base 0x%.8x\n" % image_base)

    analyzer = TraceReader(filename)
    analyzer.parse(match_events="XL") # Allow X (resolved branches) and L (load library)
    
    resolver = AddressResolver(analyzer.getLoadedImages())
    
    resolved = []

    # get a list of all the resolved branches 
    for x in analyzer.getResolvedBranches():
        ins_addr = resolver.getAddress(x.ins_addr, image_base, image_name)
        branch_addr = resolver.getAddress(x.branch_addr, image_base, image_name)
        
        # Second element of the tuple indicates that it could resolve the address.
        if ins_addr[1] == True:
            resolved.append((ins_addr[0], branch_addr[0]))
            
    rb_dialog = ResolvedBranchesDialog(resolved)
    rb_dialog.show()
    
    ins2branches = {}
    for (ins_addr, branch_addr) in resolved:
        ins2branches.setdefault(ins_addr, set()).add(branch_addr)
    
    for ins_addr, branches in ins2branches.iteritems():
        comment = "\nResolved branches:\n"
        for branch in branches:
            comment += "%s : %.8x\n" % (GetAddressName(branch), branch)

            # Check if we already have a cross reference
            if ins_addr in [ref.frm for ref in XrefsTo(branch, 0)]:
                continue
            
            if AddCodeXref(ins_addr, branch, fl_CN) != True:
                idaapi.msg("Could not create cross reference from %x to %x\n" %(ins_addr, branch))
            
        idc.MakeComm(ins_addr, comment)
    
    """
Beispiel #2
0
    def __init__(self, reached_functions):
        Choose2.__init__(self, "Functions reached",
                         [["Address", 16], ["Name", 16]])
        self.n = 0

        self.items = []
        for value in reached_functions:
            self.items += [self.make_item(value, GetAddressName(value))]

        self.icon = 0
        self.selcount = 0
        self.deflt = -1
        self.popup_names = ["NOSE"]
Beispiel #3
0
    def __export_functions__(self):
        # Loop from start to end in the current segment
        for funcea in Functions():
            func = get_func(funcea)

            cconv = guess_calling_conv(func)
            if cconv == CCONV_INVALID:
                print "Skiping function 0x%.8x, it has no clear start basic block" % func.startEA
                continue

            self.fd.write(
                "F;0x%x;0x%x;0x%x;%s\n" %
                (func.startEA - self.image_base, func.endEA - self.image_base,
                 cconv, GetAddressName(func.startEA)))

            # Export all the basic blocks
            for block in idaapi.FlowChart(func):
                self.fd.write(
                    "B;0x%x;0x%x;0x%x;0x%x\n" %
                    (func.startEA - self.image_base, block.startEA -
                     self.image_base, block.endEA - self.image_base, block.id))
Beispiel #4
0
    def __export_imports__(self):
        imports = []

        def imp_cb(ea, name, ord):
            if name:
                imports.append(ea)

            # True -> Continue enumeration
            # False -> Stop enumeration
            return True

        nimps = idaapi.get_import_module_qty()

        for i in xrange(0, nimps):
            name = idaapi.get_import_module_name(i)
            if not name:
                continue

            idaapi.enum_import_names(i, imp_cb)

        for imp in imports:
            self.fd.write("I;0x%x;%s\n" %
                          (imp - self.image_base, GetAddressName(imp)))
Beispiel #5
0
    def export(self, resolved_branches):
        dict_ = {}
        for r in resolved_branches:
            dict_.setdefault(r[0], set()).add(r[1])

        for key, val in dict_.iteritems():
            prev_comment = idc.GetCommentEx(key, False)

            if not prev_comment or "Resolved:" in prev_comment:
                prev_comment = "Resolved:\n"

            for v in val:
                prev_comment += "%s : %.8x\n" % (GetAddressName(v), v)

                # Check if we already have a cross reference
                if key in [ref.frm for ref in XrefsTo(v, 0)]:
                    continue

                if AddCodeXref(key, v, fl_CN) != True:
                    idaapi.msg(
                        "Could not create cross reference from %x to %x\n" %
                        (key, v))

            idc.MakeComm(key, prev_comment)
 def make_item(self, branch_address, branch_target):
     r = ["0x%08x" % branch_address, "0x%08x" % branch_target, GetAddressName(branch_target), GetDisasm(branch_address).split(";")[0]]
     self.n += 1
     return r
Beispiel #7
0
 def make_item(self, function_address):
     r = ["0x%08x" % function_address, GetAddressName(function_address)]
     self.n += 1
     return r