Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythonCFG-1.1.5.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

pythonCFG-1.1.5-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file pythonCFG-1.1.5.tar.gz.

File metadata

  • Download URL: pythonCFG-1.1.5.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for pythonCFG-1.1.5.tar.gz
Algorithm Hash digest
SHA256 cc9e085bc4b46c9037bb733c2dabcec31bde52120a55d5f577772f3361dc9ec6
MD5 9cac5e65af9f6d66d392bce9c67cfcca
BLAKE2b-256 0565f3fdc876596280c5d86f54c3da72d3b63b77cb1648375b16fb4cb53070eb

See more details on using hashes here.

File details

Details for the file pythonCFG-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: pythonCFG-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for pythonCFG-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a9fc38d4f35c99214e7346e06dd70fb4960839910a0bc62017029ed8ee0c49c2
MD5 4fc4f9123e5a6a6982c09bfb95f88943
BLAKE2b-256 6c6f0135148d05952a00e2a4c7c92abdc841d8bf3ddebb730ed06eacc8dc399c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page