public CallGraph GenerateCallGraph() { var callGraph = new CallGraph(); callGraph.BeginRecording(); Console.WriteLine("Recording " + Elements.Count + " instructions in the call graph!"); var firstCall = Elements.First(); var lastCall = Elements.Last(); foreach (var instruction in Elements) { //if (instruction.Eip!=0) // Console.WriteLine("Found an instruction that's not at zero! It's at " + instruction.Eip); var instVersion = instruction as InstInstruction; if (instVersion != null) { callGraph.RecordInstructionCall(instVersion); } if (instruction.CpuTime > lastCall.CpuTime) { lastCall = instruction; } if (instruction.CpuTime < firstCall.CpuTime) { firstCall = instruction; } } callGraph.RecordFunctionCall(0, firstCall.CpuTime); foreach (var instruction in Elements.Where(i => i is InstInstruction).Cast <InstInstruction>()) { if (instruction.Nature == InstInstructionNature.FunctionCall) { callGraph.RecordFunctionCall(instruction.GetCalledAddress(), instruction.CpuTime); } else if (instruction.Nature == InstInstructionNature.FunctionReturn) { callGraph.RecordFunctionReturn(instruction.CpuTime); } } callGraph.RecordFunctionReturn(lastCall.CpuTime); callGraph.EndRecording(lastCall.CpuTime); return(callGraph); }
public CallGraph GenerateCallGraph() { var callGraph = new CallGraph(); callGraph.BeginRecording(); Console.WriteLine("Recording " + Elements.Count + " instructions in the call graph!"); if (Elements.Count == 0) { Console.WriteLine("No elements in this trace!"); callGraph.RecordFunctionCall(0, 0); callGraph.RecordFunctionReturn(1); callGraph.EndRecording(1); return(callGraph); } var firstCall = Elements.First(); var lastCall = Elements.Last(); callGraph.Annotations = Annotations; foreach (var instruction in Elements.Where(i => i is IDisasmElement)) { //if (instruction.Eip!=0) // Console.WriteLine("Found an instruction that's not at zero! It's at " + instruction.Eip); var instVersion = new InstInstruction(); instVersion.CpuTime = GetCallTime(instruction); instVersion.Eip = instruction.Eip; var disAsm = (instruction as IDisasmElement); if (disAsm != null) { instVersion.Instruction = disAsm.Disassembly; } else { instVersion.Instruction = "N/A"; } //if (instVersion != null) callGraph.RecordInstructionCall(instVersion); if (GetCallTime(instruction) > GetCallTime(lastCall)) { lastCall = instruction; } if (GetCallTime(instruction) < GetCallTime(firstCall)) { firstCall = instruction; } //Console.WriteLine("Recording instruction timing " + GetCallTime(instruction)); } //Console.WriteLine("Greatest instruction timing is " + GetCallTime(lastCall)); callGraph.RecordFunctionCall(0, GetCallTime(firstCall)); foreach (var instruction in Elements.Where(i => i is BranchElement).Cast <BranchElement>()) { if (instruction.BranchTypeName == BranchElement.BranchTypes.Call) { callGraph.RecordFunctionCall(instruction.ToEip, GetCallTime(instruction)); } else if (instruction.BranchTypeName == BranchElement.BranchTypes.Return) { callGraph.RecordFunctionReturn(GetCallTime(instruction)); } } callGraph.RecordFunctionReturn(GetCallTime(lastCall)); callGraph.EndRecording(GetCallTime(lastCall)); return(callGraph); }