Xiaomi: Fix gps track parsing

The crc at the end was not being taken into account to check the file
size.
This commit is contained in:
José Rebelo 2024-09-15 18:35:31 +01:00
parent e3e5c20a5a
commit edd1a660da
3 changed files with 6 additions and 5 deletions

View File

@ -63,6 +63,7 @@ public class DailyDetailsParser extends XiaomiActivityParser {
} }
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN); final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
buf.limit(buf.limit() - 4); // discard crc at the end
buf.get(new byte[7]); // skip fileId bytes buf.get(new byte[7]); // skip fileId bytes
final byte fileIdPadding = buf.get(); final byte fileIdPadding = buf.get();
if (fileIdPadding != 0) { if (fileIdPadding != 0) {
@ -80,7 +81,7 @@ public class DailyDetailsParser extends XiaomiActivityParser {
timestamp.setTime(fileId.getTimestamp()); timestamp.setTime(fileId.getTimestamp());
final List<XiaomiActivitySample> samples = new ArrayList<>(); final List<XiaomiActivitySample> samples = new ArrayList<>();
while (buf.position() < buf.limit() - 4 /* crc at the end */) { while (buf.position() < buf.limit()) {
complexParser.reset(); complexParser.reset();
final XiaomiActivitySample sample = new XiaomiActivitySample(); final XiaomiActivitySample sample = new XiaomiActivitySample();

View File

@ -51,6 +51,7 @@ public class ManualSamplesParser extends XiaomiActivityParser {
} }
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN); final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
buf.limit(buf.limit() - 4); // discard crc at the end
buf.get(new byte[7]); // skip fileId bytes buf.get(new byte[7]); // skip fileId bytes
final byte fileIdPadding = buf.get(); final byte fileIdPadding = buf.get();
if (fileIdPadding != 0) { if (fileIdPadding != 0) {
@ -67,7 +68,7 @@ public class ManualSamplesParser extends XiaomiActivityParser {
final List<XiaomiManualSample> samples = new ArrayList<>(); final List<XiaomiManualSample> samples = new ArrayList<>();
while (buf.position() < buf.limit() - 4 /* crc at the end */) { while (buf.position() < buf.limit()) {
final int timestamp = buf.getInt(); final int timestamp = buf.getInt();
final int type = buf.get() & 0xff; final int type = buf.get() & 0xff;

View File

@ -68,12 +68,12 @@ public class WorkoutGpsParser extends XiaomiActivityParser {
} }
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN); final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
buf.limit(buf.limit() - 4); // discard crc at the end
buf.get(new byte[7]); // skip fileId bytes buf.get(new byte[7]); // skip fileId bytes
final byte fileIdPadding = buf.get(); final byte fileIdPadding = buf.get();
if (fileIdPadding != 0) { if (fileIdPadding != 0) {
LOG.warn("Expected 0 padding after fileId, got {} - parsing might fail", fileIdPadding); LOG.warn("Expected 0 padding after fileId, got {} - parsing might fail", fileIdPadding);
} }
final byte[] header = new byte[headerSize]; final byte[] header = new byte[headerSize];
buf.get(header); buf.get(header);
@ -81,12 +81,11 @@ public class WorkoutGpsParser extends XiaomiActivityParser {
if ((buf.limit() - buf.position()) % sampleSize != 0) { if ((buf.limit() - buf.position()) % sampleSize != 0) {
LOG.warn("Remaining data in the buffer is not a multiple of {}", sampleSize); LOG.warn("Remaining data in the buffer is not a multiple of {}", sampleSize);
return false;
} }
final ActivityTrack activityTrack = new ActivityTrack(); final ActivityTrack activityTrack = new ActivityTrack();
while (buf.position() < buf.limit() - 4 /* crc at the end */) { while (buf.position() < buf.limit()) {
final int ts = buf.getInt(); final int ts = buf.getInt();
final float longitude = buf.getFloat(); final float longitude = buf.getFloat();
final float latitude = buf.getFloat(); final float latitude = buf.getFloat();