rizin/librz/util
Ahmed Mohamed Ibrahim 38a530dbe3
librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271)
* Rename librz/util/ubase64.c into librz/util/base64.c for consistency #5216

* Add Doxygen documentation to function in librz/util/base85.c #5216

* Add unit-tests for librz/util/base85.c #5216

* Refactor base85 API and internal functions #5216

base85 was using a FILE as an input and it used to print its result to
STDOUT, which was very bad for having unit-testing or to use it to
extend rz-hash functionality, since the solution I really had was
through using pipes which isn't ideal as much as the refactoring one.

* Extend rz-hash with base85 #5126

* Fix formatting #5216

* Extract base36 decoding function from subprojects/rzwinkd/iob_net.c to librz/util/base36.c #5216

- Also, added Doxygen docs to rz_base36_decode function

* Added rz_base36_encode_dyn #5216

- this function encode a u64 value to it's char[13+1] base36 counterpart
- later, it will be helpful in expanding the funcitionality of rz-hash
- added its Doxygen docs

* Expand rz-hash with base36 encoding/decoding #5216

* Refactor rz_base36_decode to return a suitable error code like -1 #5216

- that should help testing it later for valid and invalid decodings
- keeping the original behaviour as it was in
subprojects/rzwinkd/iob_net.c

* Add unit-tests for base36 encoding & decoding functions #5216

* Fix formatting #5216

* Fix base36.h header file guards #5216

* Add base32 encoding & decoding #5216

added their Doxygen Docs as well

* Add base32 encoding and decoding unti-tests #5216

* Expand rz-hash with base32 encoding/decoding functionality #5216

* Fix formatting #5216

* Fix add base32 to codec_name_bytes #5216

* Fix base32 docs #5216

* Add base16 encoding/decoding functions #5216

- added their Doxygen docs as well.

* Add base16 unit-tests #5216

* Fix test_base85 conversions warnings #5216

* Expand rz-hash with base16 encoding/decoding functionality #5216

* Fix formatting #5216

* Fix doxygen docs #5216

* Restore subprojects/rizin-shell-parser/parser.c to match origin/dev

* Fix the order by baseXX

* Fix base16 - invert the logic in calculate_src_length

* Fix base16 - intialize variables in rz_base16_encode

* Fix base16 - null terminate the output buffer of rz_base16_encode_dyn

* Fix base16 - get rid of unnecessary else in rz_base16_decode

* Fix base16 - use `len & 1` instead of `(len % 2) != 0`

* Fix base32 - invert the logic in calculate_src_length

* Fix base32 - compress two return statments by using `rz_return_val_if_fail(src && dest, 0);`

* Fix base32 - null terminate the output of rz_base32_encode

* Fix base32 - get rid of unnecessary else in rz_base32_decode

add more parentheses to split addition from mult for better clarity

* Fix base32 - intialize variables in rz_base32_encode_dyn

* Fix base36 - intialize `tmp` variable in rz_base36_encode_dyn

* Fix base36 - use RZ_LOG_ERROR instead of eprintf

* Fix base36 - use RZ_NULLABLE for the API interface

* Fix base85 - use RZ_OUT & RZ_NULLABLE for the API interface

* Fix base85 - use RZ_LOG_ERROR instead of eprintf

* Fix base85 - use size_t instead of int for decode_tuple_buf

* Fix base85 - remove unused varaible, `out_len`, in rz_base85_encode_dyn

* Fix base85 - correct decode buffer size calculation

The previous rz_base85_dec_buflen() underestimated the worst‑case output
size (3 bytes per 4 input chars), causing overflows when using ‘z’/’y’
abbreviations. Update it to allocate 4 bytes per input character plus
one for the NUL terminator, eliminating heap-buffer-overflow errors.

* Fix formatting

* Fix base85-test - use `newlines` variable to make sure line breaks were inserted as expected

* Fix base85-test - remove unnecessary includes

