def a3(traces, referenceTrace, depth=-1): from tools import sequence, algorithms seqRef = sequence.Sequence(algorithms.removeRepetitions(referenceTrace.getNormalizedSequence(depth))) seqRef.removeAll(referenceTrace.getVirtualStartingNode()) seqs = [] for trace in traces: seq = sequence.Sequence(algorithms.removeRepetitions(trace.getNormalizedSequence(depth))) seq.removeAll(trace.getVirtualStartingNode()) seqs.append(seq) return DecisionNodeFinding._a3core(seqs, seqRef)
def a0(traces, referenceTrace): """ Assumes the trace for the invalid command as fixed-point. Consists of the following steps: 1) Normalizes all traces and removes repetitions. 2) Determines the largest common sub-sequence of the trace of the invalid command and each valid command. 3) Determines the largest common sub-sequence of all previously determined invalid command/command sub-sequences 4) Outputs the sequence determined in step 3) in reverse order. The first function in this output is likely to be the command-dispatcher. If not, it could likely be the functions at the subsequent positions. Functions should get a score depending on their position in the sequence (lower == better) and the overall lenght of the sequence (longer == better). If the returned list is empty, it is likely that the server-application in question does not possess a central command-dispatcher (maybe multiple for different commands or chained command-handlers with each having its own dispatcher). Possible further improvements: 1) If the length of the lcss drops significantly for a certain subseq, then this subseq should be left out, at the cost of a lower scoring for the result. @param traces: A list of function traces belonging to a certain protocol string @type traces: pygdb.trace.FunctionTrace @param referenceTrace: A trace """ from tools import sequence, algorithms seqRef = sequence.Sequence(algorithms.removeRepetitions(referenceTrace.getNormalizedSequence())) seqRef.removeAll(referenceTrace.getVirtualStartingNode()) subSeqsInvalid = [] for trace in traces: if trace is None: continue seq = sequence.Sequence(algorithms.removeRepetitions(trace.getNormalizedSequence())) seq.removeAll(trace.getVirtualStartingNode()) lcss = seqRef.findLargestCommonSubSequence(seq) if lcss is not None: subSeqsInvalid.append(lcss) if len(subSeqsInvalid) == 0: return [] lcss = subSeqsInvalid[0] for subSeqInvalid in subSeqsInvalid[1:]: if lcss is None: return [] lcss = lcss.findLargestCommonSubSequence(subSeqInvalid) if lcss is None: return [] return _Helper.normalizeScores({lcss.rawSeq[i] : i for i in range(len(lcss.rawSeq))})