Skip to content

Commit

Permalink
Optimized disassembling, fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Oct 5, 2018
1 parent d3db3e3 commit 51a824a
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin/
gen/
obj/
libs/*/*.so


6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ Use Android studio.
- Changed to Android Studio structure.

# TODO
- Optimization
- Optimization(Done)
- Support x86 files.
- fix bugs
- add menus on clicking disassemblies.
- add coloring.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:remove="android:maxSdkVersion"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity = "true">
android:resizeableActivity = "true"
android:largeHeap="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/capstone/Arm_const.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.util.*;
import java.lang.reflect.*;
import java.util.*;

public class Arm_const
{
Expand Down Expand Up @@ -39,8 +40,44 @@ public class Arm_const
public static final int ARM_CC_GT = 13;
public static final int ARM_CC_LE = 14;
public static final int ARM_CC_AL = 15;
private static final Map<Integer, String> _int2string;

static
{
final Map<Integer, String> int2string = new HashMap<>();

try
{
for (Field field: Arm_const.class.getFields())
{
final int mod = field.getModifiers();

if (!int.class.equals(field.getType()))
continue;

if (!Modifier.isStatic(mod) || !Modifier.isPublic(mod))
continue;

if (!field.getName().startsWith("ARM_CC_"))
continue;

int2string.put(field.getInt(null),
field.getName().substring("ARM_CC_".length()));
}
}
catch (IllegalAccessException l_e)
{
throw new RuntimeException(l_e); // should not occur
}

_int2string = Collections.unmodifiableMap(int2string);
}

public static String getCCName(int cc)
{
return _int2string.get(cc);
}
public static String getCCName2(int cc)
{
Class clazz=Arm_const.class;
Field[] fields=clazz.getFields();
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/capstone/Capstone.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ private OpInfo getOptInfo(_cs_detail detail)

return op_info;
}

int opCount;
int opIndex;
int regRead;
int regWrite;
byte[] bytes;
public int opCount(int type)
{
return cs.cs_op_count(csh, raw.getPointer(), type);
Expand Down Expand Up @@ -276,8 +280,7 @@ protected void finalize() throws Throwable
// TODO: Implement this method
super.finalize();
cs.cs_free(raw.getPointer(),new NativeLong(1));
}

}
}

private CsInsn[] fromArrayRaw(_cs_insn[] arr_raw)
Expand Down Expand Up @@ -564,11 +567,11 @@ public CsInsn[] disasm(byte[] code, long address, long count)

return allInsn;
}
public CsInsn[] disasm(byte[] code,long offset, long address, long count)
public CsInsn[] disasm(byte[] code,long offset, long length,long address, long count)
{
PointerByReference insnRef = new PointerByReference();

NativeLong c = cs.cs_disasm2(ns.csh, code,new NativeLong(offset), new NativeLong(code.length), address, new NativeLong(count), insnRef);
NativeLong c = cs.cs_disasm2(ns.csh, code,new NativeLong(offset), new NativeLong(length), address, new NativeLong(count), insnRef);

if (0 == c.intValue())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public DisasmResult()
address=0L;
size=0;
bytes=new byte[16];
mnemonic=new String("undefined");
op_str=new String("undefined");
mnemonic="undefined";
op_str="undefined";
regs_read=new byte[12];
regs_read_count=0;
regs_write=new byte[20];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public ListViewAdapter()
{

}
//You should not modify
public ArrayList<ListViewItem> itemList()
{
return listViewItemList;
}

// Adapter에 사용되는 데이터의 개수를 리턴. : 필수 구현
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public ListViewItem(DisasmResult disasmResult)
this.disasmResult = disasmResult;
this.address=Long.toHexString(disasmResult.address);
byte[] bytestmp=new byte[disasmResult.size];
//System.arraycopy();
for(int i=0;i<disasmResult.size;++i)
{
bytestmp[i]=disasmResult.bytes[i];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package com.kyhsgeekcode.disassembler;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.webkit.*;
import android.content.*;

import android.app.Activity;
import android.os.Bundle;

public class MadeByActivity extends Activity {
public class MadeByActivity extends Activity implements View.OnClickListener
{
@Override
public void onClick(View p1)
{
// TODO: Implement this method
int id=p1.getId();
switch(id)
{
case R.id.activitymadebyTextView1:
//Intent intent=new Intent(Inte
//https://stackexchange.com/users/11771696/kyhsgeekcode?tab=accounts
}
return ;
}

TextView tvKyhs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_made_by);
tvKyhs=(TextView) findViewById(R.id.activitymadebyTextView1);
tvKyhs.setOnClickListener(this);

}

}
Loading

0 comments on commit 51a824a

Please sign in to comment.