* Fix rz-hash test - updated rz-hash -L expected result

* Fix crypto_base36 - use RZ_LOG_ERROR instead of eprintf

* Fix base16 - compress rz_return_val_if_fail statements and move before locals

* Update base16 - use hex.c existing encoding/decoding logic

- base16.c encoding/decoding functions are now wrappers for hex.c
  `rz_hex_bin2str` and `rz_hex_str2bin` functions
- updated related base16 unit testing and documentation
- updated the integraion with rz-hash binary (or crypto_base16)

* Fix formatting

* Add documentation to rz_hex_bin2str

* Fix base85 - add missing `reutrn` docs to rz_base85_encode function

* Fix base85 - use RZ_NONNULL for dest and src function instead of RZ_NULLABLE

* Fix base36 - use RZ_NONNULL for dest and src function instead of RZ_NULLABLE

* Fix base16 - use RZ_NONNULL for dest and src function instead of RZ_NULLABLE

* Fix base32 - use RZ_NONNULL for dest and src function instead of RZ_NULLABLE

* Fix base16 - add missig checks for invalid inputs in rz_base16_encode & rz_base16_encode_dyn

* Fix base32 - add missing checks for bad encoding

* Fix - add missing SPDX

* Fix Formatting

* Add rz_base36_encode & rz_base36_decode_dyn functions to base36 API
2025-08-17 15:26:25 +08:00
..
float librz/util/float: fix cast of negative zero to integer. (#5291) 2025-08-06 00:06:43 +08:00
ht util: implement iterator for hash tables and sets (#4639) 2024-09-24 21:36:54 +08:00
sdb Remove global variables from sdb/main.c (#5284) 2025-07-23 19:17:25 +00:00
alloc.c
annotated_code.c
ascii_table.c
asn1.c Implement /cm and remove /cd /ca /cr 2025-03-04 02:45:15 +08:00
asn1_oids.h Implement /cm and remove /cd /ca /cr 2025-03-04 02:45:15 +08:00
assert.c
astr.c
axml.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
axml_resources.h
base16.c librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
base32.c librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
base36.c librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
base64.c librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
base85.c librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
base91.c
big-gmp.c
big-ssl.c
big.c
bitvector.c Fix some coverity issues. (#5043) 2025-03-27 12:38:42 +08:00
buf.c Introduce buffer_from_bytes and helper functions to rz_buf. 2025-02-13 22:55:33 +08:00
buf_bytes.c RzBuffer consistency and make buffer type public (#4666) 2024-10-12 11:27:21 +02:00
buf_file.c RzBuffer consistency and make buffer type public (#4666) 2024-10-12 11:27:21 +02:00
buf_io.c RzBuffer consistency and make buffer type public (#4666) 2024-10-12 11:27:21 +02:00
buf_io_fd.c RzBuffer consistency and make buffer type public (#4666) 2024-10-12 11:27:21 +02:00
buf_mmap.c
buf_ref.c
buf_sparse.c
calc.c
chmod.c
compression.c
debruijn.c
ebcdic.c String/Hex-Search 2/9: Improve Unicode support. 2025-02-22 04:12:49 +08:00
event.c
file.c doc: add some rz_file_*() functions descriptions (#4991) 2025-03-12 11:41:17 +08:00
getopt.c
graph.c
graph_drawable.c
hex.c librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
idpool.c
intervaltree.c
iterator.c refactor: Use HtSP for storing plugins. (#4687) 2024-10-26 16:31:13 +08:00
itv.c librz/util: implement a bounded interval. (#4977) 2025-03-09 15:24:07 +08:00
json_indent.c librz/core/cmd: convert pj to RzShell (#4726) 2024-11-24 10:20:06 +08:00
json_parser.c Rename RzRune to RzCodePoint. (#4860) 2025-01-24 20:39:04 +08:00
lang_byte_array.c
lib.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
list.c /z: Remove hit dupes (#5029) 2025-03-23 21:08:49 +08:00
log.c Replace rz_core_warn_after_output function with RZ_LOG_WARN_AFTER macro (#5227) 2025-06-27 15:03:42 +08:00
luhn.c
mem.c String/Hex-Search 3/9: Rename search related config values. 2025-02-22 04:12:49 +08:00
meson.build librz/util: base64, base85, base36, base32, base16 support and refactor (#5216) (#5271) 2025-08-17 15:26:25 +08:00
name.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
path.c Remove Global/Static variables in path.c to make it thread safe (#5148) 2025-06-13 21:34:33 +08:00
pj.c
pkcs7.c
print.c hexII mode: add option to hide dots in for printable characters (#5126) 2025-05-05 21:50:58 +08:00
protobuf.c
punycode.c
range.c
rbtree.c
README.md
regex.c Add rz_regex_new_bytes(), rz_regex_match_all_overlap() and rz_regex_parse_flag_desc(). 2025-02-14 00:27:53 +08:00
serialize_spaces.c
set.c util: implement iterator for hash tables and sets (#4639) 2024-09-24 21:36:54 +08:00
signal.c
skiplist.c
skyline.c
spaces.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
stack.c
str.c String/Hex-Search 3/9: Rename search related config values. 2025-02-22 04:12:49 +08:00
str_constpool.c
str_search.c String/Hex-Search 8/9: Add vastly improved string search. 2025-02-22 04:12:49 +08:00
str_trim.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
strbuf.c Move RzBreakpoint into RzDebug (#5124) 2025-05-13 01:57:37 +08:00
strpool.c
subprocess.c Move RzBreakpoint into RzDebug (#5124) 2025-05-13 01:57:37 +08:00
sys.c Remove unused rz_sys_cmdbg() function (#5268) 2025-07-14 17:57:07 +00:00
syscmd.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
table.c util/table: add basic query tests 2025-06-21 01:31:53 +08:00
thread.c
thread.h
thread_cond.c
thread_hash_table.c
thread_iterators.c Fix some coverity issues. (#5043) 2025-03-27 12:38:42 +08:00
thread_lock.c
thread_pool.c
thread_queue.c
thread_sem.c
thread_types.c
time.c struct timezone is obsolete/deprecated (#4672) 2024-10-16 17:13:17 +08:00
tree.c
uleb128.c Check we do not shift more than 63. in [us]leb128 2024-09-08 17:34:55 +08:00
unicode.c String/Hex-Search 2/9: Improve Unicode support. 2025-02-22 04:12:49 +08:00
unum.c Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
utf8.c /z: Set min_length to max(|search literal|, search.str.min_length) (#5083) 2025-04-12 14:53:22 +08:00
utf16.c String/Hex-Search 2/9: Improve Unicode support. 2025-02-22 04:12:49 +08:00
utf32.c String/Hex-Search 2/9: Improve Unicode support. 2025-02-22 04:12:49 +08:00
vector.c Fix possible segfaults derefencing vec->v.a if vector is empty. 2025-02-13 22:55:50 +08:00
version.c Remove Global/Static variables in path.c to make it thread safe (#5148) 2025-06-13 21:34:33 +08:00
w32-sys.c
x509.c
x509.h

RzUtil

This library contains all common utilities and functions that are used by other modules in the Rizin framework, like string manipulation, data structures (lists, vectors, trees, etc.), JSON parsing/printing, and others.

What can I expect here?

  • Numbers/math functions
  • Functions likely needed across several other modules
  • Data structures: lists, vectors, trees, graphs, skiplist
  • RzBuffer
  • JSON parsing, JSON printing
  • PKCS7
  • BitVector
  • Functions that are very common and not specific to other modules
  • SDB
  • Floating point number operations
  • OS/Platform-independent abstractions for common operations (e.g. rename a file, create temporary file, etc.)