Skip to content

Commit

Permalink
added Instant mode(demo)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Sep 22, 2018
1 parent 80a010e commit 52b957c
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 13 deletions.
Binary file modified bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bin/classesdebug/com/jourhyang/disasmarm/MainActivity.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bin/classesrelease/com/jourhyang/disasmarm/MainActivity.class
Binary file not shown.
Binary file modified bin/classesrelease/com/jourhyang/disasmarm/MainActivity.dex
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
16 changes: 9 additions & 7 deletions res/layout/listview_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF">
android:background="#FFFFFF"
android:weightSum="8"
android:baselineAligned="true">

<TextView
android:layout_height="wrap_content"
Expand All @@ -23,7 +25,7 @@
android:text="Label"
android:layout_width="0dp"
android:id="@+id/tvLabel"
android:layout_weight="1"
android:layout_weight="0.5"
android:textColor="#000000"
android:singleLine="true"
android:padding="5dp"
Expand All @@ -35,7 +37,7 @@
android:text="Bytes"
android:layout_width="0dp"
android:id="@+id/tvBytes"
android:layout_weight="2"
android:layout_weight="1.6"
android:textColor="#000000"
android:singleLine="true"
android:padding="5dp"
Expand All @@ -47,7 +49,7 @@
android:text="Instruction"
android:layout_width="0dp"
android:id="@+id/tvInst"
android:layout_weight="1"
android:layout_weight="1.5"
android:textColor="#000000"
android:singleLine="true"
android:padding="5dp"
Expand All @@ -58,7 +60,7 @@
android:text="Condition"
android:layout_width="0dp"
android:id="@+id/tvCond"
android:layout_weight="1"
android:layout_weight="0.2"
android:textColor="#000000"
android:singleLine="true"
android:padding="5dp"
Expand All @@ -70,7 +72,7 @@
android:text="operand"
android:layout_width="0dp"
android:id="@+id/tvOperand"
android:layout_weight="1"
android:layout_weight="2.5"
android:textColor="#000000"
android:singleLine="true"
android:padding="5dp"
Expand All @@ -82,7 +84,7 @@
android:text="Comment"
android:layout_width="0dp"
android:id="@+id/tvComment"
android:layout_weight="1"
android:layout_weight="1.2"
android:textColor="#000000"
android:singleLine="true"
android:padding="5dp"
Expand Down
5 changes: 2 additions & 3 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@
</LinearLayout>

<ListView
android:layout_height="0dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/listview"
android:layout_weight="1.0"/>
android:id="@+id/listview"/>

</LinearLayout>

Expand Down
125 changes: 122 additions & 3 deletions src/com/jourhyang/disasmarm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class MainActivity extends Activity implements Button.OnClickListener

private Notification.Builder mBuilder;

boolean instantMode;

private long instantEntry;

@Override
public void onClick(View p1)
{
Expand All @@ -76,7 +80,65 @@ public void onClick(View p1)
AlertSelFile();
return;
}
DisassembleFile();
final List<String> ListItems = new ArrayList<>();
ListItems.add("Instant mode");
ListItems.add("Persist mode");
// ListItems.add("");
final CharSequence[] items = ListItems.toArray(new String[ ListItems.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Disassemble as...");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int pos) {
//String selectedText = items[pos].toString();
dialog.dismiss();
if(pos==0)
{
instantMode=true;
final List<String> ListItems2 = new ArrayList<>();
ListItems2.add("Entry point");
ListItems2.add("Custom address");
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Start from...");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog2, int pos) {
if(pos==0)
{
instantEntry=elfUtil.getEntryPoint();
DisassembleInstant();
}else if(pos==1){
final EditText edittext = new EditText(MainActivity.this);

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Start from...");
builder.setMessage("Enter address to start analyzing.");
builder.setView(edittext);
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog3, int which) {
instantEntry=parseAddress(edittext.getText().toString());
DisassembleInstant();
}
});
builder.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog4, int which) {
dialog4.dismiss();
}
});
dialog2.dismiss();
builder.show();
}
}
});
builder.show();
}
else if(pos==1)
{
DisassembleFile();
}
}
});
builder.show();
break;
case R.id.btnShowdetail:
if (elfUtil == null)
Expand All @@ -97,7 +159,12 @@ public void onClick(View p1)
}

}

private long parseAddress(String toString)
{
// TODO: Implement this method
return Long.decode(toString);
}

private void AlertSelFile()
{
Toast.makeText(this, "Please Select a file first.", 2).show();
Expand All @@ -121,6 +188,7 @@ private void SaveDisasm()
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int pos) {
//String selectedText = items[pos].toString();
dialog.dismiss();
final ProgressDialog dialog2= showProgressDialog("Saving...");
SaveDisasmSub(pos);
dialog2.dismiss();
Expand Down Expand Up @@ -246,10 +314,51 @@ private void ShowDetail()
etDetails.setText(elfUtil.toString());
}

private void DisassembleInstant()
{
long startaddress=instantEntry;//file offset
long index=startaddress;
long addr=elfUtil.getCodeSectionVirtAddr();
long limit=startaddress+400;
for(;;)
{
DisasmResult dar=new DisasmResult(filecontent, index,addr);
if(dar.size==0)
{
dar.size=4;
dar.mnemonic="db";
dar.bytes=new byte[]{filecontent[(int)index],filecontent[(int)index+1],filecontent[(int)index+2],filecontent[(int)index+3]};
dar.op_str="";
Log.e(TAG,"Dar.size==0, breaking?");
//break;
}
final ListViewItem lvi=new ListViewItem(dar);
disasmResults.add(lvi);
adapter.addItem(lvi);
adapter.notifyDataSetChanged();
Log.v(TAG, "i=" + index + "lvi=" + lvi.toString());
if (index >= limit)
{
Log.i(TAG, "index is " + index + ", breaking");
break;
}
Log.v(TAG, "dar.size is =" + dar.size);
Log.i(TAG,""+index +" out of "+(limit-startaddress));
/*if((limit-start)%320==0){
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;

}
}

//TODO: DisassembleFile(long address, int amt);
private void DisassembleFile()
{
Toast.makeText(this, "started", 1).show();
Toast.makeText(this, "started", 2).show();
Log.v(TAG, "Strted disassm");

final ProgressDialog dialog= showProgressDialog("Disassembling...");
Expand Down Expand Up @@ -451,6 +560,16 @@ public void onCreate(Bundle savedInstanceState)
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);

// TODO: Implement this method
return;
}
});
// ViewGroup.LayoutParams lp= listview.getLayoutParams();
//listview.setMinimumHeight(getScreenHeight());
//listview.setLayoutParams(lp);
Expand Down

0 comments on commit 52b957c

Please sign in to comment.