Commit 88cfd036 authored by Julian Kranz's avatar Julian Kranz

Jgdrr

- Continued to implement jgdrr
parent 528d51ea
import rnati.*;
import rreil.DefaultRReilBuilder;
import rreil.IRReilCollection;
public class Program {
......@@ -6,8 +8,14 @@ public class Program {
* @param args
*/
public static void main(String[] args) {
NativeInterface n = new NativeInterface();
DefaultRReilBuilder builder = new DefaultRReilBuilder();
NativeInterface n = new NativeInterface(builder);
n.decodeAndTranslate(null);
IRReilCollection c = n.decodeAndTranslate(null);
for (int i = 0; i < c.size(); i++) {
System.out.println(c.get(i));
}
}
}
This diff is collapsed.
......@@ -394,16 +394,16 @@ JNICALL Java_rnati_NativeInterface_decodeAndTranslateNative(JNIEnv *env, jobject
if(___isNil(insn))
__fatal("decode failed");
else {
__pretty(__pretty__, insn, fmt, 1024);
//__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);
puts(fmt);
struct gdrr_config config;
......
......@@ -2,7 +2,7 @@ package rreil;
import rreil.linear.LinearExpression;
public class Address {
public class Address implements IAddress {
protected long size;
public long getSize() {
......
package rreil;
public enum BranchHint {
public enum BranchHint implements IBranchHint {
JUMP, CALL, RET
}
package rreil;
import rreil.id.IId;
import rreil.id.Id;
import rreil.id.VirtualEqualsId;
import rreil.id.VirtualEqualsNotId;
import rreil.id.VirtualLessOrEqualSignedId;
import rreil.id.VirtualLessOrEqualUnsignedId;
import rreil.id.VirtualLessSignedId;
import rreil.id.VirtualLessUnsignedId;
import rreil.id.VirtualTemporaryId;
import rreil.linear.ILinearExpression;
import rreil.linear.LinearAdditionExpression;
import rreil.linear.LinearExpression;
import rreil.linear.LinearImmediateExpression;
import rreil.linear.LinearScaleExpression;
import rreil.linear.LinearSubtractionExpression;
import rreil.linear.LinearVariableExpression;
import rreil.operation.AndOperation;
import rreil.operation.ArbitraryOperation;
import rreil.operation.CompareEqualOperation;
import rreil.operation.CompareLessOrEqualSignedOperation;
import rreil.operation.CompareLessOrEqualUnsignedOperation;
import rreil.operation.CompareLessSignedOperation;
import rreil.operation.CompareLessUnsignedOperation;
import rreil.operation.CompareNotEqualOperation;
import rreil.operation.DivisionOperation;
import rreil.operation.IOperation;
import rreil.operation.LinearOperation;
import rreil.operation.ModuloOperation;
import rreil.operation.MultiplicationOperation;
import rreil.operation.Operation;
import rreil.operation.OrOperation;
import rreil.operation.ShiftLeftOperation;
import rreil.operation.ShiftRightOperation;
import rreil.operation.ShiftRightSignedOperation;
import rreil.operation.SignExtendOperation;
import rreil.operation.SignedDivisionOperation;
import rreil.operation.XorOperation;
import rreil.operation.ZeroExtendOperation;
import rreil.statement.AssignStatement;
import rreil.statement.BranchStatement;
import rreil.statement.ConditionalBranchStatement;
import rreil.statement.IStatement;
import rreil.statement.IfThenElseStatement;
import rreil.statement.LoadStatement;
import rreil.statement.Statement;
import rreil.statement.StoreStatement;
import rreil.statement.WhileStatement;
public class DefaultRReilBuilder implements IRReilBuilder {
/*
* sem_id
*/
@Override
public Id virt_eq() {
return new VirtualEqualsId();
}
@Override
public Id virt_neq() {
return new VirtualEqualsNotId();
}
@Override
public Id virt_les() {
return new VirtualLessOrEqualSignedId();
}
@Override
public Id virt_leu() {
return new VirtualLessOrEqualUnsignedId();
}
@Override
public Id virt_lts() {
return new VirtualLessSignedId();
}
@Override
public Id virt_ltu() {
return new VirtualLessUnsignedId();
}
@Override
public Id virt_t(long t) {
return new VirtualTemporaryId(t);
}
/*
* sem_address
*/
@Override
public Address sem_address(long size, ILinearExpression address) {
return new Address(size, (LinearExpression) address);
}
/*
* sem_var
*/
@Override
public Variable sem_var(IId id, long offset) {
return new Variable((Id) id, offset);
}
/*
* sem_linear
*/
@Override
public LinearExpression sem_lin_var(IVariable _this) {
return new LinearVariableExpression((Variable) _this);
}
@Override
public LinearExpression sem_lin_imm(long imm) {
return new LinearImmediateExpression(imm);
}
@Override
public LinearExpression sem_lin_add(ILinearExpression opnd1,
ILinearExpression opnd2) {
return new LinearAdditionExpression((LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public LinearExpression sem_lin_sub(ILinearExpression opnd1,
ILinearExpression opnd2) {
return new LinearSubtractionExpression((LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public LinearExpression sem_lin_scale(long imm, ILinearExpression opnd) {
return new LinearScaleExpression(imm, (LinearExpression) opnd);
}
/*
* sem_op
*/
@Override
public Operation sem_lin(long size, ILinearExpression opnd1) {
return new LinearOperation(size, (LinearExpression) opnd1);
}
@Override
public Operation sem_mul(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new MultiplicationOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_div(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new DivisionOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_divs(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new SignedDivisionOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_mod(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new ModuloOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_shl(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new ShiftLeftOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_shr(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new ShiftRightOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_shrs(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new ShiftRightSignedOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_and(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new AndOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_or(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new OrOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_xor(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new XorOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_sx(long size, long fromsize, ILinearExpression opnd1) {
return new SignExtendOperation(size, fromsize, (LinearExpression) opnd1);
}
@Override
public Operation sem_zx(long size, long fromsize, ILinearExpression opnd1) {
return new ZeroExtendOperation(size, fromsize, (LinearExpression) opnd1);
}
@Override
public Operation sem_cmpeq(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new CompareEqualOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_cmpneq(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new CompareNotEqualOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_cmples(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new CompareLessOrEqualSignedOperation(size,
(LinearExpression) opnd1, (LinearExpression) opnd2);
}
@Override
public Operation sem_cmpleu(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new CompareLessOrEqualUnsignedOperation(size,
(LinearExpression) opnd1, (LinearExpression) opnd2);
}
@Override
public Operation sem_cmplts(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new CompareLessSignedOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_cmpltu(long size, ILinearExpression opnd1,
ILinearExpression opnd2) {
return new CompareLessUnsignedOperation(size, (LinearExpression) opnd1,
(LinearExpression) opnd2);
}
@Override
public Operation sem_arb(long size) {
return new ArbitraryOperation(size);
}
/*
* sem_branch_hint
*/
@Override
public BranchHint hint_jump() {
return BranchHint.JUMP;
}
@Override
public BranchHint hint_call() {
return BranchHint.CALL;
}
@Override
public BranchHint hint_ret() {
return BranchHint.RET;
}
/*
* sem_stmt
*/
@Override
public Statement sem_assign(IVariable lhs, IOperation rhs) {
return new AssignStatement((Variable) lhs, (Operation) rhs);
}
@Override
public Statement sem_load(IVariable lhs, long size, IAddress address) {
return new LoadStatement((Variable) lhs, size, (Address) address);
}
@Override
public Statement sem_store(IAddress lhs, IOperation rhs) {
return new StoreStatement((Address) lhs, (Operation) rhs);
}
@Override
public Statement sem_ite(ILinearExpression cond,
IRReilCollection then_branch, IRReilCollection else_branch) {
return new IfThenElseStatement((LinearExpression) cond,
(DefaultRReilCollection) then_branch,
(DefaultRReilCollection) else_branch);
}
@Override
public Statement sem_while(ILinearExpression cond, IRReilCollection body) {
return new WhileStatement((LinearExpression) cond,
(DefaultRReilCollection) body);
}
@Override
public Statement sem_cbranch(ILinearExpression cond, IAddress target_true,
IAddress target_false) {
return new ConditionalBranchStatement((LinearExpression) cond,
(Address) target_true, (Address) target_false);
}
@Override
public Statement sem_branch(IBranchHint branch_hint, IAddress target) {
return new BranchStatement((BranchHint) branch_hint, (Address) target);
}
/*
* sem_stmts
*/
@Override
public IRReilCollection list_next(IStatement next, IRReilCollection list) {
list.add(next);
return list;
}
@Override
public IRReilCollection list_init() {
return new DefaultRReilCollection();
}
}
package rreil;
import java.util.ArrayList;
import rreil.statement.IStatement;
import rreil.statement.Statement;
public class DefaultRReilCollection implements IRReilCollection {
ArrayList<Statement> statements = new ArrayList<Statement>();
public void add(IStatement s) {
statements.add((Statement)s);
}
public Statement get(int i) {
return statements.get(i);
}
public int size() {
return statements.size();
}
}
package rreil;
public interface IAddress {
}
package rreil;
public interface IBranchHint {
}
package rreil;
import rreil.id.IId;
import rreil.linear.ILinearExpression;
import rreil.operation.IOperation;
import rreil.statement.IStatement;
public interface IRReilBuilder {
/*
* sem_id
*/
IId virt_eq();
IId virt_neq();
IId virt_les();
IId virt_leu();
IId virt_lts();
IId virt_ltu();
IId virt_t(long t);
/*
* sem_address
*/
IAddress sem_address(long size, ILinearExpression address);
/*
* sem_var
*/
IVariable sem_var(IId id, long offset);
/*
* sem_linear
*/
ILinearExpression sem_lin_var(IVariable _this);
ILinearExpression sem_lin_imm(long imm);
ILinearExpression sem_lin_add(ILinearExpression opnd1,
ILinearExpression opnd2);
ILinearExpression sem_lin_sub(ILinearExpression opnd1,
ILinearExpression opnd2);
ILinearExpression sem_lin_scale(long imm, ILinearExpression opnd);
/*
* sem_op
*/
IOperation sem_lin(long size, ILinearExpression opnd1);
IOperation sem_mul(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_div(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_divs(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_mod(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_shl(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_shr(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_shrs(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_and(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_or(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_xor(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_sx(long size, long fromsize, ILinearExpression opnd1);
IOperation sem_zx(long size, long fromsize, ILinearExpression opnd1);
IOperation sem_cmpeq(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_cmpneq(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_cmples(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_cmpleu(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_cmplts(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_cmpltu(long size, ILinearExpression opnd1,
ILinearExpression opnd2);
IOperation sem_arb(long size);
/*
* sem_branch_hint
*/
IBranchHint hint_jump();
IBranchHint hint_call();
IBranchHint hint_ret();
/*
* sem_stmt
*/
IStatement sem_assign(IVariable lhs, IOperation rhs);
IStatement sem_load(IVariable lhs, long size, IAddress address);
IStatement sem_store(IAddress lhs, IOperation rhs);
IStatement sem_ite(ILinearExpression cond, IRReilCollection then_branch,
IRReilCollection else_branch);
IStatement sem_while(ILinearExpression cond, IRReilCollection body);
IStatement sem_cbranch(ILinearExpression cond, IAddress target_true,
IAddress target_false);
IStatement sem_branch(IBranchHint branch_hint, IAddress target);
/*
* sem_stmts
*/
IRReilCollection list_next(IStatement next, IRReilCollection list);
IRReilCollection list_init();
}
package rreil;
import rreil.statement.IStatement;
public interface IRReilCollection {
void add(IStatement s);
IStatement get(int i);
int size();
}
package rreil;
public interface IVariable {
}
......@@ -2,24 +2,24 @@ package rreil;
import rreil.id.Id;
public class Variable {
public class Variable implements IVariable {
protected Id id;
public Id getId() {
return id;
}
protected long offset;
public long getOffset() {
return offset;
}
public Variable(Id id, long offset) {
this.id = id;
this.offset = offset;
}
@Override
public String toString() {
return id + "@" + offset;
......
package rreil.id;
public interface IId {
}
package rreil.id;
public abstract class Id {
public abstract class Id implements IId {
}
package rreil.linear;
public interface ILinearExpression {
}
package rreil.linear;
public abstract class LinearExpression {
public abstract class LinearExpression implements ILinearExpression {
}
......@@ -11,6 +11,6 @@ public class AndOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " &:" + size + " + operand2";
return operand1 + " &:" + size + " " + operand2;
}
}
......@@ -11,6 +11,6 @@ public class CompareEqualOperation extends BinaryOperation {
@Override
public String toString() {
return operand1 + " ==:" + size + " + operand2";
return operand1 + " ==:" + size + " " + operand2;
}
}
......@@ -2,14 +2,14 @@ package rreil.operation;
import rreil.linear.LinearExpression;
public class CompareLesOrEqualSignedOperation extends BinaryOperation {
public class CompareLessOrEqualSignedOperation extends BinaryOperation {
public CompareLesOrEqualSignedOperation(long size,
public CompareLessOrEqualSignedOperation(long size,
LinearExpression operand1, LinearExpression operand2) {
super(size, operand1, operand2);
}