py2dis - A disassembly engine & library for Python

Related tags

Miscellaneouspy2dis
Overview


py2dis - A disassembly engine & library for Python.

py2dis is a disassembly library for Python that does not use any modules/libraries other than colorama, comes with a miniature built-in disassembler engine, and features to assist in disassembling classes, functions, raw bytecode, source code strings, and more!

Version

Features

  • Opcode lookups
  • Dumping bytecode
  • Instruction lookups
  • Disassembling Classes
  • Disassembling Functions
  • Disassembling raw bytecode (passed to function)
  • Disassembling source code strings (passed to function)

Disassembling Classes

from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


class Target:
  def __init__(self: None, message: str) -> None:
    self.message = message

  def function(self: None) -> None:
    print(self.message)

class Example:
  def __init__(self: None, Class: None) -> None:
    self.Class = Class

  def execute(self: None) -> None:
    py2dis.disassemble_class(self.Class)

if __name__ == "__main__":
  Example(Target).execute()

Disassembling Functions

None: self.function = function def execute(self: None) -> None: py2dis.disassemble_function(self.function) if __name__ == "__main__": Example(LoginSystem).execute() ">
from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


def LoginSystem() -> bool:
  if input("Enter the secret code: ") == "1337":
    print("You have successfully authenticated!")
    return True
  return False

class Example:
  def __init__(self: None, function: None) -> None:
    self.function = function

  def execute(self: None) -> None:
    py2dis.disassemble_function(self.function)

if __name__ == "__main__":
  Example(LoginSystem).execute()	

Disassembling Raw Bytecode

from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


class Example:
  def __init__(self: None, bytecode: bytes) -> None:
    self.bytecode = bytecode

  def execute(self: None) -> None:
    py2dis.disassemble_bytecode(self.bytecode)

if __name__ == "__main__":
  Example(b"t\x00d\x01\x83\x01\x01\x00d\x00S\x00").execute()

Disassembling Source Code Strings

from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


class Example:
  def __init__(self: None, code: str) -> None:
    self.code = code

  def execute(self: None) -> None:
    py2dis.disassemble_source_code(self.code)

if __name__ == "__main__":
  Example("print('Hello, World!')").execute()

Looking up Opcodes

from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


class Example:
  def __init__(self: None, opcode: int) -> None:
    self.opcode = opcode

  def execute(self: None) -> None:
    return py2dis.opcode_lookup(self.opcode)

if __name__ == "__main__":
  print(Example(123).execute())

Looking up Instructions

from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


class Example:
  def __init__(self: None, instruction: str) -> None:
    self.instruction = instruction

  def execute(self: None) -> None:
    return py2dis.instruction_lookup(self.instruction)

if __name__ == "__main__":
  print(Example("SEND").execute())

Exporting Bytecode from a Function

None: self.function = function def execute(self: None) -> None: return py2dis.export_raw_bytecode(self.function) if __name__ == "__main__": print(Example(LoginSystem).execute())">
from lib.py2dis import *


# example.py
# Date: 01/09/22
# Author: 0x80000000


def LoginSystem() -> bool:
  if input("Enter the secret code: ") == "1337":
    print("You have successfully authenticated!")
    return True
  return False

class Example:
  def __init__(self: None, function: None) -> None:
    self.function = function

  def execute(self: None) -> None:
    return py2dis.export_raw_bytecode(self.function)

if __name__ == "__main__":
  print(Example(LoginSystem).execute())

Requirements

pip3 install colorama	

Screenshots

image image

Credits

https://github.com/0x80000000

Contributions 🎉

All contributions are accepted, simply open an Issue / Pull request.
A toy repo illustrating a minimal installable Python package

MyToy: a minimal Python package This repository contains a minimal, toy Python package with a few files as illustration for students of how to lay out

Fernando Perez 19 Apr 24, 2022
It's an .exe file that can notify your chia profit and warning message every time automatically.

chia-Notify-with-Line 警示程式 It's an .exe file that can notify your chia profit and warning message every time automatically. 這是我自行設計的小程式,有轉成.exe檔了,可以在沒

