An easy-to-use library for implementing and visualizing a control flow graph in python.
Project description
What is pythonCFG?
It is an easy-to-use library to implement control flow graph generation in your emulator.
All that is required is to wrap your instruction set around the two classes Instruction or Jump.
Downloading the library
If you wish to download the library and use it, you must install Graphviz and add it to your PATH at install.
https://graphviz.org/download/
After installing Graphviz, you can use pip to install the library for use in your own emulator.
pip install pythonCFG
Using the library
Assuming you have an emulator which contains some pseudocode such as...
emulator.execute(instruction)
You will take this instruction and wrap it into a Instruction or Jump class. An instruction can optionally take an operand, but requires a name.
A jump requires a name and "success_address" (operand) for all types of JumpType. A failure address is needed in the case of a JCC.
Some psuedocode to simulate this is...
match instruction:
case INC:
Instruction("INC")
case JUMP:
Jump("JUMP", 0x30, JumpType.JMP) ## NOTE: A failure address is not needed as this is an absolute jump!
## NOTE: You will need to dynamically determine what your success_address and failure_address.
case CONDITIONAL_JUMP:
Jump("COND", 0x30, JumpType.JCC_TAKEN, 0x20) ## NOTE: A failure address is needed as this is conditional.
After matching your instruction set into an Instruction or Jump, you will need to execute this instruction in the graph. Some pseudocode after you've matched your instruction set with its respective operands.
class Emulator:
def __init__(self):
## OTHER ARGUMENTS ARE IMPLEMENTATION SPECIFIC
self.graph = pyCFG() ## Import this class
def execute(self, instruction):
self.graph.execute( matched_instruction(instruction) )
## We are assuming you have correctly determined operands in matched_instruction.
def output(self):
self.graph.png("some_output.png") # Returns an image of the control flow graph.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pythonCFG-1.1.2.tar.gz
.
File metadata
- Download URL: pythonCFG-1.1.2.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b5e8f2be05a9af60b39ed24fb03a538dc2536ca77496cfc16149bc1acbd680c |
|
MD5 | d2955d0776fce4dc726fc1f94d3011df |
|
BLAKE2b-256 | 8cca7b7f8c323ba384ce37a9db1b1c8c337ff2ca05ed23b31d61fe5ea546fffe |
Provenance
File details
Details for the file pythonCFG-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: pythonCFG-1.1.2-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271d096087175a7eca1b0fc0f04fcc467217c101333bf5474551b0788226e33b |
|
MD5 | 1551c5853384fa090d25cf5c06859bb4 |
|
BLAKE2b-256 | 9007a8ea7f8af5209ca604a01ffd12b8f0cda1f0d822c653b62b0c173ea46ce5 |