Skip to content

Commit

Permalink
Fixed #18, #43
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Jan 15, 2019
1 parent fd1ff4b commit 1ad3a75
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 29 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Disassemble **ANY** files including android shared libraries (aka .so files) (NDK, JNI), windows PE files(EXE, DLLs, SYSs, etc..), linux executables, object files, ANY files you want like pictures, audios, etc(for fun) entirely on Android. Capstone-based disassembler application on android.

# Version 1.4.4 [release](https://github.com/KYHSGeekCode/Android-Disassembler/releases)!
# Version 1.4.5 [release](https://github.com/KYHSGeekCode/Android-Disassembler/releases)!

# What's new : Root file chooser!
## What's new : Go to last browsed folder(issue #, file chooser session), Fixed jump address issues, Fixed VirtualAddress calculation for disassembly(Sorry for inconvenience, and I highly recommend updating the app to this version)

# Features
- Shows details of elf files.
Expand All @@ -26,6 +26,9 @@ Disassemble **ANY** files including android shared libraries (aka .so files) (ND
- You can copy an instruction to the clipboard.
- It now parses *IAT, EAT* of PE headers.
- You can now choose the columns to view.
- Supports analyzing system files(which are not accessible without root permission) for rooted phones.
- Friendlier message for non-parsable files.
- The storage chooser now retains the session, so that it remembers the last browsed folder.

# [Themes Download](https://github.com/KYHSGeekCode/Android-Disassembler/tree/master/themes)
Good themes usually help you recognize some important instructions easily.
Expand Down Expand Up @@ -109,7 +112,7 @@ You can download the theme.zip here.

# TODO
- Show prototypes of NDK/C standard APIs in the symbols tab.
- More sophisticated colorizing.
- More sophisticated colorizing
- Generate more useful comments
- Provide assembly tutorials.
- Fix symbols bug.
Expand All @@ -122,7 +125,6 @@ You can download the theme.zip here.
- Add compatibility for OllyDbg's `.udd/.bak` files

# Help wanted!
- X86 jumping address calculation creates negative values.
- Don't the symbols' names look odd?

# Thanks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ else if(COPY.equals(item))
else if(JUMP.equals(item))
{
long target= dar.address+dar.jumpOffset;//NOT an offset?? FIXME
Log.d(TAG,"jump"+Long.toHexString( dar.address)+","+Long.toHexString(dar.jumpOffset)+Long.toHexString(target));
Log.d(TAG,"jump"+Long.toHexString( dar.address)+","+Long.toHexString(dar.jumpOffset)+","+Long.toHexString(target));
activity.jumpto(target);
}
return ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class DisasmIterator
//public DisasmIterator(MainActivity activity, NotificationManager mNotifyManager, Notification.Builder mBuilder, ListViewAdapter adapter, long total)
//>>>>>>> parent of 2644076... Update readme with assembly materials links
//=======
public DisasmIterator(MainActivity activity, NotificationManager mNotifyManager, Notification.Builder mBuilder, ListViewAdapter adapter, long total)
public DisasmIterator(MainActivity activity,/* NotificationManager mNotifyManager, Notification.Builder mBuilder, */ListViewAdapter adapter, long total)
//>>>>>>> parent of 2644076... Update readme with assembly materials links
{
this.activity = activity;
this.mNotifyManager = mNotifyManager;
this.mBuilder = mBuilder;
//this.mNotifyManager = mNotifyManager;
//this.mBuilder = mBuilder;
this.total = total;
this.adapter=adapter;
}
Expand Down Expand Up @@ -65,8 +65,8 @@ public int showNoti(int progress)
public native int CSoption(int type, int vslue);

MainActivity activity;
NotificationManager mNotifyManager;
Notification.Builder mBuilder;
//NotificationManager mNotifyManager;
//Notification.Builder mBuilder;
long total;
ListViewAdapter adapter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void LoadMore(int position,long address)
//this.address.clear();
Log.d(TAG,"LoadMore"+position+","+writep+","+address);
writep=position;
dit.getSome(file.fileContents,address-file.codeVirtualAddress,file.fileContents.length,address,INSERT_COUNT);
dit.getSome(file.fileContents,address+file.codeBase-file.codeVirtualAddress/*address-file.codeVirtualAddress*/,file.fileContents.length,address,INSERT_COUNT);
}
// Adapter에 사용되는 데이터의 개수를 리턴. : 필수 구현
@Override
Expand Down
30 changes: 17 additions & 13 deletions app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -898,17 +898,19 @@ protected void onProgressUpdate(Integer...a){
progress.setProgress(a[0]);
//Log.d(TAG + " onProgressUpdate", "You are in progress update ... " + a[0]);
}

