Skip to content

Commit beebc80

Browse files
committed
Linkable BiConsumer
1 parent a9783ef commit beebc80

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

debug/spigot/eula.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Accepted by Spigradle
2+
# 2023-07-25T15:01:58.662297814
3+
eula=true

debug/spigot/spigot.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
settings:
2+
restart-on-crash: false

include/net_ioixd_blackbox_BiConsumerLink.h

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/src/lib.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl LibraryManager {
5050
static mut LIBRARY_MANAGER: Lazy<LibraryManager> = Lazy::new(|| LibraryManager::new());
5151

5252
use jni::{
53-
objects::{JObject, JString},
53+
objects::{JClass, JObject, JString},
5454
sys::{jboolean, jint},
5555
JNIEnv,
5656
};
@@ -270,6 +270,28 @@ pub extern "system" fn Java_net_ioixd_blackbox_Native_execute<'a>(
270270
return func(env, address, plugin, ev);
271271
}
272272

273+
type BiConsumer = unsafe extern "system" fn(t: JObject, u: JObject);
274+
#[no_mangle]
275+
pub extern "system" fn Java_net_ioixd_blackbox_BiConsumerLink_acceptNative<'a>(
276+
mut env: JNIEnv<'a>,
277+
this: JObject,
278+
obj1: JObject,
279+
obj2: JObject,
280+
) {
281+
|| -> Result<(), Box<dyn Error>> {
282+
let field = env.get_field(this, "address", "J");
283+
let address_raw = unwrap_result_or_java_error(&mut env, "", field);
284+
let address = address_raw.j()? as u64;
285+
println!("{:#x}", address);
286+
unsafe {
287+
let func: BiConsumer = std::mem::transmute(address);
288+
func(obj1, obj2);
289+
}
290+
Ok(())
291+
}()
292+
.unwrap();
293+
}
294+
273295
pub fn unwrap_result_or_java_error<V, E, S>(
274296
mut env: &mut JNIEnv,
275297
libname: S,
@@ -304,6 +326,7 @@ where
304326
match opt {
305327
Some(v) => v,
306328
None => {
329+
panic!();
307330
throw_with_error(
308331
&mut env,
309332
"net/ioixd/blackbox/exceptions/NativeLibrarySymbolLoadException",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.ioixd.blackbox;
2+
3+
import java.util.function.BiConsumer;
4+
5+
public class BiConsumerLink implements BiConsumer {
6+
public long address;
7+
8+
BiConsumerLink(long address) {
9+
this.address = address;
10+
}
11+
12+
public native void acceptNative(Object t, Object u);
13+
14+
public void accept(Object t, Object u) {
15+
System.out.println((Object) t + "," + (Object) u);
16+
acceptNative((Object) t, (Object) u);
17+
}
18+
}

0 commit comments

Comments
 (0)