Record.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.HoneyService 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 String localHost;
  31. private int localPort;
  32. private String remoteIP;
  33. private String remoteHost;
  34. private int remotePort;
  35. private String externalIP;
  36. private String bssid;
  37. private String ssid;
  38. // location
  39. private long timestampLocation;
  40. private double latitude;
  41. private double longitude;
  42. private float accuracy;
  43. public static final Parcelable.Creator<Record> CREATOR = new Parcelable.Creator<Record>() {
  44. @Override
  45. public Record createFromParcel(Parcel source) {
  46. return new Record(source);
  47. }
  48. @Override
  49. public Record[] newArray(int size) {
  50. return new Record[size];
  51. }
  52. };
  53. public Record() {
  54. }
  55. public Record(Parcel source) {
  56. // attack
  57. this.id = source.readInt();
  58. this.attack_id = source.readLong();
  59. this.timestamp = source.readLong();
  60. this.protocol = source.readString();
  61. this.type = TYPE.valueOf(source.readString());
  62. this.packet = source.readString();
  63. // network
  64. this.localIP = source.readString();
  65. this.localHost = source.readString();
  66. this.localPort = source.readInt();
  67. this.remoteIP = source.readString();
  68. this.remoteHost = source.readString();
  69. this.remotePort = source.readInt();
  70. this.externalIP = source.readString();
  71. this.bssid = source.readString();
  72. this.ssid = source.readString();
  73. // location
  74. this.timestampLocation = source.readLong();
  75. this.latitude = source.readDouble();
  76. this.longitude = source.readDouble();
  77. this.accuracy = source.readFloat();
  78. }
  79. @Override
  80. public int describeContents() {
  81. return 0;
  82. }
  83. public float getAccuracy() {
  84. return accuracy;
  85. }
  86. public long getAttack_id() {
  87. return attack_id;
  88. }
  89. public String getBssid() {
  90. return bssid;
  91. }
  92. public String getExternalIP() {
  93. return externalIP;
  94. }
  95. public int getId() {
  96. return id;
  97. }
  98. public double getLatitude() {
  99. return latitude;
  100. }
  101. public String getLocalHost() {
  102. return localHost;
  103. }
  104. public String getLocalIP() {
  105. return localIP;
  106. }
  107. public int getLocalPort() {
  108. return localPort;
  109. }
  110. public double getLongitude() {
  111. return longitude;
  112. }
  113. public String getPacket() {
  114. return packet;
  115. }
  116. public String getProtocol() {
  117. return protocol;
  118. }
  119. public String getRemoteHost() {
  120. return remoteHost;
  121. }
  122. public String getRemoteIP() {
  123. return remoteIP;
  124. }
  125. public int getRemotePort() {
  126. return remotePort;
  127. }
  128. public String getSsid() {
  129. return ssid;
  130. }
  131. public long getTimestamp() {
  132. return timestamp;
  133. }
  134. public long getTimestampLocation() {
  135. return timestampLocation;
  136. }
  137. public TYPE getType() {
  138. return type;
  139. }
  140. public void setAccuracy(float accuracy) {
  141. this.accuracy = accuracy;
  142. }
  143. public void setAttack_id(long attack_id) {
  144. this.attack_id = attack_id;
  145. }
  146. public void setBssid(String bssid) {
  147. this.bssid = bssid;
  148. }
  149. public void setExternalIP(String externalIP) {
  150. this.externalIP = externalIP;
  151. }
  152. public void setId(int id) {
  153. this.id = id;
  154. }
  155. public void setLatitude(double latitude) {
  156. this.latitude = latitude;
  157. }
  158. public void setLocalHost(String localHost) {
  159. this.localHost = localHost;
  160. }
  161. public void setLocalIP(String localIP) {
  162. this.localIP = localIP;
  163. }
  164. public void setLocalPort(int localPort) {
  165. this.localPort = localPort;
  166. }
  167. public void setLongitude(double longitude) {
  168. this.longitude = longitude;
  169. }
  170. public void setPacket(String packet) {
  171. this.packet = packet;
  172. }
  173. public void setProtocol(String protocol) {
  174. this.protocol = protocol;
  175. }
  176. public void setRemoteHost(String remoteHost) {
  177. this.remoteHost = remoteHost;
  178. }
  179. public void setRemoteIP(String remoteIP) {
  180. this.remoteIP = remoteIP;
  181. }
  182. public void setRemotePort(int remotePort) {
  183. this.remotePort = remotePort;
  184. }
  185. public void setSsid(String ssid) {
  186. this.ssid = ssid;
  187. }
  188. public void setTimestamp(long timestamp) {
  189. this.timestamp = timestamp;
  190. }
  191. public void setTimestampLocation(long timestampLocation) {
  192. this.timestampLocation = timestampLocation;
  193. }
  194. public void setType(TYPE type) {
  195. this.type = type;
  196. }
  197. @Override
  198. public String toString() {
  199. return toString(null);
  200. }
  201. public String toString(Formatter formatter) {
  202. if (null == formatter) {
  203. return Formatter.getDefault().format(this);
  204. }
  205. return formatter.format(this);
  206. }
  207. @Override
  208. public void writeToParcel(Parcel dest, int flags) {
  209. // attack
  210. dest.writeInt(id);
  211. dest.writeLong(attack_id);
  212. dest.writeLong(timestamp);
  213. dest.writeString(protocol);
  214. dest.writeString(type.name());
  215. dest.writeString(packet);
  216. // network
  217. dest.writeString(localIP);
  218. dest.writeString(localHost);
  219. dest.writeInt(localPort);
  220. dest.writeString(remoteIP);
  221. dest.writeString(remoteHost);
  222. dest.writeInt(remotePort);
  223. dest.writeString(externalIP);
  224. dest.writeString(bssid);
  225. dest.writeString(ssid);
  226. // location
  227. dest.writeLong(timestampLocation);
  228. dest.writeDouble(latitude);
  229. dest.writeDouble(longitude);
  230. dest.writeFloat(accuracy);
  231. }
  232. }