Skip to content

Commit

Permalink
Fixed bugs, reduced app size, deprecated instant mode, fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Oct 5, 2018
1 parent 6e30331 commit 5dd377a
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
114 changes: 86 additions & 28 deletions app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -356,17 +373,23 @@ 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();
long limit=startaddress + 400;
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;
Expand All @@ -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(){
Expand All @@ -423,16 +449,24 @@ 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")
.setContentText("Disassembling in progress")
.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()
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -856,35 +906,42 @@ 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());
//listview.setLayoutParams(lp);
// 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;
Expand Down Expand Up @@ -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)
Expand Down
Binary file removed app/src/main/jniLibs/armeabi-v7a/libcapstone.so
Binary file not shown.
Binary file modified app/src/main/jniLibs/armeabi-v7a/libhello-jni.so
Binary file not shown.
Binary file removed app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so
Binary file not shown.
Binary file removed app/src/main/jniLibs/x86/libcapstone.so
Binary file not shown.
Binary file modified app/src/main/jniLibs/x86/libhello-jni.so
Binary file not shown.
Binary file removed app/src/main/jniLibs/x86/libjnidispatch.so
Binary file not shown.
27 changes: 19 additions & 8 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
android:layout_weight="1.0"/>

</LinearLayout>
<!--SO-->

<com.kyhsgeekcode.disassembler.RadioGridGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -152,13 +152,18 @@

</LinearLayout>

<EditText
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:layout_width="match_parent"
android:layout_span="4"
android:id="@+id/detailText"/>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent">

<EditText
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:layout_width="match_parent"
android:id="@+id/detailText"/>

</ScrollView>

</LinearLayout>

Expand Down Expand Up @@ -187,6 +192,12 @@
android:layout_width="wrap_content"
android:id="@+id/btnSaveDisasm"/>

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Abort"
android:id="@+id/btAbort"/>

</LinearLayout>

<ListView
Expand Down

0 comments on commit 5dd377a

Please sign in to comment.