joaofbsm
joaofbsm

Reputation: 635

Error reassembling Java bytecode into .class file using Krakatau

I'm trying to use Krakatau to assemble a native Java bytecode, acquired with javap -c, but I'm getting a weird error:

> python Krakatau/assemble.py Main.bc
Krakatau  Copyright (C) 2012-17  Robert Grosse
This program is provided as open source under the GNU General Public License.
See LICENSE.TXT for more details.

Processing file Main.bc, 1/1 remaining
Main.bc:1:1: error: Expected '.class' or '.version'.
Compiled from "Main.java"

I have checked everything on the project's GitHub repository already, but nothing seems to help it. How is it expecting a .class file when I'm using the assembler? Should my bytecode be in some form of Jasmin syntax?

Upvotes: 0

Views: 529

Answers (2)

Stephen C
Stephen C

Reputation: 718926

Nothing in the Krakatau documentation says that it is designed to convert the output of javap -c.

If you want to use Krakatau to convert bytecode files, you should use Krakatau for the disassembly step not javap -c.

The Krakatua README.txt file explains how to do that.

Upvotes: 1

Antimony
Antimony

Reputation: 39451

The output of javap cannot be reassembled. It's designed to help Java programmers to debug their code and isn't complete or machine readable.

Krakatau uses an assembly format based on Jasmin syntax. Krakatau contains both an assembler and a disassembler, so you can use the Krakatau disassembler to disassemble a classfile into a textual assembly file, and then reassemble it into a classfile.

On a side note, javap is missing a lot of features and hides things from the output. It's useful for a quick check, but if you really want to see what is in a classfile at a low level, you need to use Krakatau anyway.

Upvotes: 1

Related Questions