Skip to content

Commit

Permalink
Added root file chooser (Fix #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Jan 10, 2019
1 parent b5cd98f commit f757c19
Show file tree
Hide file tree
Showing 11 changed files with 748 additions and 134 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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.3 [release](https://github.com/KYHSGeekCode/Android-Disassembler/releases)!
### Sorry, saved raw disasms are now incompatible with this version!
# Version 1.4.4 [release](https://github.com/KYHSGeekCode/Android-Disassembler/releases)!

# What's new : Root file chooser!

# Features
- Shows details of elf files.
Expand All @@ -24,10 +25,6 @@ Disassemble **ANY** files including android shared libraries (aka .so files) (ND
- Can override auto parse setup
- You can copy an instruction to the clipboard.
- It now parses *IAT, EAT* of PE headers.

# What's new

- Fixed bugs.
- You can now choose the columns to view.

# [Themes Download](https://github.com/KYHSGeekCode/Android-Disassembler/tree/master/themes)
Expand Down Expand Up @@ -73,6 +70,9 @@ Slow. Not recommended.
- [Wiki](https://github.com/KYHSGeekCode/Android-Disassembler/wiki)

# Error Handling

### Sorry, saved raw disasms are now incompatible with this version!

Here are some common issues and some solutons for them.
- The app crashes!

Expand Down Expand Up @@ -103,6 +103,7 @@ You can download the theme.zip here.
- [Colorpickerview](https://github.com/skydoves/ColorPickerView)
- [Java-binutils](https://github.com/jawi/java-binutils)
- [PECOFF4J](https://github.com/kichik/pecoff4j).
- [Root File Chooser](https://github.com/KYHSGeekCode/RootFilePicker)


# TODO
Expand All @@ -113,7 +114,6 @@ You can download the theme.zip here.
- Fix symbols bug.
- Add pseudo-virtual machine to debug.
- Allow users to analyze active processes.
- Allow root file chooser.
- Add arrow beside the disassembly.
- Row selection
- Better support for thumb assemblies
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<!--activity android:name=".MadeByActivity"/-->
<!--activity android:name=".OpenSourceActivity"/-->
<activity android:name=".FileSelectorActivity"/>

<activity android:name="com.kyhsgeekcode.rootpicker.FileSelectorActivity"/>
</application>

</manifest>
Binary file added app/src/main/assets/ls-arm
Binary file not shown.
Binary file added app/src/main/assets/ls-x86
Binary file not shown.
157 changes: 123 additions & 34 deletions app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.regex.*;
import java.util.zip.*;
import nl.lxtreme.binutils.elf.*;
import com.stericson.RootTools.*;


public class MainActivity extends AppCompatActivity implements Button.OnClickListener, ProjectManager.OnProjectOpenListener
Expand Down Expand Up @@ -244,7 +245,7 @@ public void onOpen(ProjectManager.Project proj)

private static final int REQUEST_SELECT_FILE = 123;
private static final int BULK_SIZE = 1024;
private static final String SETTINGKEY="setting";
public static final String SETTINGKEY="setting";
private static final String LASTPROJKEY = "lastProject";
String fpath;
byte[] filecontent=null;
Expand Down Expand Up @@ -2062,32 +2063,57 @@ private void showFileChooser()
tmp=tmp.getParentFile();
prepath=tmp.getAbsolutePath();
}
StorageChooser chooser = new StorageChooser.Builder()
.withActivity(MainActivity.this)
.withFragmentManager(getFragmentManager())
.withMemoryBar(true)
.allowCustomPath(true)
.setType(StorageChooser.FILE_PICKER)
.actionSave(true)
//.withPreference(settingPath)
.withPredefinedPath(prepath)
.build();
// Show dialog whenever you want by
chooser.show();
// get path that the user has chosen
chooser.setOnSelectListener(new StorageChooser.OnSelectListener() {
@Override
public void onSelect(String path) {
SharedPreferences.Editor edi=settingPath.edit();
edi.putString(DiskUtil.SC_PREFERENCE_KEY,path);
edi.commit();
disableEnableControls(false,llmainLinearLayoutSetupRaw);
OnChoosePath(path);
//Log.e("SELECTED_PATH", path);
}
});
//Intent i=new Intent(this, FileSelectorActivity.class);
//startActivityForResult(i, REQUEST_SELECT_FILE);
SharedPreferences spPicker=getSharedPreferences(SETTINGKEY,MODE_PRIVATE);
int picker=spPicker.getInt("Picker",0);
switch(picker)
{
case 0:
StorageChooser chooser = new StorageChooser.Builder()
.withActivity(MainActivity.this)
.withFragmentManager(getFragmentManager())
.withMemoryBar(true)
.allowCustomPath(true)
.setType(StorageChooser.FILE_PICKER)
.actionSave(true)
//.withPreference(settingPath)
.withPredefinedPath(prepath)
.build();
// Show dialog whenever you want by
chooser.show();
// get path that the user has chosen
chooser.setOnSelectListener(new StorageChooser.OnSelectListener() {
@Override
public void onSelect(String path) {
SharedPreferences.Editor edi=settingPath.edit();
edi.putString(DiskUtil.SC_PREFERENCE_KEY,path);
edi.commit();
disableEnableControls(false,llmainLinearLayoutSetupRaw);
OnChoosePath(path);
//Log.e("SELECTED_PATH", path);
}
});
break;
case 1:
Intent i=new Intent(this, com.kyhsgeekcode.rootpicker.FileSelectorActivity.class);
startActivityForResult(i, REQUEST_SELECT_FILE);
break;
} //
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_SELECT_FILE)
{
if (resultCode == Activity.RESULT_OK)
{
String path=data.getStringExtra("path");
SharedPreferences.Editor edi=settingPath.edit();
edi.putString(DiskUtil.SC_PREFERENCE_KEY,path);
edi.commit();
disableEnableControls(false,llmainLinearLayoutSetupRaw);
OnChoosePath(path);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
Expand Down Expand Up @@ -2129,12 +2155,13 @@ public void onRequestPermissionsResult(int requestCode,

private void OnChoosePath(Uri uri)
{
File tmpfile=new File(getFilesDir(),"tmp.so");
try
{
InputStream is=(InputStream)getContentResolver().openInputStream(uri);
//ByteArrayOutputStream bis=new ByteArrayOutputStream();
setFilecontent(Utils.getBytes(is));
File tmpfile=new File(getFilesDir(),"tmp.so");

tmpfile.createNewFile();
FileOutputStream fos=new FileOutputStream(tmpfile);
fos.write(filecontent);
Expand All @@ -2144,6 +2171,36 @@ private void OnChoosePath(Uri uri)
}
catch (IOException e)
{
if(e.getMessage().contains("Permission denied"))
{
if(RootTools.isRootAvailable())
{
while(!RootTools.isAccessGiven())
{
Toast.makeText(this,"This file requires root to read.",3).show();
RootTools.offerSuperUser(this);
}
try{
RootTools.copyFile(uri.getPath(),tmpfile.getPath(),false,false);
setFilecontent(Utils.getBytes(new FileInputStream(tmpfile)));
setFpath( tmpfile.getAbsolutePath());//uri.getPath();
AfterReadFully(tmpfile);
return;
}
catch (IOException f)
{
Log.e(TAG,"",f);
//?
}
}
else
{
Toast.makeText(this,"This file requires root permission to read.",3).show();
}
}else{
Log.e(TAG,"",e);
//Toast.makeText(this,"Not needed",3).show();
}
AlertError(R.string.fail_readfile,e);
}
}
Expand Down Expand Up @@ -2171,15 +2228,16 @@ public static byte[] getBytes(InputStream is) throws IOException {
bos.write(buf, 0, len);
buf = bos.toByteArray();
}
is.close();
return buf;
}
}

private void OnChoosePath(String p)//Intent data)
private void OnChoosePath(String path)//Intent data)
{
try
{
String path=p;//data.getStringExtra("com.jourhyang.disasmarm.path");
//String path=path;//data.getStringExtra("com.jourhyang.disasmarm.path");
File file=new File(path);
setFpath(path);
etFilename.setText(file.getAbsolutePath());
Expand All @@ -2200,16 +2258,47 @@ private void OnChoosePath(String p)//Intent data)
counter++;
}
}
in.close();
;
in.close();
AfterReadFully(file);
Toast.makeText(this, "success size=" + index /*+ type.name()*/, 3).show();

//OnOpenStream(fsize, path, index, file);
}catch (Exception e)
}catch (IOException e)
{
if(e.getMessage().contains("Permission denied"))
{
File tmpfile=new File(getFilesDir(),"tmp.so");
if(RootTools.isRootAvailable())
{
while(!RootTools.isAccessGiven())
{
Toast.makeText(this,"This file requires root to read.",3).show();
RootTools.offerSuperUser(this);
}
try{
RootTools.copyFile(path,tmpfile.getPath(),false,false);
setFilecontent(Utils.getBytes(new FileInputStream(tmpfile)));
setFpath( tmpfile.getAbsolutePath());//uri.getPath();
AfterReadFully(tmpfile);
return;
}
catch (IOException f)
{
Log.e(TAG,"",f);
//?
}
}
else
{
Toast.makeText(this,"This file requires root permission to read.",3).show();
}
}else{
Log.e(TAG,"",e);
//Toast.makeText(this,"Not needed",3).show();
}
AlertError(R.string.fail_readfile,e);
//Log.e(TAG, "", e);
AlertError("Failed to open and parse the file",e);
//AlertError("Failed to open and parse the file",e);
//Toast.makeText(this, Log.getStackTraceString(e), 30).show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void onClick(View p1)
{
palette.Save();
colorhelper.addPalette(palette);
SharedPreferences sp=getSharedPreferences(MainActivity.SETTINGKEY,MODE_PRIVATE);
SharedPreferences.Editor ed=sp.edit();
ed.putString("PaletteName",palette.name).commit();
colorhelper.setPalette(palette.name);
return ;
}
Expand All @@ -59,7 +62,27 @@ public void onClick(DialogInterface p1,int p2)
return false;
}
String name=prefnames[val-1];
SharedPreferences sp=getSharedPreferences(MainActivity.SETTINGKEY,MODE_PRIVATE);
SharedPreferences.Editor ed=sp.edit();
ed.putString("PaletteName",name).commit();
colorhelper.setPalette(name);
}else if("filepicker".equals(key))
{

int val=Integer.parseInt((String)p2);
SharedPreferences sp=getSharedPreferences(MainActivity.SETTINGKEY,MODE_PRIVATE);
SharedPreferences.Editor ed=sp.edit();
/*switch(val)
{
case 0:
//CodeKidX
break;
case 1:
//root
break;
}*/
ed.putInt("Picker",val).commit();
}
return false;
}
Expand Down Expand Up @@ -136,6 +159,10 @@ public boolean onPreferenceClick(Preference preference) {
}
});
lp.setOnPreferenceChangeListener(this);

final ListPreference lp2=(ListPreference) findPreference("filepicker");
lp2.setOnPreferenceChangeListener(this);

PreferenceScreen scrn=(PreferenceScreen) findPreference("openscrn");
//scrn.setOnPreferenceClickListener(this);
int cnt=scrn.getPreferenceCount();
Expand Down
Loading

0 comments on commit f757c19

Please sign in to comment.