Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connected Jakstab to the Capstone library to replace Jakstab's dissembler component #8

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f99dc4
Updated gitignore to ignore intellij project files
Dmium Jul 18, 2017
84cb98e
Added Capstone and JNA jars
Dmium Jul 18, 2017
b07ac7d
Added copy of libcapstone.so. Copy this to bin to run
Dmium Jul 18, 2017
25abaa5
Capstone now dissasembles at the same time as Jakstab(not sending dat…
Dmium Jul 18, 2017
4bb9357
Working calll instructions with capstone instructions and operands
Dmium Jul 28, 2017
1c4a9f7
Parsing Capstone instructions partially working. DataType converstion…
Dmium Jul 28, 2017
887317e
Begun work on compatablility with CFA
Dmium Jul 28, 2017
f4ba4cb
Fully functional CFA using capstone. Currently mem operands are not f…
Dmium Aug 1, 2017
a274e01
Cleaned up the Parser and Disassembler. Fixed mem operands (mostly)
Dmium Aug 1, 2017
eb74981
Cleaned up some more and (maybe) correctly setup ELF dissassembly.
Dmium Aug 14, 2017
6d2a484
Begun removing unused classes
Dmium Aug 14, 2017
93dd7ff
More cleaning. Remove relative address hack
Dmium Aug 14, 2017
dbe5332
did some more cleaning up and begun work on fixing mem edge cases bef…
Dmium Aug 16, 2017
4148407
Cleaned up some more. Memory operand parsing is cleaner and more conv…
Dmium Aug 17, 2017
d6448bf
more cleaning. rebuilt capstone
Dmium Aug 23, 2017
0cba168
Merged changes and hopefully cleaned up from accedently working in ma…
Dmium Aug 23, 2017
62425d5
Continued testing. Removed some debugging output and speed has increa…
Dmium Aug 25, 2017
801e121
More cleaning. Working on prefixes.
Dmium Aug 29, 2017
e8b36f1
Updated Architecture.java, X86Registers and X86SegmentRegisters to wo…
Dmium Sep 4, 2017
0767667
Fixed registers using old Jakstab numbers. Now using Capstone numbers…
Dmium Sep 5, 2017
1e525b6
Updated jackstab script
Dmium Sep 8, 2017
7d3ad5a
Fixed Float Register parsing bug and removed Float Registers class
Dmium Sep 12, 2017
7b6fac3
Cleaned git ignore and removed testing methods
Dmium Sep 14, 2017
e9d961d
More cleaning. Code sticking a bit closer to convention. Deleted some…
Dmium Sep 14, 2017
bc8d561
Even more cleaning. Commented out some unused and possibly broken met…
Dmium Sep 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.dot
*_jak.asm
*.pdf
.idea/
Jakstab.iml
2 changes: 1 addition & 1 deletion jakstab
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
JS_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
JSCLASSPATH=${JS_HOME}/lib/antlr.jar:${JS_HOME}/lib/google-collect-1.0.jar:lib/javabdd-1.0b2.jar:${JS_HOME}/bin
JSCLASSPATH=${JS_HOME}/lib/antlr.jar:${JS_HOME}/lib/google-collect-1.0.jar:lib/javabdd-1.0b2.jar:${JS_HOME}/bin:${JS_HOME}/lib/capstone.jar:${JS_HOME}/lib/jna-4.4.0.jar
case `uname` in
CYGWIN*)
JSCLASSPATH=`cygpath -p -w -m -s "$JSCLASSPATH"`
Expand Down
Binary file added lib/capstone.jar
Binary file not shown.
Binary file added lib/jna-4.4.0.jar
Binary file not shown.
Binary file added lib/jna-platform-4.4.0.jar
Binary file not shown.
Binary file added lib/libcapstone.so
Binary file not shown.
3 changes: 2 additions & 1 deletion src/org/jakstab/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ public final Instruction getInstruction(AbsoluteAddress address) {
logger.error("Requested instruction outside code section: " + address);
return null;
}
instr = module.getDisassembler().decodeInstruction(fp);
instr = module.getDisassembler().decodeInstruction(fp, address.getValue());
//logger.warn("TT: " + fp + " " + address);
if (instr == null) {
logger.error("Instruction could not be disassembled at: " + address);
}
Expand Down
4 changes: 1 addition & 3 deletions src/org/jakstab/asm/AbsoluteAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
AbsoluteAddress other = (AbsoluteAddress) obj;
if (value != other.value)
return false;
return true;
return (value == other.value);
}
}
4 changes: 4 additions & 0 deletions src/org/jakstab/asm/AbstractInstruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public abstract class AbstractInstruction implements Instruction {
* @param name the instruction mnemonic.
*/
public AbstractInstruction(String name) {
if (name.contains(" "))//TODO-Dom Actually replace with real code this hack is worse than before
name = name.split(" ")[1];
this.name = name;
}

Expand All @@ -52,4 +54,6 @@ public String getName() {
public String toString(long currentPc, SymbolFinder symFinder) {
return name;
}

}

2 changes: 1 addition & 1 deletion src/org/jakstab/asm/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum DataType {

private int bits;

private DataType(int bits) {
DataType(int bits) {
this.bits = bits;
}

Expand Down
8 changes: 4 additions & 4 deletions src/org/jakstab/asm/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public Register(int number) {
* Returns the total number of available registers on this platform
*/
public abstract int getNumberOfRegisters();

/**
/*
*//**
* Returns whether this register has a valid code number.
*/
*//*
public boolean isValid() {
return ((0 <= number) && (number <= getNumberOfRegisters()));
}
}*/

/**
* Returns the code of this register as it appears in instructions.
Expand Down
11 changes: 6 additions & 5 deletions src/org/jakstab/asm/x86/X86ControlRegisters.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

package org.jakstab.asm.x86;

import capstone.X86_const;
import org.jakstab.util.Logger;

/**
Expand All @@ -52,11 +53,11 @@ public class X86ControlRegisters {
private static X86ControlRegister controlRegisters[];

static {
CR0 = new X86ControlRegister(0, "%cr0");
INVALID = new X86ControlRegister(1, "Invalid Control Register");
CR2 = new X86ControlRegister(2, "%cr2");
CR3 = new X86ControlRegister(3, "%cr3");
CR4 = new X86ControlRegister(4, "%cr4");
CR0 = new X86ControlRegister(X86_const.X86_REG_CR0, "%cr0");
INVALID = new X86ControlRegister(X86_const.X86_REG_CR1, "Invalid Control Register");//Not sure if capstone would output CR1 or invalid must test.
CR2 = new X86ControlRegister(X86_const.X86_REG_CR2, "%cr2");
CR3 = new X86ControlRegister(X86_const.X86_REG_CR3, "%cr3");
CR4 = new X86ControlRegister(X86_const.X86_REG_CR4, "%cr4");

controlRegisters = (new X86ControlRegister[] {
CR0, INVALID, CR2, CR3, CR4
Expand Down
17 changes: 10 additions & 7 deletions src/org/jakstab/asm/x86/X86FloatRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@
import org.jakstab.asm.Register;

public class X86FloatRegister extends Register {

public X86FloatRegister(int number) {
protected String name;
public X86FloatRegister(int number, String name) {
super(number);
this.name = name;
}

public int getNumber() {
return number;
}

public int getNumberOfRegisters() {
return X86FloatRegisters.getNumRegisters();
return 8;//X86FloatRegisters.getNumRegisters();
}

public boolean isFloat() {
Expand All @@ -58,12 +59,14 @@ public boolean isStackPointer() {
return false;
}

public boolean isValid() {
return number >= 0 && number < X86FloatRegisters.getNumRegisters();
}
/* public boolean isValid() {
return true;//TODO-Dom temporary fix
//return number >= 0 && number < X86FloatRegisters.getNumRegisters();
}*/

public String toString() {
return X86FloatRegisters.getRegisterName(number);
return name;
//return X86FloatRegisters.getRegisterName(number);
}

}
84 changes: 0 additions & 84 deletions src/org/jakstab/asm/x86/X86FloatRegisters.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/org/jakstab/asm/x86/X86Instruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Instruction evaluate(Context ctx) {
if (!changed)
return this;
else {
X86Instruction inst = null;
X86Instruction inst;
try {
inst = (X86Instruction) super.clone();
inst.operands = new Operand[inst.operands.length];
Expand Down
2 changes: 2 additions & 0 deletions src/org/jakstab/asm/x86/X86InstructionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ public interface X86InstructionFactory {

public X86Instruction newGeneralInstruction(String name, Operand op1, int size, int prefixes);

public X86Instruction newGeneralInstruction(String name, int size, int prefixes);

}
4 changes: 4 additions & 0 deletions src/org/jakstab/asm/x86/X86InstructionFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,9 @@ public X86Instruction newGeneralInstruction(String name, Operand op1, int size,
return new X86Instruction(name, op1, size, prefixes);
}

@Override
public X86Instruction newGeneralInstruction(String name, int size, int prefixes) {
return new X86Instruction(name, size, prefixes);
}
}

17 changes: 9 additions & 8 deletions src/org/jakstab/asm/x86/X86MMXRegisters.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

package org.jakstab.asm.x86;

import capstone.X86_const;
import org.jakstab.util.Logger;

public class X86MMXRegisters {
Expand All @@ -50,14 +51,14 @@ public class X86MMXRegisters {
private static X86MMXRegister mmxRegisters[];

static {
MM0 = new X86MMXRegister(0, "%mm0");
MM1 = new X86MMXRegister(1, "%mm1");
MM2 = new X86MMXRegister(2, "%mm2");
MM3 = new X86MMXRegister(3, "%mm3");
MM4 = new X86MMXRegister(4, "%mm4");
MM5 = new X86MMXRegister(5, "%mm5");
MM6 = new X86MMXRegister(6, "%mm6");
MM7 = new X86MMXRegister(7, "%mm7");
MM0 = new X86MMXRegister(X86_const.X86_REG_MM0, "%mm0");
MM1 = new X86MMXRegister(X86_const.X86_REG_MM1, "%mm1");
MM2 = new X86MMXRegister(X86_const.X86_REG_MM2, "%mm2");
MM3 = new X86MMXRegister(X86_const.X86_REG_MM3, "%mm3");
MM4 = new X86MMXRegister(X86_const.X86_REG_MM4, "%mm4");
MM5 = new X86MMXRegister(X86_const.X86_REG_MM5, "%mm5");
MM6 = new X86MMXRegister(X86_const.X86_REG_MM6, "%mm6");
MM7 = new X86MMXRegister(X86_const.X86_REG_MM7, "%mm7");

mmxRegisters = (new X86MMXRegister[] {
MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7
Expand Down
8 changes: 6 additions & 2 deletions src/org/jakstab/asm/x86/X86MemoryOperand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ public X86SegmentRegister getSegmentRegister() {
}

public X86MemoryOperand(DataType dataType, X86SegmentRegister segReg, X86Register base, X86Register index, long disp, int scale) {
super(dataType, base, index, disp, 1 << scale);
super(dataType, base, index, disp, scale);//1 << scale);
this.segReg = segReg;
}

public X86MemoryOperand(DataType dataType, X86SegmentRegister segReg, X86Register base, X86Register index, long disp) {
this(dataType, segReg, base, index, disp, 0);
}

public X86MemoryOperand(DataType dataType, X86SegmentRegister segReg, X86Register base) {
public X86MemoryOperand(DataType dataType, X86SegmentRegister segReg, X86Register base, long disp){//Dom- Added long disp instead of assuming 0
this(dataType, segReg, base, null, disp, 0);
}

public X86MemoryOperand(DataType dataType, X86SegmentRegister segReg, X86Register base){//Dom- Added long disp instead of assuming 0
this(dataType, segReg, base, null, 0, 0);
}

Expand Down
3 changes: 1 addition & 2 deletions src/org/jakstab/asm/x86/X86PCRelativeAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public long getEffectiveValue(long pcValue) {
* @return the target's displacement from the start of the next instruction.
*/
public long getDisplacement() {
long displacement = super.getDisplacement();
return displacement;
return super.getDisplacement();
}
}
Loading