diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/DisasmIterator.java b/app/src/main/java/com/kyhsgeekcode/disassembler/DisasmIterator.java index 6fb37bce..e74c20fc 100644 --- a/app/src/main/java/com/kyhsgeekcode/disassembler/DisasmIterator.java +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/DisasmIterator.java @@ -26,18 +26,22 @@ public void run() }); } - public void showNoti(int progress) + public int showNoti(int progress) { mBuilder.setProgress((int)total,progress, false); // Displays the progress bar for the first time. mNotifyManager.notify(0, mBuilder.build()); activity.runOnUiThread(activity.runnableRequestLayout); - + if(Thread.interrupted()) + { + return -1; + } + return 0; } + MainActivity activity; NotificationManager mNotifyManager; Notification.Builder mBuilder; long total; ListViewAdapter adapter; - } diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java b/app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java index 1f2efe3f..c3cc491a 100644 --- a/app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java @@ -31,7 +31,7 @@ public class MainActivity extends Activity implements Button.OnClickListener SharedPreferences setting; SharedPreferences.Editor editor; private static final String TAG="Disassembler"; - + private static final String RATIONALSETTING = "showRationals"; boolean showAddress=true; boolean showLabel=true; boolean showBytes=true; @@ -64,6 +64,8 @@ public class MainActivity extends Activity implements Button.OnClickListener private Button btSavDit; + private Button btAbort; + private NotificationManager mNotifyManager; private Notification.Builder mBuilder; @@ -75,6 +77,10 @@ public class MainActivity extends Activity implements Button.OnClickListener Thread workerThread; private Capstone cs; + + private String EXTRA_NOTIFICATION_ID; + + private String ACTION_SNOOZE; @Override public void onClick(View p1) { @@ -152,6 +158,15 @@ else if (pos == 1) case R.id.btnSaveDetails: SaveDetail(); break; + case R.id.btAbort: + if(workerThread!=null) + { + if(workerThread.isAlive()) + { + workerThread.interrupt(); + } + } + break; default: break; } @@ -199,11 +214,13 @@ private long parseAddress(String toString) { Toast.makeText(this,"Did you enter valid address?",3).show(); } + return elfUtil.getEntryPoint(); } private void AlertSelFile() { Toast.makeText(this, "Please Select a file first.", 2).show(); + showFileChooser(); } private void SaveDisasm() @@ -356,6 +373,8 @@ private void ShowDetail() private void DisassembleInstant() { + Toast.makeText(this,"Not supported by now. Please just use persist mode instead.",3).show(); + long startaddress=instantEntry;//file offset long index=startaddress; long addr=elfUtil.getCodeSectionVirtAddr(); @@ -363,10 +382,14 @@ private void DisassembleInstant() if(limit>=filecontent.length) { Toast.makeText(this,"Odd address :(",3).show(); + return; } - for (;;) + btDisasm.setEnabled(false); + //disasmResults.clear(); + //setupListView(); + /*for (;;) { - DisasmResult dar=new DisasmResult(filecontent, index, addr); + /*DisasmResult dar=new DisasmResult(filecontent, index, addr); if (dar.size == 0) { dar.size = 4; @@ -392,11 +415,14 @@ private void DisassembleInstant() mBuilder.setProgress((int)(limit-startaddress), (int)(index-start), false); // Displays the progress bar for the first time. mNotifyManager.notify(0, mBuilder.build()); - }*/ + }// index += dar.size; addr += dar.size; - } + }*/ + //Currently not suported + + btDisasm.setEnabled(true); } public final Runnable runnableRequestLayout=new Runnable(){ @@ -423,9 +449,11 @@ private void DisassembleFile() { Toast.makeText(this, "started", 2).show(); Log.v(TAG, "Strted disassm"); - + btDisasm.setEnabled(false); + btAbort.setEnabled(true); //final ProgressDialog dialog= showProgressDialog("Disassembling..."); disasmResults.clear(); + setupListView(); mNotifyManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new Notification.Builder(this); mBuilder.setContentTitle("Disassembler") @@ -433,6 +461,12 @@ private void DisassembleFile() .setSmallIcon(R.drawable.cell_shape) .setOngoing(true) .setProgress(100, 0, false); + /*Intent snoozeIntent = new Intent(this, MyBroadcastReceiver.class); + snoozeIntent.setAction(ACTION_SNOOZE); + snoozeIntent.putExtra(EXTRA_NOTIFICATION_ID, 0); + PendingIntent snoozePendingIntent = + PendingIntent.getBroadcast(this, 0, snoozeIntent, 0); + mBuilder.addAction(R.drawable.ic_launcher,"",snoozeIntent);*/ workerThread = new Thread(new Runnable(){ @Override public void run() @@ -503,6 +537,8 @@ public void run() listview.requestLayout(); tab2.invalidate(); //dialog.dismiss(); + btDisasm.setEnabled(true); + btAbort.setEnabled(false); Toast.makeText(MainActivity.this, "done", 2).show(); } }); @@ -756,6 +792,15 @@ public void onCreate(Bundle savedInstanceState) public void uncaughtException(Thread p1, Throwable p2) { // TODO: Implement this method + Toast.makeText(MainActivity.this,Log.getStackTraceString(p2),3).show(); + if(p2 instanceof SecurityException) + { + Toast.makeText(MainActivity.this,"Did you grant required permissions to this app?",3).show(); + setting=getSharedPreferences(RATIONALSETTING,MODE_PRIVATE); + editor=setting.edit(); + editor.putBoolean("show",true); + editor.commit(); + } requestAppPermissions(MainActivity.this); String [] accs=getAccounts(); final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); @@ -781,6 +826,7 @@ public void uncaughtException(Thread p1, Throwable p2) startActivity(Intent.createChooser(emailIntent, "Send crash report as an issue by email")); // ori.uncaughtException(p1, p2); Log.wtf(TAG,"UncaughtException",p2); + finish(); return ; } private String[] getAccounts() { @@ -818,7 +864,11 @@ private String[] getAccounts() { btSavDisasm.setOnClickListener(this); btSavDit = (Button) findViewById(R.id.btnSaveDetails); btSavDit.setOnClickListener(this); + btAbort = (Button) findViewById(R.id.btAbort); + btAbort.setOnClickListener(this); + btAbort.setEnabled(false); + etFilename = (EditText) findViewById(R.id.fileNameText); etFilename.setFocusable(false); etFilename.setEnabled(false); @@ -856,28 +906,16 @@ private String[] getAccounts() { // TableRow tbrow0 = new TableRow(MainActivity.this); // CreateDisasmTopRow(tbrow0); // tlDisasmTable.addView(tbrow0); - adapter = new ListViewAdapter(); - listview = (ListView) findViewById(R.id.listview); - listview.setAdapter(adapter); - listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){ - @Override - public void onItemClick(AdapterView parent, View p2, int position, long id) - { - ListViewItem lvi=(ListViewItem) parent.getItemAtPosition(position); - if (lvi.isBranch()) - { - - } - // TODO: Implement this method - return; - } - }); - AlertDialog.Builder builder=new AlertDialog.Builder(this); - builder.setTitle("Permissions"); - builder.setCancelable(false); - builder.setMessage("- Read/Write storage(obvious)\r\n- GetAccounts: add email address info on crash report."); - builder.setPositiveButton("OK",(DialogInterface.OnClickListener)null); - builder.show(); + setupListView(); + + setting = getSharedPreferences(RATIONALSETTING, MODE_PRIVATE); + boolean show=setting.getBoolean("show",true); + if(show){ + showPermissionRationales(); + editor=setting.edit(); + editor.putBoolean("show",false); + editor.commit(); + } requestAppPermissions(this); // ViewGroup.LayoutParams lp= listview.getLayoutParams(); //listview.setMinimumHeight(getScreenHeight()); @@ -885,6 +923,25 @@ public void onItemClick(AdapterView parent, View p2, int position, long id) // elfUtil=null; // filecontent=null; } + + private void showPermissionRationales() + { + AlertDialog.Builder builder=new AlertDialog.Builder(this); + builder.setTitle("Permissions"); + builder.setCancelable(false); + builder.setMessage("- Read/Write storage(obvious)\r\n- GetAccounts: add email address info on crash report.\r\n\r\n For more information visit https://github.com/KYHSGeekCode/Android-Disassembler/"); + builder.setPositiveButton("OK", (DialogInterface.OnClickListener)null); + builder.show(); + } + + private void setupListView() + { + adapter = new ListViewAdapter(); + listview = (ListView) findViewById(R.id.listview); + listview.setAdapter(adapter); + listview.setOnItemClickListener(new DisasmClickListener()); + + } public static int getScreenHeight() { return Resources.getSystem().getDisplayMetrics().heightPixels; @@ -1162,6 +1219,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) } } elfUtil = new ELFUtil(file, filecontent); + fpath=path; Toast.makeText(this, "success size=" + new Integer(index).toString(), 1).show(); } catch (IOException e) diff --git a/app/src/main/jniLibs/armeabi-v7a/libcapstone.so b/app/src/main/jniLibs/armeabi-v7a/libcapstone.so deleted file mode 100644 index f590e370..00000000 Binary files a/app/src/main/jniLibs/armeabi-v7a/libcapstone.so and /dev/null differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libhello-jni.so b/app/src/main/jniLibs/armeabi-v7a/libhello-jni.so index 5c3b2d75..50bfa56c 100644 Binary files a/app/src/main/jniLibs/armeabi-v7a/libhello-jni.so and b/app/src/main/jniLibs/armeabi-v7a/libhello-jni.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so b/app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so deleted file mode 100644 index 79e1fbae..00000000 Binary files a/app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so and /dev/null differ diff --git a/app/src/main/jniLibs/x86/libcapstone.so b/app/src/main/jniLibs/x86/libcapstone.so deleted file mode 100644 index 217768bd..00000000 Binary files a/app/src/main/jniLibs/x86/libcapstone.so and /dev/null differ diff --git a/app/src/main/jniLibs/x86/libhello-jni.so b/app/src/main/jniLibs/x86/libhello-jni.so index 7f277aca..5e975464 100644 Binary files a/app/src/main/jniLibs/x86/libhello-jni.so and b/app/src/main/jniLibs/x86/libhello-jni.so differ diff --git a/app/src/main/jniLibs/x86/libjnidispatch.so b/app/src/main/jniLibs/x86/libjnidispatch.so deleted file mode 100644 index 4045c86b..00000000 Binary files a/app/src/main/jniLibs/x86/libjnidispatch.so and /dev/null differ diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index b0453e9b..50d99ca2 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -70,7 +70,7 @@ android:layout_weight="1.0"/> - + - + + + + + @@ -187,6 +192,12 @@ android:layout_width="wrap_content" android:id="@+id/btnSaveDisasm"/> +