Commit 28af3bd8 authored by Julian Kranz's avatar Julian Kranz

Jgdrr

- Continued to implement jgdrr
parent 6cc2297a
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import rnati.*;
import rreil.DefaultRReilBuilder;
import rreil.IRReilCollection;
public class Program {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
DefaultRReilBuilder builder = new DefaultRReilBuilder();
NativeInterface n = new NativeInterface(builder);
IRReilCollection c = n.decodeAndTranslate(new byte[] { 0x66, 0x0f, 0x38, 0x04, (byte)0xd1 });
// IRReilCollection c = n.decodeAndTranslate(new byte[] { 0x66 });
// IRReilCollection c = n.decodeAndTranslate(null);
for (int i = 0; i < c.size(); i++) {
System.out.println(c.get(i));
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
while (true) {
String line = reader.readLine();
if(line == null)
break;
else if(line.length() == 0)
continue;
System.out.println("Interpreting \"" + line + "\"...");
ArrayList<Byte> byteList = new ArrayList<Byte>();
byte next = 0;
int part = 0;
for (int i = 0; i < line.length(); i++) {
char nextChar = line.charAt(i);
if (nextChar == 'x') {
part = next = 0;
continue;
} else if (nextChar == ' ')
continue;
else if (nextChar >= 'a' && nextChar <= 'f')
nextChar = (char) ((nextChar - 'a') + 10);
else if (nextChar >= '0' && nextChar <= '9')
nextChar -= '0';
else
throw new RuntimeException("Invalid input.");
if (part == 0)
next = (byte) (nextChar << 4);
else {
next |= nextChar;
byteList.add(next);
}
part = 1 - part;
}
byte[] bytes = new byte[byteList.size()];
for (int i = 0; i < bytes.length; i++)
bytes[i] = byteList.get(i);
DefaultRReilBuilder builder = new DefaultRReilBuilder();
NativeInterface n = new NativeInterface(builder);
System.out.println("Decoding and translating...");
IRReilCollection c = n.decodeAndTranslate(bytes);
// IRReilCollection c = n.decodeAndTranslate(new byte[] { 0x66,
// 0x0f,
// 0x38, 0x04, (byte) 0xd1 });
// IRReilCollection c = n.decodeAndTranslate(new byte[] { 0x66 });
// IRReilCollection c = n.decodeAndTranslate(null);
System.out.println("RReil:");
for (int i = 0; i < c.size(); i++) {
System.out.println(c.get(i));
}
}
}
}
package rnati;
public class RReilTranslateException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
public RReilTranslateException() {
// TODO Auto-generated constructor stub
}
public RReilTranslateException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public RReilTranslateException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
public RReilTranslateException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
}
......@@ -615,25 +615,24 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env,
__obj state = __createState(bytes, length, 0, 0);
__obj insn = __runMonadicNoArg(__decode__, &state);
if(1 || ___isNil(insn)) {
if(___isNil(insn)) {
jclass exp = (*env)->FindClass(env, "rnati/ReilDecodeException");
(*env)->ThrowNew(env, exp, "Decode failed.");
return NULL;
} else {
//__pretty(__pretty__, insn, fmt, 1024);
// puts(fmt);
printf("---------------------------\n");
// printf("---------------------------\n");
__obj r = __runMonadicOneArg(__translate__, &state, insn);
if(___isNil(r))
__fatal("translate failed");
else {
if(___isNil(r)) {
jclass exp = (*env)->FindClass(env, "rnati/RReilTranslateException");
(*env)->ThrowNew(env, exp, "Translate failed.");
return NULL;
} else {
// __pretty(__rreil_pretty__, r, fmt, 2048);
printf("---------------------------\n");
// printf("---------------------------\n");
// puts(fmt);
struct gdrr_config config;
......@@ -756,7 +755,7 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env,
cls.obj = obj;
config.closure = &cls;
gdrr_convert(r, &config);
return gdrr_convert(r, &config);
}
}
......
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