use of org.csploit.android.net.metasploit.Payload in project android by cSploit.
the class MsfPreferences method createPreferenceHierarchy.
private PreferenceScreen createPreferenceHierarchy() {
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
String title = null;
PreferenceCategory cat_required = new PreferenceCategory(this);
PreferenceCategory cat_general = new PreferenceCategory(this);
PreferenceCategory cat_advanced = new PreferenceCategory(this);
PreferenceCategory cat_evasion = new PreferenceCategory(this);
ArrayList<Preference> required = new ArrayList<Preference>();
ArrayList<Preference> general = new ArrayList<Preference>();
ArrayList<Preference> advanced = new ArrayList<Preference>();
ArrayList<Preference> evasion = new ArrayList<Preference>();
Payload payload = System.getCurrentPayload();
MsfExploit exploit = (MsfExploit) System.getCurrentExploit();
System.setCurrentPayload(null);
System.setCurrentExploit(null);
if (payload != null) {
options = payload.getOptions();
title = payload.toString();
} else if (exploit != null) {
options = exploit.getOptions();
title = exploit.toString();
}
if (options == null) {
options = new ArrayList<Option>();
title = getString(R.string.error);
String error_message;
if (exploit != null)
error_message = String.format("cannot retrieve options for '%s'", exploit.getName());
else if (payload != null)
error_message = String.format("cannot retrieve options for '%s'", payload.getName());
else
error_message = "called without Payload or MsfExploit";
Logger.error(error_message);
}
setTitle(title + " > " + getString(R.string.menu_settings));
cat_required.setTitle(R.string.required);
cat_general.setTitle(R.string.pref_general);
cat_advanced.setTitle(R.string.pref_advanced);
cat_evasion.setTitle(R.string.evasion);
for (Option opt : options) {
Preference item = null;
int inputType = 0;
switch(opt.getType()) {
case ADDRESS:
case STRING:
case PATH:
case INTEGER:
case PORT:
item = new EditTextPreference(this);
item.setTitle(opt.getName());
((EditTextPreference) item).setDialogTitle(opt.getName());
((EditTextPreference) item).setDialogMessage(opt.getDescription());
item.setSummary(opt.getDescription());
item.setKey(opt.getName());
item.setDefaultValue(opt.getValue());
break;
case BOOLEAN:
item = new CheckBoxPreference(this);
item.setTitle(opt.getName());
item.setKey(opt.getName());
item.setSummary(opt.getDescription());
((CheckBoxPreference) item).setChecked(opt.getValue().equals("true"));
break;
case ENUM:
item = new ListPreference(this);
((ListPreference) item).setEntries(opt.getEnum());
((ListPreference) item).setEntryValues(opt.getEnum());
((ListPreference) item).setDialogTitle(opt.getName());
((ListPreference) item).setValue(opt.getValue());
item.setKey(opt.getName());
item.setTitle(opt.getName());
item.setSummary(opt.getDescription());
break;
}
switch(opt.getType()) {
case ADDRESS:
inputType = InputType.TYPE_CLASS_PHONE;
break;
case PATH:
case STRING:
inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
break;
case PORT:
case INTEGER:
inputType = InputType.TYPE_CLASS_NUMBER;
break;
}
if (inputType != 0)
((EditTextPreference) item).getEditText().setInputType(inputType);
if (opt.isAdvanced())
advanced.add(item);
else if (opt.isRequired())
required.add(item);
else if (opt.isEvasion())
evasion.add(item);
else
general.add(item);
if (item != null) {
item.setOnPreferenceChangeListener(listener);
}
}
if (required.size() > 0) {
root.addPreference(cat_required);
for (Preference i : required) cat_required.addPreference(i);
}
if (general.size() > 0) {
root.addPreference(cat_general);
for (Preference i : general) cat_general.addPreference(i);
}
if (advanced.size() > 0) {
root.addPreference(cat_advanced);
for (Preference i : advanced) cat_advanced.addPreference(i);
}
if (evasion.size() > 0) {
root.addPreference(cat_evasion);
for (Preference i : evasion) cat_evasion.addPreference(i);
}
return root;
}
Aggregations