use of seemoo.fitbit.information.InformationList in project fitness-app by seemoo-lab.
the class Utilities method translate.
/**
* Converts the live mode byte array into a readable information list.
*
* @param value The byte array to convert.
* @return A readable information list.
*/
public static InformationList translate(byte[] value) {
InformationList list = new InformationList("LiveMode");
String data = Utilities.byteArrayToHexString(value);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Utilities.hexStringToInt(Utilities.rotateBytes(data.substring(0, 8))) * 1000L);
list.add(new Information("time: " + calendar.getTime()));
list.add(new Information("steps: " + Utilities.hexStringToInt(Utilities.rotateBytes(data.substring(8, 16)))));
list.add(new Information("distance: " + Utilities.hexStringToInt(Utilities.rotateBytes(data.substring(16, 24))) / 1000 + " m"));
list.add(new Information("calories: " + Utilities.hexStringToInt(Utilities.rotateBytes(data.substring(24, 28))) + " METs"));
list.add(new Information("elevation: " + Utilities.hexStringToInt(Utilities.rotateBytes(data.substring(28, 32))) / 10 + " floors"));
// list.add(new Information("heartRateConfidence: " + Utilities.hexStringToInt(Utilities.rotateBytes(data.substring(38, 40)))));
return list;
}
use of seemoo.fitbit.information.InformationList in project fitness-app by seemoo-lab.
the class DumpInteraction method finish.
/**
* {@inheritDoc}
* Returns the collected data and gets a readable translation for unencrypted parts.
*
* @return The collected data.
*/
@Override
InformationList finish() {
InformationList result = new InformationList(name);
if (!transmissionActive && data.length() > 0) {
Log.e(TAG, name + " successful.");
dataList.addAll(dataCut(data));
if (dumpType != 3) {
result.addAll(readOut());
result.add(new Information(""));
result.add(new Information(ConstantValues.RAW_OUTPUT));
result.addAll(dataList);
} else {
result.addAll(dataList);
}
} else {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
toast.setText(name + " failed.");
toast.show();
}
});
dataList = null;
Log.e(TAG, name + " failed.");
}
commands.comDisableNotifications1();
return result;
}
use of seemoo.fitbit.information.InformationList in project fitness-app by seemoo-lab.
the class DumpInteraction method readOut.
/**
* Reads out the information from a micro- or mega dump.
*
* @return The information or null if it is an alarm or memory dump.
*/
private InformationList readOut() {
InformationList result = new InformationList("");
String temp = "";
if (dumpType == 0 || dumpType == 1) {
// Microdump || Megadump
String model;
String type;
String id;
int noncePos = 12;
int serialPos = 20;
temp = dataList.get(0).toString().substring(0, 8);
switch(temp.substring(0, 2)) {
case "2c":
model = "Megadump";
break;
case "30":
model = "Microdump";
break;
case "03":
// Ionic format is new, generic dump, different offsets
model = "Dump";
noncePos = 10;
serialPos = 18;
break;
default:
model = temp.substring(0, 2);
}
switch(temp.substring(2, 4)) {
case "02":
type = "Tracker";
break;
case "04":
type = "Smartwatch";
break;
default:
type = temp.substring(2, 4);
}
temp = dataList.get(0).toString().substring(serialPos + 10, serialPos + 12);
switch(temp.substring(0, 2)) {
// FIXME do this via ConstantValues
case "01":
id = "Zip";
break;
case "05":
id = "One";
break;
case "07":
id = "Flex";
break;
case "08":
id = "Charge";
break;
case "12":
id = "Charge HR";
break;
case "15":
id = "Alta";
break;
case "10":
id = "Surge";
break;
case "11":
id = "Electron";
break;
case "1b":
id = "Ionic";
break;
default:
id = temp;
}
result.add(new Information("SiteProto: " + model + ", " + type));
result.add(new Information("Encrypted: " + encrypted()));
result.add(new Information("Nonce: " + Utilities.rotateBytes(dataList.get(0).toString().substring(noncePos, noncePos + 4))));
String productCode = dataList.get(0).toString().substring(serialPos, serialPos + 12);
result.add(new Information("Serial Number: " + Utilities.rotateBytes(productCode)));
AuthValues.setSerialNumber(productCode);
if (AuthValues.NONCE == null) {
InternalStorage.loadAuthFiles(activity);
}
result.add(new Information("ID: " + id));
if (!encrypted()) {
result.add(new Information("Version: " + Utilities.rotateBytes(dataList.get(0).toString().substring(16, 20))));
}
temp = dataList.get(dataList.size() - 2).toString() + dataList.get(dataList.size() - 1).toString();
result.add(new Information("Length: " + Utilities.hexStringToInt(Utilities.rotateBytes(temp.substring(temp.length() - 6, temp.length()))) + " byte"));
} else {
// Alarms
ArrayList<Information> input = new ArrayList<>();
input.addAll(dataList.getList());
for (int i = 0; i < 11; i++) {
temp = temp + input.get(i);
}
setAlarmIndex(temp);
result.add(new Information("Alarms:"));
for (int i = 0; i < 8; i++) {
result.add(new Alarm(temp.substring(28 + i * 48, 28 + (i + 1) * 48)));
}
result.add(new Information(""));
result.add(new Information(ConstantValues.ADDITIONAL_INFO));
result.add(new Information("Number of Alarms: " + Utilities.hexStringToInt(Utilities.rotateBytes(input.get(0).toString().substring(20, 24)))));
result.add(new Information("CRC_CCITT: " + Utilities.rotateBytes(temp.substring(412, 416))));
result.add(new Information("Length: " + Utilities.hexStringToInt(Utilities.rotateBytes(temp.substring(428, 434))) + " byte"));
}
return result;
}
use of seemoo.fitbit.information.InformationList in project fitness-app by seemoo-lab.
the class DumpInteraction method dataCut.
/**
* Decrypts the eSLIP encrypted input and cuts it into 20 byte parts. Returns the result as information list.
*
* @param input The input data as a string.
* @return An information list with decrypted input.
*/
private InformationList dataCut(String input) {
InformationList result = new InformationList("");
String temp = "";
int positionEncode = 0;
while (positionEncode < input.length()) {
// encoding of first two byte in line
if (positionEncode + 40 < input.length()) {
// line is 20 byte long
if (input.substring(positionEncode, positionEncode + 4).equals("dbdc")) {
temp = temp + "c0" + input.substring(positionEncode + 4, positionEncode + 40);
} else if (input.substring(positionEncode, positionEncode + 4).equals("dbdd")) {
temp = temp + "db" + input.substring(positionEncode + 4, positionEncode + 40);
} else {
temp = temp + input.substring(positionEncode, positionEncode + 40);
}
positionEncode = positionEncode + 40;
} else if (positionEncode + 4 < input.length()) {
// line is between two and 20 byte long
if (input.substring(positionEncode, positionEncode + 4).equals("dbdc")) {
temp = temp + "c0" + input.substring(positionEncode + 4, input.length());
} else if (input.substring(positionEncode, positionEncode + 4).equals("dbdd")) {
temp = temp + "db" + input.substring(positionEncode + 4, input.length());
} else {
temp = temp + input.substring(positionEncode, input.length());
}
break;
} else {
// line is shorter than two byte
temp = temp + input.substring(positionEncode, input.length());
break;
}
}
int position = 0;
while (position < temp.length()) {
// cut in 20 byte parts
if (position + 40 < temp.length()) {
result.add(new Information(temp.substring(position, position + 40)));
position = position + 40;
} else {
result.add(new Information(temp.substring(position, temp.length())));
break;
}
}
return result;
}
use of seemoo.fitbit.information.InformationList in project fitness-app by seemoo-lab.
the class WorkActivity method onCreate.
/**
* {@inheritDoc}
* Initializes several objects and connects to the deivec.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work);
setFinishOnTouchOutside(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
initialize();
collectBasicInformation();
connect();
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
/**
* {@inheritDoc}
* Lets the user change an alarm, with the current view shows the alarms.
*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (information.get(ConstantValues.INFORMATION_ALARM) != null && services.size() != 0 && position > 0 && position < 9) {
InformationList temp = new InformationList("");
temp.addAll(information.get(ConstantValues.INFORMATION_ALARM));
for (int i = temp.size() - 1; i >= 0; i--) {
if (!(temp.get(i) instanceof Alarm)) {
temp.remove(i);
}
}
interactions.intSetAlarm(position - 1, temp);
}
}
});
}
Aggregations