/*
protected void onPostExecute(Void result) {
super.onPostExecute(result);
//Log.d(TAG + " onPostExecute", "" + result);
}
*/
}

//18.11.22 revival!
//19.01 Deprecated
//Will be used like generate-on-need array(sth like Paging)
private void DisassembleInstant(long foffset)
/*private void DisassembleInstant(long foffset)
{
//Toast.makeText(this,"Not supported by now. Please just use persist mode instead.",3).show();
// if(limit>=filecontent.length)
Expand Down Expand Up @@ -936,7 +938,7 @@ private void DisassembleInstant(long foffset)
(MainActivity.this,mNotifyManager,mBuilder
,adapter,size);
//listview.setOnScrollListener(new DisasmPager(adapter,dai));
// dai.getSome(filecontent,start,size,addr,100/*, disasmResults*/);
// dai.getSome(filecontent,start,size,addr,100/*, disasmResults*///);
// workerThread = new Thread(new Runnable(){
// @Over
//DisasmPager pager;
Expand Down Expand Up @@ -979,7 +981,7 @@ private void DisassembleInstant(long foffset)
//Currently not suported

//btDisasm.setEnabled(true);
}
//}

public final Runnable runnableRequestLayout=new Runnable(){
@Override
Expand Down Expand Up @@ -1014,13 +1016,13 @@ private void DisassembleFile(final long offset)
//NOW there's no notion of pause or resume!!!!!
//if(offset==parsedFile.getEntryPoint())
// disasmResults.clear();//otherwise resume, not clear
mNotifyManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
/*mNotifyManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new Notification.Builder(this);
mBuilder.setContentTitle("Disassembler")
.setContentText("Disassembling in progress")
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setProgress(100, 0, false);
.setProgress(100, 0, false);*/
/*Intent snoozeIntent = new Intent(this, MyBroadcastReceiver.class);
snoozeIntent.setAction(ACTION_SNOOZE);
snoozeIntent.putExtra(EXTRA_NOTIFICATION_ID, 0);
Expand Down Expand Up @@ -1094,7 +1096,6 @@ private void DisassembleFile(final long offset)
@Override
public void run()
{

long codesection=parsedFile.getCodeSectionBase();
long start=codesection+offset;//elfUtil.getCodeSectionOffset();
long index=start;
Expand All @@ -1105,7 +1106,7 @@ public void run()
// getFunctionNames();
long size=limit - start;
long leftbytes=size;
DisasmIterator dai=new DisasmIterator(MainActivity.this,mNotifyManager,mBuilder,adapter,size);
DisasmIterator dai=new DisasmIterator(MainActivity.this,/*mNotifyManager,mBuilder,*/adapter,size);
adapter.setDit(dai);
adapter.LoadMore(0,addr);
//long toresume=dai.getSome(filecontent,start,size,addr,1000000/*, disasmResults*/);
Expand Down Expand Up @@ -2074,11 +2075,14 @@ private void showFileChooser()
.withMemoryBar(true)
.allowCustomPath(true)
.setType(StorageChooser.FILE_PICKER)
.actionSave(true)
.actionSave(true)
//.withPreference(settingPath)
.withPredefinedPath(prepath)
// .withPredefinedPath(prepath)
.shouldResumeSession(true)
.showHidden(true)
.build();
// Show dialog whenever you want by
//chooser.getsConfig().setPrimaryPath(prepath);
chooser.show();
// get path that the user has chosen
chooser.setOnSelectListener(new StorageChooser.OnSelectListener() {
Expand Down Expand Up @@ -2326,9 +2330,10 @@ private void AfterReadFully(File file) throws IOException
setParsedFile(new RawFile(file));
AllowRawSetup();
//failed to parse the file. please setup manually.
}catch(Exception g)
}
catch(Exception g)
{
AlertError("failed to parse the file. please setup manually.",g);
AlertError("Unexpected exception: failed to parse the file. please setup manually.",g);
setParsedFile(new RawFile(file));
AllowRawSetup();
}
Expand Down Expand Up @@ -2384,7 +2389,6 @@ private void AfterParse()
//if(arch==CS_ARCH_X86){
adapter.setArchitecture(arch); //wider operands
colorHelper.setArchitecture(arch);

