warlocks-stave/bridges/WarlockStaveBridge.java

62 lines
1.8 KiB
Java

package org.stave;
import java.nio.ByteBuffer;
/**
* Forms the native memory pipeline within a Java-based disassembler host.
* Manages execution events from an emulator or debug interface
* and passes raw byte arrays down to the compiled stave-core library
* with zero-copy overhead via DirectByteBuffer.
*/
public class WarlockStaveBridge {
private long nativeContextHandle = 0;
static {
// Loads the native library (libstave_core.so / stave_core.dll)
System.loadLibrary("stave_core");
}
private native long initializeWarlockStave();
private native String staveIngestGhidraFrame(
long contextPtr, ByteBuffer buffer, long rip, int eflags
);
private native void destroyWarlockStave(long contextPtr);
public void initializeComponent() {
this.nativeContextHandle = initializeWarlockStave();
}
public synchronized void processEmulatorStepEvent(
long executionRip,
byte[] memoryPageFrame,
int registerEflags
) {
if (this.nativeContextHandle == 0) return;
ByteBuffer directBuffer =
ByteBuffer.allocateDirect(memoryPageFrame.length);
directBuffer.put(memoryPageFrame);
directBuffer.flip();
String telemetryJsonOutput = staveIngestGhidraFrame(
this.nativeContextHandle,
directBuffer,
executionRip,
registerEflags
);
dispatchToWorkspace(telemetryJsonOutput);
}
private void dispatchToWorkspace(String jsonStateFrame) {
// Enqueues the serialized tracking snapshot onto
// the main UI event stream for rendering.
}
public void terminateComponent() {
if (this.nativeContextHandle != 0) {
destroyWarlockStave(this.nativeContextHandle);
this.nativeContextHandle = 0;
}
}
}