193 if (strstr(file_list,
"all")) {
203 rz_list_foreach (tokens, it, tk) {
229 if (strstr(os_list,
"all")) {
239 rz_list_foreach (tokens, it, tk) {
265 if (strstr(app_list,
"all")) {
275 rz_list_foreach (tokens, it, tk) {
288 RzListIter *pub_func_it, *ref_func_it, *tail_bytes_it;
293 rz_list_foreach (
module->public_functions, pub_func_it, func) {
305 if (pub_func_it->
n) {
310 rz_list_foreach (
module->tail_bytes, tail_bytes_it, tail_byte) {
314 if (
module->referenced_functions) {
316 rz_list_foreach (
module->referenced_functions, ref_func_it, ref_func) {
318 if (ref_func_it->
n) {
353 rz_list_foreach (node->
child_list, child_it, child) {
375 const char *extension =
rz_str_lchr(flirt_file,
'.');
376 if (
RZ_STR_ISEMPTY(extension) || (strcmp(extension,
".sig") != 0 && strcmp(extension,
".pat") != 0)) {
377 RZ_LOG_ERROR(
"FLIRT: unknown extension '%s'\n", extension);
386 RZ_LOG_ERROR(
"FLIRT: cannot open %s (read mode)\n", flirt_file);
388 }
else if (!strcmp(extension,
".pat")) {
396 RZ_LOG_ERROR(
"FLIRT: we encountered an error while parsing the file. Sorry.\n");
434 const char *extension =
rz_str_lchr(output_file,
'.');
435 if (
RZ_STR_ISEMPTY(extension) || (strcmp(extension,
".sig") != 0 && strcmp(extension,
".pat") != 0)) {
436 RZ_LOG_ERROR(
"missing or unknown extension '%s'. supported only .pat and .sig\n", extension);
442 RZ_LOG_ERROR(
"config 'flirt.node.optimize' is set to an invalid value.\n");
458 if (!strcmp(extension,
".pat")) {
460 }
else if (!strcmp(extension,
".sig")) {
462 const char *hdr_arch =
rz_config_get(core->config,
"asm.arch");
463 const char *hdr_file =
rz_config_get(core->config,
"flirt.sig.file");
464 const char *hdr_os =
rz_config_get(core->config,
"flirt.sig.os");
465 const char *hdr_lib =
rz_config_get(core->config,
"flirt.sig.library");
473 RZ_LOG_ERROR(
"FLIRT: architecture '%s' is not supported as .sig file, we suggest to use the .pat format.\n", hdr_arch);
474 RZ_LOG_ERROR(
"FLIRT: we suggest to open an issue to discuss with the rizin team about it.\n");
480 .version = hdr_version,
513 const char *in_extension =
rz_str_lchr(input_file,
'.');
514 if (
RZ_STR_ISEMPTY(in_extension) || (strcmp(in_extension,
".sig") != 0 && strcmp(in_extension,
".pat") != 0)) {
515 RZ_LOG_ERROR(
"FLIRT: unknown input extension '%s'\n", in_extension);
519 const char *out_extension =
rz_str_lchr(output_file,
'.');
520 if (
RZ_STR_ISEMPTY(out_extension) || (strcmp(out_extension,
".sig") != 0 && strcmp(out_extension,
".pat") != 0)) {
521 RZ_LOG_ERROR(
"FLIRT: unknown output extension '%s'\n", out_extension);
525 if (!strcmp(out_extension, in_extension)) {
526 RZ_LOG_ERROR(
"FLIRT: cannot convert '%s' to '%s' because the format is the same\n", input_file, output_file);
535 RZ_LOG_ERROR(
"config 'flirt.node.optimize' is set to an invalid value.\n");
540 RZ_LOG_ERROR(
"FLIRT: cannot open %s (read mode)\n", input_file);
542 }
else if (!strcmp(in_extension,
".pat")) {
550 RZ_LOG_ERROR(
"FLIRT: we encountered an error while parsing the file. Sorry.\n");
556 RZ_LOG_ERROR(
"FLIRT: cannot open %s (write mode)\n", output_file);
558 }
else if (!strcmp(out_extension,
".pat")) {
562 const char *hdr_arch =
rz_config_get(core->config,
"asm.arch");
563 const char *hdr_file =
rz_config_get(core->config,
"flirt.sig.file");
564 const char *hdr_os =
rz_config_get(core->config,
"flirt.sig.os");
565 const char *hdr_lib =
rz_config_get(core->config,
"flirt.sig.library");
573 RZ_LOG_ERROR(
"FLIRT: architecture '%s' is not supported as .sig file, we suggest to use the .pat format.\n", hdr_arch);
574 RZ_LOG_ERROR(
"FLIRT: we suggest to open an issue to discuss with the rizin team about it.\n");
580 .version = hdr_version,
581 .arch = architecture,
RzBinInfo * info(RzBinFile *bf)
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API int rz_cons_printf(const char *format,...)
RZ_API ut16 rz_core_flirt_os_from_option_list(RZ_NONNULL const char *os_list)
Returns the FLIRT file flags from a given list (comma spaced) of file types Returns RZ_FLIRT_SIG_OS_A...
const MapStringValue file_map[25]
static void flirt_print_node(const RzFlirtNode *node, int indent)
RZ_API ut16 rz_core_flirt_app_from_option_list(RZ_NONNULL const char *app_list)
Returns the FLIRT file flags from a given list (comma spaced) of file types Returns RZ_FLIRT_SIG_APP_...
const MapStringValue app_map[10]
const MapStringValue arch_map[29]
static void flirt_print_indentation(int indent)
static void flirt_print_node_pattern(const RzFlirtNode *node)
RZ_API bool rz_core_flirt_convert_file(RZ_NONNULL RzCore *core, RZ_NONNULL const char *input_file, RZ_NONNULL const char *output_file)
converts a FLIRT file to the other format.
RZ_API const char * rz_core_flirt_arch_from_id(ut8 arch)
Returns the FLIRT arch name (string format) from a given arch id Returns "unknown" if name is not fou...
RZ_API ut32 rz_core_flirt_file_from_option_list(RZ_NONNULL const char *file_list)
Returns the FLIRT file flags from a given list (comma spaced) of file types Returns RZ_FLIRT_SIG_FILE...
static void flirt_print_module(const RzFlirtModule *module)
RZ_API ut8 rz_core_flirt_arch_from_name(RZ_NONNULL const char *arch)
Returns the FLIRT arch id from a given arch name Returns RZ_FLIRT_SIG_ARCH_ANY if name is not found.
RZ_API bool rz_core_flirt_create_file(RZ_NONNULL RzCore *core, RZ_NONNULL const char *output_file, RZ_NULLABLE ut32 *written_nodes)
Generates a new FLIRT file from a given RzCore structure.
struct map_string_value_t MapStringValue
const MapStringValue os_map[6]
RZ_API bool rz_core_flirt_dump_file(RZ_NONNULL const char *flirt_file)
Dumps the contents of a FLIRT file.
int ZEXPORT deflate(z_streamp strm, int flush)
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
static const char struct stat static buf struct stat static buf static vhangup int options
#define rz_warn_if_reached()
#define rz_return_val_if_fail(expr, val)
RZ_API RZ_OWN RzBuffer * rz_buf_new_slurp(const char *file)
Creates a new buffer from a file.
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
RZ_API RZ_OWN RzBuffer * rz_buf_new_file(const char *file, int perm, int mode)
Creates a new buffer from a file.
RZ_API RZ_OWN RzFlirtNode * rz_sign_flirt_parse_string_pattern_from_buffer(RZ_NONNULL RzBuffer *flirt_buf, ut32 optimization, RZ_NULLABLE RzFlirtInfo *info)
Parses the RzBuffer containing a FLIRT signature in string format and returns an RzFlirtNode.
#define RZ_FLIRT_SIG_OS_OTHER
RZ_API void rz_sign_flirt_node_free(RZ_NULLABLE RzFlirtNode *node)
Frees an RzFlirtNode struct.
#define RZ_FLIRT_SIG_FILE_NE
#define RZ_FLIRT_SIG_FILE_SREC
#define RZ_FLIRT_SIG_APP_16_BIT
#define RZ_FLIRT_SIG_OS_MSDOS
RZ_API RZ_OWN RzFlirtNode * rz_sign_flirt_node_new(RZ_NONNULL RzAnalysis *analysis, ut32 optimization)
Generates the FLIRT signatures and returns an RzFlirtNode.
#define RZ_FLIRT_SIG_APP_GRAPHICS
#define RZ_FLIRT_SIG_FILE_COFF
#define RZ_FLIRT_SIG_FILE_W32RUN
#define RZ_FLIRT_SIG_FILE_DOS_COM
RZ_API void rz_sign_flirt_info_fini(RZ_NULLABLE RzFlirtInfo *info)
Frees an RzFlirtInfo struct elements without freeing the pointer.
#define RZ_FLIRT_SIG_FILE_DOS_EXE_OLD
#define RZ_FLIRT_SIG_FILE_ELF
RZ_API ut32 rz_sign_flirt_node_count_nodes(RZ_NONNULL const RzFlirtNode *node)
Counts the number of FLIRT signatures in the node.
#define RZ_FLIRT_SIG_APP_CONSOLE
#define RZ_FLIRT_SIG_APP_ALL
RZ_API bool rz_sign_flirt_write_string_pattern_to_buffer(RZ_NONNULL const RzFlirtNode *node, RZ_NONNULL RzBuffer *buffer)
Writes in the the RzBuffer the FLIRT signatures in string format.
#define RZ_FLIRT_SIG_APP_MULTI_THREADED
#define RZ_FLIRT_SIG_FILE_AR
@ RZ_FLIRT_NODE_OPTIMIZE_NORMAL
optimize the tree structure (keeps the tail bytes)
@ RZ_FLIRT_NODE_OPTIMIZE_MAX
optimize the tree structure and drops the tail bytes
#define RZ_FLIRT_SIG_APP_EXE
#define RZ_FLIRT_SIG_FILE_OMFLIB
#define RZ_FLIRT_SIG_APP_SINGLE_THREADED
#define RZ_FLIRT_SIG_FILE_DOSDRV
#define RZ_FLIRT_SIG_OS_ALL
#define RZ_FLIRT_SIG_APP_DRV
#define RZ_FLIRT_SIG_FILE_INTELHEX
#define RZ_FLIRT_SIG_FILE_LOADER
#define RZ_FLIRT_SIG_FILE_PILOT
#define RZ_FLIRT_SIG_OS_NETWARE
#define RZ_FLIRT_SIG_FILE_AOUT
#define RZ_FLIRT_SIG_APP_64_BIT
#define RZ_FLIRT_SIG_FILE_PE
#define RZ_FLIRT_SIG_FILE_MOSHEX
#define RZ_FLIRT_SIG_OS_WIN
#define RZ_FLIRT_SIG_FILE_NLM
RZ_API RZ_OWN RzFlirtNode * rz_sign_flirt_parse_compressed_pattern_from_buffer(RZ_NONNULL RzBuffer *flirt_buf, ut8 expected_arch, RZ_NULLABLE RzFlirtInfo *info)
Parses the RzBuffer containing a FLIRT structure and returns an RzFlirtNode.
#define RZ_FLIRT_SIG_FILE_LE
#define RZ_FLIRT_SIG_FILE_OMF
RZ_API bool rz_sign_flirt_write_compressed_pattern_to_buffer(RZ_NONNULL const RzFlirtNode *node, RZ_NONNULL RzBuffer *buffer, RzFlirtCompressedOptions *options)
Writes in the the RzBuffer the FLIRT signatures in compressed format.
#define RZ_FLIRT_SIG_OS_OS2
@ RZ_FLIRT_SIG_ARCH_SPC700
@ RZ_FLIRT_SIG_ARCH_NEC_V850X
@ RZ_FLIRT_SIG_ARCH_TMS320C55
@ RZ_FLIRT_SIG_ARCH_RISCV
@ RZ_FLIRT_SIG_ARCH_SPARC
@ RZ_FLIRT_SIG_ARCH_TRICORE
@ RZ_FLIRT_SIG_ARCH_DALVIK
@ RZ_FLIRT_SIG_ARCH_PIC16
@ RZ_FLIRT_SIG_ARCH_MSP430
@ RZ_FLIRT_SIG_ARCH_XTENSA
@ RZ_FLIRT_FILE_TYPE_PAT
.pat text format pattern file
@ RZ_FLIRT_FILE_TYPE_SIG
.sig compressed pattern file
#define RZ_FLIRT_SIG_FILE_DOS_COM_OLD
#define RZ_FLIRT_SIG_FILE_AIXAR
#define RZ_FLIRT_SIG_APP_32_BIT
#define RZ_FLIRT_SIG_OS_UNIX
#define RZ_FLIRT_SIG_FILE_ZIP
#define RZ_FLIRT_SIG_FILE_ALL
#define RZ_FLIRT_SIG_FILE_DOS_EXE
#define RZ_FLIRT_LIBRARY_NAME_DFL
#define RZ_FLIRT_SIG_FILE_LX
#define RZ_FLIRT_SIG_APP_DLL
#define RZ_FLIRT_SIG_FILE_BIN
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
#define RZ_STR_ISNOTEMPTY(x)
RZ_API const char * rz_str_lchr(const char *str, char chr)
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
#define RZ_STR_ISEMPTY(x)
RZ_API const char * rz_str_pad(const char ch, int len)
static struct sockaddr static addrlen static backlog const void static flags void flags
char name[RZ_FLIRT_NAME_MAX]
struct rz_list_iter_t * n
ut64(WINAPI *w32_GetEnabledXStateFeatures)()