Skip to content

Commit 151b5ce

Browse files
committed
Merge branch 'issue-332' into release
2 parents 62f94f3 + 0c0e05d commit 151b5ce

2 files changed

Lines changed: 42 additions & 34 deletions

File tree

cSploit/src/org/csploit/android/core/System.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import org.acra.ACRA;
4040
import org.acra.ACRAConfiguration;
41+
import org.apache.commons.compress.utils.IOUtils;
4142
import org.csploit.android.R;
4243
import org.csploit.android.WifiScannerActivity;
4344
import org.csploit.android.gui.dialogs.FatalDialog;
@@ -149,8 +150,10 @@ public static void init(Context context) throws Exception{
149150
mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString());
150151
mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis();
151152
mKnownIssues = new KnownIssues();
152-
mPlugins = new ArrayList<Plugin>();
153+
mPlugins = new ArrayList<>();
153154
mOpenPorts = new SparseIntArray(3);
155+
mServices = new HashMap<>();
156+
mPorts = new HashMap<>();
154157

155158
// if we are here, network initialization didn't throw any error, lock wifi
156159
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
@@ -515,38 +518,39 @@ public static void unregisterSettingListener(SettingReceiver receiver) {
515518
}
516519
}
517520

518-
private static void preloadServices(){
519-
if(mServices == null || mPorts == null){
520-
try{
521-
// preload network service map and mac vendors
522-
mServices = new HashMap<String, String>();
523-
mPorts = new HashMap<String, String>();
524-
525-
@SuppressWarnings("ConstantConditions")
526-
FileInputStream fstream = new FileInputStream(mContext.getFilesDir().getAbsolutePath() + "/tools/nmap/nmap-services");
521+
public static void preloadServices(){
522+
if (!mServices.isEmpty())
523+
return;
527524

528-
DataInputStream in = new DataInputStream(fstream);
529-
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
530-
String line;
531-
Matcher matcher;
525+
FileReader fr = null;
526+
BufferedReader reader = null;
527+
try{
528+
// preload network service and ports map
532529

533-
while((line = reader.readLine()) != null){
534-
line = line.trim();
530+
fr = new FileReader(mContext.getFilesDir().getAbsolutePath() + "/tools/nmap/nmap-services");
531+
reader = new BufferedReader(fr);
532+
String line;
533+
Matcher matcher;
534+
String port, proto;
535535

536-
if((matcher = SERVICE_PARSER.matcher(line)) != null && matcher.find()){
537-
String proto = matcher.group(1),
538-
port = matcher.group(2);
536+
while ((line = reader.readLine()) != null) {
537+
if ((matcher = SERVICE_PARSER.matcher(line)) != null && matcher.find()) {
538+
proto = matcher.group(1);
539+
port = matcher.group(2);
539540

540-
mServices.put(proto, port);
541-
mPorts.put(port, proto);
542-
}
541+
mServices.put(proto, port);
542+
mPorts.put(port, proto);
543543
}
544-
545-
in.close();
546-
}
547-
catch(Exception e){
548-
errorLogging(e);
549544
}
545+
546+
} catch (Exception e) {
547+
mServices.clear();
548+
mPorts.clear();
549+
550+
errorLogging(e);
551+
} finally {
552+
IOUtils.closeQuietly(reader);
553+
IOUtils.closeQuietly(fr);
550554
}
551555
}
552556

@@ -941,7 +945,6 @@ public static String getMacVendor(byte[] mac){
941945
}
942946

943947
public static String getProtocolByPort(String port){
944-
preloadServices();
945948

946949
return mPorts.containsKey(port) ? mPorts.get(port) : null;
947950
}
@@ -951,7 +954,6 @@ public static String getProtocolByPort(int port) {
951954
}
952955

953956
public static int getPortByProtocol(String protocol){
954-
preloadServices();
955957

956958
return mServices.containsKey(protocol) ? Integer.parseInt(mServices.get(protocol)) : 0;
957959
}

cSploit/src/org/csploit/android/plugins/PortScanner.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import android.content.SharedPreferences;
2424
import android.net.Uri;
2525
import android.os.Bundle;
26-
import android.preference.PreferenceManager;
2726
import android.view.Menu;
2827
import android.view.MenuInflater;
2928
import android.view.MenuItem;
@@ -111,7 +110,7 @@ private void saveCustomParameters (boolean displayed){
111110
SharedPreferences.Editor edit = mPreferences.edit();
112111
edit.putBoolean(CUSTOM_PARAMETERS, displayed);
113112
edit.putString(CUSTOM_PARAMETERS_TEXT, mTextParameters.getText().toString());
114-
edit.commit();
113+
edit.apply();
115114
}
116115

117116
private void setStoppedState() {
@@ -187,6 +186,13 @@ public void onCreate(Bundle savedInstanceState) {
187186
mScanToggleButton = (ToggleButton) findViewById(R.id.scanToggleButton);
188187
mScanProgress = (ProgressBar) findViewById(R.id.scanActivity);
189188

189+
new Thread(new Runnable() {
190+
@Override
191+
public void run() {
192+
System.preloadServices();
193+
}
194+
}).start();
195+
190196
if (mPreferences.getBoolean(CUSTOM_PARAMETERS, false))
191197
displayParametersField();
192198

@@ -403,11 +409,11 @@ public void onPortFound(final int port, String protocol) {
403409
public void run() {
404410
String entry;
405411

406-
if (resolvedProtocol != null)
412+
if (resolvedProtocol != null) {
407413
entry = port + " ( " + resolvedProtocol + " )";
408-
409-
else
414+
} else {
410415
entry = portProtocol + " : " + port;
416+
}
411417

412418
// add open port to the listview and notify the environment
413419
// about the event

0 commit comments

Comments
 (0)