Skip to content

Commit

Permalink
fix some potential empty responses and too much inline calls
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Aug 3, 2023
1 parent a2ea5e3 commit 24a138e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/deps/hardnested/hardnested_bf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ uint64_t CRACK_STATES_BITSLICED(uint32_t cuid, uint8_t *best_first_bytes, statel
for (uint32_t tests = 0; tests < nonces_to_bruteforce; ++tests) {
// common bits with preceding test nonce
uint32_t common_bits = next_common_bits; //tests ? trailing_zeros(bf_test_nonce_2nd_byte[tests] ^ bf_test_nonce_2nd_byte[tests-1]) : 0;
next_common_bits = tests < nonces_to_bruteforce - 1 ? trailing_zeros(bf_test_nonce_2nd_byte[tests] ^ bf_test_nonce_2nd_byte[tests + 1]) : 0;
next_common_bits = (tests < nonces_to_bruteforce - 1) ? trailing_zeros(bf_test_nonce_2nd_byte[tests] ^ bf_test_nonce_2nd_byte[tests + 1]) : 0;
uint32_t parity_bit_idx = 1; // start checking with the parity of second nonce byte
bitslice_value_t fb_bits = fbb[common_bits]; // start with precomputed feedback bits from previous nonce
bitslice_value_t ks_bits = ksb[common_bits]; // dito for first keystream bits
Expand Down
2 changes: 1 addition & 1 deletion client/deps/hardnested/hardnested_bruteforce.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static uint32_t keys_found = 0;
static uint64_t num_keys_tested;
static uint64_t found_bs_key = 0;

inline uint8_t trailing_zeros(uint8_t byte) {
uint8_t trailing_zeros(uint8_t byte) {
static const uint8_t trailing_zeros_LUT[256] = {
8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
Expand Down
11 changes: 11 additions & 0 deletions client/src/cmdlf.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ int CmdLFCommandRead(const char *Cmd) {
SendCommandNG(CMD_LF_MOD_THEN_ACQ_RAW_ADC, (uint8_t *)&payload, PAYLOAD_HEADER_SIZE + cmd_len);

PacketResponseNG resp;
// init to ZERO
resp.cmd = 0,
resp.length = 0,
resp.magic = 0,
resp.status = 0,
resp.crc = 0,
resp.ng = false,
resp.oldarg[0] = 0;
resp.oldarg[1] = 0;
resp.oldarg[2] = 0;
memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE);

i = 10;
// 20sec wait loop
Expand Down
17 changes: 15 additions & 2 deletions client/src/cmdlfem4x50.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,9 +1230,22 @@ int CmdEM4x50Sim(const char *Cmd) {

clearCommandBuffer();
SendCommandNG(CMD_LF_EM4X50_SIM, (uint8_t *)&password, sizeof(password));
PacketResponseNG resp;


PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " or pm3-button to abort simulation");

PacketResponseNG resp;
// init to ZERO
resp.cmd = 0,
resp.length = 0,
resp.magic = 0,
resp.status = 0,
resp.crc = 0,
resp.ng = false,
resp.oldarg[0] = 0;
resp.oldarg[1] = 0;
resp.oldarg[2] = 0;
memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE);

bool keypress;
do {
keypress = kbd_enter_pressed();
Expand Down
8 changes: 4 additions & 4 deletions client/src/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,6 @@ static size_t communication_delay(void) {
bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms_timeout, bool show_warning) {

PacketResponseNG resp;
if (response == NULL) {
response = &resp;
}

// init to ZERO
resp.cmd = 0,
resp.length = 0,
Expand All @@ -758,6 +754,10 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
resp.oldarg[2] = 0;
memset(resp.data.asBytes, 0, PM3_CMD_DATA_SIZE);

if (response == NULL) {
response = &resp;
}

// Add delay depending on the communication channel & speed
if (ms_timeout != (size_t) - 1)
ms_timeout += communication_delay();
Expand Down

0 comments on commit 24a138e

Please sign in to comment.