Skip to content

Instantly share code, notes, and snippets.

@pgoodman
Created August 1, 2014 15:58
Show Gist options
  • Save pgoodman/71e9dfe2a99cd089906f to your computer and use it in GitHub Desktop.
Save pgoodman/71e9dfe2a99cd089906f to your computer and use it in GitHub Desktop.
/* Copyright 2014 Peter Goodman, all rights reserved. */
#include <granary/granary.h>
using namespace granary;
// Simple tool decoding all blocks in a function.
class WholeFunctionDecoder : public InstrumentationTool {
public:
virtual ~WholeFunctionDecoder(void) = default;
virtual void InstrumentControlFlow(BlockFactory *factory,
LocalControlFlowGraph *cfg) {
for (auto block : cfg->NewBlocks()) {
for (auto succ : block->Successors()) {
if (succ.cfi->IsSystemCall() || succ.cfi->IsInterruptCall()) {
break; // System calls don't always return to the next instruction.
} else if (!succ.cfi->IsFunctionCall()) {
factory->RequestBlock(succ.block);
}
}
}
}
};
// Initialize the `whole_func` tool.
GRANARY_CLIENT_INIT({
RegisterInstrumentationTool<WholeFunctionDecoder>("whole_func");
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment