def getNearestFunction(self, gdbSession, codeAddr, pid=None): if not self.addrBelongsToImage(gdbSession, codeAddr, pid): return None funcs = self.getFunctionsRebased(gdbSession, pid) funcs.sort() i = findItemInList(funcs, codeAddr)[0] return funcs[i]
def a2(traces, referenceTrace): """ Assumes the trace for the invalid command as fixed-point. Consists of the following steps: 1) Identify all nodes that are present in all graphs. 2) For each of those nodes identify all neighbors that are present in all traces. 3) Calculate a score for each node in the following way: For each neighbor in each trace that is not present in all traces a common function gets one point. 4) The score reflects the likelihood of each function to contain the command-dispatcher """ dgReference = referenceTrace.getDigraph() nodesReference = dgReference.nodes() nodesCommon = sets.Set(nodesReference) nodesCommon.discard(referenceTrace.getVirtualStartingNode()) # first get nodes present in all graphs graphs = [] for trace in traces: dgCmd = trace.getDigraph() nodesCommon = nodesCommon.intersection(dgCmd.nodes()) graphs.append(dgCmd) # now get the common neighbors for all common nodes neighborsCommon = {} for node in nodesCommon: neighborsCommon[node] = sets.Set(dgReference.neighbors(node)) for dgCmd in graphs: for node in neighborsCommon: neighborsCommon[node] = neighborsCommon[node].intersection(dgCmd.neighbors(node)) # finally calculate the 'variance of neighbors' for each node variances = {node:0 for node in neighborsCommon} for dgCmd in graphs: for node in neighborsCommon: neighborsCmd = sets.Set(dgCmd.neighbors(node)) neighborsDiff = neighborsCmd.difference(neighborsCommon[node]) variances[node] += len(neighborsDiff) from tools.algorithms import findItemInList values = [] keys = [] for node in variances: value = variances[node] i = findItemInList(values, value)[0] values = values[:i+1] + [value] + values[i+1:] keys = keys[:i+1] + [node] + keys[i+1:] return keys[::-1]