Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae73926
Adding the trace struct in the trace module
mrglm Jan 14, 2020
75405de
Modifying the input format
mrglm Jan 14, 2020
0e01a2e
Tracker now creates a trace struct for each run
mrglm Jan 14, 2020
a3f59e0
fixing the \n problem
amstramgram0 Jan 15, 2020
6655a85
creation of CFG structures, some functions related and beginning of m…
amstramgram0 Jan 20, 2020
0efb428
Change in the trace struct
Jan 20, 2020
8bf24f9
Adding functions for the cfg struct
mrglm Jan 20, 2020
74b22f8
segfault
amstramgram0 Jan 21, 2020
52dab96
we broke it :(
amstramgram0 Jan 21, 2020
b3a9a17
Fixing double free error and (some) memory leaks
mrglm Jan 21, 2020
89a1040
all the memory leaks are fixed !
amstramgram0 Jan 22, 2020
ee746c8
handling errors
amstramgram0 Jan 22, 2020
4ed6f40
we broke it again :( function localisation is causing a segfault
mrglm Jan 22, 2020
97e1aec
Formatting and adding comments in trace.h
mrglm Jan 23, 2020
6be0cb3
Enforcing coding style
mrglm Jan 23, 2020
ee16253
Improving aux_cfg_insert
mrglm Jan 23, 2020
6e3af17
f3 c3 is now a valid ret (see comment for reference)
mrglm Jan 23, 2020
89b50aa
Slight fix to aux_cfg_insert
mrglm Jan 23, 2020
bf42172
Change in aux_cfg_insert
mrglm Jan 24, 2020
0d07a91
function calls and rets are now recognized
amstramgram0 Jan 24, 2020
a2bf751
some tests added ;)
amstramgram0 Jan 24, 2020
8dc81f6
we fixed one little mistake
amstramgram0 Jan 25, 2020
018f9d1
Using cgraph to draw CFG
mrglm Jan 27, 2020
bc56253
drawing simple (and beautiful) traces ... still some problems with if…
mrglm Jan 28, 2020
0bb6e54
Adding instr_type_t enum for cosmetic reason
mrglm Jan 28, 2020
629cc8d
Some more work on trace.c
mrglm Jan 28, 2020
c78ff3f
still not working but better ; too many calls to graph_create_function
amstramgram0 Jan 29, 2020
de055f9
we did it ! we can draw graphs ! no more segfault !
amstramgram0 Jan 30, 2020
5f28699
Now drawing basic blocks (please don't judge)
mrglm Feb 5, 2020
79ccdf0
opcodes to determine type of instruction are finally correct
amstramgram0 Feb 13, 2020
3f54caa
adding some comments
amstramgram0 Feb 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ all:
@cp -f src/tracker ./

check: all
@cp tracker test/
@cd test/ && $(MAKE)

format:
Expand Down
113 changes: 101 additions & 12 deletions include/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,61 @@
#ifndef _TRACE_H
#define _TRACE_H

#include "../graphviz/cgraph.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <inttypes.h>

#define DEFAULT_HASHTABLE_SIZE 65536 /* 2^16 */

/* A more convenient byte_t type */
typedef uint8_t byte_t;

/* ***** Handling assembly instructions ***** */
/* All the possible types of instruction */
typedef enum
{
BASIC,
BRANCH,
CALL,
JUMP,
RET
} instr_type_t;

/* ***** Definitions of all the struct used ***** */

/* ***** Handling assembly instructions ***** */
typedef struct _instr_t instr_t;

/* ***** Hashtables to store cfg nodes ***** */
typedef struct _hashtable_t hashtable_t;

/* ***** cfg nodes keeping track of the executions ***** */
typedef struct _cfg_t cfg_t;

/* ***** Linked list to store a trace ***** */
typedef struct _trace_t trace_t;


/* ***** instr_t functions ***** */

/* Return a new instr_t struct, NULL otherwise (and set errno) */
instr_t *instr_new (const uintptr_t addr,
const uint8_t size,
const uint8_t *opcodes);
instr_t *instr_new (const uintptr_t addr, const uint8_t size,
const uint8_t *opcodes, char *str_name);

/* Delete the assembly instruction from memory */
void instr_delete (instr_t *instr);

/* Get the address of the instruction */
uintptr_t instr_get_addr (instr_t * const instr);
uintptr_t instr_get_addr (instr_t *const instr);

/* Get the size (in bytes) of the instruction */
size_t instr_get_size (instr_t * const instr);
size_t instr_get_size (instr_t *const instr);

/* Get a pointer to the opcodes of the instruction */
uint8_t * instr_get_opcodes (instr_t * const instr);
uint8_t * instr_get_opcodes (instr_t *const instr);

/* ***** Hashtables to store instructions ***** */

typedef struct _hashtable_t hashtable_t;
/* ***** hashtable_t functions ***** */

/* Return an hash index for the instruction */
uint64_t hash_instr (const instr_t *instr);
Expand All @@ -57,15 +79,82 @@ hashtable_t *hashtable_new (const size_t size);
void hashtable_delete (hashtable_t *ht);

/* Insert the instruction in the hashtable */
bool hashtable_insert (hashtable_t * ht, instr_t * instr);
bool hashtable_insert (hashtable_t *ht, cfg_t *cfg);

/* Look-up if current instruction is already in the hashtable */
bool hashtable_lookup (hashtable_t *ht, instr_t *instr);
cfg_t *hashtable_lookup (hashtable_t *ht, instr_t *instr);

/* Count the number of entries in the hashtable */
size_t hashtable_entries (hashtable_t *ht);

/* Count the number of collisions in the hashtable */
size_t hashtable_collisions (hashtable_t *ht);


/* ***** trace_t functions ***** */

/* Creates a trace and initialize it with ins
Returns a pointer to the created trace, or NULL if an error occured */
trace_t *trace_new (instr_t *ins);

/* Creates an element initialized with ins and insert it after t
Returns a pointer to the created element or NULL if an error occured */
trace_t *trace_insert (trace_t *t, instr_t *ins);

/* Free every element in the trace t */
void trace_delete (trace_t *t);

/* Returns a pointer to the first element where t2 differs from t1 */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be mentioned that it returns NULL if both traces are equals.

trace_t *trace_compare (trace_t *t1, trace_t *t2);


/* ***** cfg_t functions ***** */

/* Creates a cfg and it with hash_index
Returns a pointer to the created trace, or NULL if an error occured */
cfg_t *cfg_new (hashtable_t *ht, instr_t *ins, char *str);

/* Auxiliary function for cfg_insert */
cfg_t *aux_cfg_insert (cfg_t *CFG, cfg_t *new);

/* Creates an element initialized with ins and insert it in CFG's succesors
Returns a pointer to the created element or NULL if an error occured*/
cfg_t *cfg_insert (hashtable_t *ht, cfg_t *CFG, instr_t *ins, Agraph_t *g, char *str);

/* Free every allocated field of CFG, as well as CFG itself */
void cfg_delete (cfg_t *CFG);

/* Get the instruction in CFG */
instr_t *cfg_get_instr (cfg_t *CFG);

/* Get the number of successors of CFG */
uint16_t cfg_get_nb_out (cfg_t *CFG);

/* Get the number of "parents" of CFG */
uint16_t cfg_get_nb_in (cfg_t *CFG);

/* Get the type of the instruction in CFG */
instr_type_t cfg_get_type (cfg_t *CFG);

/* Get the index of the function CFG is in */
uint16_t cfg_get_name (cfg_t *CFG);

/* Get a pointer array of every successor of CFG */
cfg_t **cfg_get_successor (cfg_t *CFG);

/* Get a pointer to successor number i of CFG */
cfg_t *cfg_get_successor_i (cfg_t *CFG, uint16_t i);

/* Get the total number of functions */
size_t get_nb_name (void);

/* Get the str with the address, the opcodes, the mnemonics and the operands */
char *cfg_get_str (cfg_t *CFG);

/* Get a pointer to the first node in the function number index */
cfg_t *get_function_entry (size_t index);

/* Adds the very first node to function_entry */
void add_first_entry (cfg_t *CFG);

#endif /* _TRACE_H */
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Usual compilation flags
CFLAGS = -Wall -Wextra -std=c11 -DDEBUG -g
CPPFLAGS = -I../include
LDFLAGS = -lcapstone
LDFLAGS = -lcapstone -lcgraph

# Special rules and targets
.PHONY: all clean help
Expand Down
Loading