Record.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. import android.os.Parcel;
  3. import android.os.Parcelable;
  4. import de.tudarmstadt.informatik.hostage.logging.formatter.Formatter;
  5. /**
  6. * This class defines the attributes of a record.<br>
  7. * A Record is a single message exchanged between the application and an
  8. * attacker.<br>
  9. * The class has no own functionality except for getter and setter methods. To
  10. * change the logging mechanism you have to to change the logger in
  11. * {@link de.tudarmstadt.informatik.hostage.Hostage HoneyService} and
  12. * {@link de.tudarmstadt.informatik.hostage.ui.ViewLog ViewLog}
  13. *
  14. * @author Mihai Plasoianu
  15. * @author Lars Pandikow
  16. */
  17. public class Record implements Parcelable {
  18. public static enum TYPE {
  19. SEND, RECEIVE
  20. };
  21. // attack
  22. private int id;
  23. private long attack_id;
  24. private long timestamp;
  25. private String protocol;
  26. private TYPE type;
  27. private String packet;
  28. // network
  29. private String localIP;
  30. private int localPort;
  31. private String remoteIP;
  32. private int remotePort;
  33. private String externalIP;
  34. private String bssid;
  35. private String ssid;
  36. // location
  37. private long timestampLocation;
  38. private double latitude;
  39. private double longitude;
  40. private float accuracy;
  41. public static final Parcelable.Creator<Record> CREATOR = new Parcelable.Creator<Record>() {
  42. @Override
  43. public Record createFromParcel(Parcel source) {
  44. return new Record(source);
  45. }
  46. @Override
  47. public Record[] newArray(int size) {
  48. return new Record[size];
  49. }
  50. };
  51. public Record() {
  52. }
  53. public Record(Parcel source) {
  54. // attack
  55. this.id = source.readInt();
  56. this.attack_id = source.readLong();
  57. this.timestamp = source.readLong();
  58. this.protocol = source.readString();
  59. this.type = TYPE.valueOf(source.readString());
  60. this.packet = source.readString();
  61. // network
  62. this.localIP = source.readString();
  63. this.localPort = source.readInt();
  64. this.remoteIP = source.readString();
  65. this.remotePort = source.readInt();
  66. this.externalIP = source.readString();
  67. this.bssid = source.readString();
  68. this.ssid = source.readString();
  69. // location
  70. this.timestampLocation = source.readLong();
  71. this.latitude = source.readDouble();
  72. this.longitude = source.readDouble();
  73. this.accuracy = source.readFloat();
  74. }
  75. @Override
  76. public int describeContents() {
  77. return 0;
  78. }
  79. public float getAccuracy() {
  80. return accuracy;
  81. }
  82. public long getAttack_id() {
  83. return attack_id;
  84. }
  85. public String getBssid() {
  86. return bssid;
  87. }
  88. public String getExternalIP() {
  89. return externalIP;
  90. }
  91. public int getId() {
  92. return id;
  93. }
  94. public double getLatitude() {
  95. return latitude;
  96. }
  97. public String getLocalIP() {
  98. return localIP;
  99. }
  100. public int getLocalPort() {
  101. return localPort;
  102. }
  103. public double getLongitude() {
  104. return longitude;
  105. }
  106. public String getPacket() {
  107. return packet;
  108. }
  109. public String getProtocol() {
  110. return protocol;
  111. }
  112. public String getRemoteIP() {
  113. return remoteIP;
  114. }
  115. public int getRemotePort() {
  116. return remotePort;
  117. }
  118. public String getSsid() {
  119. return ssid;
  120. }
  121. public long getTimestamp() {
  122. return timestamp;
  123. }
  124. public long getTimestampLocation() {
  125. return timestampLocation;
  126. }
  127. public TYPE getType() {
  128. return type;
  129. }
  130. public void setAccuracy(float accuracy) {
  131. this.accuracy = accuracy;
  132. }
  133. public void setAttack_id(long attack_id) {
  134. this.attack_id = attack_id;
  135. }
  136. public void setBssid(String bssid) {
  137. this.bssid = bssid;
  138. }
  139. public void setExternalIP(String externalIP) {
  140. this.externalIP = externalIP;
  141. }
  142. public void setId(int id) {
  143. this.id = id;
  144. }
  145. public void setLatitude(double latitude) {
  146. this.latitude = latitude;
  147. }
  148. public void setLocalIP(String localIP) {
  149. this.localIP = localIP;
  150. }
  151. public void setLocalPort(int localPort) {
  152. this.localPort = localPort;
  153. }
  154. public void setLongitude(double longitude) {
  155. this.longitude = longitude;
  156. }
  157. public void setPacket(String packet) {
  158. this.packet = packet;
  159. }
  160. public void setProtocol(String protocol) {
  161. this.protocol = protocol;
  162. }
  163. public void setRemoteIP(String remoteIP) {
  164. this.remoteIP = remoteIP;
  165. }
  166. public void setRemotePort(int remotePort) {
  167. this.remotePort = remotePort;
  168. }
  169. public void setSsid(String ssid) {
  170. this.ssid = ssid;
  171. }
  172. public void setTimestamp(long timestamp) {
  173. this.timestamp = timestamp;
  174. }
  175. public void setTimestampLocation(long timestampLocation) {
  176. this.timestampLocation = timestampLocation;
  177. }
  178. public void setType(TYPE type) {
  179. this.type = type;
  180. }
  181. @Override
  182. public String toString() {
  183. return toString(null);
  184. }
  185. public String toString(Formatter formatter) {
  186. if (null == formatter) {
  187. return Formatter.getDefault().format(this);
  188. }
  189. return formatter.format(this);
  190. }
  191. @Override
  192. public void writeToParcel(Parcel dest, int flags) {
  193. // attack
  194. dest.writeInt(id);
  195. dest.writeLong(attack_id);
  196. dest.writeLong(timestamp);
  197. dest.writeString(protocol);
  198. dest.writeString(type.name());
  199. dest.writeString(packet);
  200. // network
  201. dest.writeString(localIP);
  202. dest.writeInt(localPort);
  203. dest.writeString(remoteIP);
  204. dest.writeInt(remotePort);
  205. dest.writeString(externalIP);
  206. dest.writeString(bssid);
  207. dest.writeString(ssid);
  208. // location
  209. dest.writeLong(timestampLocation);
  210. dest.writeDouble(latitude);
  211. dest.writeDouble(longitude);
  212. dest.writeFloat(accuracy);
  213. }
  214. }