Record.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. import java.io.Serializable;
  3. import java.net.InetAddress;
  4. /**
  5. * This class defines the attributes of a record.<br>
  6. * A Record is a single message exchanged between the application and an attacker.<br>
  7. * The class has no own functionality except for getter and setter methods.
  8. * @author Mihai Plasoianu
  9. * @author Lars Pandikow
  10. */
  11. public class Record implements Serializable {
  12. private static final long serialVersionUID = 1L;
  13. public static enum TYPE {
  14. SEND, RECEIVE
  15. };
  16. private int id;
  17. private long attack_id;
  18. private String protocol;
  19. private TYPE type;
  20. private long timestamp;
  21. private InetAddress localIP;
  22. private int localPort;
  23. private InetAddress remoteIP;
  24. private int remotePort;
  25. private String BSSID;
  26. private String SSID;
  27. private String packet;
  28. /**
  29. * @return the id
  30. */
  31. public int getID() {
  32. return id;
  33. }
  34. /**
  35. * @param id
  36. * the id to set
  37. */
  38. public void setID(int id) {
  39. this.id = id;
  40. }
  41. /**
  42. * @return the attack_id
  43. */
  44. public long getAttack_id() {
  45. return attack_id;
  46. }
  47. /**
  48. * @param attack_id
  49. * the attack_id to set
  50. */
  51. public void setAttack_id(long attack_id) {
  52. this.attack_id = attack_id;
  53. }
  54. /**
  55. * @return the protocol
  56. */
  57. public String getProtocol() {
  58. return protocol;
  59. }
  60. /**
  61. * @param string the protocol to set
  62. */
  63. public void setProtocol(String string) {
  64. this.protocol = string;
  65. }
  66. public TYPE getType() {
  67. return type;
  68. }
  69. public void setType(TYPE type) {
  70. this.type = type;
  71. }
  72. public long getTimestamp() {
  73. return timestamp;
  74. }
  75. public void setTimestamp(long timestamp) {
  76. this.timestamp = timestamp;
  77. }
  78. public InetAddress getLocalIP() {
  79. return localIP;
  80. }
  81. public void setLocalIP(InetAddress localIP) {
  82. this.localIP = localIP;
  83. }
  84. public int getLocalPort() {
  85. return localPort;
  86. }
  87. public void setLocalPort(int localPort) {
  88. this.localPort = localPort;
  89. }
  90. public InetAddress getRemoteIP() {
  91. return remoteIP;
  92. }
  93. public void setRemoteIP(InetAddress remoteIP) {
  94. this.remoteIP = remoteIP;
  95. }
  96. public int getRemotePort() {
  97. return remotePort;
  98. }
  99. public void setRemotePort(int remotePort) {
  100. this.remotePort = remotePort;
  101. }
  102. /**
  103. * @return the bSSID
  104. */
  105. public String getBSSID() {
  106. return BSSID;
  107. }
  108. /**
  109. * @param bSSID the bSSID to set
  110. */
  111. public void setBSSID(String bSSID) {
  112. BSSID = bSSID;
  113. }
  114. /**
  115. * @return the sSID
  116. */
  117. public String getSSID() {
  118. return SSID;
  119. }
  120. /**
  121. * @param sSID the sSID to set
  122. */
  123. public void setSSID(String sSID) {
  124. SSID = sSID;
  125. }
  126. public String getPacket() {
  127. return packet;
  128. }
  129. public void setPacket(String packet) {
  130. this.packet = packet;
  131. }
  132. @Override
  133. public String toString() {
  134. return String.format("%d %s [%d,%s:%d,%s:%d,%s]", attack_id,
  135. ((type == TYPE.SEND) ? "SEND" : "RECEIVE"), timestamp,
  136. localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  137. remotePort, packet);
  138. }
  139. /**
  140. * Returns a string representation after a chosen format. Formats should be defined in /res/values/export_formats.xml to use {@link de.tudarmstadt.informatik.hostage.ui.ViewLog#exportDatabase(android.view.View)}
  141. * The Intger representation of the format is equal to its position in the format array.
  142. * @param format Integer representation of the format.
  143. * @return A string representation after chosen format.
  144. */
  145. public String toString(int format){
  146. // Choose String Format
  147. // Add additional case for your own Format. Also add format Name to
  148. switch (format){
  149. case 1:
  150. return String.format("{ \"src\":{\"IP\": %s, \"Port\": %d} \"dst\": {\"IP\": %s, \"Port\": %d} \"type\": 0 \"name\": \"HOsTaGe\" }", localIP.getHostAddress(), localPort, remoteIP.getHostAddress(),
  151. remotePort);
  152. case 2:
  153. return String.format("%d: %s in %s(%s) from [%s:%d] to [%s:%d]", attack_id, protocol, SSID, BSSID, remoteIP.getHostAddress(), remotePort, localIP.getHostAddress(), localPort);
  154. default:
  155. return toString();
  156. }
  157. }
  158. }