style
This commit is contained in:
1 parent
4762f5f33b
commit
3f6ea0f0fc
20 files changed
+4407
-4498
No files matched your search
@@ -125,4 +125,4 @@ local function main(args)
|
||||
end
|
||||
end
|
||||
|
||||
main(args)
|
||||
main(args)
|
||||
@@ -1743,12 +1743,12 @@ static int CmdSetGraphMarkers(const char *Cmd) {
|
||||
g_MarkerC.pos = arg_get_u32_def(ctx, 4, (keep ? g_MarkerC.pos : 0));
|
||||
g_MarkerD.pos = arg_get_u32_def(ctx, 5, (keep ? g_MarkerD.pos : 0));
|
||||
CLIParserFree(ctx);
|
||||
PrintAndLogEx(INFO, "Setting markers " _BRIGHT_YELLOW_("A") "=%u, "_BRIGHT_MAGENTA_("B") "=%u, "_RED_("C") "=%u, "_BLUE_("D") "=%u",
|
||||
g_MarkerA.pos,
|
||||
g_MarkerB.pos,
|
||||
g_MarkerC.pos,
|
||||
g_MarkerD.pos
|
||||
);
|
||||
PrintAndLogEx(INFO, "Setting markers " _BRIGHT_YELLOW_("A") "=%u, "_BRIGHT_MAGENTA_("B") "=%u, "_RED_("C") "=%u, "_BLUE_("D") "=%u",
|
||||
g_MarkerA.pos,
|
||||
g_MarkerB.pos,
|
||||
g_MarkerC.pos,
|
||||
g_MarkerD.pos
|
||||
);
|
||||
RepaintGraphWindow();
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -3701,7 +3701,7 @@ static command_t CommandTable[] = {
|
||||
{"save", CmdSave, AlwaysAvailable, "Save signal trace data"},
|
||||
{"setdebugmode", CmdSetDebugMode, AlwaysAvailable, "Set Debugging Level on client side"},
|
||||
{"xor", CmdXor, AlwaysAvailable, "Xor a input string"},
|
||||
|
||||
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("Modulation") "-------------------------"},
|
||||
{"biphaserawdecode", CmdBiphaseDecodeRaw, AlwaysAvailable, "Biphase decode bin stream in DemodBuffer"},
|
||||
{"detectclock", CmdDetectClockRate, AlwaysAvailable, "Detect ASK, FSK, NRZ, PSK clock rate of wave in GraphBuffer"},
|
||||
|
||||
@@ -2737,7 +2737,7 @@ static int CmdHF15CSetUID(const char *Cmd) {
|
||||
"Set UID for magic Chinese card (only works with such cards)\n",
|
||||
"hf 15 csetuid -u E011223344556677 -> use gen1 command\n"
|
||||
"hf 15 csetuid -u E011223344556677 --v2 -> use gen2 command"
|
||||
);
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
|
||||
@@ -355,7 +355,7 @@ static int CmdHFMFPInfo(const char *Cmd) {
|
||||
if (supportVersion) {
|
||||
|
||||
int cardtype = getCardType(version[1], version[3], version[4]);
|
||||
switch(cardtype) {
|
||||
switch (cardtype) {
|
||||
case PLUS_EV1: {
|
||||
if (supportSignature) {
|
||||
PrintAndLogEx(INFO, "Tech..... " _GREEN_("MIFARE Plus EV1"));
|
||||
|
||||
+34
-34
@@ -474,7 +474,7 @@ static bool ht2_check_cryptokeys(const uint64_t *keys, const uint32_t keycount,
|
||||
}
|
||||
|
||||
static int ht2_check_dictionary(uint32_t key_count, uint8_t *keys, uint8_t keylen, uint32_t *found_idx) {
|
||||
|
||||
|
||||
lf_hitag_data_t packet;
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
@@ -735,10 +735,10 @@ void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize,
|
||||
if (ht2_check_cryptokeys(keys, keycount, cmd)) {
|
||||
|
||||
_ht2state.cipher_state = ht2_hitag2_init(
|
||||
_ht2state.key,
|
||||
_ht2state.uid,
|
||||
REV32((cmd[3] << 24) + (cmd[2] << 16) + (cmd[1] << 8) + cmd[0])
|
||||
);
|
||||
_ht2state.key,
|
||||
_ht2state.uid,
|
||||
REV32((cmd[3] << 24) + (cmd[2] << 16) + (cmd[1] << 8) + cmd[0])
|
||||
);
|
||||
ht2_hitag2_cipher_transcrypt(&_ht2state.cipher_state, _ht2state.plain + 4, 4, 0);
|
||||
|
||||
uint64_t key = REV64(_ht2state.key);
|
||||
@@ -1001,7 +1001,7 @@ static int CmdLFHitagReader(const char *Cmd) {
|
||||
}
|
||||
|
||||
if (use_nrar) {
|
||||
return PM3_SUCCESS;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t *data = resp.data.asBytes;
|
||||
@@ -1312,15 +1312,15 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "lf hitag dump",
|
||||
"Read all Hitag 2 card memory and save to file\n"
|
||||
"Crypto mode key format: ISK high + ISK low, 4F4E4D494B52 (ONMIKR)\n"
|
||||
"Password mode, default key 4D494B52 (MIKR)\n",
|
||||
"lf hitag dump --pwd -> use def pwd\n"
|
||||
"lf hitag dump -k 4D494B52 -> pwd mode\n"
|
||||
"lf hitag dump --crypto -> use def crypto\n"
|
||||
"lf hitag dump -k 4F4E4D494B52 -> crypto mode\n"
|
||||
"lf hitag dump --nrar 0102030411223344\n"
|
||||
);
|
||||
"Read all Hitag 2 card memory and save to file\n"
|
||||
"Crypto mode key format: ISK high + ISK low, 4F4E4D494B52 (ONMIKR)\n"
|
||||
"Password mode, default key 4D494B52 (MIKR)\n",
|
||||
"lf hitag dump --pwd -> use def pwd\n"
|
||||
"lf hitag dump -k 4D494B52 -> pwd mode\n"
|
||||
"lf hitag dump --crypto -> use def crypto\n"
|
||||
"lf hitag dump -k 4F4E4D494B52 -> crypto mode\n"
|
||||
"lf hitag dump --nrar 0102030411223344\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
@@ -1376,10 +1376,10 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (keylen != 0 &&
|
||||
keylen != HITAG_PASSWORD_SIZE &&
|
||||
keylen != HITAG_CRYPTOKEY_SIZE &&
|
||||
keylen != HITAG_NRAR_SIZE) {
|
||||
if (keylen != 0 &&
|
||||
keylen != HITAG_PASSWORD_SIZE &&
|
||||
keylen != HITAG_CRYPTOKEY_SIZE &&
|
||||
keylen != HITAG_NRAR_SIZE) {
|
||||
PrintAndLogEx(WARNING, "Wrong KEY len expected (0,4,6,8) got %d", keylen);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
@@ -1450,9 +1450,9 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
|
||||
} else if (use_ht2 && use_nrar) {
|
||||
|
||||
|
||||
|
||||
memcpy(packet.NrAr, nrar, sizeof(packet.NrAr));
|
||||
|
||||
|
||||
PrintAndLogEx(INFO, _YELLOW_("Hitag 2") " - Challenge mode (NrAR)");
|
||||
|
||||
uint64_t t1 = msclock();
|
||||
@@ -1464,7 +1464,7 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
uint8_t attempt = 30;
|
||||
do {
|
||||
|
||||
PrintAndLogEx(INPLACE, "Attack 1 running..." );
|
||||
PrintAndLogEx(INPLACE, "Attack 1 running...");
|
||||
fflush(stdout);
|
||||
|
||||
if (WaitForResponseTimeout(CMD_LF_HITAG2_CRACK, &resp, 1000) == false) {
|
||||
@@ -1472,7 +1472,7 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lf_hitag_crack_response_t *payload = (lf_hitag_crack_response_t*)resp.data.asBytes;
|
||||
lf_hitag_crack_response_t *payload = (lf_hitag_crack_response_t *)resp.data.asBytes;
|
||||
|
||||
if (resp.status == PM3_SUCCESS) {
|
||||
PrintAndLogEx(NORMAL, " ( %s )", _GREEN_("ok"));
|
||||
@@ -1498,7 +1498,7 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
case -3: {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(FAILED, "Cannot find encrypted 'read page0' command!");
|
||||
return PM3_ESOFT;
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
case -4: {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
@@ -1508,7 +1508,7 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
}
|
||||
|
||||
} while (attempt);
|
||||
|
||||
|
||||
if (attempt == 0) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
@@ -1539,12 +1539,12 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
||||
|
||||
data = resp.data.asBytes;
|
||||
|
||||
out:
|
||||
out:
|
||||
|
||||
|
||||
// block3, 1 byte
|
||||
uid = bytes_to_num(data, HITAG_UID_SIZE);
|
||||
|
||||
|
||||
if (use_ht2) {
|
||||
print_hitag2_configuration(uid, data[HITAG_BLOCK_SIZE * 3]);
|
||||
print_hitag2_blocks(data, HITAG2_MAX_BYTE_SIZE);
|
||||
@@ -1915,7 +1915,7 @@ static int CmdLFHitag2Chk(const char *Cmd) {
|
||||
|
||||
uint64_t t1 = msclock();
|
||||
|
||||
// just loop twice at max. Starting with 4 or 6.
|
||||
// just loop twice at max. Starting with 4 or 6.
|
||||
for (; keylen < 7; keylen += 2) {
|
||||
// load keys
|
||||
uint8_t *keys = NULL;
|
||||
@@ -1934,7 +1934,7 @@ static int CmdLFHitag2Chk(const char *Cmd) {
|
||||
int status = ht2_check_dictionary(key_count, keys, keylen, &found_idx);
|
||||
|
||||
if (status == PM3_SUCCESS) {
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
if (keylen == 6) {
|
||||
PrintAndLogEx(SUCCESS, "found valid key [ " _GREEN_("%s") " ]", sprint_hex_inrow(keys + (found_idx * keylen), keylen));
|
||||
@@ -2037,17 +2037,17 @@ static int CmdLFHitag2Lookup(const char *Cmd) {
|
||||
// - crypto stream generated is in BE/MSB order in Pm3 code.
|
||||
// - crypto state is in ?
|
||||
// - lfsr state is in ?
|
||||
//
|
||||
//
|
||||
// Different implementations handles internally the state either in MSB or LSB.
|
||||
// Something to keep an eye for when looking at code.
|
||||
//
|
||||
//
|
||||
// Termology:
|
||||
// cs / hstate.shiftregister / crypto state = same
|
||||
// lsfr = some implementations mixes cs and lsfr into one and only use the state. Some differentiate between them.
|
||||
// usually the key recovery functions under /tools/hitag2crack
|
||||
// IV / Nonce Reader 1 / Nr1 = same (clear text), always 00 00 00 00 in PM3 code when acting as reader.
|
||||
// Answer Reader 1 / Ar1 = encrypted and BE/MSB, +32, the clear text is always FF FF FF FF.
|
||||
// Answer Tag 1 / At1 = encrypted and BE/MSB, +32,
|
||||
// IV / Nonce Reader 1 / Nr1 = same (clear text), always 00 00 00 00 in PM3 code when acting as reader.
|
||||
// Answer Reader 1 / Ar1 = encrypted and BE/MSB, +32, the clear text is always FF FF FF FF.
|
||||
// Answer Tag 1 / At1 = encrypted and BE/MSB, +32,
|
||||
|
||||
/*
|
||||
When initializer the crypto engine
|
||||
|
||||
+10
-10
@@ -736,9 +736,9 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||
|
||||
// mark short bytes (less than 8 Bit + Parity)
|
||||
if (protocol == ISO_14443A ||
|
||||
protocol == PROTO_MIFARE ||
|
||||
protocol == PROTO_MFPLUS ||
|
||||
protocol == THINFILM) {
|
||||
protocol == PROTO_MIFARE ||
|
||||
protocol == PROTO_MFPLUS ||
|
||||
protocol == THINFILM) {
|
||||
|
||||
// approximated with 128 * (9 * data_len);
|
||||
uint16_t bitime = 1056 + 32;
|
||||
@@ -978,14 +978,14 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||
}
|
||||
}
|
||||
|
||||
if (protocol == PROTO_HITAG2) {
|
||||
if (protocol == PROTO_HITAG2) {
|
||||
|
||||
uint8_t ht2plain[9] = {0};
|
||||
uint8_t n = 0;
|
||||
if (hitag2_get_plain(ht2plain, &n)) {
|
||||
|
||||
memset(explanation, 0x00, sizeof(explanation));
|
||||
|
||||
|
||||
// handle partial bytes. The parity array[0] is used to store number of left over bits from NBYTES
|
||||
// This part prints the number of bits in the trace entry for hitag.
|
||||
uint8_t nbits = parityBytes[0];
|
||||
@@ -1019,7 +1019,7 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||
|
||||
} else {
|
||||
snprintf(line[j / 18] + ((j % 18) * 4) + offset, 120, "%02X ", ht2plain[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
num_lines = MIN((n - 1) / TRACE_MAX_HEX_BYTES + 1, TRACE_MAX_HEX_BYTES);
|
||||
@@ -1041,7 +1041,7 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_last_record(tracepos, traceLen)) {
|
||||
return traceLen;
|
||||
@@ -1480,7 +1480,7 @@ int CmdTraceList(const char *Cmd) {
|
||||
if (diclen > 0) {
|
||||
uint8_t *keyBlock = NULL;
|
||||
int res = loadFileDICTIONARY_safe(dictionary, (void **) &keyBlock, 6, &dicKeysCount);
|
||||
if (res != PM3_SUCCESS || dicKeysCount == 0 || keyBlock == NULL) {
|
||||
if (res != PM3_SUCCESS || dicKeysCount == 0 || keyBlock == NULL) {
|
||||
PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)");
|
||||
} else {
|
||||
dicKeys = calloc(dicKeysCount, sizeof(uint64_t));
|
||||
@@ -1500,8 +1500,8 @@ int CmdTraceList(const char *Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( protocol == PROTO_HITAG2) {
|
||||
|
||||
if (protocol == PROTO_HITAG2) {
|
||||
|
||||
if (strlen(dictionary) == 0) {
|
||||
snprintf(dictionary, sizeof(dictionary), HITAG_DICTIONARY);
|
||||
}
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ size_t getFromGraphBufferEx(uint8_t *dest, size_t maxLen) {
|
||||
}
|
||||
|
||||
//TODO: In progress function to get chunks of data from the GB w/o modifying the GB
|
||||
//Currently seems like it doesn't work correctly?
|
||||
//Currently seems like it doesn't work correctly?
|
||||
size_t getGraphBufferChunk(uint8_t *dest, size_t start, size_t end) {
|
||||
if (dest == NULL) return 0;
|
||||
if (g_GraphTraceLen == 0) return 0;
|
||||
|
||||
@@ -742,7 +742,7 @@ static int DesfireExchangeISONative(bool activate_field, DesfireContext_t *ctx,
|
||||
pos += buflen;
|
||||
if (enable_chaining == false) {
|
||||
if (sw == DESFIRE_GET_ISO_STATUS(MFDES_S_OPERATION_OK) ||
|
||||
sw == DESFIRE_GET_ISO_STATUS(MFDES_ADDITIONAL_FRAME)) {
|
||||
sw == DESFIRE_GET_ISO_STATUS(MFDES_ADDITIONAL_FRAME)) {
|
||||
|
||||
if (resplen) {
|
||||
*resplen = pos;
|
||||
|
||||
@@ -626,13 +626,13 @@ static void DesfireSecureChannelDecodeEV1(DesfireContext_t *ctx, uint8_t *srcdat
|
||||
PrintAndLogEx(INFO, " calculated MAC: %s", sprint_hex(cmac, DesfireGetMACLength(ctx)));
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (GetAPDULogging()) {
|
||||
PrintAndLogEx(INFO, "Received MAC OK");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (ctx->commMode == DCMEncrypted || ctx->commMode == DCMEncryptedWithPadding) {
|
||||
} else if (ctx->commMode == DCMEncrypted || ctx->commMode == DCMEncryptedWithPadding) {
|
||||
|
||||
if (srcdatalen < desfire_get_key_block_length(ctx->keyType)) {
|
||||
memcpy(dstdata, srcdata, srcdatalen);
|
||||
|
||||
+1763
-1839
File diff suppressed because it is too large.
Load diff
+2275
-2320
File diff suppressed because it is too large.
Load diff
@@ -75,6 +75,15 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 1, "analyse foo" },
|
||||
{ 1, "analyse units" },
|
||||
{ 1, "data help" },
|
||||
{ 1, "data clear" },
|
||||
{ 1, "data hide" },
|
||||
{ 1, "data load" },
|
||||
{ 1, "data num" },
|
||||
{ 1, "data plot" },
|
||||
{ 1, "data print" },
|
||||
{ 1, "data save" },
|
||||
{ 1, "data setdebugmode" },
|
||||
{ 1, "data xor" },
|
||||
{ 1, "data biphaserawdecode" },
|
||||
{ 1, "data detectclock" },
|
||||
{ 1, "data fsktonrz" },
|
||||
@@ -83,43 +92,32 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 1, "data rawdemod" },
|
||||
{ 1, "data askedgedetect" },
|
||||
{ 1, "data autocorr" },
|
||||
{ 1, "data convertbitstream" },
|
||||
{ 1, "data cthreshold" },
|
||||
{ 1, "data dirthreshold" },
|
||||
{ 1, "data decimate" },
|
||||
{ 1, "data envelope" },
|
||||
{ 1, "data undecimate" },
|
||||
{ 1, "data hide" },
|
||||
{ 1, "data grid" },
|
||||
{ 1, "data getbitstream" },
|
||||
{ 1, "data hpf" },
|
||||
{ 1, "data iir" },
|
||||
{ 1, "data grid" },
|
||||
{ 1, "data ltrim" },
|
||||
{ 1, "data mtrim" },
|
||||
{ 1, "data norm" },
|
||||
{ 1, "data plot" },
|
||||
{ 1, "data cthreshold" },
|
||||
{ 1, "data rtrim" },
|
||||
{ 1, "data setgraphmarkers" },
|
||||
{ 1, "data shiftgraphzero" },
|
||||
{ 1, "data timescale" },
|
||||
{ 1, "data undecimate" },
|
||||
{ 1, "data zerocrossings" },
|
||||
{ 1, "data convertbitstream" },
|
||||
{ 1, "data getbitstream" },
|
||||
{ 1, "data asn1" },
|
||||
{ 1, "data atr" },
|
||||
{ 1, "data bin2hex" },
|
||||
{ 0, "data bitsamples" },
|
||||
{ 1, "data bmap" },
|
||||
{ 1, "data clear" },
|
||||
{ 1, "data crypto" },
|
||||
{ 1, "data diff" },
|
||||
{ 0, "data hexsamples" },
|
||||
{ 1, "data hex2bin" },
|
||||
{ 1, "data load" },
|
||||
{ 1, "data num" },
|
||||
{ 1, "data print" },
|
||||
{ 0, "data samples" },
|
||||
{ 1, "data save" },
|
||||
{ 1, "data setdebugmode" },
|
||||
{ 1, "data xor" },
|
||||
{ 1, "emv help" },
|
||||
{ 1, "emv list" },
|
||||
{ 1, "emv test" },
|
||||
@@ -558,11 +556,11 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 0, "lf sniff" },
|
||||
{ 0, "lf tune" },
|
||||
{ 1, "lf awid help" },
|
||||
{ 0, "lf awid brute" },
|
||||
{ 0, "lf awid clone" },
|
||||
{ 1, "lf awid demod" },
|
||||
{ 0, "lf awid reader" },
|
||||
{ 0, "lf awid clone" },
|
||||
{ 0, "lf awid sim" },
|
||||
{ 0, "lf awid brute" },
|
||||
{ 0, "lf awid watch" },
|
||||
{ 1, "lf cotag help" },
|
||||
{ 1, "lf cotag demod" },
|
||||
@@ -647,16 +645,19 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 1, "lf hitag help" },
|
||||
{ 1, "lf hitag list" },
|
||||
{ 0, "lf hitag info" },
|
||||
{ 1, "lf hitag selftest" },
|
||||
{ 0, "lf hitag dump" },
|
||||
{ 0, "lf hitag read" },
|
||||
{ 0, "lf hitag sniff" },
|
||||
{ 1, "lf hitag view" },
|
||||
{ 0, "lf hitag wrbl" },
|
||||
{ 0, "lf hitag sniff" },
|
||||
{ 0, "lf hitag cc" },
|
||||
{ 0, "lf hitag ta" },
|
||||
{ 0, "lf hitag eload" },
|
||||
{ 0, "lf hitag eview" },
|
||||
{ 0, "lf hitag sim" },
|
||||
{ 0, "lf hitag cc" },
|
||||
{ 0, "lf hitag chk" },
|
||||
{ 1, "lf hitag lookup" },
|
||||
{ 0, "lf hitag ta" },
|
||||
{ 1, "lf idteck help" },
|
||||
{ 1, "lf idteck demod" },
|
||||
{ 0, "lf idteck reader" },
|
||||
|
||||
@@ -138,12 +138,12 @@ extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char
|
||||
}
|
||||
|
||||
void add_temporary_marker(uint32_t position, const char *label) {
|
||||
if(g_TempMarkerSize == 0) { //Initialize the marker array
|
||||
g_TempMarkers = (marker_t*)calloc(1, sizeof(marker_t));
|
||||
if (g_TempMarkerSize == 0) { //Initialize the marker array
|
||||
g_TempMarkers = (marker_t *)calloc(1, sizeof(marker_t));
|
||||
} else { //add more space to the marker array using realloc()
|
||||
marker_t *temp = (marker_t*)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t)));
|
||||
marker_t *temp = (marker_t *)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t)));
|
||||
|
||||
if(temp == NULL) { //Unable to reallocate memory for a new marker
|
||||
if (temp == NULL) { //Unable to reallocate memory for a new marker
|
||||
PrintAndLogEx(FAILED, "Unable to allocate memory for a new temporary marker!");
|
||||
free(temp);
|
||||
return;
|
||||
@@ -155,10 +155,10 @@ void add_temporary_marker(uint32_t position, const char *label) {
|
||||
|
||||
g_TempMarkers[g_TempMarkerSize].pos = position;
|
||||
|
||||
char *markerLabel = (char*)calloc(1, strlen(label) + 1);
|
||||
char *markerLabel = (char *)calloc(1, strlen(label) + 1);
|
||||
strcpy(markerLabel, label);
|
||||
|
||||
if(strlen(markerLabel) > 30) {
|
||||
if (strlen(markerLabel) > 30) {
|
||||
PrintAndLogEx(WARNING, "Label for temporary marker too long! Trunicating...");
|
||||
markerLabel[30] = '\0';
|
||||
}
|
||||
@@ -171,7 +171,7 @@ void add_temporary_marker(uint32_t position, const char *label) {
|
||||
}
|
||||
|
||||
void remove_temporary_markers(void) {
|
||||
if(g_TempMarkerSize == 0) return;
|
||||
if (g_TempMarkerSize == 0) return;
|
||||
|
||||
memset(g_TempMarkers, 0x00, (g_TempMarkerSize * sizeof(marker_t)));
|
||||
free(g_TempMarkers);
|
||||
|
||||
+89
-89
@@ -598,7 +598,7 @@ void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) {
|
||||
}
|
||||
|
||||
void Plot::appendMax(int *buffer, size_t len, QRect plotRect) {
|
||||
if(len == 0) {
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -750,12 +750,12 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe
|
||||
painter->drawPath(penPath);
|
||||
char str[200];
|
||||
snprintf(str, sizeof(str), "max=%d min=%d mean=%" PRId64 " n=%u/%zu",
|
||||
vMax,
|
||||
vMin,
|
||||
vMean,
|
||||
g_GraphStop - g_GraphStart,
|
||||
len
|
||||
);
|
||||
vMax,
|
||||
vMin,
|
||||
vMean,
|
||||
g_GraphStop - g_GraphStart,
|
||||
len
|
||||
);
|
||||
|
||||
painter->drawText(20, annotationRect.bottom() - (48 - (12 * graphNum)), str);
|
||||
}
|
||||
@@ -781,37 +781,37 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
|
||||
|
||||
//Print the Graph Information
|
||||
char graphText[] = "@%u..%u dt=%i %s zoom=%2.3f";
|
||||
length = ((sizeof(graphText))+(sizeof(uint32_t)*3)+sizeof(scalestr)+sizeof(float_t));
|
||||
length = ((sizeof(graphText)) + (sizeof(uint32_t) * 3) + sizeof(scalestr) + sizeof(float_t));
|
||||
|
||||
annotation = (char*)calloc(1, length);
|
||||
annotation = (char *)calloc(1, length);
|
||||
|
||||
snprintf(annotation, length, graphText,
|
||||
g_GraphStart,
|
||||
g_GraphStop,
|
||||
g_MarkerB.pos - g_MarkerA.pos,
|
||||
scalestr,
|
||||
g_GraphPixelsPerPoint
|
||||
);
|
||||
g_GraphStart,
|
||||
g_GraphStop,
|
||||
g_MarkerB.pos - g_MarkerA.pos,
|
||||
scalestr,
|
||||
g_GraphPixelsPerPoint
|
||||
);
|
||||
|
||||
painter->setPen(GREEN);
|
||||
painter->drawText(82, annotationRect.bottom() - 62, annotation);
|
||||
|
||||
//Print Grid Information if the grid is enabled
|
||||
if(g_PlotGridX > 0) {
|
||||
if (g_PlotGridX > 0) {
|
||||
free(annotation);
|
||||
|
||||
const char *gridLocked = (g_GridLocked ? "Locked" : "Unlocked");
|
||||
char gridText[] = "GridX=%lf GridY=%lf (%s) GridXoffset=%lf";
|
||||
length = (sizeof(gridText) + (sizeof(double)*3) + sizeof(gridLocked));
|
||||
length = (sizeof(gridText) + (sizeof(double) * 3) + sizeof(gridLocked));
|
||||
|
||||
annotation = (char*)calloc(1, length);
|
||||
annotation = (char *)calloc(1, length);
|
||||
|
||||
snprintf(annotation, length, gridText,
|
||||
g_DefaultGridX,
|
||||
g_DefaultGridY,
|
||||
gridLocked,
|
||||
g_GridOffset
|
||||
);
|
||||
g_DefaultGridX,
|
||||
g_DefaultGridY,
|
||||
gridLocked,
|
||||
g_GridOffset
|
||||
);
|
||||
|
||||
painter->setPen(WHITE);
|
||||
painter->drawText(800, annotationRect.bottom() - 62, annotation);
|
||||
@@ -822,21 +822,21 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
|
||||
uint32_t pos = 0, loc = 375;
|
||||
painter->setPen(WHITE);
|
||||
|
||||
if(g_MarkerA.pos > 0) {
|
||||
if (g_MarkerA.pos > 0) {
|
||||
free(annotation);
|
||||
|
||||
length = (sizeof(markerText) + (sizeof(uint32_t)*3) + sizeof(" ") + 1);
|
||||
length = (sizeof(markerText) + (sizeof(uint32_t) * 3) + sizeof(" ") + 1);
|
||||
pos = g_MarkerA.pos;
|
||||
bool flag = false;
|
||||
size_t value;
|
||||
|
||||
annotation = (char*)calloc(1, length);
|
||||
char *textA = (char*)calloc(1, length);
|
||||
annotation = (char *)calloc(1, length);
|
||||
char *textA = (char *)calloc(1, length);
|
||||
|
||||
strcat(textA, markerText);
|
||||
strcat(textA, " (%s%u)");
|
||||
|
||||
if(g_GraphBuffer[pos] <= g_OperationBuffer[pos]) {
|
||||
if (g_GraphBuffer[pos] <= g_OperationBuffer[pos]) {
|
||||
flag = true;
|
||||
value = (g_OperationBuffer[pos] - g_GraphBuffer[pos]);
|
||||
} else {
|
||||
@@ -844,65 +844,65 @@ void Plot::drawAnnotations(QRect annotationRect, QPainter *painter) {
|
||||
}
|
||||
|
||||
snprintf(annotation, length, textA,
|
||||
"A",
|
||||
pos,
|
||||
g_GraphBuffer[pos],
|
||||
flag ? "+" : "-",
|
||||
value
|
||||
);
|
||||
"A",
|
||||
pos,
|
||||
g_GraphBuffer[pos],
|
||||
flag ? "+" : "-",
|
||||
value
|
||||
);
|
||||
|
||||
painter->drawText(loc, annotationRect.bottom() - 48, annotation);
|
||||
|
||||
free(textA);
|
||||
}
|
||||
|
||||
if(g_MarkerB.pos > 0) {
|
||||
if (g_MarkerB.pos > 0) {
|
||||
free(annotation);
|
||||
|
||||
length = ((sizeof(markerText))+(sizeof(uint32_t)*2)+1);
|
||||
length = ((sizeof(markerText)) + (sizeof(uint32_t) * 2) + 1);
|
||||
pos = g_MarkerB.pos;
|
||||
|
||||
annotation = (char*)calloc(1, length);
|
||||
annotation = (char *)calloc(1, length);
|
||||
|
||||
snprintf(annotation, length, markerText,
|
||||
"B",
|
||||
pos,
|
||||
g_GraphBuffer[pos]
|
||||
);
|
||||
"B",
|
||||
pos,
|
||||
g_GraphBuffer[pos]
|
||||
);
|
||||
|
||||
painter->drawText(loc, annotationRect.bottom() - 36, annotation);
|
||||
}
|
||||
|
||||
if(g_MarkerC.pos > 0) {
|
||||
if (g_MarkerC.pos > 0) {
|
||||
free(annotation);
|
||||
|
||||
length = ((sizeof(markerText))+(sizeof(uint32_t)*2)+1);
|
||||
length = ((sizeof(markerText)) + (sizeof(uint32_t) * 2) + 1);
|
||||
pos = g_MarkerC.pos;
|
||||
|
||||
annotation = (char*)calloc(1, length);
|
||||
annotation = (char *)calloc(1, length);
|
||||
|
||||
snprintf(annotation, length, markerText,
|
||||
"C",
|
||||
pos,
|
||||
g_GraphBuffer[pos]
|
||||
);
|
||||
"C",
|
||||
pos,
|
||||
g_GraphBuffer[pos]
|
||||
);
|
||||
|
||||
painter->drawText(loc, annotationRect.bottom() - 24, annotation);
|
||||
}
|
||||
|
||||
if(g_MarkerD.pos > 0) {
|
||||
if (g_MarkerD.pos > 0) {
|
||||
free(annotation);
|
||||
|
||||
length = ((sizeof(markerText))+(sizeof(uint32_t)*2)+1);
|
||||
length = ((sizeof(markerText)) + (sizeof(uint32_t) * 2) + 1);
|
||||
pos = g_MarkerD.pos;
|
||||
|
||||
annotation = (char*)calloc(1, length);
|
||||
annotation = (char *)calloc(1, length);
|
||||
|
||||
snprintf(annotation, length, markerText,
|
||||
"D",
|
||||
pos,
|
||||
g_GraphBuffer[pos]
|
||||
);
|
||||
"D",
|
||||
pos,
|
||||
g_GraphBuffer[pos]
|
||||
);
|
||||
|
||||
painter->drawText(loc, annotationRect.bottom() - 12, annotation);
|
||||
}
|
||||
@@ -951,7 +951,7 @@ void Plot::plotGridLines(QPainter *painter, QRect r) {
|
||||
}
|
||||
|
||||
void Plot::plotOperations(int *buffer, size_t len, QPainter *painter, QRect plotRect) {
|
||||
if(len == 0) {
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -973,10 +973,10 @@ void Plot::plotOperations(int *buffer, size_t len, QPainter *painter, QRect plot
|
||||
y = yCoordOf(current, plotRect, gs_absVMax);
|
||||
|
||||
//We only want to graph changes between the Graph Buffer and the Operation Buffer
|
||||
if(current == g_GraphBuffer[pos]) {
|
||||
if (current == g_GraphBuffer[pos]) {
|
||||
//If this point is the same, but the last point is different, we want to plot that line
|
||||
//as well
|
||||
if((pos == 0) || (prev == g_GraphBuffer[pos - 1])) {
|
||||
if ((pos == 0) || (prev == g_GraphBuffer[pos - 1])) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -1045,8 +1045,8 @@ void Plot::paintEvent(QPaintEvent *event) {
|
||||
// End graph drawing
|
||||
|
||||
//Draw the markers
|
||||
if(g_TempMarkerSize > 0) {
|
||||
for(int i = 0; i < g_TempMarkerSize; i++) {
|
||||
if (g_TempMarkerSize > 0) {
|
||||
for (int i = 0; i < g_TempMarkerSize; i++) {
|
||||
draw_marker(g_TempMarkers[i], plotRect, GRAY100, &painter);
|
||||
}
|
||||
}
|
||||
@@ -1074,15 +1074,15 @@ void Plot::draw_marker(marker_t marker, QRect plotRect, QColor color, QPainter *
|
||||
painter->setPen(color);
|
||||
|
||||
//If the marker is outside the buffer length, reset
|
||||
if(marker.pos > g_GraphTraceLen) {
|
||||
if (marker.pos > g_GraphTraceLen) {
|
||||
marker.pos = 0;
|
||||
}
|
||||
|
||||
//Make sure the marker is inside the current plot view to render
|
||||
if(marker.pos > g_GraphStart && xCoordOf(marker.pos, plotRect) < plotRect.right()) {
|
||||
if (marker.pos > g_GraphStart && xCoordOf(marker.pos, plotRect) < plotRect.right()) {
|
||||
painter->drawLine(xCoordOf(marker.pos, plotRect), plotRect.top(), xCoordOf(marker.pos, plotRect), plotRect.bottom());
|
||||
|
||||
if(strlen(marker.label) > 0) {
|
||||
if (strlen(marker.label) > 0) {
|
||||
painter->drawText(xCoordOf(marker.pos, plotRect) + 1, plotRect.top() + 12, marker.label);
|
||||
}
|
||||
}
|
||||
@@ -1295,7 +1295,7 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
offset = 1;
|
||||
} else {
|
||||
offset = int(ZOOM_LIMIT / g_GraphPixelsPerPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (event->key()) {
|
||||
@@ -1393,9 +1393,9 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9 + 9, _RED_("[ ") "/" _RED_(" ]"), "Move yellow marker left/right by 1 sample");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9 + 9, _RED_("{ ") "/" _RED_(" }"), "Move pink marker left/right by 1 sample");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9, " + " _RED_("Ctrl"), "... by 5 samples");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9 +9, _RED_("= ") "/" _RED_(" -"), "Add/Subtract to the plot point (Operation Buffer) over the yellow marker by 1");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9 + 9, _RED_("= ") "/" _RED_(" -"), "Add/Subtract to the plot point (Operation Buffer) over the yellow marker by 1");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9, " + " _RED_("Ctrl"), "... by 5");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9 +9, _RED_("+ ") "/" _RED_(" _"), "Add/Subtract to the plot point (Graph Buffer) over the yellow marker by 1");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9 + 9, _RED_("+ ") "/" _RED_(" _"), "Add/Subtract to the plot point (Graph Buffer) over the yellow marker by 1");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9, " + " _RED_("Ctrl"), "... by 5");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9, _RED_("h"), "Show this help");
|
||||
PrintAndLogEx(NORMAL, " %-*s%s", 25 + 9, _RED_("q"), "Close plot window");
|
||||
@@ -1441,9 +1441,9 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
if (g_GraphStart > startMax)
|
||||
g_GraphStart = startMax;
|
||||
break;
|
||||
|
||||
|
||||
case Qt::Key_Equal:
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_OperationBuffer[g_MarkerA.pos] += 5;
|
||||
} else {
|
||||
g_OperationBuffer[g_MarkerA.pos] += 1;
|
||||
@@ -1451,9 +1451,9 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
|
||||
RepaintGraphWindow();
|
||||
break;
|
||||
|
||||
|
||||
case Qt::Key_Minus:
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_OperationBuffer[g_MarkerA.pos] -= 5;
|
||||
} else {
|
||||
g_OperationBuffer[g_MarkerA.pos] -= 1;
|
||||
@@ -1463,7 +1463,7 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
break;
|
||||
|
||||
case Qt::Key_Plus:
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_GraphBuffer[g_MarkerA.pos] += 5;
|
||||
} else {
|
||||
g_GraphBuffer[g_MarkerA.pos] += 1;
|
||||
@@ -1471,9 +1471,9 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
|
||||
RepaintGraphWindow();
|
||||
break;
|
||||
|
||||
|
||||
case Qt::Key_Underscore:
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_GraphBuffer[g_MarkerA.pos] -= 5;
|
||||
} else {
|
||||
g_GraphBuffer[g_MarkerA.pos] -= 1;
|
||||
@@ -1483,77 +1483,77 @@ void Plot::keyPressEvent(QKeyEvent *event) {
|
||||
break;
|
||||
|
||||
case Qt::Key_BracketLeft: {
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_MarkerA.pos -= 5;
|
||||
} else {
|
||||
g_MarkerA.pos -= 1;
|
||||
}
|
||||
|
||||
if((g_MarkerA.pos >= g_GraphStop) || (g_MarkerA.pos <= g_GraphStart)) {
|
||||
if ((g_MarkerA.pos >= g_GraphStop) || (g_MarkerA.pos <= g_GraphStart)) {
|
||||
uint32_t halfway = PageWidth / 2;
|
||||
|
||||
if((g_MarkerA.pos - halfway) > g_GraphTraceLen) {
|
||||
if ((g_MarkerA.pos - halfway) > g_GraphTraceLen) {
|
||||
g_GraphStart = 0;
|
||||
} else {
|
||||
g_GraphStart = g_MarkerA.pos - halfway;
|
||||
}
|
||||
}
|
||||
|
||||
if(g_MarkerA.pos < g_GraphStart) {
|
||||
if (g_MarkerA.pos < g_GraphStart) {
|
||||
g_MarkerA.pos = g_GraphStart;
|
||||
}
|
||||
|
||||
RepaintGraphWindow();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case Qt::Key_BracketRight: {
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_MarkerA.pos += 5;
|
||||
} else {
|
||||
g_MarkerA.pos += 1;
|
||||
}
|
||||
|
||||
if((g_MarkerA.pos >= g_GraphStop) || (g_MarkerA.pos <= g_GraphStart)) {
|
||||
if ((g_MarkerA.pos >= g_GraphStop) || (g_MarkerA.pos <= g_GraphStart)) {
|
||||
uint32_t halfway = PageWidth / 2;
|
||||
|
||||
if((g_MarkerA.pos + halfway) >= g_GraphTraceLen) {
|
||||
if ((g_MarkerA.pos + halfway) >= g_GraphTraceLen) {
|
||||
g_GraphStart = g_GraphTraceLen - halfway;
|
||||
} else {
|
||||
g_GraphStart = g_MarkerA.pos - halfway;
|
||||
}
|
||||
}
|
||||
|
||||
if(g_MarkerA.pos >= g_GraphTraceLen) {
|
||||
if (g_MarkerA.pos >= g_GraphTraceLen) {
|
||||
g_MarkerA.pos = g_GraphTraceLen;
|
||||
}
|
||||
|
||||
RepaintGraphWindow();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case Qt::Key_BraceLeft:
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_MarkerB.pos -= 5;
|
||||
} else {
|
||||
g_MarkerB.pos -= 1;
|
||||
}
|
||||
|
||||
if(g_MarkerB.pos < g_GraphStart) {
|
||||
if (g_MarkerB.pos < g_GraphStart) {
|
||||
g_MarkerB.pos = g_GraphStart;
|
||||
}
|
||||
|
||||
|
||||
RepaintGraphWindow();
|
||||
break;
|
||||
|
||||
|
||||
case Qt::Key_BraceRight:
|
||||
if(event->modifiers() & Qt::ControlModifier) {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
g_MarkerB.pos += 5;
|
||||
} else {
|
||||
g_MarkerB.pos += 1;
|
||||
}
|
||||
|
||||
if(g_MarkerB.pos >= g_GraphTraceLen) {
|
||||
if (g_MarkerB.pos >= g_GraphTraceLen) {
|
||||
g_MarkerB.pos = g_GraphTraceLen;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user