Baseer 0.2.0
Baseer is an advanced binary analysis tool designed to provide deep insights into any file.
Loading...
Searching...
No Matches
baseer.h
Go to the documentation of this file.
1
8
9/* Baseer 0.2.0 */
10#ifndef BASEER_H
11#define BASEER_H
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <sys/stat.h>
16#include <stdbool.h>
17#include <assert.h>
18#include <string.h>
19#include <ctype.h>
20#include <stdlib.h>
21#include "linenoise.h"
22#define BASEER_VERSION_MAJOR 0
23#define BASEER_VERSION_MINOR 2
24#define BASEER_VERSION_MICRO 0
25
26#define STRINGIFY(x) #x
27#define TOSTRING(x) STRINGIFY(x)
28
29#define BASEER_VERSION \
30 TOSTRING(BASEER_VERSION_MAJOR) "." \
31 TOSTRING(BASEER_VERSION_MINOR) "." \
32 TOSTRING(BASEER_VERSION_MICRO)
33
34#define BASEER_MAX_FILE_SIZE 1024 * 1024 * 4
35#define RETURN_NULL_IF(con) \
36 if ((con)) \
37 { \
38 return NULL; \
39 }
40
41#define BASEER_BASE_OFFSET(b, i, sf) (b) + ((i) * (sf))
42
43#define COLOR_RESET "\033[0m"
44// Regular colors
45#define COLOR_BLACK "\033[30m"
46#define COLOR_GRAY "\033[90m"
47#define COLOR_RED "\033[31m"
48#define COLOR_GREEN "\033[32m"
49#define COLOR_YELLOW "\033[33m"
50#define COLOR_BLUE "\033[34m"
51#define COLOR_MAGENTA "\033[35m"
52#define COLOR_CYAN "\033[36m"
53#define COLOR_WHITE "\033[37m"
54// Bold (bright) colors
55#define COLOR_BBLACK "\033[1;30m"
56#define COLOR_BRED "\033[1;31m"
57#define COLOR_BGREEN "\033[1;32m"
58#define COLOR_BYELLOW "\033[1;33m"
59#define COLOR_BBLUE "\033[1;34m"
60#define COLOR_BMAGENTA "\033[1;35m"
61#define COLOR_BCYAN "\033[1;36m"
62#define COLOR_BWHITE "\033[1;37m"
63// Background colors
64#define COLOR_BG_BLACK "\033[40m"
65#define COLOR_BG_RED "\033[41m"
66#define COLOR_BG_GREEN "\033[42m"
67#define COLOR_BG_YELLOW "\033[43m"
68#define COLOR_BG_BLUE "\033[44m"
69#define COLOR_BG_MAGENTA "\033[45m"
70#define COLOR_BG_CYAN "\033[46m"
71#define COLOR_BG_WHITE "\033[47m"
72
73#define MAX_INPUT_ARGS 20
74#define DEFAULT_BLOCK_LENGTH 16
75// #define BLOCK_LENGTH 40
76
77#define BLOCK_LENGTH (get_block_length())
78
79static inline int get_block_length(void)
80{
81 char *env = getenv("BLOCK_LENGTH");
82 if (env != NULL) {
83 int val = atoi(env);
84 if (val > 0) return val;
85 }
86 return DEFAULT_BLOCK_LENGTH;
87}
88
89
90
94typedef struct {
95 int *argc;
96 char** args;
97 int input_argc;
98 char* input_args[MAX_INPUT_ARGS];
99} inputs;
100
104typedef enum {
105 BASEER_MODE_MEMORY,
106 BASEER_MODE_STREAM,
107 BASEER_MODE_BOTH
109
113typedef struct baseer_target_t {
114 FILE* fp;
116 unsigned int size;
117 void *block;
119
127typedef bool (*baseer_callback_t)(baseer_target_t *, void *arg);
128
136// baseer_target_t *baseer_open_memory(char *file_path);
137baseer_target_t *baseer_open(char *file_path, baseer_mode_t mode);
138
144void baseer_close(baseer_target_t *target);
145
151void baseer_print(baseer_target_t *target);
152
161bool baseer_execute(baseer_target_t *target, baseer_callback_t callback, void *arg);
162
163#endif
bool(* baseer_callback_t)(baseer_target_t *, void *arg)
Callback function type for file analysis.
Definition baseer.h:127
baseer_target_t * baseer_open(char *file_path, baseer_mode_t mode)
Open a file in specified mode (memory, streaming, or both)
Definition baseer.c:15
baseer_mode_t
Enum representing file access modes.
Definition baseer.h:104
bool baseer_execute(baseer_target_t *target, baseer_callback_t callback, void *arg)
Execute a callback on a file target.
Definition baseer.c:118
void baseer_close(baseer_target_t *target)
Close a file target and free associated resources.
Definition baseer.c:67
void baseer_print(baseer_target_t *target)
Print a hex dump of the file target.
Definition baseer.c:102
Struct representing a file target in memory or streaming mode.
Definition baseer.h:113
baseer_mode_t mode
Definition baseer.h:115
FILE * fp
Definition baseer.h:114
void * block
Definition baseer.h:117
unsigned int size
Definition baseer.h:116
Struct representing command-line inputs.
Definition baseer.h:94