Skip to content

Commit

Permalink
Merge branch 'hotfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
tux-mind committed Jan 16, 2016
2 parents 6d5126b + cc50526 commit 2104667
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cSploit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 5
versionName "1.6.4"
versionCode 6
versionName "1.6.5"
if(System.getenv("NIGHTLY_BUILD")) {
versionName += "+" + System.getenv("NIGHTLY_BUILD_COMMIT").substring(0, 7)
}
Expand Down
1 change: 1 addition & 0 deletions cSploit/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,5 @@
<string name="mitm_ss_select_target_prompt">Select %s ?</string>
<string name="github_issues_url" translatable="false">https://github.com/cSploit/android/issues</string>
<string name="issue_message"><![CDATA[<p>Before opening a new issue, please, take the time to read the already <a href="%1$s">open issues</a>, probably it\' s already open. If it\' s not open we\'ll need as much information as you can get, so please, read <a href="%2$s">this guide</a> in order to know how to report a bug properly.</p>]]></string>
<string name="pref_err_empty_or_old">must be empty or an old installation directory.</string>
</resources>
107 changes: 80 additions & 27 deletions cSploit/src/org/csploit/android/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,84 @@ public void onEnd(int exitCode) {
}
}

private boolean isDirectoryEmptyOrWithVersion(File folder) {
String[] files = folder.list();

if(files.length > 0) {
for(String fname : files) {
if("VERSION".equals(fname)) {
return true;
}
}
return false;
}

return true;
}

private ExecChecker getCheckerForKey(String key) {
switch (key) {
case "RUBY_DIR":
return ExecChecker.ruby();
case "MSF_DIR":
return ExecChecker.msf();
}
return null;
}

private String getCurrentPathForKey(String key) {
switch (key) {
case "RUBY_DIR":
return System.getRubyPath();
case "MSF_DIR":
return System.getMsfPath();
}
return null;
}

private boolean shallAskForDelete(String key) {
return key.equals("RUBY_DIR") || key.equals("MSF_DIR");
}

/**
* check if selected directory is valid for the given key.
* @param key to be updated
* @param path of the chosen directory
* @return true if {@code path} is valid, false otherwise
*/
private boolean canChangeDirectoryTo(String key, String path) {
File folder = new File(path);
ExecChecker checker = getCheckerForKey(key);
String oldPath = getCurrentPathForKey(key);
String toastMessage = null;
boolean valid = false;
boolean checkEmptyOrVersion = shallAskForDelete(key);

if (!folder.exists()) {
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_exists);
} else if (!folder.canWrite()) {
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_writable);
} else if (checker != null && !checker.canExecuteInDir(path)) {
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_executable);
} else if (checkEmptyOrVersion && !isDirectoryEmptyOrWithVersion(folder)) {
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_empty_or_old);
} else if (oldPath == null || !oldPath.equals(path)) {
valid = true;
}

if(toastMessage != null) {
Toast.makeText(getContext(), toastMessage, Toast.LENGTH_LONG).show();
}

return valid;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == DirectoryPicker.PICK_DIRECTORY && resultCode != RESULT_CANCELED) {
Bundle extras = intent.getExtras();
String path;
String key;
File folder;
String oldPath = null;

if (extras == null) {
Logger.debug("null extra: " + intent);
Expand All @@ -236,35 +306,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
return;
}

folder = new File(path);
ExecChecker checker = null;


if (key.equals("RUBY_DIR")) {
oldPath = System.getRubyPath();
checker = ExecChecker.ruby();
} else if (key.equals("MSF_DIR")) {
oldPath = System.getMsfPath();
checker = ExecChecker.msf();
}

if (!folder.exists())
Toast.makeText(getActivity(), getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_exists), Toast.LENGTH_SHORT).show();

else if (!folder.canWrite())
Toast.makeText(getActivity(), getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_writable), Toast.LENGTH_SHORT).show();
if(canChangeDirectoryTo(key, path)) {

else if (checker != null && !checker.canExecuteInDir(path))
Toast.makeText(getActivity(), getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_executable), Toast.LENGTH_LONG).show();

else {
//noinspection ConstantConditions
getPreferenceManager().getSharedPreferences().edit().putString(key, path).commit();
if (oldPath != null && !oldPath.equals(path)) {
File current = new File(oldPath);

if (current.exists() && current.isDirectory() && current.listFiles().length > 2) {
wipe_prompt_older(current);
if(shallAskForDelete(key)) {
String oldPath = getCurrentPathForKey(key);
if(oldPath != null) {
File current = new File(oldPath);
if(current.exists() && current.isDirectory() && current.list().length > 0) {
wipe_prompt_older(current);
}
}
}
}
Expand Down

0 comments on commit 2104667

Please sign in to comment.