Skip to main content

staq

A terminal based application for visualizing stack operations and creating stack diagrams.

pip install staq

cli

To run the cli;

staq

This will start the cli interface. Here is a quick example of some commands:

$> int etc[64]
$> call main(1,"hello")
$> char buf[64] , note on local variable
$> call strcpy(buf,argv[0])
docs/assets/images/stack2.png

Because this is really just a tool for visualization, types are not strictly defined or used. For instance the following command is valid:

It will add a word to the stack with label i and value “index of buffer”

Local vars

you can declare local variables using standard C syntax.

char buffer[64]
int i = 0x89

Loading a C file

You can load a file with C syntax to import functions. The functions will be loaded into the context including arguments, local variables, and calls to other functions.

load test.c

Write

The write command lets you write data to the stack at a given address.

write 0x1000: [0x56, 0x78, 0x90, 0x12]

#you can also use references to variables with offsets
write &buffer : [0x56, 0x78, 0x90, 0x12]
write &buffer+4 : [0x56, 0x78, 0x90, 0x12]

Push

push will push a single stack cell onto the stack. A cell contains one or more words. Each cell can have a label, note, and words

push 0x56, arg1                  #Shortcut for 'push 0x56 , label: arg1'
push label: buffer,  size: 64    #creates a 64 word cell with no specified data
push [1,2,3,4,5]                 #creates a 5 word cell with the values filled in
push <main+0x54> , note: return  #creates a single word on the stack with no label, and a note
push {r0,r3,r7-r9 }              #pushes the registers r0, r3, r7, r8, and r9 onto the stack

Pop

pop will remove words from the stack

pop             #remove a single word
pop esp         #remove a single word and set the register esp to the value popped
pop 4           #remove 4 words
pop frame       #remove current frame
pop {r0-r3 }    #pops 4 words from the stack into the registers r0, r1, r2, and r3

Call

The call command will create a new stack frame and push the return address. If arguments are given, they will be pushed to the stack automatically.

Functions

The call command gets run through a CallingConvention subclass (currently only cdecl is available) and performs operations according to the convention:

  • push arguments to stack

  • create a new stack frame

  • pushes return address

You can declare functions to give the app context about argument type/size and labels, but you can also call arbitrary functions. It will just assume all arguments are a single row on the stack.

function myFunction(int a, int b)
call myFunction(41,32)

call undeclaredFunction(1,2,3,4)     # Will assume all args are 32 bit values and label arg1, arg2, arg3, etc

run

The run command is similar to call, but it will continue calling the first known function call in each function until it runs out of calls or hits the ~~limit arg.

leave

The leave command will pop all local variables from the stack. This is the same as setting the stack pointer to the base of the current frame.

jmp

The jmp command will create a new stack frame and set the instruction pointer to the address given. It is similar to call but does not push args or a return address.

ret

ret will pop one word and then perform a jmp to that address.

save

The save command will save the current state of the stack to a file. The extension will determine the format. currently .html, .png, and .txt are supported.

.html will save the stack as an interactive html file.

.png will save the stack as a png image.

.txt will save the stack as a text file containing all of the commands to recreate the stack.

example png output:

docs/assets/images/stack3-out.png

back/forward

The session keeps a history of commands. You can move back and forward through the history with ctrl+ left-arrow and ctrl+ right-arrow

Sphinx extension

The package provides a Sphinx extension that allows you to add stack diaragrams to your documentation using the stack command structure

The stack directive can be used with inline code, or by pointing to a file

.. stack::

    push ... , size: 256
    jmp main
    char buf[64]
    call printf("Args: %d, %d", 12,34)
.. stack:: assets/diagrams/demo.staq

Metadata

Release files for staq 0.2.12

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

Source distribution (sdist)

Source distribution for staq 0.2.12
File Size Uploaded Provenance Actions
staq-0.2.12.tar.gz 22.1 kB Without provenance Details for staq-0.2.12.tar.gz

Built distribution (wheel)

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

Total release size: 50.4 kB

Release files / staq-0.2.12.tar.gz

Download URL staq-0.2.12.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c5001523347e3ec8905a1f86f93ba3b6c3f7a207d6b8257e33e8a1ea0db34eef
BLAKE2b-256 checksum
How to use checksums
8a1ad9809d0811df4b6cdc706afefbe92590536e6e8c68cb212aa986be3805f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / staq-0.2.12-py3-none-any.whl

Download URL staq-0.2.12-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c34e19ab75c784ca1127f76039a685806472e4a2ac102db34de316fcbfd564e9
BLAKE2b-256 checksum
How to use checksums
5cf6b6c766b768ad29068fbc706a174032a9ce3b638f6bb8770e1aa4d300754f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Security for staq 0.2.12

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.

Release history Release notifications | RSS feed

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