### Field Definitions in Assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Defines instance and static fields with access flags, names, and type descriptors. Includes examples of fields with initial values and attributes like '.deprecated'. ```java .class public Person .super java/lang/Object ; Instance fields .field private name Ljava/lang/String; .field private age I ; Static fields with initial values .field public static final VERSION I = 1 .field public static final NAME Ljava/lang/String; = "Person" ; Field with attributes .field private data [B .fieldattributes .deprecated .end fieldattributes .method public getName : ()Ljava/lang/String; .code stack 1 locals 1 aload_0 getfield Field Person name Ljava/lang/String; areturn .end code .end method .method public setName : (Ljava/lang/String;)V .code stack 2 locals 2 aload_0 aload_1 putfield Field Person name Ljava/lang/String; return .end code .end method .end class ``` -------------------------------- ### Assemble and run a classfile Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_tutorial.md Commands to assemble a .j file and execute the resulting class using the Java runtime. ```Shell > krak2 asm -o Foo.class examples/minimal.j got 1 classes Wrote 55 bytes to Foo.class > java Foo Error: Main method not found in class Foo, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application ``` ```Shell > krak2 asm -o Foo.class examples/hello.j got 1 classes Wrote 278 bytes to Foo.class > java Foo Hello World! ``` ```Shell > krak2 asm -o Foo.class examples/greet1.j got 1 classes Wrote 361 bytes to Foo.class > java Foo Alice Hello, Alice > java Foo Bob Hello, Bob ``` -------------------------------- ### Control Flow with Labels in Assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Demonstrates using labels (e.g., LELSE, LEND) with branch instructions like 'ifeq' and 'goto' for conditional execution and jumps in assembly bytecode. ```java .class public Greeter .super java/lang/Object .method public static main : ([Ljava/lang/String;)V .code stack 13 locals 13 getstatic Field java/lang/System out Ljava/io/PrintStream; ; Get args[0] - the user's name aload_0 iconst_0 aaload astore_0 ; Store name in local variable 0 ; Check if name contains "Bob" aload_0 ldc "Bob" invokevirtual Method java/lang/String contains (Ljava/lang/CharSequence;)Z ; Branch based on result (0 = false, 1 = true) ifeq LELSE ; Jump to LELSE if result is 0 (false) ldc "Special hello, " goto LEND ; Skip the else branch LELSE: ldc "Hello, " LEND: ; Concatenate greeting with name aload_0 invokevirtual Method java/lang/String concat (Ljava/lang/String;)Ljava/lang/String; invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class ``` -------------------------------- ### Assembly Syntax - Exception Handling Source: https://context7.com/storyyeller/krakatau/llms.txt Demonstrates how to define exception handlers using `.catch` directives in Krakatau's assembly syntax. ```APIDOC ## Assembly Syntax - Exception Handling Exception handling uses `.catch` directives to define try-catch regions. Specify the exception class, the protected range (from/to labels), and the handler label. ```java .class public ExceptionDemo .super java/lang/Object .method public static safeParse : (Ljava/lang/String;)I .code stack 2 locals 2 ; Define exception handler for NumberFormatException .catch java/lang/NumberFormatException from LTRY to LEND using LCATCH LTRY: aload_0 invokestatic Method java/lang/Integer parseInt (Ljava/lang/String;)I LEND: ireturn LCATCH: ; Exception object is on stack, pop it pop ; Return default value of 0 iconst_0 ireturn .end code .end method .method public static main : ([Ljava/lang/String;)V .code stack 2 locals 1 getstatic Field java/lang/System out Ljava/io/PrintStream; ldc "abc" invokestatic Method ExceptionDemo safeParse (Ljava/lang/String;)I invokevirtual Method java/io/PrintStream println (I)V return .end code .end method .end class ``` ``` -------------------------------- ### Assemble bytecode files with krak2 Source: https://context7.com/storyyeller/krakatau/llms.txt Convert .j assembly files back into binary classfiles or JAR archives. ```bash # Assemble a single .j file to a classfile krak2 asm --out Foo.class examples/hello.j # Assemble to a specific output directory krak2 asm --out temp examples/minimal.j # Assemble a zip/jar of .j files into a JAR krak2 asm --out output.jar source_files.zip # Short form output option krak2 asm -o Foo.class examples/greet1.j ``` -------------------------------- ### Assemble .j File to Classfile Source: https://github.com/storyyeller/krakatau/blob/v2/README.md Assembles a human-readable Java bytecode file (`.j`) into a binary Java classfile. The output is written to the specified file. ```bash krak2 asm --out temp Krakatau/tests/assembler/good/strictfp.j ``` -------------------------------- ### Define a main method printing Hello World Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_tutorial.md A class definition containing a main method that prints a string to standard output. ```Krakatau .class public Foo .super java/lang/Object ; ([Ljava/lang/String;)V means "takes a single String[] argument and returns void" .method public static main : ([Ljava/lang/String;)V ; We have to put an upper bound on the number of locals and the operand stack ; Machine generated code will usually calculate the exact limits, but that's a pain to do ; when writing bytecode by hand, especially as we'll be making changes to the code. ; Therefore, we'll just set a value that's way more than we're using, 13 in this case .code stack 13 locals 13 ; Equivalent to "System.out" in Java code getstatic Field java/lang/System out Ljava/io/PrintStream; ; put our argument on the operand stack ldc "Hello World!" ; now invoke println() invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class ``` -------------------------------- ### Library API - Assemble Function Source: https://context7.com/storyyeller/krakatau/llms.txt Shows how to use the `assemble` function from the Krakatau Rust library to convert assembly source code into Java bytecode. ```APIDOC ## Library API - Assemble Function The `assemble` function takes source code and options, returning a vector of assembled class names and their bytecode. It handles multiple class definitions in a single source file. ```rust use krakatau2::assemble; use krakatau2::AssemblerOptions; fn main() -> Result<(), Box> { let source = r#" .class public Example .super java/lang/Object .method public static main : ([Ljava/lang/String;)V .code stack 2 locals 1 getstatic Field java/lang/System out Ljava/io/PrintStream; ldc "Hello from Krakatau!" invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class "#; let opts = AssemblerOptions {}; let classes = assemble(source, opts)?; for (name, bytecode) in classes { println!("Assembled class: {:?}", name); println!("Bytecode size: {} bytes", bytecode.len()); // Write bytecode to file // std::fs::write(format!("{}.class", name.unwrap()), bytecode)?; } Ok(()) } ``` ``` -------------------------------- ### Assemble Bytecode using Rust API Source: https://context7.com/storyyeller/krakatau/llms.txt Demonstrates using the `assemble` function from the Krakatau Rust library to convert assembly source code into Java bytecode. Handles multiple class definitions. ```rust use krakatau2::assemble; use krakatau2::AssemblerOptions; fn main() -> Result<(), Box> { let source = r#"# .class public Example .super java/lang/Object .method public static main : ([Ljava/lang/String;)V .code stack 2 locals 1 getstatic Field java/lang/System out Ljava/io/PrintStream; ldc "Hello from Krakatau!" invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class "#; let opts = AssemblerOptions {}; let classes = assemble(source, opts)?; for (name, bytecode) in classes { println!("Assembled class: {:?}", name); println!("Bytecode size: {} bytes", bytecode.len()); // Write bytecode to file // std::fs::write(format!("{}.class", name.unwrap()), bytecode)?; } Ok(()) } ``` -------------------------------- ### Constants and Literals in Assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Shows how to load various constants and literals, including integers, longs, floats, doubles, strings, and class references, using 'ldc' and 'ldc2_w'. ```java .class public Constants .super java/lang/Object .method public static demo : ()V .code stack 10 locals 10 ; Integer constants iconst_0 ; Push 0 iconst_5 ; Push 5 bipush 100 ; Push byte (-128 to 127) sipush 1000 ; Push short (-32768 to 32767) ldc 999999 ; Push any int ; Long constant (takes 2 stack slots) ldc2_w 9999999999L ; Float and double ldc 3.14f ldc2_w 3.14159265358979 ; Special float values ldc +Infinity ldc -Infinity ldc +NaN ; String constant ldc "Hello World" ; Class reference ldc Class java/lang/String ; Clear stack for return pop2 pop2 pop2 pop2 pop2 pop pop return .end code .end method .end class ``` -------------------------------- ### Roundtrip Workflow CLI Source: https://context7.com/storyyeller/krakatau/llms.txt Illustrates the command-line interface workflow for disassembling, editing, and reassembling Java code while preserving binary structure. ```APIDOC ## Roundtrip Workflow The roundtrip workflow enables modifying obfuscated or compiled Java code by disassembling, editing, and reassembling. Roundtrip mode preserves exact binary structure for cases requiring bit-for-bit compatibility. ```bash # Step 1: Disassemble a JAR file in roundtrip mode krak2 dis --roundtrip --out modified/ target.jar # Step 2: Edit the .j files in the modified/ directory # (Make your bytecode modifications) # Step 3: Reassemble back to a JAR krak2 asm --out modified-target.jar modified/ # Verify the result java -jar modified-target.jar # For single class modification workflow: krak2 dis -r --out MyClass.j MyClass.class # Edit MyClass.j krak2 asm --out MyClass.class MyClass.j ``` ``` -------------------------------- ### Compile and Execute Krakatau Bytecode Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_tutorial.md Commands to assemble the bytecode file and test the conditional logic with various inputs. ```Shell > krak2 asm -o Foo.class examples/greet2.j got 1 classes Wrote 453 bytes to Foo.class > java Foo Alice Hello, Alice > java Foo Bob Fuck you, Bob > java Foo "Alice Margatroid" Hello, Alice Margatroid > java Foo "Totally Not Bob" Fuck you, Totally Not Bob ``` -------------------------------- ### Execute decompile.py with correct path Source: https://github.com/storyyeller/krakatau/wiki/Small-correction Run the decompiler by specifying the current directory in the -path argument. ```bash python Krakatau\decompile.py -path . Test ``` -------------------------------- ### Reference fields and methods in assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Use Field, Method, and InterfaceMethod keywords to reference class members with appropriate type descriptors. ```java .class public Example .super java/lang/Object .method public static demo : ()V .code stack 10 locals 10 ; Static field access: ClassName fieldName fieldType getstatic Field java/lang/System out Ljava/io/PrintStream; ; Instance field access ; getfield Field com/example/Person name Ljava/lang/String; ; Virtual method call: ClassName methodName descriptor ldc "test" invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V ; Static method call invokestatic Method java/io/Integer parseInt (Ljava/lang/String;)I pop ; Interface method call ; invokeinterface InterfaceMethod java/util/List size ()I return .end code .end method .end class ``` -------------------------------- ### Implement methods in Krakatau assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Methods require a .method directive with a descriptor, followed by a .code block defining stack and local limits. ```java .class public Foo .super java/lang/Object ; Main method: public static void main(String[] args) ; ([Ljava/lang/String;)V means "takes String[] argument, returns void" .method public static main : ([Ljava/lang/String;)V ; Set generous stack and locals limits (13 each) .code stack 13 locals 13 ; Get System.out (PrintStream) getstatic Field java/lang/System out Ljava/io/PrintStream; ; Push string constant onto stack ldc "Hello World!" ; Call println(Object) invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class ``` -------------------------------- ### Library API - Disassemble Function Source: https://context7.com/storyyeller/krakatau/llms.txt Demonstrates the usage of the `disassemble` function from the Krakatau Rust library to convert Java classfile bytes into assembly text. ```APIDOC ## Library API - Disassemble Function The `disassemble` function takes raw classfile bytes and options, returning the class name and disassembled text. Parser options control attribute handling while disassembler options control output format. ```rust use krakatau2::disassemble; use krakatau2::DisassemblerOptions; use krakatau2::ParserOptions; fn main() -> Result<(), Box> { // Read a classfile let class_data = std::fs::read("Example.class")?; let parse_opts = ParserOptions { no_short_code_attr: false, // Use short code attribute format }; let dis_opts = DisassemblerOptions { roundtrip: false, // Set true for bit-for-bit reproducibility }; let (class_name, assembly_text) = disassemble(&class_data, parse_opts, dis_opts)?; println!("Disassembled class: {:?}", class_name); println!("Assembly:\n{}", String::from_utf8_lossy(&assembly_text)); // Write to .j file // std::fs::write(format!("{}.j", class_name.unwrap()), assembly_text)?; Ok(()) } ``` ``` -------------------------------- ### Access command line arguments Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_tutorial.md A main method that retrieves the first command line argument from the string array and concatenates it with a greeting. ```Krakatau .class public Foo .super java/lang/Object .method public static main : ([Ljava/lang/String;)V .code stack 13 locals 13 getstatic Field java/lang/System out Ljava/io/PrintStream; ldc "Hello, " ; Access args[0] aload_0 iconst_0 aaload ; Concat the strings invokevirtual Method java/lang/String concat (Ljava/lang/String;)Ljava/lang/String; ; Now print like normal invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class ``` -------------------------------- ### Disassemble Jar to Zipfile (Roundtrip Mode) Source: https://github.com/storyyeller/krakatau/blob/v2/README.md Disassembles all classfiles within a JAR archive and packages the bit-for-bit identical assembly output into a new zipfile. Recommended for code relying on non-standard attributes. ```bash krak2 dis --out disassembled.zip --roundtrip r0lling-challenge.jar ``` -------------------------------- ### Disassemble Classfile to Standard Output Source: https://github.com/storyyeller/krakatau/blob/v2/README.md Disassembles a single classfile and writes the human-readable assembly to standard output. Use default mode for readability or `--roundtrip` for bit-for-bit identical output. ```bash krak2 dis --out temp RecordTest.class ``` -------------------------------- ### Bytecode Instruction Set Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_specification.md A comprehensive list of supported JVM bytecode instructions, including stack manipulation, arithmetic, control flow, and object operations. ```APIDOC ## Bytecode Instructions ### Description The Krakatau assembler supports the full range of standard JVM bytecode instructions. These instructions are categorized by their function, such as stack operations (e.g., `dup`, `pop`), arithmetic (e.g., `iadd`, `fmul`), control flow (e.g., `goto`, `if_icmpeq`), and object/field access (e.g., `getfield`, `invokevirtual`). ### Usage Instructions are defined by their mnemonic followed by optional operands (e.g., `aload u8`, `bipush i8`, `checkcast clsref`). Complex instructions like `lookupswitch` and `tableswitch` follow specific block formatting rules. ``` -------------------------------- ### Disassemble Classfile Bytes using Rust API Source: https://context7.com/storyyeller/krakatau/llms.txt Shows how to use the `disassemble` function from the Krakatau Rust library to convert raw classfile bytes into assembly text. Options control parsing and output format. ```rust use krakatau2::disassemble; use krakatau2::DisassemblerOptions; use krakatau2::ParserOptions; fn main() -> Result<(), Box> { // Read a classfile let class_data = std::fs::read("Example.class")?; let parse_opts = ParserOptions { no_short_code_attr: false, // Use short code attribute format }; let dis_opts = DisassemblerOptions { roundtrip: false, // Set true for bit-for-bit reproducibility }; let (class_name, assembly_text) = disassemble(&class_data, parse_opts, dis_opts)?; println!("Disassembled class: {:?}", class_name); println!("Assembly:\n{}", String::from_utf8_lossy(&assembly_text)); // Write to .j file // std::fs::write(format!("{}.j", class_name.unwrap()), assembly_text)?; Ok(()) } ``` -------------------------------- ### Disassemble Java classfiles with krak2 Source: https://context7.com/storyyeller/krakatau/llms.txt Use the disassembler to convert binary classfiles or JARs into assembly format. Roundtrip mode is recommended for non-standard attributes or exact binary reproduction. ```bash # Disassemble a single classfile to a directory krak2 dis --out temp RecordTest.class # Disassemble a JAR file in roundtrip mode to a zip archive krak2 dis --out disassembled.zip --roundtrip r0lling-challenge.jar # Disassemble to stdout (no --out option) krak2 dis MyClass.class # Disassemble with roundtrip mode for exact binary reproduction krak2 dis -r --out output.j Original.class # Disassemble entire JAR to individual files in a directory krak2 dis --out ./disassembled/ application.jar ``` -------------------------------- ### Array Operations in Assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Illustrates array manipulation in assembly using instructions like 'aload_0', 'iconst_0', and 'aaload' to access elements from an object array. ```java .class public ArrayExample .super java/lang/Object .method public static main : ([Ljava/lang/String;)V .code stack 13 locals 13 getstatic Field java/lang/System out Ljava/io/PrintStream; ; Access first command line argument: args[0] aload_0 ; Load args array reference iconst_0 ; Push index 0 aaload ; Load element at index (object array) ; String concatenation ldc "Hello, " swap ; Swap so "Hello, " is first invokevirtual Method java/lang/String concat (Ljava/lang/String;)Ljava/lang/String; invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class ``` -------------------------------- ### Define Exception Handler in Assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Demonstrates how to define a try-catch region for a specific exception class in Krakatau assembly syntax. The `.catch` directive specifies the exception, protected range, and handler label. ```java .class public ExceptionDemo .super java/lang/Object .method public static safeParse : (Ljava/lang/String;)I .code stack 2 locals 2 ; Define exception handler for NumberFormatException .catch java/lang/NumberFormatException from LTRY to LEND using LCATCH LTRY: aload_0 invokestatic Method java/lang/Integer parseInt (Ljava/lang/String;)I LEND: ireturn LCATCH: ; Exception object is on stack, pop it pop ; Return default value of 0 iconst_0 ireturn .end code .end method .method public static main : ([Ljava/lang/String;)V .code stack 2 locals 1 getstatic Field java/lang/System out Ljava/io/PrintStream; ldc "abc" invokestatic Method ExceptionDemo safeParse (Ljava/lang/String;)I invokevirtual Method java/io/PrintStream println (I)V return .end code .end method .end class ``` -------------------------------- ### Define classes in Krakatau assembly Source: https://context7.com/storyyeller/krakatau/llms.txt Classes are defined using .class and .super directives. Versioning and interface implementation can be specified as needed. ```java ; Minimal class definition .class public Foo .super java/lang/Object .end class ; Class with interface implementation .class public MyList .super java/lang/Object .implements java/util/List .end class ; Abstract class with version specification .version 55 0 ; Java 11 .class public abstract BaseHandler .super java/lang/Object .end class ``` -------------------------------- ### Define attribute structures Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_specification.md Grammar definitions for various class and method attributes. ```Krakatau attrbody: ".annotationdefault" element_value ".bootstrapmethods" ".code" code_attr ".constantvalue" ldc_rhs ".deprecated" ".enclosing" "method" clsref natref ".exceptions" clsref* ".innerclasses" NL (clsref clsref utfref flags NL)* ".end" "innerclasses" ".linenumbertable" NL (lbl u16 NL)* ".end" "linenumbertable" ".localvariabletable" NL (local_var_table_item NL)* ".end" "localvariabletable" ".localvariabletypetable" NL (local_var_table_item NL)* ".end" "localvariabletypetable" ".methodparameters" NL (utfref flags NL)* ".end" "methodparameters" ".module" module ".modulemainclass" clsref ".modulepackages" single* ".nesthost" clsref ".nestmembers" clsref* ".permittedsubclasses" clsref* ".record" NL (recorD_item NL)* ".end" "record" ".runtime" runtime_visibility runtime_attr ".signature" utfref ".sourcedebugextension" STRING_LITERAL ".sourcefile" utfref ".stackmaptable" ".synthetic" annotation: annotation_sub "annotation" annotation_sub: utfref NL (utfref "=" element_value NL)* ".end" element_value: "annotation" annotation "array" NL (element_value NL)* ".end" "array" "boolean" ldc_rhs "byte" ldc_rhs "char" ldc_rhs "class" utfref "double" ldc_rhs "enum" utfref utfref "float" ldc_rhs "int" ldc_rhs "long" ldc_rhs "short" ldc_rhs "string" utfref local_var_table_item: u16 "is" utfref utfref "from" lbl "to" lbl module: utfref flags "version" utfref NL (".requires" single flags "version" utfref NL)* (".exports" exports_item NL)* (".opens" exports_item NL)* (".uses" clsref NL)* (".provides" clsref "with" (clsref NL)* NL)* ".end" "module" exports_item: single flags ("to" (single NL)*)? record_item: utfref utfref record_attrs? NL record_attrs: ".attributes" (attribute NL)* ".end" "attributes" runtime_visibility: "visible" "invisible" runtime_attr: "annotations" NL (annotation NL)* ".end" "annotations" "paramannotations" NL (param_annotation NL)* ".end" "paramannotations" "typeannotations" NL (type_annotation NL)* ".end" "typeannotations" param_annotation: ".paramannotation" NL (annotation NL)* ".end" "paramannotation" type_annotation: ".typeannotation" ta_target_info ta_target_path annotation_sub "typeannotation" ta_target_info: u8 ta_target_info_body NL ta_target_info_body: "typeparam" u8 "super" u16 "typeparambound" u8 u8 "empty" "methodparam" u8 "throws" u16 "localvar" NL (localvar_info NL)* ".end" "localvar" "catch" u16 "offset" lbl "typearg" lbl u8 localvar_info: "nowhere" "from" lbl "to" lbl ta_target_path: ".typepath" NL (u8 u8 NL)* ".end" "typepath" NL ``` -------------------------------- ### Define a minimal class Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_tutorial.md A basic class definition inheriting from java/lang/Object with no fields or methods. ```Krakatau ; This is a comment. Comments start with ; and go until end of the line .class public Foo .super java/lang/Object ; Java bytecode requires us to explicitly inherit from java.lang.Object .end class ``` -------------------------------- ### Disassemble JAR in Roundtrip Mode Source: https://context7.com/storyyeller/krakatau/llms.txt Command-line usage for disassembling a JAR file in roundtrip mode using Krakatau. This preserves exact binary structure for bit-for-bit compatibility. ```bash # Step 1: Disassemble a JAR file in roundtrip mode krak2 dis --roundtrip --out modified/ target.jar # Step 2: Edit the .j files in the modified/ directory # (Make your bytecode modifications) # Step 3: Reassemble back to a JAR krak2 asm --out modified-target.jar modified/ # Verify the result java -jar modified-target.jar # For single class modification workflow: krak2 dis -r --out MyClass.j MyClass.class # Edit MyClass.j krak2 asm --out MyClass.class MyClass.j ``` -------------------------------- ### Implement Conditional Logic in Krakatau Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_tutorial.md Uses labels and the ifeq instruction to branch execution based on the result of a String.contains() call. ```Krakatau .class public Foo .super java/lang/Object .method public static main : ([Ljava/lang/String;)V .code stack 13 locals 13 getstatic Field java/lang/System out Ljava/io/PrintStream; ; Access the user's name aload_0 iconst_0 aaload ; Store name in the first variable slot for later astore_0 ; See if name contains "Bob" aload_0 ldc "Bob" invokevirtual Method java/lang/String contains (Ljava/lang/CharSequence;)Z ifeq LELSE ldc "Fuck you, " goto LEND LELSE: ldc "Hello, " LEND: ; Load name again so we can concat it to the prefix above aload_0 invokevirtual Method java/lang/String concat (Ljava/lang/String;)Ljava/lang/String; invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V return .end code .end method .end class ``` -------------------------------- ### Constant Pool Definitions Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_specification.md Definitions for constant pool entries including primitive types, class references, and method handles. ```APIDOC ## Constant Pool Structures ### Description Defines how constants are represented in the Krakatau assembly format. This includes tagged constants like `Utf8`, `Int`, `Float`, `Class`, and `MethodHandle`. ### Supported Types - **tagged_const**: Represents structured constants including `Field`, `Method`, `InterfaceMethod`, and `InvokeDynamic`. - **ref_or_tagged_const**: Allows referencing existing constants via `REF` or defining new `tagged_const` entries. - **bsref**: Used for bootstrap method references in dynamic invocation. ``` -------------------------------- ### Krakatau Assembler Token Definitions Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_specification.md Defines regular expressions for various tokens used in Krakatau assembly, including words, references, and different literal types. Ensure correct whitespace separation between tokens. ```regex WORD: (?:[a-zA-Z_$\(<]|[\[A-Z\[])[\w$;/\-\[\(\)<>\+\-]* ``` ```regex REF: \[[a-z0-9_]+\] ``` ```regex BSREF: \[bs:[a-z0-9_]+\] ``` ```regex LABEL_DEF: L\w+: ``` ```regex STRING_LITERAL: b?"[^"\n\\]*(?:\\.[^"\n\\]*)*" b?'[^'\n\\]*(?:\\.[^'\n\\]*)*' ``` ```regex INT_LITERAL: [+-]?(?:0x[0-9a-fA-F]+|[1-9][0-9]*|0) ``` ```regex DOUBLE_LITERAL: [+-]Infinity [+-]NaN(?:<0x[0-9a-fA-F]+>)? [+-]?\d+\.\d+(?:e[+-]?\d+)? // decimal float [+-]?\d+(?:e[+-]?\d+) // decimal float without fraction (exponent mandatory) [+-]?0x[0-9a-fA-F]+(?:\.[0-9a-fA-F]+)?(?:p[+-]?\d+) // hex float ``` -------------------------------- ### Define Krakatau source file structure Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_specification.md The top-level structure of a Krakatau assembly file, which can contain multiple class definitions. ```Krakatau source_file: NL? class_def* class_def: (".version" u16 u16 NL)? ".class" flags clsref NL ".super" clsref NL interface* clsitem* ".end" "class" NL interface: ".implements" clsref NL clsitem: ".bootstrap" BSREF "=" ref_or_tagged_bootstrap NL ".const" REF "=" ref_or_tagged_const NL field NL method NL attribute NL field: ".field" flags utfref utfref ("=" ldc_rhs)? fieldattrs? fieldattrs: ".fieldattributes" NL (attribute NL)* ".end" "fieldattributes" method: ".method" flags utfref ":" utfref NL (attribute NL)* ".end" "method" attribute: ".attribute" utfref ("length" u32)? STRING_LITERAL ".attribute" utfref ("length" u32)? attrbody attrbody ``` -------------------------------- ### Define code attribute structure Source: https://github.com/storyyeller/krakatau/blob/v2/docs/assembly_specification.md Grammar for the .code attribute, including stack map frames and instructions. ```Krakatau code_attr: "long"? "stack" u16 "locals" u16 NL (code_item NL)* (attribute NL)* ".end" "code" code_item: LABEL_DEF instruction? instruction code_directive code_directive: ".catch" clsref "from" lbl "to" lbl "using" lbl ".stack" stack_map_item stack_map_item: "same" "stack_1" vtype "stack_1_extended" vtype "chop" u8 "same_extended" "append" vtype+ "full" NL "locals" vtype* NL "stack" vtype* NL ".end" "stack" vtype: ``` -------------------------------- ### Modify ClassLoaderError in error.py Source: https://github.com/storyyeller/krakatau/wiki/Small-correction Update the exception constructor to provide clearer instructions regarding the -path option. ```python class ClassLoaderError(Exception): def __init__(self, typen=None, data=""): self.type = typen self.data = data message = "\nI'm gonna die now. Did you pass the current directory (.) to the -path option when calling decompile.py??" message += "\n{}: {}".format(typen, data) if typen else str(data) super(ClassLoaderError, self).__init__(message) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.