Commit ea4f0504 authored by Julian Kranz's avatar Julian Kranz

Jgdrr

- Continued to implement gdrr
- Continued to implement jgdrr
parent 88cfd036
/*
* gdrr.h
* gdrr_types.h
*
* Created on: Feb 22, 2013
* Created on: Mar 10, 2013
* Author: jucs
*/
#ifndef GDRR_H_
#define GDRR_H_
#include <dis.h>
typedef void gdrr_sem_id_t;
typedef void gdrr_sem_address_t;
typedef void gdrr_sem_var_t;
typedef void gdrr_sem_linear_t;
typedef void gdrr_sem_op_t;
typedef void gdrr_sem_branch_hint;
typedef void gdrr_sem_stmt_t;
typedef void gdrr_sem_stmts_t;
struct gdrr_sem_id_callbacks {
gdrr_sem_id_t *(*virt_eq)(void *closure);
gdrr_sem_id_t *(*virt_neq)(void *closure);
gdrr_sem_id_t *(*virt_les)(void *closure);
gdrr_sem_id_t *(*virt_leu)(void *closure);
gdrr_sem_id_t *(*virt_lts)(void *closure);
gdrr_sem_id_t *(*virt_ltu)(void *closure);
gdrr_sem_id_t *(*virt_t)(void *closure, __word this);
};
struct gdrr_sem_address_callbacks {
gdrr_sem_address_t *(*sem_address)(void *closure, __word size,
gdrr_sem_linear_t *address);
};
struct gdrr_sem_var_callbacks {
gdrr_sem_var_t *(*sem_var)(void *closure, gdrr_sem_id_t *id, __word offset);
};
struct gdrr_sem_linear_callbacks {
gdrr_sem_linear_t *(*sem_lin_var)(void *closure, gdrr_sem_var_t *this);
gdrr_sem_linear_t *(*sem_lin_imm)(void *closure, __word imm);
gdrr_sem_linear_t *(*sem_lin_add)(void *closure, gdrr_sem_linear_t *opnd1,
gdrr_sem_linear_t *opnd2);
gdrr_sem_linear_t *(*sem_lin_sub)(void *closure, gdrr_sem_linear_t *opnd1,
gdrr_sem_linear_t *opnd2);
gdrr_sem_linear_t *(*sem_lin_scale)(void *closure, __word imm,
gdrr_sem_linear_t *opnd);
};
struct gdrr_sem_op_callbacks {
gdrr_sem_op_t *(*sem_lin)(void *closure, __word size,
gdrr_sem_linear_t *opnd1);
gdrr_sem_op_t *(*sem_mul)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_div)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_divs)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_mod)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_shl)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_shr)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_shrs)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_and)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_or)(void *closure, __word size, gdrr_sem_linear_t *opnd1,
gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_xor)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_sx)(void *closure, __word size, __word fromsize,
gdrr_sem_linear_t *opnd1);
gdrr_sem_op_t *(*sem_zx)(void *closure, __word size, __word fromsize,
gdrr_sem_linear_t *opnd1);
gdrr_sem_op_t *(*sem_cmpeq)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_cmpneq)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_cmples)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_cmpleu)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_cmplts)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_cmpltu)(void *closure, __word size,
gdrr_sem_linear_t *opnd1, gdrr_sem_linear_t *opnd2);
gdrr_sem_op_t *(*sem_arb)(void *closure, __word size);
};
struct gdrr_sem_stmt_callbacks {
gdrr_sem_stmt_t *(*sem_assign)(void *closure, gdrr_sem_var_t *lhs,
gdrr_sem_op_t *rhs);
gdrr_sem_stmt_t *(*sem_load)(void *closure, gdrr_sem_var_t *lhs, __word size,
gdrr_sem_address_t *address);
gdrr_sem_stmt_t *(*sem_store)(void *closure, gdrr_sem_var_t *lhs,
gdrr_sem_op_t *rhs);
gdrr_sem_stmt_t *(*sem_ite)(void *closure, gdrr_sem_linear_t *cond,
gdrr_sem_stmts_t *then_branch, gdrr_sem_stmts_t *else_branch);
gdrr_sem_stmt_t *(*sem_while)(void *closure, gdrr_sem_linear_t *cond,
gdrr_sem_stmts_t *body);
gdrr_sem_stmt_t *(*sem_cbranch)(void *closure, gdrr_sem_linear_t *cond,
gdrr_sem_address_t *target_true, gdrr_sem_address_t *target_false);
gdrr_sem_stmt_t *(*sem_branch)(void *closure,
gdrr_sem_branch_hint *branch_hint, gdrr_sem_address_t *target);
};
struct gdrr_sem_branch_hint_callbacks {
gdrr_sem_branch_hint *(*hint_jump)(void *closure);
gdrr_sem_branch_hint *(*hint_call)(void *closure);
gdrr_sem_branch_hint *(*hint_ret)(void *closure);
};
struct gdrr_sem_stmts_callbacks {
gdrr_sem_stmts_t *(*sem_cons)(void *closure, gdrr_sem_stmt_t *hd,
gdrr_sem_stmts_t *tl);
gdrr_sem_stmts_t *(*sem_nil)(void *closure);
};
struct gdrr_sem_stmts_list_callbacks {
gdrr_sem_stmts_t *(*list_next)(void *closure, gdrr_sem_stmt_t *next,
gdrr_sem_stmts_t *list);
gdrr_sem_stmts_t *(*list_init)(void *closure);
};
enum gdrr_config_stmts_handling {
GDRR_CONFIG_STMTS_HANDLING_RECURSIVE, GDRR_CONFIG_STMTS_HANDLING_LIST
};
struct gdrr_config {
struct {
struct gdrr_sem_id_callbacks sem_id;
struct gdrr_sem_address_callbacks sem_address;
struct gdrr_sem_var_callbacks sem_var;
struct gdrr_sem_linear_callbacks sem_linear;
struct gdrr_sem_op_callbacks sem_op;
struct gdrr_sem_stmt_callbacks sem_stmt;
struct gdrr_sem_branch_hint_callbacks sem_branch_hint;
union {
struct gdrr_sem_stmts_callbacks sem_stmts;
struct gdrr_sem_stmts_list_callbacks sem_stmts_list;
};
} callbacks;
enum gdrr_config_stmts_handling gdrr_config_stmts_handling;
void *closure;
};
#include <gdrr_config.h>
gdrr_sem_stmts_t *gdrr_convert(__obj semantics, struct gdrr_config *config);
......
......@@ -9,7 +9,8 @@
#include <stdio.h>
#include <stdint.h>
#include <dis.h>
#include "gdrr.h"
#include <gdrr.h>
#include <x86.h>
static gdrr_sem_id_t *gdrr_convert_sem_id(__obj sem_id_obj,
struct gdrr_config *config);
......@@ -67,6 +68,10 @@ static gdrr_sem_id_t *gdrr_convert_sem_id(__obj sem_id_obj,
__CASETAGINT(this));
break;
}
default: {
sem_id = gdrr_convert_sem_id_x86(sem_id_obj, config);
break;
}
}
return sem_id;
......
/*
* x86.c
*
* Created on: Mar 10, 2013
* Author: jucs
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <dis.h>
#include <gdrr_config.h>
#include <x86.h>
gdrr_sem_id_t *gdrr_convert_sem_id_x86(__obj sem_id_obj,
struct gdrr_config *config) {
gdrr_sem_id_t *sem_id = NULL;
switch(__CASETAGCON(sem_id_obj)) {
case __Sem_SP: {
sem_id = config->callbacks.arch.x86.sem_id.sem_sp(config->closure);
break;
}
}
return sem_id;
}
......@@ -54,6 +54,10 @@ public class NativeInterface {
private Object virt_t(Object t) {
return builder.virt_t((Long) t);
}
private Object sem_sp() {
return builder.sem_sp();
}
/*
* sem_address
......
......@@ -117,6 +117,10 @@ static gdrr_sem_id_t *virt_t(void *closure, __word t) {
java_long_create(closure, (long int)t));
return (gdrr_sem_id_t*)ret;
}
static gdrr_sem_id_t *sem_sp(void *closure) {
jobject ret = java_method_call(closure, "sem_sp", 0);
return (gdrr_sem_id_t*)ret;
}
// sem_address
static gdrr_sem_address_t *sem_address(void *closure, __word size,
......@@ -373,8 +377,8 @@ static gdrr_sem_stmts_t *list_init(void *closure) {
JNIEXPORT
jobject
JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject obj,
jbyteArray input) {
JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env,
jobject obj, jbyteArray input) {
__char blob[15];
char fmt[1024];
__word sz = 15;
......@@ -397,13 +401,16 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject
//__pretty(__pretty__, insn, fmt, 1024);
puts(fmt);
//printf("---------------------------\n");
printf("---------------------------\n");
__obj r = __translate(__translate__, insn);
if(___isNil(r))
__fatal("translate failed");
else {
//__pretty(__rreil_pretty__, r, fmt, 1024);
__pretty(__rreil_pretty__, r, fmt, 1024);
printf("---------------------------\n");
puts(fmt);
struct gdrr_config config;
......@@ -415,6 +422,7 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject
config.callbacks.sem_id.virt_lts = &virt_lts;
config.callbacks.sem_id.virt_ltu = &virt_ltu;
config.callbacks.sem_id.virt_t = &virt_t;
config.callbacks.arch.x86.sem_id.sem_sp = &sem_sp;
config.callbacks.sem_address.sem_address = &sem_address;
......
......@@ -9,6 +9,8 @@ import rreil.id.VirtualLessOrEqualUnsignedId;
import rreil.id.VirtualLessSignedId;
import rreil.id.VirtualLessUnsignedId;
import rreil.id.VirtualTemporaryId;
import rreil.id.x86.X86Register;
import rreil.id.x86.X86RegisterId;
import rreil.linear.ILinearExpression;
import rreil.linear.LinearAdditionExpression;
import rreil.linear.LinearExpression;
......@@ -88,6 +90,11 @@ public class DefaultRReilBuilder implements IRReilBuilder {
public Id virt_t(long t) {
return new VirtualTemporaryId(t);
}
@Override
public IId sem_sp() {
return new X86RegisterId(X86Register.SP);
}
/*
* sem_address
......
......@@ -23,6 +23,8 @@ public interface IRReilBuilder {
IId virt_ltu();
IId virt_t(long t);
IId sem_sp();
/*
* sem_address
......
......@@ -15,7 +15,7 @@ public class Variable implements IVariable {
return offset;
}
public Variable(Id id, long offset) {
public Variable(Id id, long offset) {
this.id = id;
this.offset = offset;
}
......
package rreil.id.x86;
public enum X86Register {
SP
}
package rreil.id.x86;
import rreil.id.Id;
public class X86RegisterId extends Id {
private X86Register register;
public X86Register getRegister() {
return register;
}
public X86RegisterId(X86Register register) {
this.register = register;
}
@Override
public String toString() {
return register.toString();
}
}
......@@ -22,6 +22,6 @@ public abstract class LinearBinaryExpression extends LinearExpression {
@Override
public String toString() {
return "(" + operand1 + " " + getOperatorString() + " " + ")";
return "(" + operand1 + " " + getOperatorString() + " " + operand2 + ")";
}
}
......@@ -11,6 +11,6 @@ public class AndOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " &:" + size + " " + operand2;
return operand1 + " &:" + size + " " + operand2;
}
}
......@@ -10,6 +10,6 @@ public class CompareLessOrEqualSignedOperation extends BinaryOperation {
}
public String toString() {
return operand1 + " <=s:" + size + " " + operand2;
return operand1 + " <=s:" + size + " " + operand2;
}
}
......@@ -10,6 +10,6 @@ public class CompareLessOrEqualUnsignedOperation extends BinaryOperation {
}
public String toString() {
return operand1 + " <=u:" + size + " " + operand2;
return operand1 + " <=u:" + size + " " + operand2;
}
}
......@@ -10,6 +10,6 @@ public class CompareLessSignedOperation extends BinaryOperation {
}
public String toString() {
return operand1 + " <s:" + size + " " + operand2;
return operand1 + " <s:" + size + " " + operand2;
}
}
......@@ -10,6 +10,6 @@ public class CompareLessUnsignedOperation extends BinaryOperation {
}
public String toString() {
return operand1 + " <u:" + size + " " + operand2;
return operand1 + " <u:" + size + " " + operand2;
}
}
......@@ -10,6 +10,6 @@ public class CompareNotEqualOperation extends BinaryOperation {
}
public String toString() {
return operand1 + " !=:" + size + " " + operand2;
return operand1 + " !=:" + size + " " + operand2;
}
}
......@@ -10,6 +10,6 @@ public class DivisionOperation extends BinaryOperation {
}
public String toString() {
return operand1 + " /u:" + size + " " + operand2;
return operand1 + " /u:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class ModuloOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " %:" + size + " " + operand2;
return operand1 + " %:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class MultiplicationOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " *:" + size + " " + operand2;
return operand1 + " *:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class OrOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " |:" + size + " " + operand2;
return operand1 + " |:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class ShiftLeftOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " <<:" + size + " " + operand2;
return operand1 + " <<:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class ShiftRightOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " >>u:" + size + " " + operand2;
return operand1 + " >>u:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class ShiftRightSignedOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " >>s:" + size + " " + operand2;
return operand1 + " >>s:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class SignedDivisionOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " /s:" + size + " " + operand2;
return operand1 + " /s:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class XorOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " ^:" + size + " " + operand2;
return operand1 + " ^:" + size + " " + operand2;
}
}
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