From e24d8c21a3ce9c0ae36c65ac790f564f7bd59885 Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Sun, 17 Jul 2016 01:24:05 +0200 Subject: [PATCH] DBG: various fixes in RecursiveAnalysis --- src/dbg/analysis/recursiveanalysis.cpp | 21 +++++++++++++++++++-- src/dbg/instruction.cpp | 1 - 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/dbg/analysis/recursiveanalysis.cpp b/src/dbg/analysis/recursiveanalysis.cpp index d50029af..25bfd26f 100644 --- a/src/dbg/analysis/recursiveanalysis.cpp +++ b/src/dbg/analysis/recursiveanalysis.cpp @@ -33,6 +33,8 @@ void RecursiveAnalysis::SetMarkers() duint icount = 0; for(const auto & node : function.nodes) { + if(!inRange(node.second.start)) + continue; icount += node.second.icount; start = min(node.second.start, start); end = max(node.second.end, end); @@ -64,11 +66,18 @@ void RecursiveAnalysis::analyzeFunction(duint entryPoint) { auto start = queue.front(); queue.pop(); - if(visited.count(start) || !inRange(start)) //already visited or out of range + if(visited.count(start)) //already visited continue; visited.insert(start); CFNode node(graph.entryPoint, start, start); + + if(!inRange(start)) //out of range + { + graph.AddNode(node); + continue; + } + while(true) { node.icount++; @@ -151,7 +160,7 @@ void RecursiveAnalysis::analyzeFunction(duint entryPoint) addr += size; } } - //third pass: correct the parents + add brtrue and brfalse to the exits + //third pass: correct the parents + add brtrue and brfalse to the exits + get data graph.parents.clear(); for(auto & nodeIt : graph.nodes) { @@ -162,6 +171,14 @@ void RecursiveAnalysis::analyzeFunction(duint entryPoint) node.exits.push_back(node.brtrue); if(node.brfalse) node.exits.push_back(node.brfalse); + if(node.brtrue && !node.brfalse) + node.brtrue = 0; + if(!node.icount) + continue; + auto size = node.end - node.start + (mCp.Disassemble(node.end, translateAddr(node.end)) ? mCp.Size() : 1); + node.data.resize(size); + for(duint i = 0; i < size; i++) + node.data[i] = inRange(node.start + i) ? *translateAddr(node.start + i) : 0x90; } mFunctions.push_back(graph); } diff --git a/src/dbg/instruction.cpp b/src/dbg/instruction.cpp index bddb8730..3be6c1e6 100644 --- a/src/dbg/instruction.cpp +++ b/src/dbg/instruction.cpp @@ -2804,7 +2804,6 @@ CMDRESULT cbInstrGraph(int argc, char* argv[]) } RecursiveAnalysis analysis(base, size, entry, 0); analysis.Analyse(); - analysis.SetMarkers(); auto graph = analysis.GetFunctionGraph(entry); if(!graph) {