Rizin
unix-like reverse engineering framework and cli tools
|
Go to the source code of this file.
Classes | |
struct | idasig_v5_t |
struct | idasig_v6_v7_t |
struct | idasig_v8_v9_t |
struct | idasig_v10_t |
struct | parse_status_t |
Macros | |
#define | MAX_WBITS 15 |
#define | sig_dbg(...) |
#define | sig_dbg_buffer(n, b, s) |
#define | rz_buf_append_le_bits(buffer, tmp, value, bits) |
#define | rz_buf_append_be_bits(buffer, tmp, value, bits) |
#define | IDASIG_FEATURE_NONE 0x00 |
#define | IDASIG_FEATURE_STARTUP 0x01 |
#define | IDASIG_FEATURE_CTYPE_CRC 0x02 |
#define | IDASIG_FEATURE_2BYTE_CTYPE 0x04 |
#define | IDASIG_FEATURE_ALT_CTYPE_CRC 0x08 |
#define | IDASIG_FEATURE_COMPRESSED 0x10 |
#define | IDASIG_PARSE_MORE_PUBLIC_NAMES 0x01 |
#define | IDASIG_PARSE_READ_TAIL_BYTES 0x02 |
#define | IDASIG_PARSE_READ_REFERENCED_FUNCTIONS 0x04 |
#define | IDASIG_PARSE_MORE_MODULES_WITH_SAME_CRC 0x08 |
#define | IDASIG_PARSE_MORE_MODULES 0x10 |
#define | IDASIG_FUNCTION_LOCAL 0x02 |
#define | IDASIG_FUNCTION_UNRESOLVED_COLLISION 0x08 |
#define | is_status_err_or_eof(p) (p->eof || p->error) |
#define | POLY 0x8408 |
Typedefs | |
typedef struct idasig_v5_t | idasig_v5_t |
typedef struct idasig_v6_v7_t | idasig_v6_v7_t |
typedef struct idasig_v8_v9_t | idasig_v8_v9_t |
typedef struct idasig_v10_t | idasig_v10_t |
typedef struct parse_status_t | ParseStatus |
typedef struct idasig_v10_t idasig_v10_t |
typedef struct idasig_v5_t idasig_v5_t |
typedef struct idasig_v6_v7_t idasig_v6_v7_t |
typedef struct idasig_v8_v9_t idasig_v8_v9_t |
typedef struct parse_status_t ParseStatus |
Definition at line 204 of file flirt.c.
References i, length, and POLY.
Referenced by flirt_module_new(), and module_match_buffer().
|
static |
Definition at line 1402 of file flirt.c.
References rz_list_length().
Referenced by flirt_write_module().
Returns the FLIRT file version read from the RzBuffer This function returns the FLIRT file version, when it fails returns 0.
buffer | The buffer to read |
Definition at line 1021 of file flirt.c.
References test-lz4-list::exit, free(), header, rz_buf_read(), RZ_LOG_ERROR, and RZ_NEW0.
Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer().
|
static |
Definition at line 1413 of file flirt.c.
References flags, flirt_has_references(), IDASIG_FUNCTION_LOCAL, IDASIG_FUNCTION_UNRESOLVED_COLLISION, IDASIG_PARSE_MORE_PUBLIC_NAMES, IDASIG_PARSE_READ_REFERENCED_FUNCTIONS, IDASIG_PARSE_READ_TAIL_BYTES, rz_flirt_function_t::is_collision, rz_flirt_function_t::is_local, length, rz_flirt_function_t::name, rz_flirt_tail_byte_t::offset, rz_flirt_function_t::offset, rz_buf_append_be_bits, rz_buf_append_bytes(), rz_buf_append_le_bits, rz_buf_append_string(), rz_list_length(), RZ_LOG_WARN, rz_write_versioned_vle(), rz_write_vle16(), rz_write_vle32(), autogen_x86imm::tmp, value, and rz_flirt_tail_byte_t::value.
Referenced by flirt_write_node().
|
static |
Definition at line 1507 of file flirt.c.
References rz_flirt_module_t::crc16, flags, flirt_write_module(), i, IDASIG_PARSE_MORE_MODULES, IDASIG_PARSE_MORE_MODULES_WITH_SAME_CRC, rz_flirt_node_t::length, rz_flirt_node_t::pattern_bytes, rz_flirt_node_t::pattern_mask, rz_buf_append_bytes(), rz_list_iter_get_next_data(), rz_list_last(), rz_list_length(), RZ_LOG_ERROR, rz_write_vle16(), rz_write_vle32(), rz_write_vle64(), UT16_MAX, UT32_MAX, and rz_flirt_node_t::variant_mask.
Referenced by rz_sign_flirt_write_compressed_pattern_to_buffer().
|
static |
Checks if a pattern does match the buffer data.
p_size | The pattern size |
pattern | The pattern to check agains |
mask | The pattern mask |
b | Buffer to check |
b_size | Size of the buffer to check |
Definition at line 336 of file flirt.c.
Referenced by node_match_buffer().
void module_free | ( | RzFlirtModule * | module | ) |
Definition at line 284 of file flirt.c.
References free(), and rz_list_free().
Referenced by flirt_create_child(), flirt_create_child_from_analysis(), flirt_module_new(), flirt_pat_parse_line(), and parse_leaf().
|
static |
Checks if the module matches the buffer and renames the matched functions.
analysis | The RzAnalysis struct from where to fetch and modify the functions |
module | The FLIRT module to match against the buffer |
b | Buffer to check |
address | Function address |
buf_size | Size of the buffer to check |
Definition at line 359 of file flirt.c.
References rz_analysis_function_t::addr, b, rz_analysis_function_t::bbs, buf_size, rz_list_iter_t::data, rz_flag_bind_t::f, rz_analysis_t::fcns, rz_analysis_t::flb, flirt_crc16(), free(), rz_flag_bind_t::get_at_by_spaces, rz_flirt_function_t::is_local, rz_list_iter_t::n, rz_analysis_function_t::name, rz_flirt_function_t::name, rz_flirt_function_t::negative_offset, rz_analysis_function_t::ninstr, NULL, rz_flirt_tail_byte_t::offset, rz_flirt_function_t::offset, rz_analysis_function_add_block(), rz_analysis_function_delete(), rz_analysis_function_linear_size(), rz_analysis_function_rename(), rz_analysis_function_resize(), rz_analysis_get_function_at(), rz_analysis_trim_jmprefs(), RZ_LOG_DEBUG, RZ_LOG_ERROR, rz_name_filter(), rz_str_newf(), rz_flag_bind_t::set, rz_flag_bind_t::unset, ut64(), and rz_flirt_tail_byte_t::value.
Referenced by node_match_buffer().
|
static |
Definition at line 458 of file flirt.c.
References b, buf_size, rz_flirt_node_t::child_list, is_pattern_matching(), rz_flirt_node_t::length, rz_flirt_node_t::module_list, module_match_buffer(), rz_flirt_node_t::pattern_bytes, and rz_flirt_node_t::pattern_mask.
Referenced by node_match_functions().
|
static |
Tries to find matching functions between the signature infos in root_node and the analyzed functions in analysis.
analysis | The analysis |
root_node | The root node |
Definition at line 490 of file flirt.c.
References rz_analysis_function_t::addr, rz_flirt_node_t::child_list, rz_flag_bind_t::f, rz_analysis_t::fcns, rz_analysis_t::flb, rz_io_bind_t::io, rz_analysis_t::iob, malloc(), rz_analysis_function_t::name, node_match_buffer(), PFMT64x, rz_flag_bind_t::pop_fs, rz_flag_bind_t::push_fs, rz_io_bind_t::read_at, RZ_ANALYSIS_FCN_TYPE_FCN, RZ_ANALYSIS_FCN_TYPE_LOC, rz_analysis_function_linear_size(), RZ_FREE, rz_list_length(), RZ_LOG_ERROR, rz_analysis_function_t::type, and ut64().
Referenced by rz_sign_flirt_apply().
|
static |
Definition at line 762 of file flirt.c.
References b, flags, IDASIG_PARSE_MORE_MODULES, IDASIG_PARSE_MORE_MODULES_WITH_SAME_CRC, IDASIG_PARSE_READ_REFERENCED_FUNCTIONS, IDASIG_PARSE_READ_TAIL_BYTES, is_status_err_or_eof, module_free(), rz_flirt_node_t::module_list, NULL, read_byte(), read_max_2_bytes(), read_module_public_functions(), read_module_referenced_functions(), read_module_tail_bytes(), read_multiple_bytes(), read_short(), rz_list_append(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, and sig_dbg.
Referenced by parse_tree().
|
static |
Definition at line 902 of file flirt.c.
References b, rz_flirt_node_t::child_list, i, is_status_err_or_eof, rz_flirt_node_t::length, NULL, parse_leaf(), read_multiple_bytes(), read_node_bytes(), read_node_length(), read_node_variant_mask(), rz_list_append(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, rz_sign_flirt_node_free(), and sig_dbg.
Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer().
|
static |
Definition at line 1005 of file flirt.c.
References header, rz_buf_read_le16, and RZ_LOG_ERROR.
Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer(), and rz_sign_flirt_parse_header_compressed_pattern_from_buffer().
|
static |
Definition at line 945 of file flirt.c.
References header, rz_buf_read(), rz_buf_read_le16, rz_buf_read_le32, rz_buf_seek(), and RZ_BUF_SET.
Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer(), and rz_sign_flirt_parse_header_compressed_pattern_from_buffer().
|
static |
Definition at line 987 of file flirt.c.
References header, rz_buf_read_le32, and RZ_LOG_ERROR.
Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer(), and rz_sign_flirt_parse_header_compressed_pattern_from_buffer().
|
static |
Definition at line 996 of file flirt.c.
References header, rz_buf_read_le16, and RZ_LOG_ERROR.
Referenced by rz_sign_flirt_parse_compressed_pattern_from_buffer(), and rz_sign_flirt_parse_header_compressed_pattern_from_buffer().
|
static |
Definition at line 230 of file flirt.c.
References b, length, r, and rz_buf_read().
Referenced by parse_leaf(), read_max_2_bytes(), read_module_public_functions(), read_module_referenced_functions(), read_module_tail_bytes(), read_multiple_bytes(), read_node_bytes(), read_node_length(), and read_short().
|
static |
Definition at line 261 of file flirt.c.
References b, r, and read_byte().
Referenced by parse_leaf(), read_module_public_functions(), read_module_referenced_functions(), read_module_tail_bytes(), and read_node_variant_mask().
|
static |
Definition at line 687 of file flirt.c.
References b, flags, free(), i, IDASIG_FUNCTION_LOCAL, IDASIG_FUNCTION_UNRESOLVED_COLLISION, IDASIG_PARSE_MORE_PUBLIC_NAMES, is_status_err_or_eof, NULL, read_byte(), read_max_2_bytes(), read_multiple_bytes(), RZ_FLIRT_NAME_MAX, rz_list_append(), rz_list_newf(), RZ_LOG_ERROR, RZ_LOG_WARN, RZ_NEW0, and sig_dbg.
Referenced by parse_leaf().
|
static |
Definition at line 597 of file flirt.c.
References b, free(), i, is_status_err_or_eof, rz_flirt_function_t::name, rz_flirt_function_t::negative_offset, NULL, rz_flirt_function_t::offset, read_byte(), read_max_2_bytes(), read_multiple_bytes(), RZ_FLIRT_NAME_MAX, rz_list_append(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, and sig_dbg.
Referenced by parse_leaf().
|
static |
Definition at line 532 of file flirt.c.
References b, free(), i, is_status_err_or_eof, NULL, rz_flirt_tail_byte_t::offset, read_byte(), read_max_2_bytes(), read_multiple_bytes(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, sig_dbg, and rz_flirt_tail_byte_t::value.
Referenced by parse_leaf().
|
static |
Definition at line 268 of file flirt.c.
References b, r, read_byte(), read_short(), and read_word().
Referenced by parse_leaf(), parse_tree(), read_module_public_functions(), read_module_referenced_functions(), read_module_tail_bytes(), and read_node_variant_mask().
|
static |
Definition at line 870 of file flirt.c.
References b, i, is_status_err_or_eof, rz_flirt_node_t::length, malloc(), rz_flirt_node_t::pattern_bytes, rz_flirt_node_t::pattern_mask, read_byte(), sig_dbg_buffer, ut64(), and rz_flirt_node_t::variant_mask.
Referenced by parse_tree().
|
static |
Definition at line 836 of file flirt.c.
References b, is_status_err_or_eof, rz_flirt_node_t::length, read_byte(), and sig_dbg.
Referenced by parse_tree().
|
static |
Definition at line 845 of file flirt.c.
References b, is_status_err_or_eof, rz_flirt_node_t::length, read_max_2_bytes(), read_multiple_bytes(), sig_dbg, ut64(), and rz_flirt_node_t::variant_mask.
Referenced by parse_tree().
|
static |
Definition at line 249 of file flirt.c.
References b, r, and read_byte().
Referenced by parse_leaf(), read_multiple_bytes(), and read_word().
|
static |
Definition at line 255 of file flirt.c.
References b, r, and read_short().
Referenced by read_multiple_bytes().
RZ_API bool rz_sign_flirt_apply | ( | RZ_NONNULL RzAnalysis * | analysis, |
RZ_NONNULL const char * | flirt_file, | ||
ut8 | expected_arch | ||
) |
Parses the FLIRT file and applies the signatures.
analysis | The RzAnalysis structure |
flirt_file | The FLIRT file to parse |
Definition at line 1289 of file flirt.c.
References node_match_functions(), NULL, rz_buf_free(), rz_buf_new_slurp(), RZ_FLIRT_NODE_OPTIMIZE_MAX, RZ_FLIRT_SIG_ARCH_ANY, RZ_LOG_ERROR, rz_return_val_if_fail, rz_sign_flirt_node_free(), rz_sign_flirt_parse_compressed_pattern_from_buffer(), rz_sign_flirt_parse_string_pattern_from_buffer(), RZ_STR_ISEMPTY, RZ_STR_ISNOTEMPTY, and rz_str_lchr().
Referenced by rz_core_analysis_sigdb_apply(), and rz_flirt_scan_handler().
RZ_API void rz_sign_flirt_info_fini | ( | RZ_NULLABLE RzFlirtInfo * | info | ) |
Frees an RzFlirtInfo struct elements without freeing the pointer.
RzFlirtInfo | The RzFlirtInfo elements to be freed |
Definition at line 315 of file flirt.c.
References free(), info(), memset(), RZ_FLIRT_FILE_TYPE_SIG, and rz_bin_info_t::type.
Referenced by rz_core_flirt_dump_file(), and sigdb_signature_resolve_details().
RZ_API ut32 rz_sign_flirt_node_count_nodes | ( | RZ_NONNULL const RzFlirtNode * | node | ) |
Counts the number of FLIRT signatures in the node.
flirt_file | The FLIRT node to use to count |
Definition at line 1334 of file flirt.c.
References count, rz_list_length(), rz_return_val_if_fail, and rz_sign_flirt_node_count_nodes().
Referenced by rz_core_flirt_create_file(), rz_sign_flirt_node_count_nodes(), rz_sign_flirt_parse_compressed_pattern_from_buffer(), rz_sign_flirt_parse_string_pattern_from_buffer(), and rz_sign_flirt_write_compressed_pattern_to_buffer().
RZ_API void rz_sign_flirt_node_free | ( | RZ_NULLABLE RzFlirtNode * | node | ) |
Frees an RzFlirtNode struct.
RzFlirtNode | The RzFlirtNode to be freed |
Definition at line 299 of file flirt.c.
References free(), and rz_list_free().
Referenced by flirt_create_child(), flirt_create_child_from_analysis(), flirt_node_optimize(), flirt_node_shorten_and_insert(), flirt_pat_parse_line(), parse_tree(), rz_core_flirt_convert_file(), rz_core_flirt_create_file(), rz_core_flirt_dump_file(), rz_sign_flirt_apply(), rz_sign_flirt_node_new(), rz_sign_flirt_parse_string_pattern_from_buffer(), and sigdb_signature_resolve_details().
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.
Parses the RzBuffer containing a FLIRT structure and returns an RzFlirtNode if expected_arch matches the id or RZ_FLIRT_SIG_ARCH_ANY is set.
flirt_buf | The buffer to read |
expected_arch | The expected arch to be used for the buffer |
info | Pointer to a RzFlirtInfo that can be used to get info about the sig file |
Definition at line 1136 of file flirt.c.
References parse_status_t::buffer, test-lz4-list::exit, flirt_parse_version(), free(), header, IDASIG_FEATURE_COMPRESSED, info(), malloc(), NULL, parse_tree(), parse_v10_header(), parse_v5_header(), parse_v6_v7_header(), parse_v8_v9_header(), rz_buf_free(), rz_buf_new_with_pointers(), rz_buf_read(), rz_buf_size(), rz_buf_tell(), RZ_FLIRT_FILE_TYPE_SIG, RZ_FLIRT_SIG_ARCH_ANY, RZ_FREE, rz_inflate(), rz_inflate_ignore_header(), RZ_LOG_ERROR, RZ_NEW0, rz_return_val_if_fail, rz_sign_flirt_node_count_nodes(), rz_bin_info_t::type, and parse_status_t::version.
Referenced by rz_core_flirt_convert_file(), rz_core_flirt_dump_file(), and rz_sign_flirt_apply().
RZ_API RZ_OWN bool rz_sign_flirt_parse_header_compressed_pattern_from_buffer | ( | RZ_NONNULL RzBuffer * | flirt_buf, |
RZ_NONNULL RzFlirtInfo * | info | ||
) |
Parses the RzBuffer containing a FLIRT structure and returns an RzFlirtInfo.
Parses the RzBuffer containing a FLIRT structure and returns an RzFlirtNode if expected_arch matches the id or RZ_FLIRT_SIG_ARCH_ANY is set.
flirt_buf | The buffer to read |
expected_arch | The expected arch to be used for the buffer |
info | Pointer to a RzFlirtInfo that can be used to get info about the sig file |
Definition at line 1062 of file flirt.c.
References idasig_v5_t::arch, test-lz4-list::exit, free(), info(), idasig_v5_t::library_name_len, idasig_v5_t::magic, malloc(), idasig_v6_v7_t::n_functions, NULL, idasig_v5_t::old_n_functions, parse_v10_header(), parse_v5_header(), parse_v6_v7_header(), parse_v8_v9_header(), rz_buf_read(), RZ_FLIRT_FILE_TYPE_SIG, RZ_LOG_ERROR, rz_return_val_if_fail, rz_bin_info_t::type, and idasig_v5_t::version.
Referenced by sigdb_signature_resolve_details().
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.
node | The FLIRT node to use as input |
buffer | The buffer to write to |
Definition at line 1580 of file flirt.c.
References flirt_write_node(), IDASIG_FEATURE_COMPRESSED, IDASIG_FEATURE_NONE, memset(), NULL, options, rz_buf_append_bytes(), rz_buf_append_le_bits, rz_buf_append_string(), rz_buf_free(), rz_buf_new_empty(), rz_deflatew_buf(), RZ_FLIRT_LIBRARY_NAME_MAX, RZ_FLIRT_SIG_ARCH_ANY, RZ_LOG_ERROR, rz_return_val_if_fail, rz_sign_flirt_node_count_nodes(), RZ_STR_ISEMPTY, autogen_x86imm::tmp, and ut64().
Referenced by rz_core_flirt_convert_file(), and rz_core_flirt_create_file().
Definition at line 1406 of file flirt.c.
References rz_write_vle16(), rz_write_vle32(), and value.
Referenced by flirt_write_module().
Definition at line 1348 of file flirt.c.
References rz_buf_append_bytes(), RZ_LOG_ERROR, autogen_x86imm::tmp, and val.
Referenced by flirt_write_module(), flirt_write_node(), and rz_write_versioned_vle().
Definition at line 1368 of file flirt.c.
References rz_buf_append_bytes(), autogen_x86imm::tmp, and val.
Referenced by flirt_write_module(), flirt_write_node(), rz_write_versioned_vle(), and rz_write_vle64().
Definition at line 1398 of file flirt.c.
References rz_write_vle32(), UT32_MAX, and val.
Referenced by flirt_write_node().