diff --git a/src/main/java/io/github/dsheirer/bits/BinaryMessage.java b/src/main/java/io/github/dsheirer/bits/BinaryMessage.java
index 13aae11d..1853eb1f 100644
--- a/src/main/java/io/github/dsheirer/bits/BinaryMessage.java
+++ b/src/main/java/io/github/dsheirer/bits/BinaryMessage.java
@@ -1,32 +1,28 @@
/*
+ * *****************************************************************************
+ * Copyright (C) 2014-2023 Dennis Sheirer
*
- * * ******************************************************************************
- * * Copyright (C) 2014-2019 Dennis Sheirer
- * *
- * * This program is free software: you can redistribute it and/or modify
- * * it under the terms of the GNU General Public License as published by
- * * the Free Software Foundation, either version 3 of the License, or
- * * (at your option) any later version.
- * *
- * * This program is distributed in the hope that it will be useful,
- * * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * * GNU General Public License for more details.
- * *
- * * You should have received a copy of the GNU General Public License
- * * along with this program. If not, see
- * * *****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * ****************************************************************************
*/
package io.github.dsheirer.bits;
import io.github.dsheirer.edac.CRC;
+import java.util.BitSet;
import org.apache.commons.lang3.Validate;
import org.apache.commons.math3.util.FastMath;
-import java.util.BitSet;
-
public class BinaryMessage extends BitSet
{
private static final long serialVersionUID = 1L;
@@ -1038,6 +1034,51 @@ public class BinaryMessage extends BitSet
return buffer;
}
+ /**
+ * Loads the hexadecimal text into a binary message
+ * @param hex text to load from
+ * @return loaded binary message
+ */
+ public static BinaryMessage loadHex(String hex)
+ {
+ if(!hex.matches("[0-9A-F]*"))
+ {
+ throw new IllegalArgumentException("Message must contain only 0-9 and A-F hexadecimal characters");
+ }
+
+ int length = hex.length() / 2;
+
+ if(length * 2 < hex.length())
+ {
+ length++;
+ }
+
+ BinaryMessage buffer = new BinaryMessage(length * 8);
+
+ int bufferOffset = 0;
+ for(int x = 0; x < hex.length(); x += 2)
+ {
+ int endIndex = x + 2;
+ if(endIndex > hex.length())
+ {
+ endIndex--;
+ }
+
+ String rawHex = hex.substring(x, endIndex);
+
+ if(rawHex.length() == 1)
+ {
+ rawHex = rawHex + "0";
+ }
+
+ int value = Integer.parseInt(rawHex, 16);
+ buffer.setByte(bufferOffset, (byte)(value & 0xFF));
+ bufferOffset += 8;
+ }
+
+ return buffer;
+ }
+
/**
* Left rotates the bits between start and end indices, number of places.
*/
diff --git a/src/main/java/io/github/dsheirer/module/decode/ip/ars/DeviceRegistration.java b/src/main/java/io/github/dsheirer/module/decode/ip/ars/DeviceRegistration.java
index e219f9c2..61b4db8d 100644
--- a/src/main/java/io/github/dsheirer/module/decode/ip/ars/DeviceRegistration.java
+++ b/src/main/java/io/github/dsheirer/module/decode/ip/ars/DeviceRegistration.java
@@ -1,7 +1,6 @@
/*
- * ******************************************************************************
- * sdrtrunk
- * Copyright (C) 2014-2018 Dennis Sheirer
+ * *****************************************************************************
+ * Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
- * *****************************************************************************
+ * ****************************************************************************
*/
package io.github.dsheirer.module.decode.ip.ars;
@@ -25,11 +24,10 @@ import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSDevice;
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSPassword;
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSUser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Automatic Registration Service - Device Registration
@@ -176,7 +174,7 @@ public class DeviceRegistration extends ARSHeader
pointer += 8;
- if(deviceIdentifierSize > 0)
+ if(deviceIdentifierSize > 0 && deviceIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();
@@ -186,21 +184,13 @@ public class DeviceRegistration extends ARSHeader
pointer += 8;
}
- try
- {
- int device = Integer.parseInt(sb.toString());
- mDevice = ARSDevice.createFrom(device);
- }
- catch(Exception e)
- {
- mLog.error("Error parsing ARS device identifier from value [" + sb.toString() + "]");
- }
+ mDevice = ARSDevice.createFrom(sb.toString());
}
int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;
- if(userIdentifierSize > 0)
+ if(userIdentifierSize > 0 && userIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();
@@ -216,7 +206,7 @@ public class DeviceRegistration extends ARSHeader
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;
- if(passwordSize > 0)
+ if(passwordSize > 0 && passwordSize < 8)
{
StringBuilder sb = new StringBuilder();
diff --git a/src/main/java/io/github/dsheirer/module/decode/ip/ars/UserRegistration.java b/src/main/java/io/github/dsheirer/module/decode/ip/ars/UserRegistration.java
index b42a86b8..fdf55026 100644
--- a/src/main/java/io/github/dsheirer/module/decode/ip/ars/UserRegistration.java
+++ b/src/main/java/io/github/dsheirer/module/decode/ip/ars/UserRegistration.java
@@ -1,7 +1,6 @@
/*
- * ******************************************************************************
- * sdrtrunk
- * Copyright (C) 2014-2018 Dennis Sheirer
+ * *****************************************************************************
+ * Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
- * *****************************************************************************
+ * ****************************************************************************
*/
package io.github.dsheirer.module.decode.ip.ars;
@@ -25,11 +24,10 @@ import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSDevice;
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSPassword;
import io.github.dsheirer.module.decode.ip.ars.identifier.ARSUser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class UserRegistration extends ARSHeader
{
@@ -108,7 +106,7 @@ public class UserRegistration extends ARSHeader
pointer += 8;
- if(deviceIdentifierSize > 0)
+ if(deviceIdentifierSize > 0 && deviceIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();
@@ -118,22 +116,13 @@ public class UserRegistration extends ARSHeader
pointer += 8;
}
- try
- {
- int device = Integer.parseInt(sb.toString());
- mDevice = ARSDevice.createFrom(device);
- }
- catch(Exception e)
- {
- //Abort processing
- return;
- }
+ mDevice = ARSDevice.createFrom(sb.toString());
}
int userIdentifierSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;
- if(userIdentifierSize > 0)
+ if(userIdentifierSize > 0 && deviceIdentifierSize < 8)
{
StringBuilder sb = new StringBuilder();
@@ -149,7 +138,7 @@ public class UserRegistration extends ARSHeader
int passwordSize = getMessage().getInt(BYTE_VALUE, pointer);
pointer += 8;
- if(passwordSize > 0)
+ if(passwordSize > 0 && passwordSize < 8)
{
StringBuilder sb = new StringBuilder();
diff --git a/src/main/java/io/github/dsheirer/module/decode/ip/ars/identifier/ARSDevice.java b/src/main/java/io/github/dsheirer/module/decode/ip/ars/identifier/ARSDevice.java
index 7909c7cc..6547d7df 100644
--- a/src/main/java/io/github/dsheirer/module/decode/ip/ars/identifier/ARSDevice.java
+++ b/src/main/java/io/github/dsheirer/module/decode/ip/ars/identifier/ARSDevice.java
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
- * Copyright (C) 2014-2020 Dennis Sheirer
+ * Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,20 +22,20 @@ package io.github.dsheirer.module.decode.ip.ars.identifier;
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.Role;
-import io.github.dsheirer.identifier.integer.IntegerIdentifier;
+import io.github.dsheirer.identifier.string.StringIdentifier;
import io.github.dsheirer.protocol.Protocol;
/**
* Automatic Registration Service - Device Identifier
*/
-public class ARSDevice extends IntegerIdentifier
+public class ARSDevice extends StringIdentifier
{
/**
* Constructs an instance
* @param value of the device identifier
* @param role of the device (TO/FROM)
*/
- public ARSDevice(int value, Role role)
+ public ARSDevice(String value, Role role)
{
super(value, IdentifierClass.USER, Form.ARS_DEVICE, role);
}
@@ -49,7 +49,7 @@ public class ARSDevice extends IntegerIdentifier
/**
* Creates an ARS device with a FROM role
*/
- public static ARSDevice createFrom(int value)
+ public static ARSDevice createFrom(String value)
{
return new ARSDevice(value, Role.FROM);
}
@@ -57,7 +57,7 @@ public class ARSDevice extends IntegerIdentifier
/**
* Creates an ARS device with a TO role
*/
- public static ARSDevice createTo(int value)
+ public static ARSDevice createTo(String value)
{
return new ARSDevice(value, Role.TO);
}