Added hexConverter helper-module
This commit is contained in:
parent
09bea81058
commit
ffe14e3f53
@ -13,6 +13,7 @@ const PacketType = {
|
||||
AssociationRequest: 'AssociationRequest',
|
||||
AssociationResponse: 'AssociationResponse',
|
||||
Disassociation: 'Disassociation',
|
||||
Handshake: 'Handshake',
|
||||
Unknown: 'Unknown'
|
||||
}
|
||||
|
||||
@ -65,6 +66,17 @@ class DisassociationPacket extends Packet{
|
||||
disassociationReason;
|
||||
}
|
||||
|
||||
|
||||
const HandshakeStage = {
|
||||
1: '1',
|
||||
2: '2',
|
||||
3: '3',
|
||||
4: '4'
|
||||
}
|
||||
class HandshakePacket extends Packet{
|
||||
handshakeStage;
|
||||
}
|
||||
|
||||
// Specify exports
|
||||
module.exports = {
|
||||
PacketType,
|
||||
@ -77,4 +89,6 @@ module.exports = {
|
||||
AuthenticationPacket,
|
||||
AssociationRequestPacket,
|
||||
AssociationResponsePacket,
|
||||
HandshakeStage,
|
||||
HandshakePacket,
|
||||
};
|
||||
|
24
src/helper/hexConverter.js
Normal file
24
src/helper/hexConverter.js
Normal file
@ -0,0 +1,24 @@
|
||||
// From https://stackoverflow.com/a/34356351
|
||||
|
||||
// Convert a hex string to a byte array
|
||||
function hexToBytes(hex) {
|
||||
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Convert a byte array to a hex string
|
||||
function bytesToHex(bytes) {
|
||||
for (var hex = [], i = 0; i < bytes.length; i++) {
|
||||
var current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
|
||||
hex.push((current >>> 4).toString(16));
|
||||
hex.push((current & 0xF).toString(16));
|
||||
}
|
||||
return hex.join("");
|
||||
}
|
||||
|
||||
// Specify exports
|
||||
module.exports = {
|
||||
hexToBytes,
|
||||
bytesToHex
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
const logger = require.main.require("./helper/logger.js")("PacketStreamFactory");
|
||||
const { Transform } = require('stream');
|
||||
const { DateTime } = require("luxon");
|
||||
const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket } = require.main.require('./dto/Packet.js');
|
||||
const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket, HandshakePacket, HandshakeStage } = require.main.require('./dto/Packet.js');
|
||||
|
||||
const PACKET_TYPE_MAP = {
|
||||
"Beacon": PacketType.Beacon,
|
||||
@ -17,6 +17,7 @@ const PACKET_TYPE_MAP = {
|
||||
"Assoc Request": PacketType.AssociationRequest,
|
||||
"Assoc Response": PacketType.AssociationResponse,
|
||||
"Disassociation:": PacketType.Disassociation,
|
||||
"EAPOL": PacketType.Handshake,
|
||||
};
|
||||
const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join('|');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user