Skip to content

Adding and managing interfaces

hydrophobis edited this page Mar 25, 2025 · 1 revision

Overview

These functions manage the interfaces section of the Java class file. This section lists interfaces implemented by the class.


1. Initialization & Finalization

  • void interfaces_start()
    Initializes the interfaces section. Reserves space for the interfaces_count and starts the counter at 0.

  • void interfaces_end()
    Finalizes the interfaces section by patching the total entry count at the reserved location.


2. Interface Entry Function

  • Interface Referenceinterface_entry(uint16_t interface_val)
    Adds an interface reference to the section. Increments the counter.

3. Utility Functions

  • void patch_u2(size_t pos, uint16_t v)
    Updates a 2-byte value in the buffer (used to finalize interfaces_count).

Usage Example

interfaces_start();
interface_entry(1); // Adds an interface reference to the first object in the constant pool
interface_entry(2); // Adds another interface reference to the second
interfaces_end();

This will generate an interfaces section with two entries.


Clone this wiki locally