rizin/librz/bin/bobj_process_string.c
Rot127 d79ff51157
librz/bin: define string search parameters in plugins (#5406)
* Clarify docs of raw_alignment

* Set Go and Rust string encoding for binary string search.

* Add detailed doxygen about string search in bin plugins.

* Add the number string code points as detail to string search hits.

* Add helper to check if string encoding needs scanning.

* Add helper to generate a string wildcard pattern.

The pattern is supposed to match any human readable string.
Before the string search refactor there was no explicit definition
what characters mark the end of a string and which ones don't.

This pattern should match strings of the old interpretation.

* Enable the RzBin plugin to search strings with direct matching instead of scanning.

This significantly speeds up the string search when a binary is opened.
The prerequisite is that the plugin specifies the string encoding.

* Enforce UTF-8 for initial string search.

* Add custom string search for PE files.

* Clean up and document rz_utf8_encode

* Don't demote explicit UTF-8 encoding to ASCII.

* Increase min JIT stack size due to not reproducable search results.

* Simplify wildcard regex pattern.
2025-10-08 10:02:32 +08:00

46 lines
1.2 KiB
C

// SPDX-FileCopyrightText: 2023 RizinOrg <info@rizin.re>
// SPDX-FileCopyrightText: 2023 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_bin.h>
#include "i/private.h"
RZ_IPI void rz_bin_set_and_process_strings(RzBinFile *bf, RzBinObject *o) {
RzBin *bin = bf->rbin;
rz_bin_string_database_free(o->strings);
if (!(bin->filter_rules & RZ_BIN_REQ_STRINGS)) {
o->strings = rz_bin_string_database_new(NULL);
return;
}
RzPVector *strings = NULL;
RzBinPlugin *plugin = o->plugin;
/**
* We call rz_bin_file_strings only if the seach mode is not `auto`
* or if the plugin fails to generate the string vector.
*/
if (bin->str_search_cfg.mode != RZ_BIN_STRING_SEARCH_MODE_AUTO ||
!plugin->strings ||
!(strings = plugin->strings(bf))) {
switch (bf->o->lang) {
default:
break;
case RZ_BIN_LANGUAGE_GO:
case RZ_BIN_LANGUAGE_RUST:
bin->str_search_cfg.string_encoding = RZ_STRING_ENC_UTF8;
break;
}
strings = rz_bin_file_strings(bf, &bin->str_search_cfg);
}
void **it;
RzBinString *string;
rz_pvector_foreach (strings, it) {
string = *it;
// rebase physical address
string->paddr += o->opts.loadaddr;
}
o->strings = rz_bin_string_database_new(strings);
}