8 #define UTIL_STR_SCAN_OPT_BUFFER_SIZE 2048
9 #define RAW_FILE_ALIGNMENT 0x10000
47 if (
s->has_strings ||
s->is_data) {
49 }
else if (!
s->name) {
53 return strstr(
s->name,
"_const") !=
NULL;
60 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate RzBinString.\n");
86 .prefer_big_endian =
false,
92 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate string seac buffer.\n");
111 ut64 paddr = 0, psize = 0;
175 for (
size_t i = 0;
i < pool_size; ++
i) {
184 bool check_ascii_freq =
false;
197 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate SearchThreadData.\n");
215 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate RzThread\n");
219 RZ_LOG_ERROR(
"bin_file_strings: cannot add thread to pool\n");
229 if (
b->paddr >
a->paddr) {
231 }
else if (
b->paddr <
a->paddr) {
233 }
else if (
b->vaddr >
a->vaddr) {
235 }
else if (
b->vaddr <
a->vaddr) {
246 const int cfstr_size = (
bits == 64) ? 32 : 16;
247 const int cfstr_offs = (
bits == 64) ? 16 : 8;
251 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate RzBinString.\n");
265 if (!cstr_vaddr || cstr_vaddr ==
UT64_MAX) {
276 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate RzBinString\n");
284 bs->
vaddr = cfstr_vaddr;
288 ht_up_insert(strings_db, bs->
vaddr, bs);
303 }
else if (max_interval &&
section->
size > max_interval) {
305 ") exeeds bin.maxstrbuf (0x%" PFMT64x "), skipping it.\n",
310 if (strstr(
section->name,
"__cfstring")) {
328 HtUP *strings_db =
NULL;
333 ut64 max_interval = 0;
334 size_t pool_size = 1;
336 if (min_length < 1) {
341 max_interval = bf->rbin->maxstrbuf;
346 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate thread pool.\n");
353 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate thread lock.\n");
359 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate intervals queue.\n");
363 strings_db = ht_up_new0();
365 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate string map.\n");
371 ut64 section_size = bf->size / pool_size;
380 if (max_interval && section_size > max_interval) {
382 ") exeeds bin.maxstrbuf (0x%" PFMT64x "), skipping it.\n",
383 section_size, max_interval);
390 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate SearchInterval.\n");
395 itv->
psize = section_size;
402 RZ_LOG_ERROR(
"bin_file_strings: cannot append SearchInterval to list.\n");
406 }
else if (bf->o && !rz_list_empty(bf->o->sections)) {
414 }
else if (max_interval &&
section->
size > max_interval) {
416 ") exeeds bin.maxstrbuf (0x%" PFMT64x "), skipping it.\n",
427 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate SearchInterval.\n");
439 RZ_LOG_ERROR(
"bin_file_strings: cannot append SearchInterval to list.\n");
448 .strings_db = strings_db,
452 for (
size_t i = 0;
i < pool_size; ++
i) {
463 RZ_LOG_ERROR(
"bin_file_strings: cannot allocate results list.\n");
467 for (
ut32 i = 0;
i < pool_size; ++
i) {
487 rz_list_foreach (results, it, bstr) {
495 for (
ut32 i = 0;
i < pool_size; ++
i) {
505 ht_up_free(strings_db);
RZ_API RzBinPlugin * rz_bin_file_cur_plugin(RzBinFile *bf)
#define UTIL_STR_SCAN_OPT_BUFFER_SIZE
static void scan_cfstring_table(RzBinFile *bf, HtUP *strings_db, RzList *results, ut64 max_interval)
static RzBinString * to_bin_string(RzDetectedString *src)
static void interrupt_pool(RzThreadPool *pool)
static bool is_data_section(RzBinFile *a, RzBinSection *s)
RZ_API RZ_OWN RzList * rz_bin_file_strings(RZ_NONNULL RzBinFile *bf, size_t min_length, bool raw_strings)
Generates a RzList struct containing RzBinString from a given RzBinFile.
struct search_thread_data_t SearchThreadData
#define RAW_FILE_ALIGNMENT
static void bin_file_string_search_free(SearchThreadData *std)
struct search_interval_t SearchInterval
static void * search_string_thread_runner(SearchThreadData *std)
static int string_compare_sort(const RzBinString *a, const RzBinString *b)
static st64 shared_data_read_at(SharedData *sd, ut64 addr, ut8 *buf, ut64 size)
static bool create_string_search_thread(RzThreadPool *pool, size_t min_length, RzThreadQueue *intervals, SharedData *shared)
static void interrupt_thread(RzThread *thread)
static RzList * string_scan_range(SearchThreadData *std, const ut64 paddr, const ut64 size)
struct shared_data_t SharedData
static bool shared_ht_up_insert(SharedData *sd, const ut64 key, void *value)
static void string_scan_range_cfstring(RzBinFile *bf, HtUP *strings_db, RzList *results, const RzBinSection *section)
RZ_API void rz_bin_string_free(void *_str)
int bits(struct state *s, int need)
RZ_API ut64 rz_bin_object_v2p(RZ_NONNULL RzBinObject *obj, ut64 vaddr)
Convert virtual address to offset in the file according to binary mappings.
RZ_API ut64 rz_bin_object_p2v(RZ_NONNULL RzBinObject *obj, ut64 paddr)
Convert offset in the file to virtual address according to binary mappings.
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API const KEY_TYPE bool * found
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
RZ_API bool rz_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2)
Joins 2 list into one (list2 pointer needs to be freed by the user)
RZ_API RZ_OWN void * rz_list_pop_head(RZ_NONNULL RzList *list)
Removes and returns the first element of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
RZ_API void rz_th_free(RZ_NULLABLE RzThread *th)
Frees a RzThread structure.
RZ_API RZ_OWN void * rz_th_get_user(RZ_NONNULL RzThread *th)
Returns user pointer of thread.
RZ_API RZ_OWN RzThread * rz_th_new(RZ_NONNULL RzThreadFunction function, RZ_NULLABLE void *user)
Creates and starts a new thread.
RZ_API bool rz_th_wait(RZ_NONNULL RzThread *th)
Awaits indefinetely for a thread to join.
void * calloc(size_t number, size_t size)
#define rz_return_val_if_fail(expr, val)
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
static ut32 rz_read_le32(const void *src)
static ut64 rz_read_le64(const void *src)
void(* RzListFree)(void *ptr)
int(* RzListComparator)(const void *value, const void *list_data)
#define RZ_LOG_VERBOSE(fmtstr,...)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_DEBUG(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API RzStrEnc rz_str_enc_string_as_type(RZ_NULLABLE const char *enc)
converts an encoding name to RzStrEnc
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_scan_strings_raw(RZ_NONNULL const ut8 *buf, RZ_NONNULL RzList *list, RZ_NONNULL const RzUtilStrScanOptions *opt, const ut64 from, const ut64 to, RzStrEnc type)
Look for strings in an RzBuffer.
RZ_API void rz_detected_string_free(RzDetectedString *str)
void *(* RzThreadFunction)(void *user)
#define RZ_THREAD_POOL_ALL_CORES
#define RZ_THREAD_QUEUE_UNLIMITED
#define RZ_FREE_CUSTOM(x, y)
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
size_t buf_size
Maximum size of a detected string.
XX curplugin == o->plugin.
bool strseach_check_ascii_freq
RzThreadPool is a structure which handles n-threads threads.
RzThreadQueue is a thread-safe queue that can be listened on from multiple threads.
RzThreadQueue * intervals
RZ_API void rz_th_lock_leave(RZ_NONNULL RzThreadLock *thl)
Releases a RzThreadLock structure.
RZ_API void rz_th_lock_free(RZ_NULLABLE RzThreadLock *thl)
Frees a RzThreadLock structure.
RZ_API RZ_OWN RzThreadLock * rz_th_lock_new(bool recursive)
Allocates and initialize a RzThreadLock structure.
RZ_API void rz_th_lock_enter(RZ_NONNULL RzThreadLock *thl)
Acquires a RzThreadLock structure.
RZ_API void rz_th_pool_free(RZ_NULLABLE RzThreadPool *pool)
Kills (and frees) the threads and frees the RzThreadPool struct.
RZ_API RZ_BORROW RzThread * rz_th_pool_get_thread(RZ_NONNULL RzThreadPool *pool, size_t index)
Returns the n-th thread in the thread pool.
RZ_API bool rz_th_pool_wait(RZ_NONNULL RzThreadPool *pool)
Waits the end of all the threads in the thread pool.
RZ_API bool rz_th_pool_add_thread(RZ_NONNULL RzThreadPool *pool, RZ_NONNULL RzThread *thread)
Adds a thread to the thread pool.
RZ_API size_t rz_th_pool_size(RZ_NONNULL RzThreadPool *pool)
Returns the thread pool size.
RZ_API RZ_OWN RzThreadPool * rz_th_pool_new(size_t max_threads)
returns a new RzThreadPool structure with a pool of thread
RZ_API bool rz_th_queue_push(RZ_NONNULL RzThreadQueue *queue, RZ_NONNULL void *user, bool tail)
Pushes a new element into the queue.
RZ_API void rz_th_queue_free(RZ_NULLABLE RzThreadQueue *queue)
Frees a RzThreadQueue structure.
RZ_API RZ_OWN void * rz_th_queue_pop(RZ_NONNULL RzThreadQueue *queue, bool tail)
Removes an element from the queue, but does not awaits when empty.
RZ_API RZ_OWN RzThreadQueue * rz_th_queue_new(size_t max_size, RZ_NULLABLE RzListFree qfree)
Allocates and initializes a new fifo queue.
RZ_API RZ_OWN RzAtomicBool * rz_atomic_bool_new(bool value)
Initialize a thread safe bool type container.
RZ_API bool rz_atomic_bool_get(RZ_NONNULL RzAtomicBool *tbool)
Gets the current value hold by the RzAtomicBool structure.
RZ_API void rz_atomic_bool_free(RZ_NULLABLE RzAtomicBool *tbool)
Frees a RzAtomicBool structure.
RZ_API void rz_atomic_bool_set(RZ_NONNULL RzAtomicBool *tbool, bool value)
Sets the value int the RzAtomicBool structure.
static void lock(volatile int *lk)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()