py2dis - A disassembly engine & library for Python

Related tags

Miscellaneous py2dis
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.
You might also like...
Msgpack serialization/deserialization library for Python, written in Rust using PyO3 and rust-msgpack. Reboot of orjson. msgpack.org[Python]

ormsgpack ormsgpack is a fast msgpack library for Python. It is a fork/reboot of orjson It serializes faster than msgpack-python and deserializes a bi

PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standard Library.

PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standar

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

A Python library to simulate a Zoom H6 recorder remote control
A Python library to simulate a Zoom H6 recorder remote control

H6 A Python library to emulate a Zoom H6 recorder remote control Introduction This library allows you to control your Zoom H6 recorder from your compu

Python library for creating PEG parsers

PyParsing -- A Python Parsing Module Introduction The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the t

Python library to natively send files to Trash (or Recycle bin) on all platforms.

Send2Trash -- Send files to trash on all platforms Send2Trash is a small package that sends files to the Trash (or Recycle Bin) natively and on all pl

Python screenshot library, replacement for the Pillow ImageGrab module on Linux.

tldr: Use Pillow The pyscreenshot module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux

A functional standard library for Python.

Toolz A set of utility functions for iterators, functions, and dictionaries. See the PyToolz documentation at https://toolz.readthedocs.io LICENSE New

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

Owner
null
A parallel branch-and-bound engine for Python.

pybnb A parallel branch-and-bound engine for Python. This software is copyright (c) by Gabriel A. Hackebeil (gabe.hacke

Gabriel Hackebeil 52 Nov 12, 2022
🛠️ Learn a technology X by doing a project - Search engine of project-based learning

Learn X by doing Y ??️ Learn a technology X by doing a project Y Website You can contribute by adding projects to the CSV file.

William 408 Dec 20, 2022
frida-based ceserver. iOS analysis is possible with Cheat Engine.

frida-ceserver frida-based ceserver. iOS analysis is possible with Cheat Engine. Original by Dark Byte. Usage Install frida on iOS. python main.py Cyd

KenjiroIchise 89 Jan 8, 2023
bamboo-engine 是一个通用的流程引擎,他可以解析,执行,调度由用户创建的流程任务,并提供了如暂停,撤销,跳过,强制失败,重试和重入等等灵活的控制能力和并行、子流程等进阶特性,并可通过水平扩展来进一步提升任务的并发处理能力。

bamboo-engine 是一个通用的流程引擎,他可以解析,执行,调度由用户创建的流程任务,并提供了如暂停,撤销,跳过,强制失败,重试和重入等等灵活的控制能力和并行、子流程等进阶特性,并可通过水平扩展来进一步提升任务的并发处理能力。 整体设计 Quick start 1. 安装依赖 2. 项目初始

腾讯蓝鲸 96 Dec 15, 2022
Cylc: a workflow engine for cycling systems

Cylc: a workflow engine for cycling systems. Repository master branch: core meta-scheduler component of cylc-8 (in development); Repository 7.8.x branch: full cylc-7 system.

The Cylc Workflow Engine 205 Dec 20, 2022
XlvnsScriptTool - Tool for decompilation and compilation of scripts .SDT from the visual novel's engine xlvns

XlvnsScriptTool English Dual languaged (rus+eng) tool for decompiling and compiling (actually, this tool is more than just (dis)assenbler, but less th

Tester 3 Sep 15, 2022
Liquid Rocket Engine Cooling Simulation

Liquid Rocket Engine Cooling Simulation NASA CEA The implemented class calls NASA CEA via RocketCEA. INSTALL GUIDE In progress install instructions fo

John Salib 1 Jan 30, 2022
JLC2KICAD_lib is a python script that generate a component library for KiCad from the JLCPCB/easyEDA library.

JLC2KiCad_lib is a python script that generate a component library (schematic, footprint and 3D model) for KiCad from the JLCPCB/easyEDA library. This script requires Python 3.6 or higher.

Nicolas Toussaint 73 Dec 26, 2022
K2HASH Python library - NoSQL Key Value Store(KVS) library

k2hash_python Overview k2hash_python is an official python driver for k2hash. Install Firstly you must install the k2hash shared library: curl -o- htt

Yahoo! JAPAN 3 Oct 19, 2022