Skip to content

Commit 2104667

Browse files
committed
Merge branch 'hotfix'
2 parents 6d5126b + cc50526 commit 2104667

File tree

3 files changed

+83
-29
lines changed

3 files changed

+83
-29
lines changed

cSploit/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ android {
5252
defaultConfig {
5353
minSdkVersion 9
5454
targetSdkVersion 22
55-
versionCode 5
56-
versionName "1.6.4"
55+
versionCode 6
56+
versionName "1.6.5"
5757
if(System.getenv("NIGHTLY_BUILD")) {
5858
versionName += "+" + System.getenv("NIGHTLY_BUILD_COMMIT").substring(0, 7)
5959
}

cSploit/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,4 +529,5 @@
529529
<string name="mitm_ss_select_target_prompt">Select %s ?</string>
530530
<string name="github_issues_url" translatable="false">https://github.com/cSploit/android/issues</string>
531531
<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>
532+
<string name="pref_err_empty_or_old">must be empty or an old installation directory.</string>
532533
</resources>

cSploit/src/org/csploit/android/SettingsActivity.java

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,84 @@ public void onEnd(int exitCode) {
214214
}
215215
}
216216

217+
private boolean isDirectoryEmptyOrWithVersion(File folder) {
218+
String[] files = folder.list();
219+
220+
if(files.length > 0) {
221+
for(String fname : files) {
222+
if("VERSION".equals(fname)) {
223+
return true;
224+
}
225+
}
226+
return false;
227+
}
228+
229+
return true;
230+
}
231+
232+
private ExecChecker getCheckerForKey(String key) {
233+
switch (key) {
234+
case "RUBY_DIR":
235+
return ExecChecker.ruby();
236+
case "MSF_DIR":
237+
return ExecChecker.msf();
238+
}
239+
return null;
240+
}
241+
242+
private String getCurrentPathForKey(String key) {
243+
switch (key) {
244+
case "RUBY_DIR":
245+
return System.getRubyPath();
246+
case "MSF_DIR":
247+
return System.getMsfPath();
248+
}
249+
return null;
250+
}
251+
252+
private boolean shallAskForDelete(String key) {
253+
return key.equals("RUBY_DIR") || key.equals("MSF_DIR");
254+
}
255+
256+
/**
257+
* check if selected directory is valid for the given key.
258+
* @param key to be updated
259+
* @param path of the chosen directory
260+
* @return true if {@code path} is valid, false otherwise
261+
*/
262+
private boolean canChangeDirectoryTo(String key, String path) {
263+
File folder = new File(path);
264+
ExecChecker checker = getCheckerForKey(key);
265+
String oldPath = getCurrentPathForKey(key);
266+
String toastMessage = null;
267+
boolean valid = false;
268+
boolean checkEmptyOrVersion = shallAskForDelete(key);
269+
270+
if (!folder.exists()) {
271+
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_exists);
272+
} else if (!folder.canWrite()) {
273+
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_writable);
274+
} else if (checker != null && !checker.canExecuteInDir(path)) {
275+
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_executable);
276+
} else if (checkEmptyOrVersion && !isDirectoryEmptyOrWithVersion(folder)) {
277+
toastMessage = getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_empty_or_old);
278+
} else if (oldPath == null || !oldPath.equals(path)) {
279+
valid = true;
280+
}
281+
282+
if(toastMessage != null) {
283+
Toast.makeText(getContext(), toastMessage, Toast.LENGTH_LONG).show();
284+
}
285+
286+
return valid;
287+
}
288+
217289
@Override
218290
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
219291
if (requestCode == DirectoryPicker.PICK_DIRECTORY && resultCode != RESULT_CANCELED) {
220292
Bundle extras = intent.getExtras();
221293
String path;
222294
String key;
223-
File folder;
224-
String oldPath = null;
225295

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

239-
folder = new File(path);
240-
ExecChecker checker = null;
241-
242-
243-
if (key.equals("RUBY_DIR")) {
244-
oldPath = System.getRubyPath();
245-
checker = ExecChecker.ruby();
246-
} else if (key.equals("MSF_DIR")) {
247-
oldPath = System.getMsfPath();
248-
checker = ExecChecker.msf();
249-
}
250-
251-
if (!folder.exists())
252-
Toast.makeText(getActivity(), getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_exists), Toast.LENGTH_SHORT).show();
253-
254-
else if (!folder.canWrite())
255-
Toast.makeText(getActivity(), getString(R.string.pref_folder) + " " + path + " " + getString(R.string.pref_err_writable), Toast.LENGTH_SHORT).show();
309+
if(canChangeDirectoryTo(key, path)) {
256310

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

260-
else {
261-
//noinspection ConstantConditions
262312
getPreferenceManager().getSharedPreferences().edit().putString(key, path).commit();
263-
if (oldPath != null && !oldPath.equals(path)) {
264-
File current = new File(oldPath);
265313

266-
if (current.exists() && current.isDirectory() && current.listFiles().length > 2) {
267-
wipe_prompt_older(current);
314+
if(shallAskForDelete(key)) {
315+
String oldPath = getCurrentPathForKey(key);
316+
if(oldPath != null) {
317+
File current = new File(oldPath);
318+
if(current.exists() && current.isDirectory() && current.list().length > 0) {
319+
wipe_prompt_older(current);
320+
}
268321
}
269322
}
270323
}

0 commit comments

Comments
 (0)