Skip to main content

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:
            return Instruction("INC")
            
      case JUMP:
            return 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:
            return Jump("COND", 0x30, """ JumpType.JCC_TAKEN or JumpType.JCC_NOT_TAKEN """, 0x20) ## NOTE: A failure address is needed as this is conditional.
            ## It is burden upon you to determine if the jump is taken or not as it is not feasible for this library and its goals.

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(0) ## Import this class and set your entry point address ( in this case 0 ).
              
        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.

Implementations?

There is an example implementation in the source code of pythonRSCdev.

https://github.com/Calastrophe/pythonRSC-dev/blob/master/src/pythonRSCdev/emulator.py#L41

Then the matched instruction is executed inside the start() function above it.

What does it look like?

A large execution graph will typically look something like this ( instructions in the block depend on your architecture ).

There a few things subject to change on how the control flow graph will look in coming versions in order to better analyze the graph.

image

Metadata

Release files for pythonCFG 1.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonCFG 1.2.4
File Size Uploaded Provenance Actions
pythonCFG-1.2.4.tar.gz 17.9 kB Without provenance Details for pythonCFG-1.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pythonCFG 1.2.4
File Interpreter ABI Platform Actions
pythonCFG-1.2.4-py3-none-any.whl Python 3 none any Details for pythonCFG-1.2.4-py3-none-any.whl

Total release size: 36.0 kB

Release files / pythonCFG-1.2.4.tar.gz

Download URL pythonCFG-1.2.4.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a467fcd7c1795ccaf4d6f35c58746905b98aeccf4c8cd4d3f7df020170171d3d
BLAKE2b-256 checksum
How to use checksums
d54851d2f00de45d55ead19eb6bf1ef04a8b5d9390dbecd06624f54d13790336
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / pythonCFG-1.2.4-py3-none-any.whl

Download URL pythonCFG-1.2.4-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ffb7391f24b5aa306e7e756d68eabe4a87e7d70f7af124781892acf11e3eff5
BLAKE2b-256 checksum
How to use checksums
52d8937a0a987617fe4c9c0a3d86e1dfb6be30e6a2aad433f21cf357e3701648
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Security for pythonCFG 1.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page