A Python library for inspecting JVM class files (.class)

Overview

lawu

lawu

MIT

Lawu is a human-friendly library for assembling, disassembling, and exploring JVM class files. It's highly suitable for automation tasks.

Documentation

API documentation & examples are available at https://lawu.dev

Licence

Lawu is available under the MIT licence. See LICENCE.

Comments
  • Not sure if this is a bug...

    Not sure if this is a bug...

    So recently have been using Jawa in my tool to deobfuscate MC.

    Today I found that it was erroring on a class file. Which I found that even eclipses resource loader thinks its not right.

    But reporting it here anyways.

    The following class causes

    https://minecraft16.ml/mr.class

     File "C:\Python27\lib\site-packages\jawa\cf.py", line 99, in __init__
        self._from_io(fio)
      File "C:\Python27\lib\site-packages\jawa\cf.py", line 158, in _from_io
        self._constants.unpack(fio)
      File "C:\Python27\lib\site-packages\jawa\constants.py", line 427, in unpack
        fmt, size = _constant_fmts[tag]
    IndexError: tuple index out of range
    

    I have another tool that outputted "com.sun.org.apache.bcel.internal.classfile.ClassFormatException: Invalid byte tag in constant pool: 15" as an error on the same class. So it might be a error because of java 8 or something.

    opened by wgaylord 8
  • Add support for DataInputStream

    Add support for DataInputStream

    FYI, https://github.com/arngarden/python_java_datastream by @arngarden has a nice support for reading and writing Java DataInputStream which could be a nice addition

    opened by pombredanne 5
  • No longer works on python 2.7. Should be marked on pip as such.

    No longer works on python 2.7. Should be marked on pip as such.

    The new version no long runs on python 2.7

    >>> from jawa.classloader import ClassLoader
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python27\lib\site-packages\jawa\classloader.py", line 41
        def __init__(self, *sources, max_cache: int=50, klass=ClassFile,
                                             ^
    SyntaxError: invalid syntax
    
    opened by wgaylord 3
  • Support for Python2?

    Support for Python2?

    There is a program created by a guy named Pokechu22 and he used this program in conjunction with his Python2 scripts. When I try to use his program in Python 2, it hitches here as this program is in Python 3. I'm sure there has to be Python 2 version of this somewhere, as his program would not have worked back then. Please let me know :)

    opened by MSpaceDev 2
  • Transform bytecode.yaml into bytecode.py

    Transform bytecode.yaml into bytecode.py

    Our current process is to update bytecode.yaml, run a small transform on it to fill in some defaults and convert it to JSON (so we don't add pyyaml as a distribution dependency). At runtime this JSON file is loaded and used as the bytecode reference.

    Instead, lets transform bytecode.yaml directly into python. The primary reasoning for this is to support autocomplete, help tags and type hinting for operand values. For example in our yaml file we have ->

    aaload:
        op: 0x32
        desc: load onto the stack a reference from an array
        stack:
            before:
                - ArrayRef
                - Index
            after:
                - Value
        runtime:
            - NullPointerException
            - ArrayIndexOutOfBoundsException
    

    We can turn this into ->

    class aaload(Instruction):
        """load onto the stack a reference from an array"""
        __slots__ = ('op', 'mnemonic', 'stack', 'runtime', 'operands')
        op = 0x32
        mnemonic = 'aaload'
        ...
    

    So that we can do for example...

    import jawa.bytecode as I
    
    method.code.assemble((
        I.aaload,
        I.bipush(6),
        I.return_
    ))
    
    enhancement 
    opened by TkTech 1
  • Fix python 3 support

    Fix python 3 support

    (Re?)adds python 3 compatibility.

    The only complicated change here is that StringIO has been replaced with BytesIO. While six.moves.cStringIO exists, it causes issues in the contexts it was used in (TypeError: initial_value must be str or None, not bytes). BytesIO works in both python 2 and python 3; I've also used a cStringIO when available (I'm not actually sure whether cStringIO is faster than BytesIO in python 2, but I assume it is).

    Tested against burger (with another set of changes there for python 3), so most reading stuff is covered but writing might not be.

    opened by Pokechu22 1
  • Fix misspelled 'ib2' (should be 'i2b') instruction

    Fix misspelled 'ib2' (should be 'i2b') instruction

    Not sure if I should submit this to develop or master. I found this while using burger on develop so that's the branch I made the change on, but it may make more sense on master.

    opened by Pokechu22 1
  • Add support for the Signature attribute

    Add support for the Signature attribute

    This adds support for reading the Signature attribute (jvms 4.7.9). It does not attempt to parse it, however, as the parsing rules (jvms 4.7.9.1) are rather complicated.

    opened by Pokechu22 1
  • Speed up character processing with list buffer

    Speed up character processing with list buffer

    • Characters are appended to a list buffer and converted to a unicode string at the end at once. This speeds up string processing when there is a large number of characters to decode and avoids the creation of many small intermediate strings.

    Signed-off-by: Philippe Ombredanne [email protected]

    opened by pombredanne 1
  • Fix disassemble and doc example on Windows

    Fix disassemble and doc example on Windows

    Open defaults to 'r', which means that Windows' line endings would get converted, causing class files to get parsed incorrectly. This changes to explicitly use 'rb', avoiding that problem.

    opened by Pokechu22 1
  • MethodTable.find's 'args' and 'returns' arguments don't work

    MethodTable.find's 'args' and 'returns' arguments don't work

    MethodTable.find's 'args' and 'returns' arguments are ignored.

    From here:

    args = descriptor[1:end_para]
    if args is not None and args != args:
        continue
    returns = descriptor[end_para + 1:]
    if returns is not None and returns != returns:
        continue
    

    args and returns need to be named something different than their respective parameters, as otherwise the if condition will never be true.

    opened by Pokechu22 1
  • More downstream stuff

    More downstream stuff

    This gets entries for all of the various table attributes out of the AST.

    For BootstrapMethods, it unrolls the MethodHandle constant. Admittedly I don't understand this recommendation 100%, but I don't have a good reason not to do it either. Constants are still rolled into all other attributes though, so let me know if I should be unrolling constants across the board. If that's the case we might want to look into a more universal to_attr method or something.

    A TableAttribute base class is added

    ReferenceKind is now an IntEnum

    opened by nickelpro 4
  • Jasmin (.j) Assembler & Output Format

    Jasmin (.j) Assembler & Output Format

    We should support something very close to Jasmin as both an input and output target.

    • [x] Tokenizer
    • [x] Parser
    • [ ] .class -> ast transform
    • [ ] ast pretty printer
    enhancement 
    opened by TkTech 0
  • Missing Attribute Tests

    Missing Attribute Tests

    • [ ] BootstrapMethods - Added in: 7 (J2SE_7)
    • [ ] Code - Added in: 1.0.2 (JDK1_1)
    • [ ] ConstantValue - Added in: 1.0.2 (JDK1_1)
    • [ ] Deprecated - Added in: 1.1.0 (JDK1_1)
    • [ ] EnclosingMethod - Added in: 5.0.0 (J2SE_5)
    • [ ] Exceptions - Added in: 1.0.2 (JDK1_1)
    • [ ] InnerClasses - Added in: 1.1.0 (JDK1_1)
    • [ ] LineNumberTable - Added in: 1.0.2 (JDK1_1)
    • [ ] LocalVariableTable - Added in: 1.0.2 (JDK1_1)
    • [ ] LocalVariableTypeTable - Added in: 1.0.2 (JDK1_1)
    • [ ] Signature - Added in: 5.0.0 (J2SE_5)
    • [ ] SourceFile - Added in: 1.0.2 (JDK1_1)
    • [ ] StackMapTable - Added in: 6.0.0 (J2SE_6)
    • [ ] Synthetic - Added in: 5.0.0 (J2SE_5)
    WIP Development Branch 
    opened by TkTech 0
  • Java 7/8 Support (including tests)

    Java 7/8 Support (including tests)

    Jawa is currently only thoroughly tested up to Java 6. We should implement tests for 7 and 8, then implement any missing parts of the new specifications.

    enhancement WIP Development Branch 
    opened by TkTech 2
  • Stack Map Support In Assembler

    Stack Map Support In Assembler

    The assembler currently lacks support for stack maps, a newly required feature for targeting Java 7 and above.

    • [x] Reading
    • [ ] Writing (uncompressed, simple frames)
    • [ ] Writing (compressed frames)
    enhancement WIP Development Branch 
    opened by TkTech 1
Owner
Tyler Kennedy
Tyler Kennedy
Python meta class and abstract method library with restrictions.

abcmeta Python meta class and abstract method library with restrictions. This library provides a restricted way to validate abstract methods. The Pyth

Morteza NourelahiAlamdari 8 Dec 14, 2022
Cross-platform MachO/ObjC Static binary analysis tool & library. class-dump + otool + lipo + more

ktool Static Mach-O binary metadata analysis tool / information dumper pip3 install k2l Development is currently taking place on the @python3.10 branc

Kritanta 301 Dec 28, 2022
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

Andrew Senetar 224 Jan 4, 2023
Python library for creating and parsing HSReplay XML files

python-hsreplay A python module for HSReplay support. https://hearthsim.info/hsreplay/ Installation The library is available on PyPI. pip install hsre

HearthSim 45 Mar 28, 2022
Python library for parsing Godot scene files

Godot Parser This is a python library for parsing Godot scene (.tscn) and resource (.tres) files. It's intended to make it easier to automate certain

Steven Arcangeli 30 Jan 4, 2023
Advanced python code - For students in my advanced python class

advanced_python_code For students in my advanced python class Week Topic Recordi

Ariel Avshalom 3 May 27, 2022
MiniJVM is simple java virtual machine written by python language, it can load class file from file system and run it.

MiniJVM MiniJVM是一款使用python编写的简易JVM,能够从本地加载class文件并且执行绝大多数指令。 支持的功能 1.从本地磁盘加载class并解析 2.支持绝大多数指令集的执行 3.支持虚拟机内存分区以及对象的创建 4.支持方法的调用和参数传递 5.支持静态代码块的初始化 不支

keguoyu 60 Apr 1, 2022
SuperMario - Python programming class ending assignment SuperMario, using pygame

SuperMario - Python programming class ending assignment SuperMario, using pygame

mars 2 Jan 4, 2022
What Do Deep Nets Learn? Class-wise Patterns Revealed in the Input Space

What Do Deep Nets Learn? Class-wise Patterns Revealed in the Input Space Introduction: Environment: Python3.6.5, PyTorch1.5.0 Dataset: CIFAR-10, Image

null 8 Mar 23, 2022
Coursework project for DIP class. The goal is to use vision to guide the Dashgo robot through two traffic cones in bright color.

Coursework project for DIP class. The goal is to use vision to guide the Dashgo robot through two traffic cones in bright color.

Yueqian Liu 3 Oct 24, 2022
A class to draw curves expressed as L-System production rules

A class to draw curves expressed as L-System production rules

Juna Salviati 6 Sep 9, 2022
A simple flashcard app built as a final project for a databases class.

CS2300 Final Project - Flashcard app 'FlashStudy' Tech stack Backend Python (Language) Django (Web framework) SQLite (Database) Frontend HTML/CSS/Java

Christopher Spencer 2 Feb 3, 2022
Final project in KAIST AI class

mmodal_mixer MLP-Mixer based Multi-modal image-text retrieval Image: Original image is cropped with 16 x 16 patch size without overlap. Then, it is re

SuperSuperMoon 5 May 30, 2022
Toppr Os Auto Class Joiner

Toppr Os Auto Class Joiner Toppr os is a irritating platform to work with especially for students it takes a while and is problematic most of the time

null 1 Dec 18, 2021
Create a simple program by applying the use of class

TUGAS PRAKTIKUM 8 ?? Nama : Achmad Mahfud NIM : 312110520 Kelas : TI.21.C5 Perintah : Buat program sederhana dengan mengaplikasikan pengguna

Achmad Mahfud 1 Dec 23, 2021
Class and mathematical functions for quaternion numbers.

Quaternions Class and mathematical functions for quaternion numbers. Installation Python This is a Python 3 module. If you don't have Python installed

null 3 Nov 8, 2022
Class XII computer science project.

Computer Science Project — Class XII Kshitij Srivastava (XI – A) Introduction The aim of this project is to create a fully operational system for a me

Kshitij Srivastava 2 Jul 21, 2022
Arcpy Tool developed for ArcMap 10.x that checks DVOF points against TDS data and creates an output feature class as well as a check database.

DVOF_check_tool Arcpy Tool developed for ArcMap 10.x that checks DVOF points against TDS data and creates an output feature class as well as a check d

null 3 Apr 18, 2022