From 451a320920c6e2f60445938aa98d4fe817c3d36a Mon Sep 17 00:00:00 2001 From: Mosder Date: Tue, 15 Sep 2026 15:52:47 +0200 Subject: formatting: run codebase through new .clang-format --- analyzer/analyzer.c | 13 ++++++-- analyzer/analyzer.h | 6 ++-- analyzer/commands.c | 12 +++++-- analyzer/parser/fight_results/drif.h | 6 ++-- analyzer/parser/fight_results/entity.h | 30 ++++++++++------- analyzer/parser/fight_results/fight_results.c | 48 ++++++++++++++++++++++----- analyzer/parser/fight_results/gear.h | 15 ++++++--- analyzer/parser/fight_results/gear_info.h | 18 ++++++---- analyzer/parser/parser.c | 17 +++++++--- analyzer/parser/parser.h | 3 +- analyzer/parser/structs.c | 9 ++++- analyzer/parser/structs.h | 9 ++++- analyzer/render.c | 20 +++++++++-- analyzer/render.h | 6 ++-- analyzer/structures/array.c | 4 ++- analyzer/structures/hashmap.h | 6 ++-- analyzer/structures/heap.h | 6 ++-- analyzer/utils/tcp.c | 11 +++--- analyzer/utils/tcp.h | 7 ++-- analyzer/utils/time.c | 11 +++++- csv_table_gen.c | 17 ++++++++-- 21 files changed, 206 insertions(+), 68 deletions(-) diff --git a/analyzer/analyzer.c b/analyzer/analyzer.c index 194ac5c..fc64957 100644 --- a/analyzer/analyzer.c +++ b/analyzer/analyzer.c @@ -24,7 +24,8 @@ void cleanup_str_pointer(void *str_pointer) { // initalize new total rewards TotalRewards new_total_rewards() { - HashMap *saturations = hashmap_new(sizeof(const char *), sizeof(int), hash_str, compare_strs, NULL, NULL); + HashMap *saturations = + hashmap_new(sizeof(const char *), sizeof(int), hash_str, compare_strs, NULL, NULL); TotalRewards rewards = { .exp = 0, .gold = 0, @@ -38,7 +39,9 @@ TotalRewards new_total_rewards() { // initalize file analysis state FileAnalState init_file_anal_state() { - HashMap *characters = hashmap_new(sizeof(char *), sizeof(TotalRewards), hash_str, compare_strs, NULL, cleanup_total_rewards); + HashMap *characters = hashmap_new( + sizeof(char *), sizeof(TotalRewards), hash_str, compare_strs, NULL, cleanup_total_rewards + ); FileAnalState state = {.fight_count = 0, .curr_character = {0}, .characters = characters}; return state; } @@ -114,7 +117,11 @@ void file_parsed_data_handler(void *state, DynArray parsed_data) { // loop through packets received from pcap_handle and analyze the TCP streams void analyzer_loop( - TCPStream *server_stream, TCPStream *client_stream, pcap_t *pcap_handle, void *state, void (*parsed_data_handler)(void *state, DynArray parsed_data) + TCPStream *server_stream, + TCPStream *client_stream, + pcap_t *pcap_handle, + void *state, + void (*parsed_data_handler)(void *state, DynArray parsed_data) ) { // read packets from handle struct pcap_pkthdr *packet_data; diff --git a/analyzer/analyzer.h b/analyzer/analyzer.h index 15bddf2..9e50976 100644 --- a/analyzer/analyzer.h +++ b/analyzer/analyzer.h @@ -1,9 +1,9 @@ // analyzer.h // functions for analyzing the packets received from the game server -#include "structures/hashmap.h" -#include "structures/array.h" #include "parser/fight_results/fight_results.h" +#include "structures/array.h" +#include "structures/hashmap.h" #ifndef ANALYZER_H #define ANALYZER_H @@ -20,7 +20,7 @@ typedef struct { typedef struct { size_t fight_count; - char curr_character[MAX_NAME_LENGTH+1]; + char curr_character[MAX_NAME_LENGTH + 1]; HashMap *characters; // nick -> TotalRewards } FileAnalState; diff --git a/analyzer/commands.c b/analyzer/commands.c index 706a8f2..ff06dca 100644 --- a/analyzer/commands.c +++ b/analyzer/commands.c @@ -86,7 +86,13 @@ int file_anal(int argc, char *argv[]) { const Command help_command = {"help", "h", "", {"display this help"}, 1, print_help}; const Command commands[] = { {"live", "l", "", {"start live analysis"}, 1, live_anal}, - {"capture", "c", "[file]", {"start capturing packers to file", "If file isn't provided - captures to: $HOME/.local/share/branal/captures"}, 2, capture}, + {"capture", + "c", + "[file]", + {"start capturing packers to file", + "If file isn't provided - captures to: $HOME/.local/share/branal/captures"}, + 2, + capture}, {"file", "f", "", {"analyze the specified file(s)"}, 1, file_anal}, help_command }; @@ -98,5 +104,7 @@ int is_command(Command command, char *str) { void command_not_recognized(const char *prog_name) { printf("Command not recognized\n"); - printf("Use \"%s (%s | %s)\" for help\n", prog_name, help_command.short_name, help_command.name); + printf( + "Use \"%s (%s | %s)\" for help\n", prog_name, help_command.short_name, help_command.name + ); } diff --git a/analyzer/parser/fight_results/drif.h b/analyzer/parser/fight_results/drif.h index 1f8b3e2..d73e948 100644 --- a/analyzer/parser/fight_results/drif.h +++ b/analyzer/parser/fight_results/drif.h @@ -16,8 +16,10 @@ typedef struct { char *field4; int field5; int id; // id of orb type - float value1; // value1, value2 (in %) - one is start value, the other is value per lvl (both are the same) - float value2; // value1, value2 (in %) - one is start value, the other is value per lvl (both are the same) + float value1; // value1, value2 (in %) - one is start value, the other is value per lvl (both + // are the same) + float value2; // value1, value2 (in %) - one is start value, the other is value per lvl (both + // are the same) int field9; int field10; char *field11; diff --git a/analyzer/parser/fight_results/entity.h b/analyzer/parser/fight_results/entity.h index 8e082ec..4436f07 100644 --- a/analyzer/parser/fight_results/entity.h +++ b/analyzer/parser/fight_results/entity.h @@ -52,16 +52,22 @@ typedef struct { } EntityResults; static const StructField entity_fields[] = { - {INT, offsetof(EntityResults, team)}, {STRING, offsetof(EntityResults, name)}, {INT, offsetof(EntityResults, exp)}, - {FLOAT, offsetof(EntityResults, field4)}, {INT, offsetof(EntityResults, gold)}, {FLOAT, offsetof(EntityResults, field6)}, - {STRING, offsetof(EntityResults, field7)}, {STRING, offsetof(EntityResults, gear)}, {INT, offsetof(EntityResults, field9)}, - {STRING, offsetof(EntityResults, items)}, {INT, offsetof(EntityResults, field11)}, {INT, offsetof(EntityResults, field12)}, - {FLOAT, offsetof(EntityResults, field13)}, {FLOAT, offsetof(EntityResults, field14)}, {FLOAT, offsetof(EntityResults, field15)}, - {INT, offsetof(EntityResults, level)}, {DOUBLE, offsetof(EntityResults, field17)}, {FLOAT, offsetof(EntityResults, field18)}, - {INT, offsetof(EntityResults, field19)}, {INT, offsetof(EntityResults, field20)}, {FLOAT, offsetof(EntityResults, field21)}, - {FLOAT, offsetof(EntityResults, field22)}, {INT, offsetof(EntityResults, field23)}, {INT, offsetof(EntityResults, field24)}, - {INT, offsetof(EntityResults, psycho)}, {STRING, offsetof(EntityResults, drifs)}, {INT, offsetof(EntityResults, splinters)}, - {INT, offsetof(EntityResults, field28)}, {STRING, offsetof(EntityResults, field29)}, {INT, offsetof(EntityResults, field30)}, - {INT, offsetof(EntityResults, field31)}, {INT, offsetof(EntityResults, field32)}, {INT, offsetof(EntityResults, field33)}, - {STRING, offsetof(EntityResults, field34)}, {STRING, offsetof(EntityResults, saturation)}, + {INT, offsetof(EntityResults, team)}, {STRING, offsetof(EntityResults, name)}, + {INT, offsetof(EntityResults, exp)}, {FLOAT, offsetof(EntityResults, field4)}, + {INT, offsetof(EntityResults, gold)}, {FLOAT, offsetof(EntityResults, field6)}, + {STRING, offsetof(EntityResults, field7)}, {STRING, offsetof(EntityResults, gear)}, + {INT, offsetof(EntityResults, field9)}, {STRING, offsetof(EntityResults, items)}, + {INT, offsetof(EntityResults, field11)}, {INT, offsetof(EntityResults, field12)}, + {FLOAT, offsetof(EntityResults, field13)}, {FLOAT, offsetof(EntityResults, field14)}, + {FLOAT, offsetof(EntityResults, field15)}, {INT, offsetof(EntityResults, level)}, + {DOUBLE, offsetof(EntityResults, field17)}, {FLOAT, offsetof(EntityResults, field18)}, + {INT, offsetof(EntityResults, field19)}, {INT, offsetof(EntityResults, field20)}, + {FLOAT, offsetof(EntityResults, field21)}, {FLOAT, offsetof(EntityResults, field22)}, + {INT, offsetof(EntityResults, field23)}, {INT, offsetof(EntityResults, field24)}, + {INT, offsetof(EntityResults, psycho)}, {STRING, offsetof(EntityResults, drifs)}, + {INT, offsetof(EntityResults, splinters)}, {INT, offsetof(EntityResults, field28)}, + {STRING, offsetof(EntityResults, field29)}, {INT, offsetof(EntityResults, field30)}, + {INT, offsetof(EntityResults, field31)}, {INT, offsetof(EntityResults, field32)}, + {INT, offsetof(EntityResults, field33)}, {STRING, offsetof(EntityResults, field34)}, + {STRING, offsetof(EntityResults, saturation)}, }; diff --git a/analyzer/parser/fight_results/fight_results.c b/analyzer/parser/fight_results/fight_results.c index f79d113..9087f70 100644 --- a/analyzer/parser/fight_results/fight_results.c +++ b/analyzer/parser/fight_results/fight_results.c @@ -46,7 +46,9 @@ byte_t *find_fight_results(byte_t *bytes, size_t bytes_count, int *length) { byte_t *start = memmem(bytes, bytes_count, FIGHT_RESULTS_START, strlen(FIGHT_RESULTS_START)); byte_t *end = NULL; if (start) - end = memmem(start, bytes_count - (start - bytes), FIGHT_RESULTS_END, strlen(FIGHT_RESULTS_END)); + end = memmem( + start, bytes_count - (start - bytes), FIGHT_RESULTS_END, strlen(FIGHT_RESULTS_END) + ); *length = end ? (int)(end - start + strlen(FIGHT_RESULTS_END)) : -1; return start; } @@ -73,7 +75,14 @@ void add_gear(DynArray *items, char *gears_str) { // get gear info for rank, name and stars / syng level GearInfo gear_info = {0}; - fill_struct(&gear_info, gear_info_fields, ARR_LEN(gear_info_fields), gear.info, strlen(gear.info), SEPARATOR_GEAR_INFO_FIELD); + fill_struct( + &gear_info, + gear_info_fields, + ARR_LEN(gear_info_fields), + gear.info, + strlen(gear.info), + SEPARATOR_GEAR_INFO_FIELD + ); // create the buffer of information about gear char buffer[SINGLE_ITEM_BUFFER_LEN]; @@ -121,10 +130,22 @@ void add_gear(DynArray *items, char *gears_str) { // add orb to items if it exists if (strlen(gear.orb)) { Orb orb = {0}; - fill_struct(&orb, orb_fields, ARR_LEN(orb_fields), gear.orb, strlen(gear.orb), SEPARATOR_ORB_FIELD); + fill_struct( + &orb, + orb_fields, + ARR_LEN(orb_fields), + gear.orb, + strlen(gear.orb), + SEPARATOR_ORB_FIELD + ); char buffer[SINGLE_ITEM_BUFFER_LEN]; - sprintf(buffer, "%sorb %s", get_artifact_size_from_id(orb.size), get_orb_name_from_id(orb.id)); + sprintf( + buffer, + "%sorb %s", + get_artifact_size_from_id(orb.size), + get_orb_name_from_id(orb.id) + ); Item item = {.data = strdup(buffer), .type = ORB}; array_append(items, &item); @@ -215,7 +236,9 @@ EnemyResults parse_to_enemy(EntityResults entity_results) { } ParsedData parse_fight_results(byte_t *data, size_t length) { - ParsedData parsed_data = {.data_type = TYPE_FIGHT_RESULTS, .data_cleanup = cleanup_fight_results}; + ParsedData parsed_data = { + .data_type = TYPE_FIGHT_RESULTS, .data_cleanup = cleanup_fight_results + }; // ignore start and end indicators data += strlen(FIGHT_RESULTS_START); @@ -223,8 +246,10 @@ ParsedData parse_fight_results(byte_t *data, size_t length) { FightResults *results = safe_malloc(sizeof(FightResults)); - results->friendly_results = array_new(sizeof(FriendlyResults), INIT_ENTITIES_PER_SIDE, cleanup_friendly_results); - results->enemy_results = array_new(sizeof(EnemyResults), INIT_ENTITIES_PER_SIDE, cleanup_enemy_results); + results->friendly_results = + array_new(sizeof(FriendlyResults), INIT_ENTITIES_PER_SIDE, cleanup_friendly_results); + results->enemy_results = + array_new(sizeof(EnemyResults), INIT_ENTITIES_PER_SIDE, cleanup_enemy_results); byte_t *entity_separator; do { @@ -232,7 +257,14 @@ ParsedData parse_fight_results(byte_t *data, size_t length) { entity_separator = memmem(data, length, SEPARATOR_ENTITY, strlen(SEPARATOR_ENTITY)); size_t len = entity_separator ? (size_t)(entity_separator - data) : length; EntityResults entity_results = {0}; - fill_struct(&entity_results, entity_fields, ARR_LEN(entity_fields), (char *)data, len, SEPARATOR_ENTITY_FIELD); + fill_struct( + &entity_results, + entity_fields, + ARR_LEN(entity_fields), + (char *)data, + len, + SEPARATOR_ENTITY_FIELD + ); // depending on team - parse it into friendly or enemy results switch (entity_results.team) { diff --git a/analyzer/parser/fight_results/gear.h b/analyzer/parser/fight_results/gear.h index 66f52f3..a311262 100644 --- a/analyzer/parser/fight_results/gear.h +++ b/analyzer/parser/fight_results/gear.h @@ -37,9 +37,14 @@ typedef struct { } Gear; static const StructField gear_fields[] = { - {STRING, offsetof(Gear, stats)}, {STRING, offsetof(Gear, resistances)}, {STRING, offsetof(Gear, info)}, {STRING, offsetof(Gear, reqs)}, - {STRING, offsetof(Gear, field5)}, {STRING, offsetof(Gear, psycho)}, {STRING, offsetof(Gear, field7)}, {STRING, offsetof(Gear, field8)}, - {STRING, offsetof(Gear, field9)}, {STRING, offsetof(Gear, syng_tier)}, {INT, offsetof(Gear, field11)}, {INT, offsetof(Gear, field12)}, - {INT, offsetof(Gear, field13)}, {STRING, offsetof(Gear, field14)}, {INT, offsetof(Gear, type)}, {INT, offsetof(Gear, field16)}, - {STRING, offsetof(Gear, orb)}, {STRING, offsetof(Gear, field18)}, {STRING, offsetof(Gear, field19)}, + {STRING, offsetof(Gear, stats)}, {STRING, offsetof(Gear, resistances)}, + {STRING, offsetof(Gear, info)}, {STRING, offsetof(Gear, reqs)}, + {STRING, offsetof(Gear, field5)}, {STRING, offsetof(Gear, psycho)}, + {STRING, offsetof(Gear, field7)}, {STRING, offsetof(Gear, field8)}, + {STRING, offsetof(Gear, field9)}, {STRING, offsetof(Gear, syng_tier)}, + {INT, offsetof(Gear, field11)}, {INT, offsetof(Gear, field12)}, + {INT, offsetof(Gear, field13)}, {STRING, offsetof(Gear, field14)}, + {INT, offsetof(Gear, type)}, {INT, offsetof(Gear, field16)}, + {STRING, offsetof(Gear, orb)}, {STRING, offsetof(Gear, field18)}, + {STRING, offsetof(Gear, field19)}, }; diff --git a/analyzer/parser/fight_results/gear_info.h b/analyzer/parser/fight_results/gear_info.h index f0cf83a..f9bd103 100644 --- a/analyzer/parser/fight_results/gear_info.h +++ b/analyzer/parser/fight_results/gear_info.h @@ -35,10 +35,16 @@ typedef struct { } GearInfo; static const StructField gear_info_fields[] = { - {STRING, offsetof(GearInfo, name)}, {INT, offsetof(GearInfo, field2)}, {INT, offsetof(GearInfo, lvl)}, {INT, offsetof(GearInfo, price)}, - {INT, offsetof(GearInfo, field5)}, {INT, offsetof(GearInfo, field6)}, {INT, offsetof(GearInfo, field7)}, {INT, offsetof(GearInfo, rank)}, - {INT, offsetof(GearInfo, field9)}, {INT, offsetof(GearInfo, field10)}, {INT, offsetof(GearInfo, field11)}, {INT, offsetof(GearInfo, durability)}, - {STRING, offsetof(GearInfo, field13)}, {INT, offsetof(GearInfo, field14)}, {INT, offsetof(GearInfo, field15)}, {FLOAT, offsetof(GearInfo, charges)}, - {STRING, offsetof(GearInfo, field17)}, {INT, offsetof(GearInfo, field18)}, {INT, offsetof(GearInfo, stars)}, {INT, offsetof(GearInfo, field20)}, - {INT, offsetof(GearInfo, field21)}, {INT, offsetof(GearInfo, field22)}, {INT, offsetof(GearInfo, field23)}, + {STRING, offsetof(GearInfo, name)}, {INT, offsetof(GearInfo, field2)}, + {INT, offsetof(GearInfo, lvl)}, {INT, offsetof(GearInfo, price)}, + {INT, offsetof(GearInfo, field5)}, {INT, offsetof(GearInfo, field6)}, + {INT, offsetof(GearInfo, field7)}, {INT, offsetof(GearInfo, rank)}, + {INT, offsetof(GearInfo, field9)}, {INT, offsetof(GearInfo, field10)}, + {INT, offsetof(GearInfo, field11)}, {INT, offsetof(GearInfo, durability)}, + {STRING, offsetof(GearInfo, field13)}, {INT, offsetof(GearInfo, field14)}, + {INT, offsetof(GearInfo, field15)}, {FLOAT, offsetof(GearInfo, charges)}, + {STRING, offsetof(GearInfo, field17)}, {INT, offsetof(GearInfo, field18)}, + {INT, offsetof(GearInfo, stars)}, {INT, offsetof(GearInfo, field20)}, + {INT, offsetof(GearInfo, field21)}, {INT, offsetof(GearInfo, field22)}, + {INT, offsetof(GearInfo, field23)}, }; diff --git a/analyzer/parser/parser.c b/analyzer/parser/parser.c index 9265153..48f26bb 100644 --- a/analyzer/parser/parser.c +++ b/analyzer/parser/parser.c @@ -14,7 +14,12 @@ void cleanup_parsed_data(void *parsed_data) { } // find earliest data to parse in stream -byte_t *find_earliest_data(TCPStream *stream, size_t stream_offset, int *earliest_length, parse_function_t **earliest_parse_fun) { +byte_t *find_earliest_data( + TCPStream *stream, + size_t stream_offset, + int *earliest_length, + parse_function_t **earliest_parse_fun +) { byte_t *earliest_data = NULL; for (size_t i = 0; i < ARR_LEN(all_find_parse_functions); i++) { // ignore if not correct stream @@ -22,7 +27,9 @@ byte_t *find_earliest_data(TCPStream *stream, size_t stream_offset, int *earlies continue; int length; - byte_t *data = all_find_parse_functions[i].find_fn(stream->bytes.data + stream_offset, stream->bytes.count - stream_offset, &length); + byte_t *data = all_find_parse_functions[i].find_fn( + stream->bytes.data + stream_offset, stream->bytes.count - stream_offset, &length + ); // if it's the first found or earlier than earliest - save it if (data && (!earliest_data || data < earliest_data)) { earliest_data = data; @@ -34,7 +41,8 @@ byte_t *find_earliest_data(TCPStream *stream, size_t stream_offset, int *earlies } DynArray parse_stream(TCPStream *stream, size_t *parsed_len) { - DynArray parsed_data = array_new(sizeof(ParsedData), INIT_PARSED_DATA_CAPACITY, cleanup_parsed_data); + DynArray parsed_data = + array_new(sizeof(ParsedData), INIT_PARSED_DATA_CAPACITY, cleanup_parsed_data); size_t stream_offset = 0; byte_t *earliest_data; @@ -42,7 +50,8 @@ DynArray parse_stream(TCPStream *stream, size_t *parsed_len) { // find earliest data to parse int earliest_length; parse_function_t *earliest_parse_fun; - earliest_data = find_earliest_data(stream, stream_offset, &earliest_length, &earliest_parse_fun); + earliest_data = + find_earliest_data(stream, stream_offset, &earliest_length, &earliest_parse_fun); // if start of data to parse was found, but not the end, then finish here // set parsed_len, so that the beginning of that data is at the beginning of the stream diff --git a/analyzer/parser/parser.h b/analyzer/parser/parser.h index 221d3bd..14ab75e 100644 --- a/analyzer/parser/parser.h +++ b/analyzer/parser/parser.h @@ -9,7 +9,8 @@ // parse a stream of TCP data // params: // - stream - the stream to parse -// - parsed_len - pointer to inform how much of the stream was parsed (not all if e.g. start of data is there, but the end isn't yet) +// - parsed_len - pointer to inform how much of the stream was parsed (not all if e.g. start of +// data is there, but the end isn't yet) // returns: // array of parsed data extern DynArray parse_stream(TCPStream *stream, size_t *parsed_len); diff --git a/analyzer/parser/structs.c b/analyzer/parser/structs.c index 28376e5..4b58343 100644 --- a/analyzer/parser/structs.c +++ b/analyzer/parser/structs.c @@ -6,7 +6,14 @@ #include "utils/memory.h" -void fill_struct(void *obj, const StructField *fields, size_t n_fields, const char *data, size_t data_len, const char *sep) { +void fill_struct( + void *obj, + const StructField *fields, + size_t n_fields, + const char *data, + size_t data_len, + const char *sep +) { for (size_t i = 0; i < n_fields; i++) { char *next_sep = memmem(data, data_len, sep, strlen(sep)); size_t len = next_sep ? (size_t)(next_sep - data) : data_len; diff --git a/analyzer/parser/structs.h b/analyzer/parser/structs.h index 023c19b..68a1809 100644 --- a/analyzer/parser/structs.h +++ b/analyzer/parser/structs.h @@ -21,7 +21,14 @@ typedef struct { // - data - data to fill the struct with // - data_len - length of the data // - sep - separator seperating the fields in data -extern void fill_struct(void *obj, const StructField *fields, size_t n_fields, const char *data, size_t data_len, const char *sep); +extern void fill_struct( + void *obj, + const StructField *fields, + size_t n_fields, + const char *data, + size_t data_len, + const char *sep +); // cleanup allocations inside generic struct // params: diff --git a/analyzer/render.c b/analyzer/render.c index cd4835d..e888b49 100644 --- a/analyzer/render.c +++ b/analyzer/render.c @@ -46,7 +46,13 @@ void print_enemy_list(DynArray enemies) { EnemyResults *enemy = NULL; while ((enemy = array_next(enemies, enemy))) { char enemy_buffer[TABLE_LINE_WIDTH + 1]; - sprintf(enemy_buffer, "%s (%d)%s", enemy->name, enemy->level, array_next(enemies, enemy) ? ", " : ""); + sprintf( + enemy_buffer, + "%s (%d)%s", + enemy->name, + enemy->level, + array_next(enemies, enemy) ? ", " : "" + ); // break line if length would be too big if (line_length + utf8_strlen(enemy_buffer) > TABLE_LINE_WIDTH - TABLE_LINE_END_WIDTH) { @@ -134,7 +140,11 @@ void print_player_rewards(FriendlyResults results) { char *sep = array_next(results.items, item) ? ", " : ""; size_t item_len = utf8_strlen(item->data) + strlen(sep); if (line_len + item_len > TABLE_ITEMS_WIDTH) { - printf("%*s" TABLE_LINE_END "\n" TABLE_LINE_START, (int)(TABLE_ITEMS_WIDTH - line_len), ""); + printf( + "%*s" TABLE_LINE_END "\n" TABLE_LINE_START, + (int)(TABLE_ITEMS_WIDTH - line_len), + "" + ); line_len = 0; } print_color(item->data, item_type_to_color(item->type)); @@ -203,7 +213,11 @@ void render_total_rewards(TotalRewards rewards) { char *sep = array_next(rewards.items[i], item) ? ", " : ""; size_t item_len = utf8_strlen(*item) + strlen(sep); if (line_len + item_len > TABLE_ITEMS_WIDTH) { - printf("%*s" TABLE_LINE_END "\n" TABLE_LINE_START, (int)(TABLE_ITEMS_WIDTH - line_len), ""); + printf( + "%*s" TABLE_LINE_END "\n" TABLE_LINE_START, + (int)(TABLE_ITEMS_WIDTH - line_len), + "" + ); line_len = 0; } print_color(*item, item_type_to_color(i)); diff --git a/analyzer/render.h b/analyzer/render.h index 7ad2e92..6c9f844 100644 --- a/analyzer/render.h +++ b/analyzer/render.h @@ -1,9 +1,9 @@ // render.h // functions for "rendering" data onto the terminal +#include "analyzer.h" #include "parser/fight_results/fight_results.h" #include "utils/memory.h" -#include "analyzer.h" // ANSI escape sequence colors #define COLOR_GOLD 33 @@ -46,7 +46,9 @@ inline static size_t sum_col_widths() { return sum; } -#define TABLE_LINE_WIDTH (TABLE_LINE_START_WIDTH + sum_col_widths() + (ARR_LEN(columns) - 1) * TABLE_LINE_SEPARATOR_WIDTH + TABLE_LINE_END_WIDTH) +#define TABLE_LINE_WIDTH \ + (TABLE_LINE_START_WIDTH + sum_col_widths() + \ + (ARR_LEN(columns) - 1) * TABLE_LINE_SEPARATOR_WIDTH + TABLE_LINE_END_WIDTH) #define TABLE_ITEMS_WIDTH (TABLE_LINE_WIDTH - TABLE_LINE_START_WIDTH - TABLE_LINE_END_WIDTH) diff --git a/analyzer/structures/array.c b/analyzer/structures/array.c index 7c7d4f8..faaed60 100644 --- a/analyzer/structures/array.c +++ b/analyzer/structures/array.c @@ -80,7 +80,9 @@ void array_remove_front(DynArray *array, size_t to_remove) { } array->count -= to_remove; - memmove(array->data, (char *)array->data + to_remove * array->el_size, array->count * array->el_size); + memmove( + array->data, (char *)array->data + to_remove * array->el_size, array->count * array->el_size + ); } void array_remove_back(DynArray *array, size_t to_remove) { diff --git a/analyzer/structures/hashmap.h b/analyzer/structures/hashmap.h index 7559010..227b15b 100644 --- a/analyzer/structures/hashmap.h +++ b/analyzer/structures/hashmap.h @@ -40,11 +40,13 @@ typedef struct { // - key2 - pointer to the second of the keys to compare // returns: // truthy if the keys are identical, falsy if they are different -// - key_cleanup - function for cleaning up any internal allocations inside node->key (not the key itself) +// - key_cleanup - function for cleaning up any internal allocations inside node->key (not the +// key itself) // if it has no heap allocations, this should be NULL // params: // - key - pointer to the key to cleanup -// - val_cleanup - function for cleaning up any internal allocations inside node->val (not the value itself) +// - val_cleanup - function for cleaning up any internal allocations inside node->val (not the +// value itself) // if it has no heap allocations, this should be NULL // params: // - val - pointer to the value to cleanup diff --git a/analyzer/structures/heap.h b/analyzer/structures/heap.h index a2d7333..bfeb4b6 100644 --- a/analyzer/structures/heap.h +++ b/analyzer/structures/heap.h @@ -27,13 +27,15 @@ typedef struct { // - el2 - pointer to the second of the elements to compare // returns: // truthy if el1 should be el2's parent (e.g. el1 > el2 for max heap), falsy otherwise -// - el_cleanup - function for cleaning up any internal allocations inside element (not the element itself) +// - el_cleanup - function for cleaning up any internal allocations inside element (not the +// element itself) // if it has no heap allocations, this should be NULL // params: // - el - pointer to the element to cleanup // returns: // pointer to the new heap -extern Heap *heap_new(size_t el_size, int (*compare)(void *el1, void *el2), void (*el_cleanup)(void *el)); +extern Heap * +heap_new(size_t el_size, int (*compare)(void *el1, void *el2), void (*el_cleanup)(void *el)); // insert new element into the heap // params: diff --git a/analyzer/utils/tcp.c b/analyzer/utils/tcp.c index a5d0366..8979483 100644 --- a/analyzer/utils/tcp.c +++ b/analyzer/utils/tcp.c @@ -56,7 +56,8 @@ TCPSegment get_segment_from_packet(const byte_t *packet, const struct pcap_pkthd return segment; // get TCP header - const struct tcphdr *tcp_header = (const struct tcphdr *)(packet + eth_header_len + ip_header_len); + const struct tcphdr *tcp_header = + (const struct tcphdr *)(packet + eth_header_len + ip_header_len); int tcp_header_len = tcp_header->th_off * 4; // get TCP sequence number and client port @@ -91,8 +92,9 @@ void remove_parsed_data(TCPStream *stream, size_t parsed_len) { stream->seq += parsed_len; } -// get the index of the first relevant byte in segment (its tcp sequence number is the one stream is expecting) -// return the index of the first relevant byte in payload or -1 if segment isn't directly connected to stream +// get the index of the first relevant byte in segment (its tcp sequence number is the one stream is +// expecting) return the index of the first relevant byte in payload or -1 if segment isn't directly +// connected to stream int get_first_relevant_byte_index(TCPStream stream, TCPSegment segment) { // expected tcp sequence numbers for stream and segment uint32_t stream_expected = stream.seq + stream.bytes.count; @@ -124,7 +126,8 @@ void add_pending_segments(TCPStream *stream) { top_changed = 1; } - // remove top if it was just added or no longer is in acceptable range (e.g. was contained within another one pending) + // remove top if it was just added or no longer is in acceptable range (e.g. was contained + // within another one pending) if (top_changed || !in_acceptable_range(*stream, *top)) { heap_top_remove(stream->pending); } diff --git a/analyzer/utils/tcp.h b/analyzer/utils/tcp.h index 55cbf3e..e2906ef 100644 --- a/analyzer/utils/tcp.h +++ b/analyzer/utils/tcp.h @@ -3,8 +3,8 @@ #include -#include "structures/heap.h" #include "structures/array.h" +#include "structures/heap.h" #ifndef TCP_H #define TCP_H @@ -29,7 +29,8 @@ typedef struct { // - packet_data - metadata about packet // returns: // TCPSegment from packet, payload is NULL if the received packet was incorrect -extern TCPSegment get_segment_from_packet(const byte_t *packet, const struct pcap_pkthdr *packet_data); +extern TCPSegment +get_segment_from_packet(const byte_t *packet, const struct pcap_pkthdr *packet_data); // struct that stores all the information about stream typedef struct { @@ -37,7 +38,7 @@ typedef struct { uint32_t seq; // TCP sequence number of the first byte in the stream uint16_t port; // client port of currently analyzed connection ConnectionSource src; // stream's source - Heap *pending; // min heap of segments yet to be added to stream (sorted by TCP sequence number) + Heap *pending; // min heap of segments yet to be added to stream (sorted by TCP sequence number) } TCPStream; #define INIT_STREAM_CAPACITY 256 diff --git a/analyzer/utils/time.c b/analyzer/utils/time.c index d95da65..740b8e9 100644 --- a/analyzer/utils/time.c +++ b/analyzer/utils/time.c @@ -6,5 +6,14 @@ void get_date_time_string(char *date_time) { time_t now = time(NULL); struct tm *t = localtime(&now); - sprintf(date_time, "%02d%02d%02d_%02d%02d%02d", t->tm_year - 100, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + sprintf( + date_time, + "%02d%02d%02d_%02d%02d%02d", + t->tm_year - 100, + t->tm_mon + 1, + t->tm_mday, + t->tm_hour, + t->tm_min, + t->tm_sec + ); } diff --git a/csv_table_gen.c b/csv_table_gen.c index 49ebe77..859b853 100644 --- a/csv_table_gen.c +++ b/csv_table_gen.c @@ -53,7 +53,14 @@ void create_h(char *path, char *from, char *to) { } // create output .c file -void create_c(char *path, char *h_path, char *from, char *to, char from_to_array[][BUFFER_SIZE], size_t max_index) { +void create_c( + char *path, + char *h_path, + char *from, + char *to, + char from_to_array[][BUFFER_SIZE], + size_t max_index +) { FILE *fp = fopen(path, "w"); char arr_name[BUFFER_SIZE], arr_len_name[BUFFER_SIZE]; @@ -81,7 +88,13 @@ void create_c(char *path, char *h_path, char *from, char *to, char from_to_array fprintf(fp, "const char *get_%s_from_%s(int %s) {\n", to, from, from); fprintf(fp, " if (%s >= 0 && %s < %s)\n", from, from, arr_len_name); fprintf(fp, " return %s[%s];\n", arr_name, from); - fprintf(fp, " fprintf(stderr, \"%s = %%d is outside of table range [0; %%d]\\n\", %s, %s - 1);\n", from, from, arr_len_name); + fprintf( + fp, + " fprintf(stderr, \"%s = %%d is outside of table range [0; %%d]\\n\", %s, %s - 1);\n", + from, + from, + arr_len_name + ); fprintf(fp, " return \"null\";\n"); fprintf(fp, "}"); -- cgit v1.2.3