//}
shouldSave = true;
List<Symbol> list=parsedFile.getExportSymbols();
Expand Down
Binary file modified app/src/main/jniLibs/armeabi-v7a/libhello-jni.so
Binary file not shown.
Binary file modified app/src/main/jniLibs/x86/libhello-jni.so
Binary file not shown.
36 changes: 31 additions & 5 deletions hello-jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern "C"
{
csh handle;
const char * errmsg(cs_err e);

int arch=CS_ARCH_ARM;

static void print_insn_detail(string &buf,cs_insn *ins);

const char * errmsg(cs_err e)
Expand Down Expand Up @@ -73,17 +76,19 @@ extern "C"
handle=0;
return 0;
}
JNIEXPORT jint JNICALL Java_com_kyhsgeekcode_disassembler_MainActivity_Open(JNIEnv * env, jobject thiz,int arch,int mode)
JNIEXPORT jint JNICALL Java_com_kyhsgeekcode_disassembler_MainActivity_Open(JNIEnv * env, jobject thiz,int arch1,int mode)
{
cs_err e;
cs_close(&handle);
if ((e=cs_open((cs_arch)arch, (cs_mode)mode, & handle) )!= CS_ERR_OK)
if ((e=cs_open((cs_arch)arch1, (cs_mode)mode, & handle) )!= CS_ERR_OK)
{
return /* env->NewStringUTF(errmsg(e));*/e;
}
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
// turn on SKIPDATA mode
cs_option(handle, CS_OPT_SKIPDATA, CS_OPT_ON);
arch=arch1;
return CS_ERR_OK;
}
JNIEXPORT void JNICALL Java_com_kyhsgeekcode_disassembler_MainActivity_Finalize(JNIEnv * env, jobject thiz)
{
Expand Down Expand Up @@ -111,7 +116,7 @@ extern "C"
return cs_option(NULL,CS_OPT_MEM,(size_t )&mem);
//return 0;
}
int arch=CS_ARCH_ARM;

JNIEXPORT jint JNICALL Java_com_kyhsgeekcode_disassembler_DisasmIterator_CSoption(JNIEnv * env, jobject thiz,jint arg1,jint arg2)
{
if(arg1==CS_OPT_MODE)
Expand Down Expand Up @@ -297,14 +302,15 @@ extern "C"
env->DeleteLocalRef(job2);
env->SetByteField(dar, fidGroupCount, detail->groups_count);
//now get the operands, etc..
long jumpOffset;
long jumpOffset=0;
switch(arch)
{
case CS_ARCH_X86: // X86 architecture (including x86 & x86-64)
{
const cs_x86 *x86=&detail->x86;
jumpOffset=X86_REL_ADDR(*insn);
jumpOffset=X86_REL_ADDR(*insn)-insn->address;
}
break;// IMPORTANT!!!!!!!!!!!!!!!!
case CS_ARCH_ARM: // ARM architecture (including Thumb, Thumb-2)
{
const cs_arm *arm=&detail->arm;
Expand All @@ -321,30 +327,50 @@ extern "C"
//TODO: parse PLT
}
}
break;
case CS_ARCH_ARM64: // ARM-64, also called AArch64
{
const cs_arm64 *arm64=&detail->arm64;
switch(arm64->op_count)
{
case 0:
break;
case 1: //B xx
jumpOffset=arm64->operands[0].type==ARM64_OP_IMM ? (arm64->operands[0].imm-insn->address):0;
break;
case 2: //mov pc,#0
jumpOffset=arm64->operands[1].type==ARM64_OP_IMM ? (arm64->operands[1].imm-insn->address):0;
break;
//TODO: parse PLT
}

}
break;
case CS_ARCH_MIPS: // Mips architecture
{
const cs_mips *mips=&detail->mips;
}
break;
case CS_ARCH_PPC: // PowerPC architecture
{
const cs_ppc *ppc=&detail->ppc;
}
break;
case CS_ARCH_SPARC: // Sparc architecture
{
const cs_sparc *sparc=&detail->sparc;
}
break;
case CS_ARCH_SYSZ: // SystemZ architecture
{
const cs_sysz *sysz=&detail->sysz;
}
break;
case CS_ARCH_XCORE: // XCore architecture
{
const cs_xcore *xcore=&detail->xcore;
}
break;
}
env->SetLongField(dar, fidJumpOffset,jumpOffset);
}
Expand Down

0 comments on commit 1ad3a75

Please sign in to comment.