Skip to content

Commit a28bd01

Browse files
committed
change autoScan state only when needed, do not check on every host found
1 parent ebb4acc commit a28bd01

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.csploit.android.gui.dialogs.ChoiceDialog;
4242
import org.csploit.android.gui.dialogs.ConfirmDialog;
4343
import org.csploit.android.net.GitHubParser;
44+
import org.csploit.android.services.Services;
4445
import org.csploit.android.tools.Raw;
4546
import org.json.JSONException;
4647

@@ -376,6 +377,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
376377
} else if (key.equals("MSF_ENABLED")) {
377378
if (mMsfEnabled.isChecked())
378379
onMsfEnabled();
380+
} else if (key.equals("PREF_AUTO_PORTSCAN")) {
381+
Services.getNetworkRadar().onAutoScanChanged();
379382
}
380383

381384
if (message != null)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ public static void shutdownCoreDaemon(){
305305
Client.Disconnect();
306306

307307
mCoreInitialized = false;
308+
Services.getNetworkRadar().onAutoScanChanged();
308309
}
309310

310311
public static void initCore() throws DaemonException, SuException {
@@ -335,6 +336,7 @@ public static void initCore() throws DaemonException, SuException {
335336
reloadTools();
336337

337338
mCoreInitialized = true;
339+
Services.getNetworkRadar().onAutoScanChanged();
338340
}
339341

340342
public static void reloadNetworkMapping(){
@@ -948,7 +950,7 @@ public static void reset() {
948950
}
949951

950952
public static void scanThemAll() {
951-
if(!mCoreInitialized) {
953+
if(!Services.getNetworkRadar().isAutoScanEnabled()) {
952954
return;
953955
}
954956
synchronized (mTargets) {
@@ -1212,6 +1214,7 @@ public static void clean(boolean releaseLocks){
12121214

12131215
Client.Disconnect();
12141216
mCoreInitialized = false;
1217+
Services.getNetworkRadar().onAutoScanChanged();
12151218
}
12161219
catch(Exception e){
12171220
errorLogging(e);

cSploit/src/org/csploit/android/services/NetworkRadar.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class NetworkRadar extends NativeService implements MenuControllableServi
2626
public static final String NRDR_STARTED = "NetworkRadar.action.STARTED";
2727
public static final String NRDR_START_FAILED = "NetworkRadar.action.START_FAILED";
2828

29+
private boolean autoScan = true;
30+
2931
public NetworkRadar(Context context) {
3032
this.context = context;
3133
}
@@ -69,26 +71,28 @@ public void buildMenuItem(MenuItem item) {
6971
item.setEnabled(System.getTools().networkRadar.isEnabled() && System.getNetwork() != null);
7072
}
7173

72-
public void onNewTargetFound(final Target target) {
73-
if (target.getType() == Target.Type.NETWORK)
74-
return;
74+
public void onAutoScanChanged() {
75+
autoScan = System.isCoreInitialized() && System.getSettings().getBoolean("PREF_AUTO_PORTSCAN", true);
76+
Logger.info("autoScan has been set to " + autoScan);
77+
}
7578

76-
if (!System.isCoreInitialized()) {
79+
public boolean isAutoScanEnabled() {
80+
return autoScan;
81+
}
82+
83+
public void onNewTargetFound(final Target target) {
84+
if(!autoScan || target.getType() == Target.Type.NETWORK)
7785
return;
78-
}
79-
SharedPreferences prefs = System.getSettings();
80-
if (prefs.getBoolean("PREF_AUTO_PORTSCAN", true)) {
81-
ThreadHelper.getSharedExecutor().execute(new Runnable() {
82-
@Override
83-
public void run() {
84-
try {
85-
System.getTools().nmap.synScan(target, new ScanReceiver(target));
86-
} catch (ChildManager.ChildNotStartedException e) {
87-
System.errorLogging(e);
88-
}
86+
ThreadHelper.getSharedExecutor().execute(new Runnable() {
87+
@Override
88+
public void run() {
89+
try {
90+
System.getTools().nmap.synScan(target, new ScanReceiver(target));
91+
} catch (ChildManager.ChildNotStartedException e) {
92+
System.errorLogging(e);
8993
}
90-
});
91-
}
94+
}
95+
});
9296
}
9397

9498
private class Receiver extends HostReceiver {

0 commit comments

Comments
 (0)