Skip to content

Commit 30999db

Browse files
committed
Add flag output string to show users which flags have been solved
From main fork PR: hackgnar#28
1 parent 24284ee commit 30999db

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

main/gatts_table_creat_demo.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ static const uint8_t char_prop_crazy = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT
193193

194194
// start ctf data vars
195195
static char writeData[100];
196-
static char flag_state[19] = {'F','F','F','F','F','F','F','F','F','F','F','F','F','F','F','F','F','F','F'};
197-
static uint8_t score_read_value[11] = {'S', 'c', 'o', 'r', 'e', ':', ' ', '0','/','1','7'};
196+
static char flag_state[17] = {'F','F','F','F','F','F','F','F','F','F','F','F','F','F','F','F','F'};
197+
static uint8_t score_read_value[31] = "Score: 0/17 [FFFFFFFFFFFFFFFFF]";
198198
static const char write_any_flag[] = "Write anything here";
199199
static const char write_ascii_flag[] = "Write the ascii value \"GLaDOS\" here";
200200
static const char write_hex_flag[] = "Write the hex value 0x07 here";
@@ -215,7 +215,6 @@ static const uint8_t flag_read_value[16] = {'W','r','i','t','e', ' ', 'F', 'l','
215215
int read_alot_counter = 0;
216216
int read_counter = 0;
217217
int score = 0;
218-
static char string_score[10] = "0";
219218
int BLINK_GPIO=2;
220219
int indicate_handle_state = 0;
221220
int send_response=0;
@@ -462,14 +461,10 @@ static void set_score()
462461
score += 1;
463462
}
464463
}
465-
466-
itoa(score, string_score, 10);
467-
for (int i = 0 ; i < strlen(string_score) ; ++i)
468-
{
469-
if (strlen(string_score) == 1){
470-
score_read_value[7] = ' ';}
471-
score_read_value[6+i] = string_score[i];
472-
}
464+
465+
snprintf((char * restrict)&score_read_value[6], 3, "%2d", score);
466+
score_read_value[8] = '/'; //overwrite the null terminator from the snprintf
467+
strncpy((char * restrict)&score_read_value[13], flag_state, 17);
473468
esp_ble_gatts_set_attr_value(blectf_handle_table[IDX_CHAR_SCORE]+1, sizeof score_read_value, score_read_value);
474469
}
475470

0 commit comments

Comments
 (0)