Skip to content

Attribute management

hydrophobis edited this page Mar 25, 2025 · 1 revision

Overview

These functions manage the attributes section of the Java class file. This section lists the attributes associated with the class.


1. Initialization & Finalization

  • void attributes_start()
    Initializes the attributes section. Reserves space for the attributes_count and starts the counter at 0.

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


2. Attribute Entry Function

  • Attribute Referenceattribute_start(uint16_t attribute_name_index)
    Adds an attribute reference to the section. Increments the counter and reserves space for attribute_length.

  • void attribute_end()
    Finalizes the current attribute by calculating its length and updating the attribute_length field.


3. Utility Functions

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

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


Usage Example

attributes_start();
attribute_start(5); // Adds an attribute reference with name index 5
attribute_end(); // Finalizes the attribute
attributes_end();

This will generate an attributes section with one entry.


Clone this wiki locally