mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-25 08:03:46 +02:00
Amazfit Bip/Cor: rework fimware detection to rely on strings instead of version numbers
The new version scheme and the fact that recent Bip and Cor firmwares are impossible to distinguish by comparing data at fixed offsets make it necessary to dynamically search for sequences of data. We do this now by searching for "Amazfit Bip Watch" and "Amazfit Cor".
This commit is contained in:
parent
6e34d313c7
commit
3236e20657
|
@ -174,4 +174,25 @@ public abstract class HuamiFirmwareInfo {
|
|||
return null;
|
||||
}
|
||||
|
||||
protected boolean searchString32BitAligned(byte[] fwbytes, String findString) {
|
||||
ByteBuffer stringBuf = ByteBuffer.wrap((findString + "\0").getBytes());
|
||||
stringBuf.order(ByteOrder.BIG_ENDIAN);
|
||||
int[] findArray = new int[stringBuf.remaining() / 4];
|
||||
for (int i = 0; i < findArray.length; i++) {
|
||||
findArray[i] = stringBuf.getInt();
|
||||
}
|
||||
|
||||
ByteBuffer buf = ByteBuffer.wrap(fwbytes);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
while (buf.remaining() > 3) {
|
||||
int arrayPos = 0;
|
||||
while (arrayPos < findArray.length && buf.remaining() > 3 && (buf.getInt() == findArray[arrayPos])) {
|
||||
arrayPos++;
|
||||
}
|
||||
if (arrayPos == findArray.length) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
|||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
||||
|
||||
public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo {
|
||||
// gps detection is totally bogus, just the first 16 bytes
|
||||
|
@ -150,12 +149,8 @@ public class AmazfitBipFirmwareInfo extends HuamiFirmwareInfo {
|
|||
return HuamiFirmwareType.GPS_CEP;
|
||||
}
|
||||
if (ArrayUtils.startsWith(bytes, FW_HEADER)) {
|
||||
String foundVersion = searchFirmwareVersion(bytes);
|
||||
if (foundVersion != null) {
|
||||
Version version = new Version(foundVersion);
|
||||
if ((version.compareTo(new Version("0.0.8.00")) >= 0) && (version.compareTo(new Version("1.0.5.00")) < 0)) {
|
||||
return HuamiFirmwareType.FIRMWARE;
|
||||
}
|
||||
if (searchString32BitAligned(bytes, "Amazfit Bip Watch")) {
|
||||
return HuamiFirmwareType.FIRMWARE;
|
||||
}
|
||||
return HuamiFirmwareType.INVALID;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
|||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
||||
|
||||
public class AmazfitCorFirmwareInfo extends HuamiFirmwareInfo {
|
||||
// this is the same as Bip
|
||||
|
@ -72,12 +71,8 @@ public class AmazfitCorFirmwareInfo extends HuamiFirmwareInfo {
|
|||
return HuamiFirmwareType.RES_COMPRESSED;
|
||||
}
|
||||
if (ArrayUtils.startsWith(bytes, FW_HEADER)) {
|
||||
String foundVersion = searchFirmwareVersion(bytes);
|
||||
if (foundVersion != null) {
|
||||
Version version = new Version(foundVersion);
|
||||
if ((version.compareTo(new Version("1.0.5.00")) >= 0) && (version.compareTo(new Version("2.0.0.00")) < 0)) {
|
||||
return HuamiFirmwareType.FIRMWARE;
|
||||
}
|
||||
if (searchString32BitAligned(bytes, "Amazfit Cor")) {
|
||||
return HuamiFirmwareType.FIRMWARE;
|
||||
}
|
||||
return HuamiFirmwareType.INVALID;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user