Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RzSearch refactor #4762

Draft
wants to merge 21 commits into
base: dev
Choose a base branch
from
Draft

RzSearch refactor #4762

wants to merge 21 commits into from

Conversation

Rot127
Copy link
Member

@Rot127 Rot127 commented Dec 10, 2024

WIP

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the rizin book with the relevant information (if needed)

Detailed description

Companion PR: rizinorg/rizin-testbins#162

What happens here:
Slowly copying changes from https://github.com/Rot127/rizin/tree/rz-search-reference (which is #4742 with some comments already addressed).

Will resend to fuzz-dist when all the tests pass here.

Stuff to do (without any order)

  • Move essential changes from https://github.com/Rot127/rizin/tree/rz-search-reference / Add / (search) commands to newshell + rewrite of rz_search #4742 before starting with commands
  • Fix commands
    • Bytes search
      • Implement
      • Fix suggestions
      • Use RzBuffer
      • Document usage in book (normal, wildcards, different maps, searching with debug + don't forget to run until mapped, API).
    • String search
      • Implement
      • Fix suggestions
      • Testing
        • Case insensitivity on non latin alphabets.
        • Encoding + endianess
        • diacritics
        • Search for strings less then 4 bytes.
        • Search within buffers which have no \0 in it.
      • Document in book (basic usage, API, usage of distance, behavior of edge cases of distance: utf8 and other encodings, diacritics), case (in)sensitive.
  • Update book (with example API implementation).
  • Implement general search IO API which doesn't require knowledge of search spaces (what rz_search_run() was before).
  • Show progress of search.
  • Use RzBuffer for byte space searches
  • search.align shoudl default to search.alignment=asm.cpu_bits/8.
  • (Optional) Allow to cancel search with ctrl + c
  • (Optional) Extend RzSearchHit to hold more complex data.
  • (Optional) Add option to define search/divide strategy.
  • (Optional) Dispatch views into IO as chunks to the find() callback.

Test plan

...

Closing issues

closes #1586

librz/include/rz_search.h Outdated Show resolved Hide resolved
librz/include/rz_search.h Outdated Show resolved Hide resolved
@wargio

This comment was marked as resolved.

@Rot127

This comment was marked as resolved.

Rot127 added 7 commits January 2, 2025 11:39
This makes only small edits (renames) to keep the build working.
This sets search.overlap=true by default.
Mostly because I think this what people expect.
Also, with the search.align or search.alignment options there will
be the option to search at alignments.

This also adds some hex string to bytes helpers.
Fixes them and adds tests.

Unfinished reimplementation of /x.

Fix up the hex string to buffer functions.

Fix fast mask comparison macro.

Fix byte comparison with UB.

Invert condition to match documentation of callback

Handle search options from the settings and add tests.

This sets search.overlap=true by default.
Mostly because I think this what people expect.
Also, with the search.align or search.alignment there are way
better options to consider for seraching not overlapping data.

Fix rz_hex_str2bin_mask() did set mask bits for 0

Refine documentation for rz_hex_str2bin functions.

Add byte search tests.

Don't allow wildcards with a custom mask.

Change buffer to chunk size and make it a search setting.

Make search over bytes more efficient. Searching over windows of memory.

Add some helper functions to read from IO into a RzBuffer

Simplify buffer management and fix leaks

Fix bugs add tests regarding search windows

Revert design with RzBuffer due to rizinorg#4769

Fix several stupidity bugs

Change order of byte pattern and mask.

Apply suggestions.
RzConfigNode *node = (RzConfigNode *)data;
RzThreadNCores max_threads = rz_th_max_threads(node->i_value);
if (node->value[0] == '?') {
rz_cons_printf("%d\n", max_threads);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return ncores. It's under rz_th.h

- name: opcodes
type: RZ_CMD_ARG_TYPE_STRING

- name: "/c"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to change this and have one command which search for all or one specific material

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port / (search) to rzshell
3 participants