Skip to content

Bytecode & Length patching

hydrophobis edited this page Mar 25, 2025 · 2 revisions

Overview

These functions manage the bytecode section of the Java class file. The bytecode section contains the actual instructions that the JVM will execute.


1. Bytecode Section Management

  • void bytecode_start()
    Initializes the bytecode section. Reserves space for the bytecode_length and sets the offset for the bytecode.

  • void ldc(1) Loads the first constant onto the stack

  • void bytecode_end()
    Finalizes the bytecode section by patching the bytecode_length at the reserved location.


2. Utility Functions

  • void patch_u4(size_t pos, uint32_t v)
    Updates a 4-byte value in the buffer (used to finalize bytecode_length).

  • size_t current_offset()
    Returns the current offset in the bytecode buffer.


Usage Example

bytecode_start();
// bytecode functions go here
bytecode_end();

This will create a bytecode section with the proper length.


Clone this wiki locally