tktech / lawu Goto Github PK
View Code? Open in Web Editor NEWA Python library for inspecting JVM class files (.class)
Home Page: https://lawu.dev
License: MIT License
A Python library for inspecting JVM class files (.class)
Home Page: https://lawu.dev
License: MIT License
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.
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
The assembler currently lacks support for stack maps, a newly required feature for targeting Java 7 and above.
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 :)
We should support something very close to Jasmin as both an input and output target.
.class
-> ast
transformast
pretty printerJawa 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.
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
Was going a bit crazy trying to find a version that worked. (Also can you start changing the version number on breaking changes)
JarFile.class_count attempts to take the len() of a generator object.
$ python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from jawa.jf import JarFile
>>> JarFile().class_count
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\site-packages\jawa\jf.py", line 54, in class_count
return len(p for p in self.namelist if p.endswith('.class'))
TypeError: object of type 'generator' has no len()
Suggestion: replace line 54 of jf.py with:
return len([p for p in self.namelist if p.endswith('.class')])
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_
))
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.
IMHO this is ready now!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.