AttackRecord.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. this.setDevice(currentDevice.getDeviceID());
  61. }
  62. }
  63. @Override
  64. public int describeContents() {
  65. return 0;
  66. }
  67. @Override
  68. public void writeToParcel(Parcel dest, int flags) {
  69. dest.writeLong(attack_id);
  70. dest.writeString(protocol);
  71. dest.writeString(localIP);
  72. dest.writeInt(localPort);
  73. dest.writeString(remoteIP);
  74. dest.writeInt(remotePort);
  75. dest.writeString(externalIP);
  76. dest.writeInt(wasInternalAttack);
  77. dest.writeString(bssid);
  78. dest.writeString(device);
  79. dest.writeLong(sync_id);
  80. }
  81. /**
  82. * @return the attack_id
  83. */
  84. public long getAttack_id() {
  85. return attack_id;
  86. }
  87. /**
  88. * @param attack_id
  89. * the attack_id to set
  90. */
  91. public void setAttack_id(long attack_id) {
  92. this.attack_id = attack_id;
  93. }
  94. /**
  95. * @return the bssid
  96. */
  97. public String getBssid() {
  98. return bssid;
  99. }
  100. /**
  101. * @param bssid
  102. * the bssid to set
  103. */
  104. public void setBssid(String bssid) {
  105. this.bssid = bssid;
  106. }
  107. /**
  108. * @return the protocol
  109. */
  110. public String getProtocol() {
  111. return protocol;
  112. }
  113. /**
  114. * @param protocol
  115. * the protocol to set
  116. */
  117. public void setProtocol(String protocol) {
  118. this.protocol = protocol;
  119. }
  120. /**
  121. * @return the localIP
  122. */
  123. public String getLocalIP() {
  124. return localIP;
  125. }
  126. /**
  127. * @param localIP
  128. * the localIP to set
  129. */
  130. public void setLocalIP(String localIP) {
  131. this.localIP = localIP;
  132. }
  133. /**
  134. * @return the localPort
  135. */
  136. public int getLocalPort() {
  137. return localPort;
  138. }
  139. /**
  140. * @param localPort
  141. * the localPort to set
  142. */
  143. public void setLocalPort(int localPort) {
  144. this.localPort = localPort;
  145. }
  146. /**
  147. * @return the remoteIP
  148. */
  149. public String getRemoteIP() {
  150. return remoteIP;
  151. }
  152. /**
  153. * @param remoteIP
  154. * the remoteIP to set
  155. */
  156. public void setRemoteIP(String remoteIP) {
  157. this.remoteIP = remoteIP;
  158. }
  159. /**
  160. * @return the remotePort
  161. */
  162. public int getRemotePort() {
  163. return remotePort;
  164. }
  165. public long getSync_id(){return sync_id;}
  166. public String getDevice(){return device;}
  167. public void setDevice(String d){this.device = d;}
  168. public void setSync_id(long i){this.sync_id = i;}
  169. /**
  170. * @param remotePort
  171. * the remotePort to set
  172. */
  173. public void setRemotePort(int remotePort) {
  174. this.remotePort = remotePort;
  175. }
  176. /**
  177. * @return the externalIP
  178. */
  179. public String getExternalIP() {
  180. return externalIP;
  181. }
  182. /**
  183. * @param externalIP
  184. * the externalIP to set
  185. */
  186. public void setExternalIP(String externalIP) {
  187. this.externalIP = externalIP;
  188. }
  189. public boolean getWasInternalAttack() {return wasInternalAttack == 1;}
  190. public void setWasInternalAttack(boolean b) {wasInternalAttack = b ? 1 : 0;}
  191. }