Commit f745158f authored by Julian Kranz's avatar Julian Kranz

jRReil / GDSL Multiplexer

parent 67d236fc
......@@ -45,7 +45,7 @@ public class Program {
System.out
.println("Using frontend " + frontends[backend_ind] + "...");
n.useBackend(frontends[backend_ind]);
n.useFrontend(backend_ind);
String line = reader.readLine();
if (line == null)
......@@ -88,6 +88,7 @@ public class Program {
System.out.println("Decoding and translating...");
IRReilCollection<IStatement> c = n.decodeAndTranslate(bytes);
n.frontendDescsFree();
n.closeBackend();
// IRReilCollection c = n.decodeAndTranslate(new byte[] { 0x66,
......
......@@ -29,7 +29,7 @@ public class NativeInterface {
@SuppressWarnings("unchecked")
public IRReilCollection<IStatement> decodeAndTranslate(byte[] bytes) {
if (!backendSet)
throw new RuntimeException("Backend not set");
throw new RuntimeException("Frontend not set");
return (IRReilCollection<IStatement>) decodeAndTranslateNative(bytes);
}
......@@ -37,17 +37,21 @@ public class NativeInterface {
return getFrontendsNative();
}
public void useBackend(String backend) {
public void useFrontend(long backend) {
if (backendSet)
throw new RuntimeException("Backend already set");
useBackendNative(backend);
throw new RuntimeException("Frontend already set");
useFrontendNative(backend);
backendSet = true;
}
public void frontendDescsFree() {
frontendDescsFreeNative();
}
public void closeBackend() {
if (!backendSet)
throw new RuntimeException("Backend not set");
closeBackendNative();
throw new RuntimeException("Frontend not set");
closeFrontendNative();
backendSet = false;
}
......@@ -622,7 +626,9 @@ public class NativeInterface {
private native String[] getFrontendsNative();
private native void useBackendNative(String backend);
private native void useFrontendNative(long backend);
private native void frontendDescsFreeNative();
private native void closeBackendNative();
private native void closeFrontendNative();
}
......@@ -858,18 +858,18 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject
return frontend.translator.rreil_convert_sem_stmts(state, &callbacks, rreil);
}
struct frontend_desc *descs;
size_t frontends_length;
struct frontend_desc *descs = NULL;
size_t descs_length = 0;
JNIEXPORT
jobjectArray
JNICALL Java_rnati_NativeInterface_getFrontendsNative(JNIEnv *env, jobject obj) {
frontends_length = gdsl_multiplex_frontends_list(&descs);
descs_length = gdsl_multiplex_frontends_list(&descs);
jobjectArray jfrontends = (*env)->NewObjectArray(env, frontends_length, (*env)->FindClass(env, "java/lang/String"),
jobjectArray jfrontends = (*env)->NewObjectArray(env, descs_length, (*env)->FindClass(env, "java/lang/String"),
(*env)->NewStringUTF(env, ""));
for(size_t i = 0; i < frontends_length; ++i) {
for(size_t i = 0; i < descs_length; ++i) {
jstring next = (*env)->NewStringUTF(env, descs[i].name);
// free(frontends[i]);
(*env)->SetObjectArrayElement(env, jfrontends, i, next);
......@@ -888,10 +888,13 @@ JNICALL Java_rnati_NativeInterface_getFrontendsNative(JNIEnv *env, jobject obj)
JNIEXPORT
void
JNICALL Java_rnati_NativeInterface_usefrontendNative(JNIEnv *env, jobject obj, jlong frontend) {
JNICALL Java_rnati_NativeInterface_useFrontendNative(JNIEnv *env, jobject obj, jlong frontend_idx) {
// const char *frontend_str_n = (*env)->GetStringUTFChars(env, frontend_str, 0);
switch(gdsl_multiplex_frontend_get(&frontend, descs[(long)frontend])) {
if(!descs || frontend_idx >= descs_length)
THROW_RUNTIME("Invalid frontend")
switch(gdsl_multiplex_frontend_get(&frontend, descs[frontend_idx])) {
case GDSL_MULTIPLEX_ERROR_FRONTENDS_PATH_NOT_SET: THROW_RUNTIME("Unable to open frontend: Path to frontends not set")
case GDSL_MULTIPLEX_ERROR_UNABLE_TO_OPEN: THROW_RUNTIME("Unable to open frontend: Unable to open frontend library")
case GDSL_MULTIPLEX_ERROR_SYMBOL_NOT_FOUND: THROW_RUNTIME("Unable to open frontend: Symbol not found")
......@@ -901,6 +904,14 @@ JNICALL Java_rnati_NativeInterface_usefrontendNative(JNIEnv *env, jobject obj, j
// (*env)->ReleaseStringUTFChars(env, frontend_str, frontend_str_n);
}
JNIEXPORT
void
JNICALL Java_rnati_NativeInterface_frontendDescsFreeNative(JNIEnv *env, jobject obj) {
gdsl_multiplex_descs_free(descs, descs_length);
descs = NULL;
descs_length = 0;
}
JNIEXPORT
void
JNICALL Java_rnati_NativeInterface_closeFrontendNative(JNIEnv *env, jobject obj) {
......
......@@ -16,6 +16,7 @@ JNIEXPORT jobject JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JN
JNIEXPORT jobjectArray JNICALL Java_rnati_NativeInterface_getFrontendsNative(JNIEnv *, jobject);
JNIEXPORT void JNICALL Java_rnati_NativeInterface_useFrontendNative(JNIEnv *, jobject, jlong);
JNIEXPORT void JNICALL Java_rnati_NativeInterface_frontendDescsFreeNative(JNIEnv *, jobject);
JNIEXPORT void JNICALL Java_rnati_NativeInterface_closeFrontendNative(JNIEnv *, jobject);
#ifdef __cplusplus
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment