AttackRecord.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. import java.io.Serializable;
  3. import android.content.SharedPreferences;
  4. import android.os.Parcel;
  5. import android.os.Parcelable;
  6. import android.preference.PreferenceManager;
  7. import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
  8. import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
  9. /**
  10. * Holds all necessary information about a single attack.
  11. */
  12. public class AttackRecord implements Parcelable, Serializable {
  13. private static final long serialVersionUID = 6111024905373724227L;
  14. private long attack_id;
  15. private long sync_id;
  16. private String bssid;
  17. private String device;
  18. private String protocol;
  19. private String localIP;
  20. private int localPort;
  21. private String remoteIP;
  22. private int remotePort;
  23. private String externalIP;
  24. private int wasInternalAttack; // 1 if attacker ip and local ip were in same subnet, else 0
  25. public static final Parcelable.Creator<AttackRecord> CREATOR = new Parcelable.Creator<AttackRecord>() {
  26. @Override
  27. public AttackRecord createFromParcel(Parcel source) {
  28. return new AttackRecord(source);
  29. }
  30. @Override
  31. public AttackRecord[] newArray(int size) {
  32. return new AttackRecord[size];
  33. }
  34. };
  35. public AttackRecord() {
  36. }
  37. public AttackRecord(Parcel source) {
  38. this.attack_id = source.readLong();
  39. this.protocol = source.readString();
  40. this.localIP = source.readString();
  41. this.localPort = source.readInt();
  42. this.remoteIP = source.readString();
  43. this.remotePort = source.readInt();
  44. this.externalIP = source.readString();
  45. this.wasInternalAttack = source.readInt();
  46. this.bssid = source.readString();
  47. this.device = source.readString();
  48. this.sync_id = source.readLong();
  49. }
  50. public AttackRecord(boolean autoincrement){
  51. if (autoincrement){
  52. SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.getContext());
  53. SharedPreferences.Editor editor = pref.edit();
  54. int attack_id = pref.getInt("ATTACK_ID_COUNTER", 0);
  55. editor.putInt("ATTACK_ID_COUNTER", attack_id + 1);
  56. editor.commit();
  57. this.attack_id = attack_id;
  58. this.sync_id = attack_id;
  59. SyncDevice currentDevice = SyncDevice.currentDevice();
  60. currentDevice.setHighest_attack_id(attack_id);
  61. this.setDevice(currentDevice.getDeviceID());
  62. }
  63. }
  64. @Override
  65. public int describeContents() {
  66. return 0;
  67. }
  68. @Override
  69. public void writeToParcel(Parcel dest, int flags) {
  70. dest.writeLong(attack_id);
  71. dest.writeString(protocol);
  72. dest.writeString(localIP);
  73. dest.writeInt(localPort);
  74. dest.writeString(remoteIP);
  75. dest.writeInt(remotePort);
  76. dest.writeString(externalIP);
  77. dest.writeInt(wasInternalAttack);
  78. dest.writeString(bssid);
  79. dest.writeString(device);
  80. dest.writeLong(sync_id);
  81. }
  82. /**
  83. * @return the attack_id
  84. */
  85. public long getAttack_id() {
  86. return attack_id;
  87. }
  88. /**
  89. * @param attack_id
  90. * the attack_id to set
  91. */
  92. public void setAttack_id(long attack_id) {
  93. this.attack_id = attack_id;
  94. }
  95. /**
  96. * @return the bssid
  97. */
  98. public String getBssid() {
  99. return bssid;
  100. }
  101. /**
  102. * @param bssid
  103. * the bssid to set
  104. */
  105. public void setBssid(String bssid) {
  106. this.bssid = bssid;
  107. }
  108. /**
  109. * @return the protocol
  110. */
  111. public String getProtocol() {
  112. return protocol;
  113. }
  114. /**
  115. * @param protocol
  116. * the protocol to set
  117. */
  118. public void setProtocol(String protocol) {
  119. this.protocol = protocol;
  120. }
  121. /**
  122. * @return the localIP
  123. */
  124. public String getLocalIP() {
  125. return localIP;
  126. }
  127. /**
  128. * @param localIP
  129. * the localIP to set
  130. */
  131. public void setLocalIP(String localIP) {
  132. this.localIP = localIP;
  133. }
  134. /**
  135. * @return the localPort
  136. */
  137. public int getLocalPort() {
  138. return localPort;
  139. }
  140. /**
  141. * @param localPort
  142. * the localPort to set
  143. */
  144. public void setLocalPort(int localPort) {
  145. this.localPort = localPort;
  146. }
  147. /**
  148. * @return the remoteIP
  149. */
  150. public String getRemoteIP() {
  151. return remoteIP;
  152. }
  153. /**
  154. * @param remoteIP
  155. * the remoteIP to set
  156. */
  157. public void setRemoteIP(String remoteIP) {
  158. this.remoteIP = remoteIP;
  159. }
  160. /**
  161. * @return the remotePort
  162. */
  163. public int getRemotePort() {
  164. return remotePort;
  165. }
  166. public long getSync_id(){return sync_id;}
  167. public String getDevice(){return device;}
  168. public void setDevice(String d){this.device = d;}
  169. public void setSync_id(long i){this.sync_id = i;}
  170. /**
  171. * @param remotePort
  172. * the remotePort to set
  173. */
  174. public void setRemotePort(int remotePort) {
  175. this.remotePort = remotePort;
  176. }
  177. /**
  178. * @return the externalIP
  179. */
  180. public String getExternalIP() {
  181. return externalIP;
  182. }
  183. /**
  184. * @param externalIP
  185. * the externalIP to set
  186. */
  187. public void setExternalIP(String externalIP) {
  188. this.externalIP = externalIP;
  189. }
  190. public boolean getWasInternalAttack() {return wasInternalAttack == 1;}
  191. public void setWasInternalAttack(boolean b) {wasInternalAttack = b ? 1 : 0;}
  192. }