CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
98 lines
2.7 KiB
C++
98 lines
2.7 KiB
C++
// Example ParseAPI program; produces a graph (in DOT format) of the
|
|
// control flow graph of the provided binary.
|
|
//
|
|
// Improvements by E. Robbins (er209 at kent dot ac dot uk)
|
|
//
|
|
|
|
#include <algorithm>
|
|
#include <stdio.h>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <sstream>
|
|
#include "CodeObject.h"
|
|
#include "CFG.h"
|
|
|
|
using namespace std;
|
|
using namespace Dyninst;
|
|
using namespace ParseAPI;
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
map<Address, bool> seen;
|
|
vector<Function *> funcs;
|
|
SymtabCodeSource *sts;
|
|
CodeObject *co;
|
|
|
|
// Create a new binary code object from the filename argument
|
|
sts = new SymtabCodeSource( argv[1] );
|
|
co = new CodeObject( sts );
|
|
|
|
// Parse the binary
|
|
co->parse();
|
|
cout << "digraph G {" << endl;
|
|
|
|
// Print the control flow graph
|
|
const CodeObject::funclist& all = co->funcs();
|
|
auto fit = all.begin();
|
|
for(int i = 0; fit != all.end(); ++fit, i++) { // i is index for clusters
|
|
Function *f = *fit;
|
|
|
|
// Make a cluster for nodes of this function
|
|
cout << "\t subgraph cluster_" << i
|
|
<< " { \n\t\t label=\""
|
|
<< f->name()
|
|
<< "\"; \n\t\t color=blue;" << endl;
|
|
|
|
cout << "\t\t\"" << hex << f->addr() << dec
|
|
<< "\" [shape=box";
|
|
if (f->retstatus() == NORETURN)
|
|
cout << ",color=red";
|
|
cout << "]" << endl;
|
|
|
|
// Label functions by name
|
|
cout << "\t\t\"" << hex << f->addr() << dec
|
|
<< "\" [label = \""
|
|
<< f->name() << "\\n" << hex << f->addr() << dec
|
|
<< "\"];" << endl;
|
|
|
|
stringstream edgeoutput;
|
|
|
|
auto bit = f->blocks().begin();
|
|
for( ; bit != f->blocks().end(); ++bit) {
|
|
Block *b = *bit;
|
|
// Don't revisit blocks in shared code
|
|
if(seen.find(b->start()) != seen.end())
|
|
continue;
|
|
|
|
seen[b->start()] = true;
|
|
|
|
cout << "\t\t\"" << hex << b->start() << dec <<
|
|
"\";" << endl;
|
|
|
|
auto it = b->targets().begin();
|
|
for( ; it != b->targets().end(); ++it) {
|
|
if(!*it) continue;
|
|
std::string s = "";
|
|
if((*it)->type() == CALL)
|
|
s = " [color=blue]";
|
|
else if((*it)->type() == RET)
|
|
s = " [color=green]";
|
|
|
|
// Store the edges somewhere to be printed outside of the cluster
|
|
edgeoutput << "\t\""
|
|
<< hex << (*it)->src()->start()
|
|
<< "\" -> \""
|
|
<< (*it)->trg()->start()
|
|
<< "\"" << s << endl;
|
|
}
|
|
}
|
|
// End cluster
|
|
cout << "\t}" << endl;
|
|
|
|
// Print edges
|
|
cout << edgeoutput.str() << endl;
|
|
}
|
|
cout << "}" << endl;
|
|
}
|