Kaynağa Gözat

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostagev2

Julien Clauter 10 yıl önce
ebeveyn
işleme
ee1cf94da8

+ 0 - 22
native/Makefile~

@@ -1,22 +0,0 @@
-arm: CC = arm-linux-androideabi-gcc
-x86: CC = i686-linux-android-gcc
-mips: CC = mipsel-linux-android-gcc
-CFLAGS = -Wall -g
-LDFLAGS = -llog
-SRC = p.c
-OBJ = $(SRC:.c=.o)
-EXE = p
-
-arm x86 mips: $(SRC) $(EXE)
-
-$(EXE): $(OBJ)
-	$(CC) -o $@ $^ $(LDFLAGS)
-
-%.o: %.c
-	$(CC) -o $@ -c $< $(CFLAGS)
-
-clean:
-	rm -f *.o $(EXE)
-
-install:
-	adb push p /data/local

BIN
native/bind.o


+ 2 - 0
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -476,6 +476,8 @@ public class MainActivity extends Activity {
 	@Override
 	public void onBackPressed() {
 		if (getFragmentManager().getBackStackEntryCount() == 1) {
+			MainActivity.getInstance().getHostageService().stopListeners();
+			MainActivity.getInstance().stopAndUnbind();
 			finish();
 		} else {
 			super.onBackPressed();

+ 83 - 9
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java

@@ -15,6 +15,8 @@ import android.widget.Switch;
 import android.widget.TextView;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.persistence.ProfileManager;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
@@ -30,6 +32,8 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
     private Context mActivity;
     private Switch mServicesSwitch;
     private CompoundButton.OnCheckedChangeListener mListener;
+    private Profile mProfile;
+    private Integer[] mGhostPorts;
 
     /**
      * constructor
@@ -99,8 +103,8 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
                 new CompoundButton.OnCheckedChangeListener() {
                     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                         ServicesListItem item = (ServicesListItem) buttonView.getTag();
-
-                        if (!HelperUtils.isWifiConnected(mActivity)) {
+                        mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
+                        if (!HelperUtils.isNetworkAvailable(mActivity)) {
                             new AlertDialog.Builder(mActivity)
                                     .setTitle(R.string.information)
                                     .setMessage(R.string.wifi_not_connected_msg)
@@ -117,7 +121,29 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
                         } else {
                             //check if switch is set to ON and start the concrete listener for the protocol
                             if (isChecked) {
-                                if (!MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                if(item.protocol.equals("GHOST")){
+                                    if(mProfile.mGhostActive){
+                                        mGhostPorts = mProfile.getGhostPorts();
+
+                                        if(mGhostPorts.length != 0) {
+                                            for(Integer port: mGhostPorts){
+                                                if(!MainActivity.getInstance().getHostageService().isRunning(item.protocol, port)) {
+                                                    MainActivity.getInstance().getHostageService().startListener(item.protocol, port);
+                                                }
+                                            }
+                                            //set the main switch to null, so that he won't react and starts all protocols
+                                            mServicesSwitch.setOnCheckedChangeListener(null);
+                                            mServicesSwitch.setChecked(true);
+                                            mServicesSwitch.setOnCheckedChangeListener(mListener);
+
+                                            buttonView.setChecked(true);
+                                        }
+                                    }
+                                    else {
+                                        buttonView.setChecked(false);
+                                    }
+                                }
+                                else if (!MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
                                     MainActivity.getInstance().getHostageService().startListener(item.protocol);
 
                                     //set the main switch to null, so that he won't react and starts all protocols
@@ -125,14 +151,23 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
                                     mServicesSwitch.setChecked(true);
                                     mServicesSwitch.setOnCheckedChangeListener(mListener);
                                     buttonView.setChecked(true);
-                                } else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                } else {
                                     buttonView.setChecked(true);
                                 }
                             } else {
-                                if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
-                                    MainActivity.getInstance().getHostageService().stopListener(item.protocol);
-                                }
-                                buttonView.setChecked(false);
+                                   if(item.protocol.equals("GHOST")) {
+                                       mGhostPorts = mProfile.getGhostPorts();
+                                       for(Integer port: mGhostPorts){
+                                           if(MainActivity.getInstance().getHostageService().isRunning("GHOST",port)){
+                                               MainActivity.getInstance().getHostageService().stopListener("GHOST", port);
+                                           }
+                                       }
+                                       buttonView.setChecked(false);
+                                   }
+                                   else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                        MainActivity.getInstance().getHostageService().stopListener(item.protocol);
+                                    }
+                                    buttonView.setChecked(false);
                             }
                         }
                     }
@@ -148,7 +183,46 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
      * @param holder ViewHolder which represents the item in the View
      */
     private void updateStatus(ServicesListItem item, ViewHolder holder) {
-        if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+        if(item.protocol.equals("GHOST")){
+            mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
+            mGhostPorts = mProfile.getGhostPorts();
+
+            boolean ghostActive = false;
+
+            for(Integer port: mGhostPorts){
+                if(MainActivity.getInstance().getHostageService().isRunning("GHOST",port)){
+                    ghostActive = true;
+                }
+            }
+            if(ghostActive){
+                holder.activated.setChecked(true);
+
+                if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
+                    if (item.attacks > 0) {
+                        setBackground(holder, R.drawable.services_circle_yellow);
+                    } else {
+                        setBackground(holder, R.drawable.services_circle_green);
+                    }
+
+                } else {
+                    if (MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
+                        setBackground(holder, R.drawable.services_circle_red);
+                    }
+                }
+
+            } else if (item.attacks > 0) {
+                holder.activated.setChecked(false);
+                setBackground(holder, R.drawable.services_circle_yellow);
+            } else {
+                holder.activated.setChecked(false);
+                setBackground(holder, R.drawable.services_circle);
+            }
+
+
+
+
+        }
+        else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
             holder.activated.setChecked(true);
             if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
                 if (item.attacks > 0) {

+ 26 - 3
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -23,6 +23,8 @@ import de.tudarmstadt.informatik.hostage.Handler;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
+import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.persistence.ProfileManager;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
@@ -55,6 +57,9 @@ public class ServicesFragment extends Fragment {
 
     private boolean mReceiverRegistered = false;
 
+    private Profile mProfile;
+    private Integer[] mGhostPorts;
+
     public ServicesFragment() {
     }
 
@@ -167,7 +172,8 @@ public class ServicesFragment extends Fragment {
         if (switchChangeListener == null) {
             switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
                 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-                    if (!HelperUtils.isWifiConnected(getActivity())) {
+                    mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
+                    if (!HelperUtils.isNetworkAvailable(getActivity())) {
                         new AlertDialog.Builder(getActivity())
                                 .setTitle(R.string.information)
                                 .setMessage(R.string.wifi_not_connected_msg)
@@ -187,8 +193,25 @@ public class ServicesFragment extends Fragment {
                         if (MainActivity.getInstance().isServiceBound()) {
                             if (isChecked) {
                                 for (String protocol : protocols) {
-                                    if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
-                                        MainActivity.getInstance().getHostageService().startListener(protocol);
+                                    if(!protocol.equals("GHOST")) {
+                                         if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
+                                             MainActivity.getInstance().getHostageService().startListener(protocol);
+                                         }
+                                    }
+                                    else {
+                                        if(mProfile.mGhostActive){
+
+                                            mGhostPorts = mProfile.getGhostPorts();
+                                            if (mGhostPorts.length != 0)  {
+                                                for (Integer port : mGhostPorts) {
+                                                    if(!MainActivity.getInstance().getHostageService().isRunning("GHOST", port)) {
+                                                        MainActivity.getInstance().getHostageService().startListener("GHOST", port);
+                                                    }
+                                                }
+                                            }
+
+
+                                        }
                                     }
                                 }
                                 setStateActive();