You,Yu 1 Oct 28, 2021
pspsps(1) is a compyuter software to call an online catgirl to the Linux terminyal.

pspsps(1): call a catgirl from the Internyet to the Linux terminyal show processes: ps show catgirls: pspsps —@ Melissa Boiko 32 Dec 19, 2022

Strong Typing in Python with Decorators

typy Strong Typing in Python with Decorators Description This light-weight library provides decorators that can be used to implement strongly-typed be

Ekin 0 Feb 06, 2022
Datargsing is a data management and manipulation Python library

Datargsing What is It? Datargsing is a data management and manipulation Python library which is currently in deving Why this library is good? This Pyt

CHOSSY Lucas 10 Oct 24, 2022
Performance monitoring and testing of OpenStack

Browbeat Browbeat is a performance tuning and analysis tool for OpenStack. Browbeat is free, Open Source software. Analyze and tune your Cloud for opt

cloud-bulldozer 83 Dec 14, 2022
Functions to analyze Cell-ID single-cell cytometry data using python language.

PyCellID (building...) Functions to analyze Cell-ID single-cell cytometry data using python language. Dependecies for this project. attrs(=21.1.0) fo

0 Dec 22, 2021
🏃 Python3 Solutions of All Problems in GKS 2022 (In Progress)

GoogleKickStart 2022 Python3 solutions of Google Kick Start 2022. Solution begins with * means it will get TLE in the largest data set. Total computat

kamyu 38 Dec 29, 2022
Active Transport Analytics Model: A new strategic transport modelling and data visualization framework

{ATAM} Active Transport Analytics Model Active Transport Analytics Model (“ATAM”

ATAM Analytics 2 Dec 21, 2022
Creates infinite amount of guilded accounts in seconds.

Guilded Cookie Creator [fuck guilded i quit working on this, they patch like every fucking method after 2/3 days i release shit] Optimizations Asynchr

scripted 7 Feb 28, 2022
An end-to-end Python-based Infrastructure as Code framework for network automation and orchestration.

Nectl An end-to-end Python-based Infrastructure as Code framework for network automation and orchestration. Features Data modelling and validation. Da

Adam Kirchberger 15 Oct 14, 2022
Hera is a Python framework for constructing and submitting Argo Workflows.

Hera is an Argo Workflows Python SDK. Hera aims to make workflow construction and submission easy and accessible to everyone! Hera abstracts away workflow setup details while still maintaining a cons

argoproj-labs 241 Jan 02, 2023
A NetBox Plugin that gives a UI for generating, comparing and deploying configurations to devices.

netbox_config_plugin - A plugin to generate, compare and deploy configurations This plugin allows you to execute your code to generate a config for a

Jo 11 Dec 21, 2022
Write Streamlit apps using Notion! (Prototype)

Streamlit + Notion test app Write Streamlit apps using Notion! ☠️ IMPORTANT: This is just a little prototype I made to play with some ideas. Not meant

Thiago Teixeira 22 Sep 08, 2022
ArinjoyTheDev 1 Jul 17, 2022
Cross-Encoder-with-Bi-Encoder를 활용한 WebPage 데모

Retrieval_Streamlit_Demo Cross-Encoder-with-Bi-Encoder를 활용한

5 Dec 29, 2021
This is a Python package named - calculator

Calculator Python Package This is a Calculator Package of Python. How To Install The Package? Install calchundred with pip (Package Installer Of Pytho

Arinjoy_Programmer 1 Nov 21, 2021
Junos PyEZ is a Python library to remotely manage/automate Junos devices.

The repo is under active development. If you take a clone, you are getting the latest, and perhaps not entirely stable code. DOCUMENTATION Official Do

Juniper Networks 623 Dec 10, 2022
Pacman - A suite of tools for manipulating debian packages

Overview Repository is a suite of tools for manipulating debian packages. At a h

Pardis Pashakhanloo 1 Feb 24, 2022
Probably the best way to simulate block scopes in Python

This is a package, as it says on the tin, to emulate block scoping in Python, the lack of which being a clever design choice yet sometimes a trouble.

88 Oct 26, 2022