This commit is contained in:
PanSi21 2025-01-05 01:03:07 +01:00
parent 84bcb9fb2e
commit 282a2d04d8
Signed by untrusted user who does not match committer: PanSi21
GPG key ID: 755F8874C65EF462
3 changed files with 14 additions and 8 deletions

View file

@ -1,21 +1,27 @@
import { dlopen, FFIType, suffix } from "bun:ffi"; import { dlopen, FFIType } from "bun:ffi";
const path = `./libtesticolo.so`; const path = `./libtesticolo.so`;
// Carica la libreria
const { symbols } = dlopen(path, { const { symbols } = dlopen(path, {
testicolo: { testicolo: {
args: [FFIType.cstring, FFIType.cstring], args: [FFIType.pointer, FFIType.pointer], // Usato pointer per i buffer
returns: FFIType.void, returns: FFIType.void,
}, },
}); });
const input = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890"; const input = "qwertyuiopasdfghjkllzxcvbnm123456789mnbvcxzlkjhgfdsapoiuytrewq1234567890";
const output = new ArrayBuffer(input.length + 1);
const outputView = new Uint8Array(output);
// Call the function with the input string // Converti la stringa in un buffer (Uint8Array)
symbols.testicolo(input, outputView); const inputBuffer = new TextEncoder().encode(input);
// Convert the output buffer to a string and log it // Crea un buffer di output della stessa dimensione
const result = new TextDecoder().decode(outputView); const outputBuffer = new ArrayBuffer(inputBuffer.length);
// Passa i buffer alla funzione C
symbols.testicolo(inputBuffer, outputBuffer);
// Decodifica l'output dal buffer
const result = new TextDecoder().decode(new Uint8Array(outputBuffer));
console.log(result); console.log(result);

BIN
libtesticolo.so Executable file

Binary file not shown.

BIN
meow Executable file

Binary file not shown.