From: rtrimana Date: Wed, 25 Apr 2018 00:49:45 +0000 (-0700) Subject: Adding the Kaitai library to parse PCAP files. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=pingpong.git;a=commitdiff_plain;h=84446f11cd7c1a809b5d1a9b3d720f465aa344ad Adding the Kaitai library to parse PCAP files. --- diff --git a/Code/Projects/SmartPlugDetector/build.gradle b/Code/Projects/SmartPlugDetector/build.gradle index 29b73eb..b0d01fc 100644 --- a/Code/Projects/SmartPlugDetector/build.gradle +++ b/Code/Projects/SmartPlugDetector/build.gradle @@ -14,4 +14,5 @@ repositories { dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' + compile group: 'io.kaitai', name: 'kaitai-struct-runtime', version: '0.8' } diff --git a/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap b/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap new file mode 100644 index 0000000..8c945a0 Binary files /dev/null and b/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap differ diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/EthernetFrame.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/EthernetFrame.java new file mode 100644 index 0000000..7c380ce --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/EthernetFrame.java @@ -0,0 +1,88 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; +import java.util.Map; +import java.util.HashMap; + +public class EthernetFrame extends KaitaiStruct { + public static EthernetFrame fromFile(String fileName) throws IOException { + return new EthernetFrame(new ByteBufferKaitaiStream(fileName)); + } + + public enum EtherTypeEnum { + IPV4(2048), + X_75_INTERNET(2049), + NBS_INTERNET(2050), + ECMA_INTERNET(2051), + CHAOSNET(2052), + X_25_LEVEL_3(2053), + ARP(2054), + IPV6(34525); + + private final long id; + EtherTypeEnum(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(8); + static { + for (EtherTypeEnum e : EtherTypeEnum.values()) + byId.put(e.id(), e); + } + public static EtherTypeEnum byId(long id) { return byId.get(id); } + } + + public EthernetFrame(KaitaiStream _io) { + this(_io, null, null); + } + + public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent, EthernetFrame _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.dstMac = this._io.readBytes(6); + this.srcMac = this._io.readBytes(6); + this.etherType = EtherTypeEnum.byId(this._io.readU2be()); + switch (etherType()) { + case IPV4: { + this._raw_body = this._io.readBytesFull(); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new Ipv4Packet(_io__raw_body); + break; + } + case IPV6: { + this._raw_body = this._io.readBytesFull(); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new Ipv6Packet(_io__raw_body); + break; + } + default: { + this.body = this._io.readBytesFull(); + break; + } + } + } + private byte[] dstMac; + private byte[] srcMac; + private EtherTypeEnum etherType; + private Object body; + private EthernetFrame _root; + private KaitaiStruct _parent; + private byte[] _raw_body; + public byte[] dstMac() { return dstMac; } + public byte[] srcMac() { return srcMac; } + public EtherTypeEnum etherType() { return etherType; } + public Object body() { return body; } + public EthernetFrame _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } + public byte[] _raw_body() { return _raw_body; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/IcmpPacket.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/IcmpPacket.java new file mode 100644 index 0000000..0c9a899 --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/IcmpPacket.java @@ -0,0 +1,222 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; +import java.util.Map; +import java.util.HashMap; + +public class IcmpPacket extends KaitaiStruct { + public static IcmpPacket fromFile(String fileName) throws IOException { + return new IcmpPacket(new ByteBufferKaitaiStream(fileName)); + } + + public enum IcmpTypeEnum { + ECHO_REPLY(0), + DESTINATION_UNREACHABLE(3), + SOURCE_QUENCH(4), + REDIRECT(5), + ECHO(8), + TIME_EXCEEDED(11); + + private final long id; + IcmpTypeEnum(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(6); + static { + for (IcmpTypeEnum e : IcmpTypeEnum.values()) + byId.put(e.id(), e); + } + public static IcmpTypeEnum byId(long id) { return byId.get(id); } + } + + public IcmpPacket(KaitaiStream _io) { + this(_io, null, null); + } + + public IcmpPacket(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public IcmpPacket(KaitaiStream _io, KaitaiStruct _parent, IcmpPacket _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.icmpType = IcmpTypeEnum.byId(this._io.readU1()); + if (icmpType() == IcmpTypeEnum.DESTINATION_UNREACHABLE) { + this.destinationUnreachable = new DestinationUnreachableMsg(this._io, this, _root); + } + if (icmpType() == IcmpTypeEnum.TIME_EXCEEDED) { + this.timeExceeded = new TimeExceededMsg(this._io, this, _root); + } + if ( ((icmpType() == IcmpTypeEnum.ECHO) || (icmpType() == IcmpTypeEnum.ECHO_REPLY)) ) { + this.echo = new EchoMsg(this._io, this, _root); + } + } + public static class DestinationUnreachableMsg extends KaitaiStruct { + public static DestinationUnreachableMsg fromFile(String fileName) throws IOException { + return new DestinationUnreachableMsg(new ByteBufferKaitaiStream(fileName)); + } + + public enum DestinationUnreachableCode { + NET_UNREACHABLE(0), + HOST_UNREACHABLE(1), + PROTOCOL_UNREACHABLE(2), + PORT_UNREACHABLE(3), + FRAGMENTATION_NEEDED_AND_DF_SET(4), + SOURCE_ROUTE_FAILED(5), + DST_NET_UNKOWN(6), + SDT_HOST_UNKOWN(7), + SRC_ISOLATED(8), + NET_PROHIBITED_BY_ADMIN(9), + HOST_PROHIBITED_BY_ADMIN(10), + NET_UNREACHABLE_FOR_TOS(11), + HOST_UNREACHABLE_FOR_TOS(12), + COMMUNICATION_PROHIBITED_BY_ADMIN(13), + HOST_PRECEDENCE_VIOLATION(14), + PRECEDENCE_CUTTOFF_IN_EFFECT(15); + + private final long id; + DestinationUnreachableCode(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(16); + static { + for (DestinationUnreachableCode e : DestinationUnreachableCode.values()) + byId.put(e.id(), e); + } + public static DestinationUnreachableCode byId(long id) { return byId.get(id); } + } + + public DestinationUnreachableMsg(KaitaiStream _io) { + this(_io, null, null); + } + + public DestinationUnreachableMsg(KaitaiStream _io, IcmpPacket _parent) { + this(_io, _parent, null); + } + + public DestinationUnreachableMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.code = DestinationUnreachableCode.byId(this._io.readU1()); + this.checksum = this._io.readU2be(); + } + private DestinationUnreachableCode code; + private int checksum; + private IcmpPacket _root; + private IcmpPacket _parent; + public DestinationUnreachableCode code() { return code; } + public int checksum() { return checksum; } + public IcmpPacket _root() { return _root; } + public IcmpPacket _parent() { return _parent; } + } + public static class TimeExceededMsg extends KaitaiStruct { + public static TimeExceededMsg fromFile(String fileName) throws IOException { + return new TimeExceededMsg(new ByteBufferKaitaiStream(fileName)); + } + + public enum TimeExceededCode { + TIME_TO_LIVE_EXCEEDED_IN_TRANSIT(0), + FRAGMENT_REASSEMBLY_TIME_EXCEEDED(1); + + private final long id; + TimeExceededCode(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(2); + static { + for (TimeExceededCode e : TimeExceededCode.values()) + byId.put(e.id(), e); + } + public static TimeExceededCode byId(long id) { return byId.get(id); } + } + + public TimeExceededMsg(KaitaiStream _io) { + this(_io, null, null); + } + + public TimeExceededMsg(KaitaiStream _io, IcmpPacket _parent) { + this(_io, _parent, null); + } + + public TimeExceededMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.code = TimeExceededCode.byId(this._io.readU1()); + this.checksum = this._io.readU2be(); + } + private TimeExceededCode code; + private int checksum; + private IcmpPacket _root; + private IcmpPacket _parent; + public TimeExceededCode code() { return code; } + public int checksum() { return checksum; } + public IcmpPacket _root() { return _root; } + public IcmpPacket _parent() { return _parent; } + } + public static class EchoMsg extends KaitaiStruct { + public static EchoMsg fromFile(String fileName) throws IOException { + return new EchoMsg(new ByteBufferKaitaiStream(fileName)); + } + + public EchoMsg(KaitaiStream _io) { + this(_io, null, null); + } + + public EchoMsg(KaitaiStream _io, IcmpPacket _parent) { + this(_io, _parent, null); + } + + public EchoMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.code = this._io.ensureFixedContents(new byte[] { 0 }); + this.checksum = this._io.readU2be(); + this.identifier = this._io.readU2be(); + this.seqNum = this._io.readU2be(); + this.data = this._io.readBytesFull(); + } + private byte[] code; + private int checksum; + private int identifier; + private int seqNum; + private byte[] data; + private IcmpPacket _root; + private IcmpPacket _parent; + public byte[] code() { return code; } + public int checksum() { return checksum; } + public int identifier() { return identifier; } + public int seqNum() { return seqNum; } + public byte[] data() { return data; } + public IcmpPacket _root() { return _root; } + public IcmpPacket _parent() { return _parent; } + } + private IcmpTypeEnum icmpType; + private DestinationUnreachableMsg destinationUnreachable; + private TimeExceededMsg timeExceeded; + private EchoMsg echo; + private IcmpPacket _root; + private KaitaiStruct _parent; + public IcmpTypeEnum icmpType() { return icmpType; } + public DestinationUnreachableMsg destinationUnreachable() { return destinationUnreachable; } + public TimeExceededMsg timeExceeded() { return timeExceeded; } + public EchoMsg echo() { return echo; } + public IcmpPacket _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Ipv4Packet.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Ipv4Packet.java new file mode 100644 index 0000000..b1ff070 --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Ipv4Packet.java @@ -0,0 +1,384 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + +public class Ipv4Packet extends KaitaiStruct { + public static Ipv4Packet fromFile(String fileName) throws IOException { + return new Ipv4Packet(new ByteBufferKaitaiStream(fileName)); + } + + public enum ProtocolEnum { + HOPOPT(0), + ICMP(1), + IGMP(2), + GGP(3), + IPV4(4), + ST(5), + TCP(6), + CBT(7), + EGP(8), + IGP(9), + BBN_RCC_MON(10), + NVP_II(11), + PUP(12), + ARGUS(13), + EMCON(14), + XNET(15), + CHAOS(16), + UDP(17), + MUX(18), + DCN_MEAS(19), + HMP(20), + PRM(21), + XNS_IDP(22), + TRUNK_1(23), + TRUNK_2(24), + LEAF_1(25), + LEAF_2(26), + RDP(27), + IRTP(28), + ISO_TP4(29), + NETBLT(30), + MFE_NSP(31), + MERIT_INP(32), + DCCP(33), + X_3PC(34), + IDPR(35), + XTP(36), + DDP(37), + IDPR_CMTP(38), + TP_PLUS_PLUS(39), + IL(40), + IPV6(41), + SDRP(42), + IPV6_ROUTE(43), + IPV6_FRAG(44), + IDRP(45), + RSVP(46), + GRE(47), + DSR(48), + BNA(49), + ESP(50), + AH(51), + I_NLSP(52), + SWIPE(53), + NARP(54), + MOBILE(55), + TLSP(56), + SKIP(57), + IPV6_ICMP(58), + IPV6_NONXT(59), + IPV6_OPTS(60), + ANY_HOST_INTERNAL_PROTOCOL(61), + CFTP(62), + ANY_LOCAL_NETWORK(63), + SAT_EXPAK(64), + KRYPTOLAN(65), + RVD(66), + IPPC(67), + ANY_DISTRIBUTED_FILE_SYSTEM(68), + SAT_MON(69), + VISA(70), + IPCV(71), + CPNX(72), + CPHB(73), + WSN(74), + PVP(75), + BR_SAT_MON(76), + SUN_ND(77), + WB_MON(78), + WB_EXPAK(79), + ISO_IP(80), + VMTP(81), + SECURE_VMTP(82), + VINES(83), + IPTM(84), + NSFNET_IGP(85), + DGP(86), + TCF(87), + EIGRP(88), + OSPFIGP(89), + SPRITE_RPC(90), + LARP(91), + MTP(92), + AX_25(93), + IPIP(94), + MICP(95), + SCC_SP(96), + ETHERIP(97), + ENCAP(98), + ANY_PRIVATE_ENCRYPTION_SCHEME(99), + GMTP(100), + IFMP(101), + PNNI(102), + PIM(103), + ARIS(104), + SCPS(105), + QNX(106), + A_N(107), + IPCOMP(108), + SNP(109), + COMPAQ_PEER(110), + IPX_IN_IP(111), + VRRP(112), + PGM(113), + ANY_0_HOP(114), + L2TP(115), + DDX(116), + IATP(117), + STP(118), + SRP(119), + UTI(120), + SMP(121), + SM(122), + PTP(123), + ISIS_OVER_IPV4(124), + FIRE(125), + CRTP(126), + CRUDP(127), + SSCOPMCE(128), + IPLT(129), + SPS(130), + PIPE(131), + SCTP(132), + FC(133), + RSVP_E2E_IGNORE(134), + MOBILITY_HEADER(135), + UDPLITE(136), + MPLS_IN_IP(137), + MANET(138), + HIP(139), + SHIM6(140), + WESP(141), + ROHC(142), + RESERVED_255(255); + + private final long id; + ProtocolEnum(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(144); + static { + for (ProtocolEnum e : ProtocolEnum.values()) + byId.put(e.id(), e); + } + public static ProtocolEnum byId(long id) { return byId.get(id); } + } + + public Ipv4Packet(KaitaiStream _io) { + this(_io, null, null); + } + + public Ipv4Packet(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public Ipv4Packet(KaitaiStream _io, KaitaiStruct _parent, Ipv4Packet _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.b1 = this._io.readU1(); + this.b2 = this._io.readU1(); + this.totalLength = this._io.readU2be(); + this.identification = this._io.readU2be(); + this.b67 = this._io.readU2be(); + this.ttl = this._io.readU1(); + this.protocol = ProtocolEnum.byId(this._io.readU1()); + this.headerChecksum = this._io.readU2be(); + this.srcIpAddr = this._io.readBytes(4); + this.dstIpAddr = this._io.readBytes(4); + this._raw_options = this._io.readBytes((ihlBytes() - 20)); + KaitaiStream _io__raw_options = new ByteBufferKaitaiStream(_raw_options); + this.options = new Ipv4Options(_io__raw_options, this, _root); + switch (protocol()) { + case TCP: { + this._raw_body = this._io.readBytes((totalLength() - ihlBytes())); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new TcpSegment(_io__raw_body); + break; + } + case ICMP: { + this._raw_body = this._io.readBytes((totalLength() - ihlBytes())); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new IcmpPacket(_io__raw_body); + break; + } + case UDP: { + this._raw_body = this._io.readBytes((totalLength() - ihlBytes())); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new UdpDatagram(_io__raw_body); + break; + } + case IPV6: { + this._raw_body = this._io.readBytes((totalLength() - ihlBytes())); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new Ipv6Packet(_io__raw_body); + break; + } + default: { + this.body = this._io.readBytes((totalLength() - ihlBytes())); + break; + } + } + } + public static class Ipv4Options extends KaitaiStruct { + public static Ipv4Options fromFile(String fileName) throws IOException { + return new Ipv4Options(new ByteBufferKaitaiStream(fileName)); + } + + public Ipv4Options(KaitaiStream _io) { + this(_io, null, null); + } + + public Ipv4Options(KaitaiStream _io, Ipv4Packet _parent) { + this(_io, _parent, null); + } + + public Ipv4Options(KaitaiStream _io, Ipv4Packet _parent, Ipv4Packet _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.entries = new ArrayList(); + { + int i = 0; + while (!this._io.isEof()) { + this.entries.add(new Ipv4Option(this._io, this, _root)); + i++; + } + } + } + private ArrayList entries; + private Ipv4Packet _root; + private Ipv4Packet _parent; + public ArrayList entries() { return entries; } + public Ipv4Packet _root() { return _root; } + public Ipv4Packet _parent() { return _parent; } + } + public static class Ipv4Option extends KaitaiStruct { + public static Ipv4Option fromFile(String fileName) throws IOException { + return new Ipv4Option(new ByteBufferKaitaiStream(fileName)); + } + + public Ipv4Option(KaitaiStream _io) { + this(_io, null, null); + } + + public Ipv4Option(KaitaiStream _io, Ipv4Packet.Ipv4Options _parent) { + this(_io, _parent, null); + } + + public Ipv4Option(KaitaiStream _io, Ipv4Packet.Ipv4Options _parent, Ipv4Packet _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.b1 = this._io.readU1(); + this.len = this._io.readU1(); + this.body = this._io.readBytes((len() > 2 ? (len() - 2) : 0)); + } + private Integer copy; + public Integer copy() { + if (this.copy != null) + return this.copy; + int _tmp = (int) (((b1() & 128) >> 7)); + this.copy = _tmp; + return this.copy; + } + private Integer optClass; + public Integer optClass() { + if (this.optClass != null) + return this.optClass; + int _tmp = (int) (((b1() & 96) >> 5)); + this.optClass = _tmp; + return this.optClass; + } + private Integer number; + public Integer number() { + if (this.number != null) + return this.number; + int _tmp = (int) ((b1() & 31)); + this.number = _tmp; + return this.number; + } + private int b1; + private int len; + private byte[] body; + private Ipv4Packet _root; + private Ipv4Packet.Ipv4Options _parent; + public int b1() { return b1; } + public int len() { return len; } + public byte[] body() { return body; } + public Ipv4Packet _root() { return _root; } + public Ipv4Packet.Ipv4Options _parent() { return _parent; } + } + private Integer version; + public Integer version() { + if (this.version != null) + return this.version; + int _tmp = (int) (((b1() & 240) >> 4)); + this.version = _tmp; + return this.version; + } + private Integer ihl; + public Integer ihl() { + if (this.ihl != null) + return this.ihl; + int _tmp = (int) ((b1() & 15)); + this.ihl = _tmp; + return this.ihl; + } + private Integer ihlBytes; + public Integer ihlBytes() { + if (this.ihlBytes != null) + return this.ihlBytes; + int _tmp = (int) ((ihl() * 4)); + this.ihlBytes = _tmp; + return this.ihlBytes; + } + private int b1; + private int b2; + private int totalLength; + private int identification; + private int b67; + private int ttl; + private ProtocolEnum protocol; + private int headerChecksum; + private byte[] srcIpAddr; + private byte[] dstIpAddr; + private Ipv4Options options; + private Object body; + private Ipv4Packet _root; + private KaitaiStruct _parent; + private byte[] _raw_options; + private byte[] _raw_body; + public int b1() { return b1; } + public int b2() { return b2; } + public int totalLength() { return totalLength; } + public int identification() { return identification; } + public int b67() { return b67; } + public int ttl() { return ttl; } + public ProtocolEnum protocol() { return protocol; } + public int headerChecksum() { return headerChecksum; } + public byte[] srcIpAddr() { return srcIpAddr; } + public byte[] dstIpAddr() { return dstIpAddr; } + public Ipv4Options options() { return options; } + public Object body() { return body; } + public Ipv4Packet _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } + public byte[] _raw_options() { return _raw_options; } + public byte[] _raw_body() { return _raw_body; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Ipv6Packet.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Ipv6Packet.java new file mode 100644 index 0000000..469ed8b --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Ipv6Packet.java @@ -0,0 +1,163 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; + +public class Ipv6Packet extends KaitaiStruct { + public static Ipv6Packet fromFile(String fileName) throws IOException { + return new Ipv6Packet(new ByteBufferKaitaiStream(fileName)); + } + + public Ipv6Packet(KaitaiStream _io) { + this(_io, null, null); + } + + public Ipv6Packet(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public Ipv6Packet(KaitaiStream _io, KaitaiStruct _parent, Ipv6Packet _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.version = this._io.readBitsInt(4); + this.trafficClass = this._io.readBitsInt(8); + this.flowLabel = this._io.readBitsInt(20); + this._io.alignToByte(); + this.payloadLength = this._io.readU2be(); + this.nextHeaderType = this._io.readU1(); + this.hopLimit = this._io.readU1(); + this.srcIpv6Addr = this._io.readBytes(16); + this.dstIpv6Addr = this._io.readBytes(16); + switch (nextHeaderType()) { + case 17: { + this.nextHeader = new UdpDatagram(this._io); + break; + } + case 0: { + this.nextHeader = new OptionHopByHop(this._io, this, _root); + break; + } + case 4: { + this.nextHeader = new Ipv4Packet(this._io); + break; + } + case 6: { + this.nextHeader = new TcpSegment(this._io); + break; + } + case 59: { + this.nextHeader = new NoNextHeader(this._io, this, _root); + break; + } + } + this.rest = this._io.readBytesFull(); + } + public static class NoNextHeader extends KaitaiStruct { + public static NoNextHeader fromFile(String fileName) throws IOException { + return new NoNextHeader(new ByteBufferKaitaiStream(fileName)); + } + + public NoNextHeader(KaitaiStream _io) { + this(_io, null, null); + } + + public NoNextHeader(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public NoNextHeader(KaitaiStream _io, KaitaiStruct _parent, Ipv6Packet _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + } + private Ipv6Packet _root; + private KaitaiStruct _parent; + public Ipv6Packet _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } + } + public static class OptionHopByHop extends KaitaiStruct { + public static OptionHopByHop fromFile(String fileName) throws IOException { + return new OptionHopByHop(new ByteBufferKaitaiStream(fileName)); + } + + public OptionHopByHop(KaitaiStream _io) { + this(_io, null, null); + } + + public OptionHopByHop(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public OptionHopByHop(KaitaiStream _io, KaitaiStruct _parent, Ipv6Packet _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.nextHeaderType = this._io.readU1(); + this.hdrExtLen = this._io.readU1(); + this.body = this._io.readBytes((hdrExtLen() - 1)); + switch (nextHeaderType()) { + case 0: { + this.nextHeader = new OptionHopByHop(this._io, this, _root); + break; + } + case 6: { + this.nextHeader = new TcpSegment(this._io); + break; + } + case 59: { + this.nextHeader = new NoNextHeader(this._io, this, _root); + break; + } + } + } + private int nextHeaderType; + private int hdrExtLen; + private byte[] body; + private KaitaiStruct nextHeader; + private Ipv6Packet _root; + private KaitaiStruct _parent; + public int nextHeaderType() { return nextHeaderType; } + public int hdrExtLen() { return hdrExtLen; } + public byte[] body() { return body; } + public KaitaiStruct nextHeader() { return nextHeader; } + public Ipv6Packet _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } + } + private long version; + private long trafficClass; + private long flowLabel; + private int payloadLength; + private int nextHeaderType; + private int hopLimit; + private byte[] srcIpv6Addr; + private byte[] dstIpv6Addr; + private KaitaiStruct nextHeader; + private byte[] rest; + private Ipv6Packet _root; + private KaitaiStruct _parent; + public long version() { return version; } + public long trafficClass() { return trafficClass; } + public long flowLabel() { return flowLabel; } + public int payloadLength() { return payloadLength; } + public int nextHeaderType() { return nextHeaderType; } + public int hopLimit() { return hopLimit; } + public byte[] srcIpv6Addr() { return srcIpv6Addr; } + public byte[] dstIpv6Addr() { return dstIpv6Addr; } + public KaitaiStruct nextHeader() { return nextHeader; } + public byte[] rest() { return rest; } + public Ipv6Packet _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java index 903839d..c66d94e 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java @@ -7,8 +7,15 @@ package edu.uci.iotproject; */ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws Exception { System.out.println("it works"); + String file = "/home/rtrimana/pcap_processing/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap"; + + try { + Pcap data = Pcap.fromFile(file); + //data.hdr(); + } catch (Exception e) { + e.printStackTrace(); + } } - } diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PacketPpi.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PacketPpi.java new file mode 100644 index 0000000..9704da5 --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PacketPpi.java @@ -0,0 +1,777 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + + +/** + * PPI is a standard for link layer packet encapsulation, proposed as + * generic extensible container to store both captured in-band data and + * out-of-band data. Originally it was developed to provide 802.11n + * radio information, but can be used for other purposes as well. + * + * Sample capture: https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&target=Http.cap + * @see PPI header format spec, section 3 + */ +public class PacketPpi extends KaitaiStruct { + public static PacketPpi fromFile(String fileName) throws IOException { + return new PacketPpi(new ByteBufferKaitaiStream(fileName)); + } + + public enum PfhType { + RADIO_802_11_COMMON(2), + RADIO_802_11N_MAC_EXT(3), + RADIO_802_11N_MAC_PHY_EXT(4), + SPECTRUM_MAP(5), + PROCESS_INFO(6), + CAPTURE_INFO(7); + + private final long id; + PfhType(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(6); + static { + for (PfhType e : PfhType.values()) + byId.put(e.id(), e); + } + public static PfhType byId(long id) { return byId.get(id); } + } + + public enum Linktype { + NULL_LINKTYPE(0), + ETHERNET(1), + AX25(3), + IEEE802_5(6), + ARCNET_BSD(7), + SLIP(8), + PPP(9), + FDDI(10), + PPP_HDLC(50), + PPP_ETHER(51), + ATM_RFC1483(100), + RAW(101), + C_HDLC(104), + IEEE802_11(105), + FRELAY(107), + LOOP(108), + LINUX_SLL(113), + LTALK(114), + PFLOG(117), + IEEE802_11_PRISM(119), + IP_OVER_FC(122), + SUNATM(123), + IEEE802_11_RADIOTAP(127), + ARCNET_LINUX(129), + APPLE_IP_OVER_IEEE1394(138), + MTP2_WITH_PHDR(139), + MTP2(140), + MTP3(141), + SCCP(142), + DOCSIS(143), + LINUX_IRDA(144), + USER0(147), + USER1(148), + USER2(149), + USER3(150), + USER4(151), + USER5(152), + USER6(153), + USER7(154), + USER8(155), + USER9(156), + USER10(157), + USER11(158), + USER12(159), + USER13(160), + USER14(161), + USER15(162), + IEEE802_11_AVS(163), + BACNET_MS_TP(165), + PPP_PPPD(166), + GPRS_LLC(169), + GPF_T(170), + GPF_F(171), + LINUX_LAPD(177), + BLUETOOTH_HCI_H4(187), + USB_LINUX(189), + PPI(192), + IEEE802_15_4(195), + SITA(196), + ERF(197), + BLUETOOTH_HCI_H4_WITH_PHDR(201), + AX25_KISS(202), + LAPD(203), + PPP_WITH_DIR(204), + C_HDLC_WITH_DIR(205), + FRELAY_WITH_DIR(206), + IPMB_LINUX(209), + IEEE802_15_4_NONASK_PHY(215), + USB_LINUX_MMAPPED(220), + FC_2(224), + FC_2_WITH_FRAME_DELIMS(225), + IPNET(226), + CAN_SOCKETCAN(227), + IPV4(228), + IPV6(229), + IEEE802_15_4_NOFCS(230), + DBUS(231), + DVB_CI(235), + MUX27010(236), + STANAG_5066_D_PDU(237), + NFLOG(239), + NETANALYZER(240), + NETANALYZER_TRANSPARENT(241), + IPOIB(242), + MPEG_2_TS(243), + NG40(244), + NFC_LLCP(245), + INFINIBAND(247), + SCTP(248), + USBPCAP(249), + RTAC_SERIAL(250), + BLUETOOTH_LE_LL(251), + NETLINK(253), + BLUETOOTH_LINUX_MONITOR(254), + BLUETOOTH_BREDR_BB(255), + BLUETOOTH_LE_LL_WITH_PHDR(256), + PROFIBUS_DL(257), + PKTAP(258), + EPON(259), + IPMI_HPM_2(260), + ZWAVE_R1_R2(261), + ZWAVE_R3(262), + WATTSTOPPER_DLM(263), + ISO_14443(264); + + private final long id; + Linktype(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(104); + static { + for (Linktype e : Linktype.values()) + byId.put(e.id(), e); + } + public static Linktype byId(long id) { return byId.get(id); } + } + + public PacketPpi(KaitaiStream _io) { + this(_io, null, null); + } + + public PacketPpi(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public PacketPpi(KaitaiStream _io, KaitaiStruct _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.header = new PacketPpiHeader(this._io, this, _root); + this._raw_fields = this._io.readBytes((header().pphLen() - 8)); + KaitaiStream _io__raw_fields = new ByteBufferKaitaiStream(_raw_fields); + this.fields = new PacketPpiFields(_io__raw_fields, this, _root); + switch (header().pphDlt()) { + case PPI: { + this._raw_body = this._io.readBytesFull(); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new PacketPpi(_io__raw_body); + break; + } + case ETHERNET: { + this._raw_body = this._io.readBytesFull(); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new EthernetFrame(_io__raw_body); + break; + } + default: { + this.body = this._io.readBytesFull(); + break; + } + } + } + public static class PacketPpiFields extends KaitaiStruct { + public static PacketPpiFields fromFile(String fileName) throws IOException { + return new PacketPpiFields(new ByteBufferKaitaiStream(fileName)); + } + + public PacketPpiFields(KaitaiStream _io) { + this(_io, null, null); + } + + public PacketPpiFields(KaitaiStream _io, PacketPpi _parent) { + this(_io, _parent, null); + } + + public PacketPpiFields(KaitaiStream _io, PacketPpi _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.entries = new ArrayList(); + { + int i = 0; + while (!this._io.isEof()) { + this.entries.add(new PacketPpiField(this._io, this, _root)); + i++; + } + } + } + private ArrayList entries; + private PacketPpi _root; + private PacketPpi _parent; + public ArrayList entries() { return entries; } + public PacketPpi _root() { return _root; } + public PacketPpi _parent() { return _parent; } + } + + /** + * @see PPI header format spec, section 4.1.3 + */ + public static class Radio80211nMacExtBody extends KaitaiStruct { + public static Radio80211nMacExtBody fromFile(String fileName) throws IOException { + return new Radio80211nMacExtBody(new ByteBufferKaitaiStream(fileName)); + } + + public Radio80211nMacExtBody(KaitaiStream _io) { + this(_io, null, null); + } + + public Radio80211nMacExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent) { + this(_io, _parent, null); + } + + public Radio80211nMacExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.flags = new MacFlags(this._io, this, _root); + this.aMpduId = this._io.readU4le(); + this.numDelimiters = this._io.readU1(); + this.reserved = this._io.readBytes(3); + } + private MacFlags flags; + private long aMpduId; + private int numDelimiters; + private byte[] reserved; + private PacketPpi _root; + private PacketPpi.PacketPpiField _parent; + public MacFlags flags() { return flags; } + public long aMpduId() { return aMpduId; } + public int numDelimiters() { return numDelimiters; } + public byte[] reserved() { return reserved; } + public PacketPpi _root() { return _root; } + public PacketPpi.PacketPpiField _parent() { return _parent; } + } + public static class MacFlags extends KaitaiStruct { + public static MacFlags fromFile(String fileName) throws IOException { + return new MacFlags(new ByteBufferKaitaiStream(fileName)); + } + + public MacFlags(KaitaiStream _io) { + this(_io, null, null); + } + + public MacFlags(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public MacFlags(KaitaiStream _io, KaitaiStruct _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.unused1 = this._io.readBitsInt(1) != 0; + this.aggregateDelimiter = this._io.readBitsInt(1) != 0; + this.moreAggregates = this._io.readBitsInt(1) != 0; + this.aggregate = this._io.readBitsInt(1) != 0; + this.dupRx = this._io.readBitsInt(1) != 0; + this.rxShortGuard = this._io.readBitsInt(1) != 0; + this.isHt40 = this._io.readBitsInt(1) != 0; + this.greenfield = this._io.readBitsInt(1) != 0; + this._io.alignToByte(); + this.unused2 = this._io.readBytes(3); + } + private boolean unused1; + private boolean aggregateDelimiter; + private boolean moreAggregates; + private boolean aggregate; + private boolean dupRx; + private boolean rxShortGuard; + private boolean isHt40; + private boolean greenfield; + private byte[] unused2; + private PacketPpi _root; + private KaitaiStruct _parent; + public boolean unused1() { return unused1; } + + /** + * Aggregate delimiter CRC error after this frame + */ + public boolean aggregateDelimiter() { return aggregateDelimiter; } + + /** + * More aggregates + */ + public boolean moreAggregates() { return moreAggregates; } + + /** + * Aggregate + */ + public boolean aggregate() { return aggregate; } + + /** + * Duplicate RX + */ + public boolean dupRx() { return dupRx; } + + /** + * RX short guard interval (SGI) + */ + public boolean rxShortGuard() { return rxShortGuard; } + + /** + * true = HT40, false = HT20 + */ + public boolean isHt40() { return isHt40; } + + /** + * Greenfield + */ + public boolean greenfield() { return greenfield; } + public byte[] unused2() { return unused2; } + public PacketPpi _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } + } + + /** + * @see PPI header format spec, section 3.1 + */ + public static class PacketPpiHeader extends KaitaiStruct { + public static PacketPpiHeader fromFile(String fileName) throws IOException { + return new PacketPpiHeader(new ByteBufferKaitaiStream(fileName)); + } + + public PacketPpiHeader(KaitaiStream _io) { + this(_io, null, null); + } + + public PacketPpiHeader(KaitaiStream _io, PacketPpi _parent) { + this(_io, _parent, null); + } + + public PacketPpiHeader(KaitaiStream _io, PacketPpi _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.pphVersion = this._io.readU1(); + this.pphFlags = this._io.readU1(); + this.pphLen = this._io.readU2le(); + this.pphDlt = PacketPpi.Linktype.byId(this._io.readU4le()); + } + private int pphVersion; + private int pphFlags; + private int pphLen; + private Linktype pphDlt; + private PacketPpi _root; + private PacketPpi _parent; + public int pphVersion() { return pphVersion; } + public int pphFlags() { return pphFlags; } + public int pphLen() { return pphLen; } + public Linktype pphDlt() { return pphDlt; } + public PacketPpi _root() { return _root; } + public PacketPpi _parent() { return _parent; } + } + + /** + * @see PPI header format spec, section 4.1.2 + */ + public static class Radio80211CommonBody extends KaitaiStruct { + public static Radio80211CommonBody fromFile(String fileName) throws IOException { + return new Radio80211CommonBody(new ByteBufferKaitaiStream(fileName)); + } + + public Radio80211CommonBody(KaitaiStream _io) { + this(_io, null, null); + } + + public Radio80211CommonBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent) { + this(_io, _parent, null); + } + + public Radio80211CommonBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.tsfTimer = this._io.readU8le(); + this.flags = this._io.readU2le(); + this.rate = this._io.readU2le(); + this.channelFreq = this._io.readU2le(); + this.channelFlags = this._io.readU2le(); + this.fhssHopset = this._io.readU1(); + this.fhssPattern = this._io.readU1(); + this.dbmAntsignal = this._io.readS1(); + this.dbmAntnoise = this._io.readS1(); + } + private long tsfTimer; + private int flags; + private int rate; + private int channelFreq; + private int channelFlags; + private int fhssHopset; + private int fhssPattern; + private byte dbmAntsignal; + private byte dbmAntnoise; + private PacketPpi _root; + private PacketPpi.PacketPpiField _parent; + public long tsfTimer() { return tsfTimer; } + public int flags() { return flags; } + public int rate() { return rate; } + public int channelFreq() { return channelFreq; } + public int channelFlags() { return channelFlags; } + public int fhssHopset() { return fhssHopset; } + public int fhssPattern() { return fhssPattern; } + public byte dbmAntsignal() { return dbmAntsignal; } + public byte dbmAntnoise() { return dbmAntnoise; } + public PacketPpi _root() { return _root; } + public PacketPpi.PacketPpiField _parent() { return _parent; } + } + + /** + * @see PPI header format spec, section 3.1 + */ + public static class PacketPpiField extends KaitaiStruct { + public static PacketPpiField fromFile(String fileName) throws IOException { + return new PacketPpiField(new ByteBufferKaitaiStream(fileName)); + } + + public PacketPpiField(KaitaiStream _io) { + this(_io, null, null); + } + + public PacketPpiField(KaitaiStream _io, PacketPpi.PacketPpiFields _parent) { + this(_io, _parent, null); + } + + public PacketPpiField(KaitaiStream _io, PacketPpi.PacketPpiFields _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.pfhType = PacketPpi.PfhType.byId(this._io.readU2le()); + this.pfhDatalen = this._io.readU2le(); + switch (pfhType()) { + case RADIO_802_11_COMMON: { + this._raw_body = this._io.readBytes(pfhDatalen()); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new Radio80211CommonBody(_io__raw_body, this, _root); + break; + } + case RADIO_802_11N_MAC_EXT: { + this._raw_body = this._io.readBytes(pfhDatalen()); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new Radio80211nMacExtBody(_io__raw_body, this, _root); + break; + } + case RADIO_802_11N_MAC_PHY_EXT: { + this._raw_body = this._io.readBytes(pfhDatalen()); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new Radio80211nMacPhyExtBody(_io__raw_body, this, _root); + break; + } + default: { + this.body = this._io.readBytes(pfhDatalen()); + break; + } + } + } + private PfhType pfhType; + private int pfhDatalen; + private Object body; + private PacketPpi _root; + private PacketPpi.PacketPpiFields _parent; + private byte[] _raw_body; + public PfhType pfhType() { return pfhType; } + public int pfhDatalen() { return pfhDatalen; } + public Object body() { return body; } + public PacketPpi _root() { return _root; } + public PacketPpi.PacketPpiFields _parent() { return _parent; } + public byte[] _raw_body() { return _raw_body; } + } + + /** + * @see PPI header format spec, section 4.1.4 + */ + public static class Radio80211nMacPhyExtBody extends KaitaiStruct { + public static Radio80211nMacPhyExtBody fromFile(String fileName) throws IOException { + return new Radio80211nMacPhyExtBody(new ByteBufferKaitaiStream(fileName)); + } + + public Radio80211nMacPhyExtBody(KaitaiStream _io) { + this(_io, null, null); + } + + public Radio80211nMacPhyExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent) { + this(_io, _parent, null); + } + + public Radio80211nMacPhyExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.flags = new MacFlags(this._io, this, _root); + this.aMpduId = this._io.readU4le(); + this.numDelimiters = this._io.readU1(); + this.mcs = this._io.readU1(); + this.numStreams = this._io.readU1(); + this.rssiCombined = this._io.readU1(); + rssiAntCtl = new ArrayList((int) (4)); + for (int i = 0; i < 4; i++) { + this.rssiAntCtl.add(this._io.readU1()); + } + rssiAntExt = new ArrayList((int) (4)); + for (int i = 0; i < 4; i++) { + this.rssiAntExt.add(this._io.readU1()); + } + this.extChannelFreq = this._io.readU2le(); + this.extChannelFlags = new ChannelFlags(this._io, this, _root); + rfSignalNoise = new ArrayList((int) (4)); + for (int i = 0; i < 4; i++) { + this.rfSignalNoise.add(new SignalNoise(this._io, this, _root)); + } + evm = new ArrayList((int) (4)); + for (int i = 0; i < 4; i++) { + this.evm.add(this._io.readU4le()); + } + } + public static class ChannelFlags extends KaitaiStruct { + public static ChannelFlags fromFile(String fileName) throws IOException { + return new ChannelFlags(new ByteBufferKaitaiStream(fileName)); + } + + public ChannelFlags(KaitaiStream _io) { + this(_io, null, null); + } + + public ChannelFlags(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent) { + this(_io, _parent, null); + } + + public ChannelFlags(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.spectrum2ghz = this._io.readBitsInt(1) != 0; + this.ofdm = this._io.readBitsInt(1) != 0; + this.cck = this._io.readBitsInt(1) != 0; + this.turbo = this._io.readBitsInt(1) != 0; + this.unused = this._io.readBitsInt(8); + this.gfsk = this._io.readBitsInt(1) != 0; + this.dynCckOfdm = this._io.readBitsInt(1) != 0; + this.onlyPassiveScan = this._io.readBitsInt(1) != 0; + this.spectrum5ghz = this._io.readBitsInt(1) != 0; + } + private boolean spectrum2ghz; + private boolean ofdm; + private boolean cck; + private boolean turbo; + private long unused; + private boolean gfsk; + private boolean dynCckOfdm; + private boolean onlyPassiveScan; + private boolean spectrum5ghz; + private PacketPpi _root; + private PacketPpi.Radio80211nMacPhyExtBody _parent; + + /** + * 2 GHz spectrum + */ + public boolean spectrum2ghz() { return spectrum2ghz; } + + /** + * OFDM (Orthogonal Frequency-Division Multiplexing) + */ + public boolean ofdm() { return ofdm; } + + /** + * CCK (Complementary Code Keying) + */ + public boolean cck() { return cck; } + public boolean turbo() { return turbo; } + public long unused() { return unused; } + + /** + * Gaussian Frequency Shift Keying + */ + public boolean gfsk() { return gfsk; } + + /** + * Dynamic CCK-OFDM + */ + public boolean dynCckOfdm() { return dynCckOfdm; } + + /** + * Only passive scan allowed + */ + public boolean onlyPassiveScan() { return onlyPassiveScan; } + + /** + * 5 GHz spectrum + */ + public boolean spectrum5ghz() { return spectrum5ghz; } + public PacketPpi _root() { return _root; } + public PacketPpi.Radio80211nMacPhyExtBody _parent() { return _parent; } + } + + /** + * RF signal + noise pair at a single antenna + */ + public static class SignalNoise extends KaitaiStruct { + public static SignalNoise fromFile(String fileName) throws IOException { + return new SignalNoise(new ByteBufferKaitaiStream(fileName)); + } + + public SignalNoise(KaitaiStream _io) { + this(_io, null, null); + } + + public SignalNoise(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent) { + this(_io, _parent, null); + } + + public SignalNoise(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent, PacketPpi _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.signal = this._io.readS1(); + this.noise = this._io.readS1(); + } + private byte signal; + private byte noise; + private PacketPpi _root; + private PacketPpi.Radio80211nMacPhyExtBody _parent; + + /** + * RF signal, dBm + */ + public byte signal() { return signal; } + + /** + * RF noise, dBm + */ + public byte noise() { return noise; } + public PacketPpi _root() { return _root; } + public PacketPpi.Radio80211nMacPhyExtBody _parent() { return _parent; } + } + private MacFlags flags; + private long aMpduId; + private int numDelimiters; + private int mcs; + private int numStreams; + private int rssiCombined; + private ArrayList rssiAntCtl; + private ArrayList rssiAntExt; + private int extChannelFreq; + private ChannelFlags extChannelFlags; + private ArrayList rfSignalNoise; + private ArrayList evm; + private PacketPpi _root; + private PacketPpi.PacketPpiField _parent; + public MacFlags flags() { return flags; } + public long aMpduId() { return aMpduId; } + public int numDelimiters() { return numDelimiters; } + + /** + * Modulation Coding Scheme (MCS) + */ + public int mcs() { return mcs; } + + /** + * Number of spatial streams (0 = unknown) + */ + public int numStreams() { return numStreams; } + + /** + * RSSI (Received Signal Strength Indication), combined from all active antennas / channels + */ + public int rssiCombined() { return rssiCombined; } + + /** + * RSSI (Received Signal Strength Indication) for antennas 0-3, control channel + */ + public ArrayList rssiAntCtl() { return rssiAntCtl; } + + /** + * RSSI (Received Signal Strength Indication) for antennas 0-3, extension channel + */ + public ArrayList rssiAntExt() { return rssiAntExt; } + + /** + * Extension channel frequency (MHz) + */ + public int extChannelFreq() { return extChannelFreq; } + + /** + * Extension channel flags + */ + public ChannelFlags extChannelFlags() { return extChannelFlags; } + + /** + * Signal + noise values for antennas 0-3 + */ + public ArrayList rfSignalNoise() { return rfSignalNoise; } + + /** + * EVM (Error Vector Magnitude) for chains 0-3 + */ + public ArrayList evm() { return evm; } + public PacketPpi _root() { return _root; } + public PacketPpi.PacketPpiField _parent() { return _parent; } + } + private PacketPpiHeader header; + private PacketPpiFields fields; + private Object body; + private PacketPpi _root; + private KaitaiStruct _parent; + private byte[] _raw_fields; + private byte[] _raw_body; + public PacketPpiHeader header() { return header; } + public PacketPpiFields fields() { return fields; } + public Object body() { return body; } + public PacketPpi _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } + public byte[] _raw_fields() { return _raw_fields; } + public byte[] _raw_body() { return _raw_body; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Pcap.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Pcap.java new file mode 100644 index 0000000..c052090 --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Pcap.java @@ -0,0 +1,319 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + + +/** + * @see Source + */ +public class Pcap extends KaitaiStruct { + public static Pcap fromFile(String fileName) throws IOException { + return new Pcap(new ByteBufferKaitaiStream(fileName)); + } + + public enum Linktype { + NULL_LINKTYPE(0), + ETHERNET(1), + AX25(3), + IEEE802_5(6), + ARCNET_BSD(7), + SLIP(8), + PPP(9), + FDDI(10), + PPP_HDLC(50), + PPP_ETHER(51), + ATM_RFC1483(100), + RAW(101), + C_HDLC(104), + IEEE802_11(105), + FRELAY(107), + LOOP(108), + LINUX_SLL(113), + LTALK(114), + PFLOG(117), + IEEE802_11_PRISM(119), + IP_OVER_FC(122), + SUNATM(123), + IEEE802_11_RADIOTAP(127), + ARCNET_LINUX(129), + APPLE_IP_OVER_IEEE1394(138), + MTP2_WITH_PHDR(139), + MTP2(140), + MTP3(141), + SCCP(142), + DOCSIS(143), + LINUX_IRDA(144), + USER0(147), + USER1(148), + USER2(149), + USER3(150), + USER4(151), + USER5(152), + USER6(153), + USER7(154), + USER8(155), + USER9(156), + USER10(157), + USER11(158), + USER12(159), + USER13(160), + USER14(161), + USER15(162), + IEEE802_11_AVS(163), + BACNET_MS_TP(165), + PPP_PPPD(166), + GPRS_LLC(169), + GPF_T(170), + GPF_F(171), + LINUX_LAPD(177), + BLUETOOTH_HCI_H4(187), + USB_LINUX(189), + PPI(192), + IEEE802_15_4(195), + SITA(196), + ERF(197), + BLUETOOTH_HCI_H4_WITH_PHDR(201), + AX25_KISS(202), + LAPD(203), + PPP_WITH_DIR(204), + C_HDLC_WITH_DIR(205), + FRELAY_WITH_DIR(206), + IPMB_LINUX(209), + IEEE802_15_4_NONASK_PHY(215), + USB_LINUX_MMAPPED(220), + FC_2(224), + FC_2_WITH_FRAME_DELIMS(225), + IPNET(226), + CAN_SOCKETCAN(227), + IPV4(228), + IPV6(229), + IEEE802_15_4_NOFCS(230), + DBUS(231), + DVB_CI(235), + MUX27010(236), + STANAG_5066_D_PDU(237), + NFLOG(239), + NETANALYZER(240), + NETANALYZER_TRANSPARENT(241), + IPOIB(242), + MPEG_2_TS(243), + NG40(244), + NFC_LLCP(245), + INFINIBAND(247), + SCTP(248), + USBPCAP(249), + RTAC_SERIAL(250), + BLUETOOTH_LE_LL(251), + NETLINK(253), + BLUETOOTH_LINUX_MONITOR(254), + BLUETOOTH_BREDR_BB(255), + BLUETOOTH_LE_LL_WITH_PHDR(256), + PROFIBUS_DL(257), + PKTAP(258), + EPON(259), + IPMI_HPM_2(260), + ZWAVE_R1_R2(261), + ZWAVE_R3(262), + WATTSTOPPER_DLM(263), + ISO_14443(264); + + private final long id; + Linktype(long id) { this.id = id; } + public long id() { return id; } + private static final Map byId = new HashMap(104); + static { + for (Linktype e : Linktype.values()) + byId.put(e.id(), e); + } + public static Linktype byId(long id) { return byId.get(id); } + } + + public Pcap(KaitaiStream _io) { + this(_io, null, null); + } + + public Pcap(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public Pcap(KaitaiStream _io, KaitaiStruct _parent, Pcap _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.hdr = new Header(this._io, this, _root); + this.packets = new ArrayList(); + { + int i = 0; + while (!this._io.isEof()) { + this.packets.add(new Packet(this._io, this, _root)); + i++; + } + } + } + + /** + * @see Source + */ + public static class Header extends KaitaiStruct { + public static Header fromFile(String fileName) throws IOException { + return new Header(new ByteBufferKaitaiStream(fileName)); + } + + public Header(KaitaiStream _io) { + this(_io, null, null); + } + + public Header(KaitaiStream _io, Pcap _parent) { + this(_io, _parent, null); + } + + public Header(KaitaiStream _io, Pcap _parent, Pcap _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.magicNumber = this._io.ensureFixedContents(new byte[] { -44, -61, -78, -95 }); + this.versionMajor = this._io.readU2le(); + this.versionMinor = this._io.readU2le(); + this.thiszone = this._io.readS4le(); + this.sigfigs = this._io.readU4le(); + this.snaplen = this._io.readU4le(); + this.network = Pcap.Linktype.byId(this._io.readU4le()); + } + private byte[] magicNumber; + private int versionMajor; + private int versionMinor; + private int thiszone; + private long sigfigs; + private long snaplen; + private Linktype network; + private Pcap _root; + private Pcap _parent; + public byte[] magicNumber() { return magicNumber; } + public int versionMajor() { return versionMajor; } + public int versionMinor() { return versionMinor; } + + /** + * Correction time in seconds between UTC and the local + * timezone of the following packet header timestamps. + */ + public int thiszone() { return thiszone; } + + /** + * In theory, the accuracy of time stamps in the capture; in + * practice, all tools set it to 0. + */ + public long sigfigs() { return sigfigs; } + + /** + * The "snapshot length" for the capture (typically 65535 or + * even more, but might be limited by the user), see: incl_len + * vs. orig_len. + */ + public long snaplen() { return snaplen; } + + /** + * Link-layer header type, specifying the type of headers at + * the beginning of the packet. + */ + public Linktype network() { return network; } + public Pcap _root() { return _root; } + public Pcap _parent() { return _parent; } + } + + /** + * @see Source + */ + public static class Packet extends KaitaiStruct { + public static Packet fromFile(String fileName) throws IOException { + return new Packet(new ByteBufferKaitaiStream(fileName)); + } + + public Packet(KaitaiStream _io) { + this(_io, null, null); + } + + public Packet(KaitaiStream _io, Pcap _parent) { + this(_io, _parent, null); + } + + public Packet(KaitaiStream _io, Pcap _parent, Pcap _root) { + super(_io); + this._parent = _parent; + this._root = _root; + _read(); + } + private void _read() { + this.tsSec = this._io.readU4le(); + this.tsUsec = this._io.readU4le(); + this.inclLen = this._io.readU4le(); + this.origLen = this._io.readU4le(); + switch (_root.hdr().network()) { + case PPI: { + this._raw_body = this._io.readBytes(inclLen()); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new PacketPpi(_io__raw_body); + break; + } + case ETHERNET: { + this._raw_body = this._io.readBytes(inclLen()); + KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body); + this.body = new EthernetFrame(_io__raw_body); + break; + } + default: { + this.body = this._io.readBytes(inclLen()); + break; + } + } + } + private long tsSec; + private long tsUsec; + private long inclLen; + private long origLen; + private Object body; + private Pcap _root; + private Pcap _parent; + private byte[] _raw_body; + public long tsSec() { return tsSec; } + public long tsUsec() { return tsUsec; } + + /** + * Number of bytes of packet data actually captured and saved in the file. + */ + public long inclLen() { return inclLen; } + + /** + * Length of the packet as it appeared on the network when it was captured. + */ + public long origLen() { return origLen; } + + /** + * @see Source + */ + public Object body() { return body; } + public Pcap _root() { return _root; } + public Pcap _parent() { return _parent; } + public byte[] _raw_body() { return _raw_body; } + } + private Header hdr; + private ArrayList packets; + private Pcap _root; + private KaitaiStruct _parent; + public Header hdr() { return hdr; } + public ArrayList packets() { return packets; } + public Pcap _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/TcpSegment.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/TcpSegment.java new file mode 100644 index 0000000..80ec76e --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/TcpSegment.java @@ -0,0 +1,64 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; + +public class TcpSegment extends KaitaiStruct { + public static TcpSegment fromFile(String fileName) throws IOException { + return new TcpSegment(new ByteBufferKaitaiStream(fileName)); + } + + public TcpSegment(KaitaiStream _io) { + this(_io, null, null); + } + + public TcpSegment(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public TcpSegment(KaitaiStream _io, KaitaiStruct _parent, TcpSegment _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.srcPort = this._io.readU2be(); + this.dstPort = this._io.readU2be(); + this.seqNum = this._io.readU4be(); + this.ackNum = this._io.readU4be(); + this.b12 = this._io.readU1(); + this.b13 = this._io.readU1(); + this.windowSize = this._io.readU2be(); + this.checksum = this._io.readU2be(); + this.urgentPointer = this._io.readU2be(); + this.body = this._io.readBytesFull(); + } + private int srcPort; + private int dstPort; + private long seqNum; + private long ackNum; + private int b12; + private int b13; + private int windowSize; + private int checksum; + private int urgentPointer; + private byte[] body; + private TcpSegment _root; + private KaitaiStruct _parent; + public int srcPort() { return srcPort; } + public int dstPort() { return dstPort; } + public long seqNum() { return seqNum; } + public long ackNum() { return ackNum; } + public int b12() { return b12; } + public int b13() { return b13; } + public int windowSize() { return windowSize; } + public int checksum() { return checksum; } + public int urgentPointer() { return urgentPointer; } + public byte[] body() { return body; } + public TcpSegment _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } +} diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/UdpDatagram.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/UdpDatagram.java new file mode 100644 index 0000000..9133029 --- /dev/null +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/UdpDatagram.java @@ -0,0 +1,56 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild +package edu.uci.iotproject; + +import io.kaitai.struct.ByteBufferKaitaiStream; +import io.kaitai.struct.KaitaiStruct; +import io.kaitai.struct.KaitaiStream; +import java.io.IOException; + + +/** + * UDP is a simple stateless transport layer (AKA OSI layer 4) + * protocol, one of the core Internet protocols. It provides source and + * destination ports, basic checksumming, but provides not guarantees + * of delivery, order of packets, or duplicate delivery. + */ +public class UdpDatagram extends KaitaiStruct { + public static UdpDatagram fromFile(String fileName) throws IOException { + return new UdpDatagram(new ByteBufferKaitaiStream(fileName)); + } + + public UdpDatagram(KaitaiStream _io) { + this(_io, null, null); + } + + public UdpDatagram(KaitaiStream _io, KaitaiStruct _parent) { + this(_io, _parent, null); + } + + public UdpDatagram(KaitaiStream _io, KaitaiStruct _parent, UdpDatagram _root) { + super(_io); + this._parent = _parent; + this._root = _root == null ? this : _root; + _read(); + } + private void _read() { + this.srcPort = this._io.readU2be(); + this.dstPort = this._io.readU2be(); + this.length = this._io.readU2be(); + this.checksum = this._io.readU2be(); + this.body = this._io.readBytesFull(); + } + private int srcPort; + private int dstPort; + private int length; + private int checksum; + private byte[] body; + private UdpDatagram _root; + private KaitaiStruct _parent; + public int srcPort() { return srcPort; } + public int dstPort() { return dstPort; } + public int length() { return length; } + public int checksum() { return checksum; } + public byte[] body() { return body; } + public UdpDatagram _root() { return _root; } + public KaitaiStruct _parent() { return _parent; } +}