Rizin
unix-like reverse engineering framework and cli tools
|
#include <rz_types.h>
#include <rz_util.h>
#include <rz_io.h>
#include "buf_file.c"
#include "buf_sparse.c"
#include "buf_bytes.c"
#include "buf_mmap.c"
#include "buf_io_fd.c"
#include "buf_io.c"
#include "buf_ref.c"
Go to the source code of this file.
Macros | |
#define | GET_STRING_BUFFER_SIZE 32 |
Enumerations | |
enum | RzBufferType { RZ_BUFFER_FILE , RZ_BUFFER_IO_FD , RZ_BUFFER_IO , RZ_BUFFER_BYTES , RZ_BUFFER_MMAP , RZ_BUFFER_SPARSE , RZ_BUFFER_REF } |
enum RzBufferType |
Definition at line 46 of file buf.c.
References b, and rz_return_val_if_fail.
Referenced by rz_buf_fini().
Definition at line 84 of file buf.c.
References d1, d2, d3, d4, dst, i, k, regress::m, n, NULL, r, rz_buf_read(), rz_buf_write(), rz_num_get(), rz_read_ble16(), rz_read_ble32(), rz_read_ble64(), rz_read_ble8(), src, st64, autogen_x86imm::tmp, and ut64().
Referenced by rz_buf_fread(), and rz_buf_fwrite().
Definition at line 52 of file buf.c.
References b, rz_return_val_if_fail, and UT64_MAX.
Referenced by rz_buf_size().
Definition at line 40 of file buf.c.
References b, and rz_return_val_if_fail.
Referenced by rz_buf_new_with_methods().
|
static |
Definition at line 181 of file buf.c.
References addr, b, err, free(), length, rz_buf_read_at(), rz_buf_resize(), rz_buf_size(), rz_buf_write_at(), RZ_NEWS, rz_return_val_if_fail, st64, autogen_x86imm::tmp, and ut64().
Referenced by rz_buf_insert_bytes().
Definition at line 58 of file buf.c.
References b, len, and rz_return_val_if_fail.
Referenced by rz_buf_read().
Definition at line 78 of file buf.c.
References b, and rz_return_val_if_fail.
Referenced by rz_buf_resize().
Definition at line 72 of file buf.c.
References addr, b, and rz_return_val_if_fail.
Referenced by rz_buf_seek().
|
static |
Definition at line 64 of file buf.c.
References b, buf_whole_buf_free(), len, and rz_return_val_if_fail.
Referenced by rz_buf_write().
Definition at line 214 of file buf.c.
References b, buf_size, buf_whole_buf_free(), NULL, rz_buf_read_at(), rz_buf_size(), RZ_FREE, RZ_NEWS, rz_return_val_if_fail, ut64(), and UT64_MAX.
Referenced by rz_buf_append_buf(), rz_buf_data(), rz_buf_dump(), and rz_buf_new_with_buf().
|
static |
Definition at line 244 of file buf.c.
References buffer_bytes_methods, buffer_file_methods, buffer_io_fd_methods, buffer_io_methods, buffer_mmap_methods, buffer_ref_methods, buffer_sparse_methods, NULL, rz_buf_new_with_methods(), RZ_BUFFER_BYTES, RZ_BUFFER_FILE, RZ_BUFFER_IO, RZ_BUFFER_IO_FD, RZ_BUFFER_MMAP, RZ_BUFFER_REF, RZ_BUFFER_SPARSE, rz_warn_if_reached, and type.
Referenced by palloc(), rz_buf_new_empty(), rz_buf_new_file(), rz_buf_new_mmap(), rz_buf_new_slice(), rz_buf_new_slurp(), rz_buf_new_sparse(), rz_buf_new_sparse_overlay(), rz_buf_new_with_bytes(), rz_buf_new_with_io(), rz_buf_new_with_io_fd(), and rz_buf_new_with_pointers().
RZ_API bool rz_buf_append_buf | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL RzBuffer * | a | ||
) |
Append the content of the buffer a to the buffer b.
dst | the destination buffer with write permission |
src | the source buffer |
The function append the content of the buffer a, the two buffer don't need to have the same back end. WARNING: This function can allocate a lot of memory.
Definition at line 685 of file buf.c.
References a, b, get_whole_buf(), rz_buf_append_bytes(), rz_return_val_if_fail, autogen_x86imm::tmp, and ut64().
Referenced by build(), and xnu_generate_corefile().
RZ_API bool rz_buf_append_buf_slice | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL RzBuffer * | a, | ||
ut64 | offset, | ||
ut64 | size | ||
) |
Append a slice of the buffer a to the buffer b.
dst | the destination buffer with write permission |
src | the source buffer |
offset | The starting offset in the buffer a. |
size | The number of bytes that will be extract from the buffer a. |
The function append a slice of the buffer a, the two buffer don't need to have the same back end. WARNING: This function can allocate a lot of memory.
Definition at line 705 of file buf.c.
References a, b, free(), r, rz_buf_append_bytes(), rz_buf_read_at(), RZ_NEWS, rz_return_val_if_fail, st64, and autogen_x86imm::tmp.
RZ_API bool rz_buf_append_bytes | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const ut8 * | buf, | ||
ut64 | length | ||
) |
Append an array of bytes to the buffer.
dst | the destination buffer with write permission |
src | the source buffer |
length | ... |
Definition at line 732 of file buf.c.
References b, length, RZ_BUF_END, rz_buf_seek(), rz_buf_write(), and rz_return_val_if_fail.
Referenced by build(), flirt_write_module(), flirt_write_node(), gprobe_debugoff(), gprobe_debugon(), gprobe_frame_sp(), gprobe_get_reply_sp(), gprobe_getdeviceid(), gprobe_getinformation(), gprobe_read(), gprobe_reset(), gprobe_runcode(), gprobe_write(), rz_buf_append_buf(), rz_buf_append_buf_slice(), rz_buf_append_string(), rz_buf_append_ut16(), rz_buf_append_ut32(), rz_buf_append_ut64(), rz_buf_set_bytes(), rz_egg_append(), rz_egg_append_bytes(), rz_egg_assemble_asm(), rz_egg_include(), rz_egg_load(), rz_egg_printf(), rz_egg_raw(), rz_sign_flirt_write_compressed_pattern_to_buffer(), rz_write_vle16(), rz_write_vle32(), socket_slurp(), xnu_generate_corefile(), and xnu_write_mem_maps_to_buffer().
RZ_API bool rz_buf_append_nbytes | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | length | ||
) |
Extend the size of the buffer.
b | A buffer with write permission. |
length | The number of bytes to add at the end of the buffer. |
Definition at line 748 of file buf.c.
References b, length, rz_buf_resize(), rz_buf_size(), and rz_return_val_if_fail.
RZ_API st64 rz_buf_append_string | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const char * | str | ||
) |
Append a string to the buffer.
b | A buffer with write permission. |
str | ... |
...
Definition at line 962 of file buf.c.
References b, rz_buf_append_bytes(), rz_return_val_if_fail, and cmd_descs_generate::str.
Referenced by add_spaces(), fill_level(), flirt_pat_write_line(), flirt_write_module(), rz_analysis_reflines_str(), rz_sign_flirt_write_compressed_pattern_to_buffer(), and rz_sign_flirt_write_string_pattern_to_buffer().
RZ_API bool rz_buf_append_ut16 | ( | RZ_NONNULL RzBuffer * | b, |
ut16 | n | ||
) |
Add a ut16 number at the end of the buffer.
b | A buffer with write permission. |
n |
...
Definition at line 762 of file buf.c.
References b, n, rz_buf_append_bytes(), and rz_return_val_if_fail.
RZ_API bool rz_buf_append_ut32 | ( | RZ_NONNULL RzBuffer * | b, |
ut32 | n | ||
) |
Add a ut32 number at the end of the buffer.
b | A buffer with write permission. |
n |
...
Definition at line 776 of file buf.c.
References b, n, rz_buf_append_bytes(), and rz_return_val_if_fail.
RZ_API bool rz_buf_append_ut64 | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | n | ||
) |
Add a ut64 number at the end of the buffer.
b | A buffer with write permission. |
n |
...
Definition at line 790 of file buf.c.
References b, n, rz_buf_append_bytes(), and rz_return_val_if_fail.
RZ_DEPRECATE RZ_API RZ_BORROW ut8* rz_buf_data | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL RZ_OUT ut64 * | size | ||
) |
Return a borrowed array of bytes representing the buffer data.
b | Buffer to get the data from. |
size | Size of the returned data. |
WARNING: this function should be used with care because it may allocate the entire buffer in memory. Consider using the rz_buf_read* APIs or rz_buf_fwd_scan API instead and read only the chunks you need.
Definition at line 1287 of file buf.c.
References b, get_whole_buf(), NULL, and rz_return_val_if_fail.
Referenced by buf_get_whole_buf(), check_buffer(), create(), gprobe_frame_sp(), gprobe_getinformation(), gprobe_send_request_sp(), io_default_get_buf(), load_buffer(), rz_bin_file_xtr_load_buffer(), rz_cmd_debug(), rz_egg_finalize(), rz_egg_run(), rz_egg_run_rop(), rz_egg_shellcode(), rz_io_open_buffer(), rz_io_zip_flush_file(), rz_main_rz_bin(), and rz_main_rz_gg().
RZ_API bool rz_buf_dump | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const char * | file | ||
) |
Dump the content of the buffer to a file.
b | A buffer with write permission. |
file | The output file where the buffer content while be outputted. |
...
Definition at line 806 of file buf.c.
References b, get_whole_buf(), rz_file_dump(), rz_return_val_if_fail, autogen_x86imm::tmp, and ut64().
Free all internal data hold by the buffer.
b | A buffer with write permission. |
...
Definition at line 822 of file buf.c.
References b, buf_fini(), and buf_whole_buf_free().
Referenced by rz_asm_op_fini(), and rz_buf_free().
RZ_API st64 rz_buf_fread | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL ut8 * | buf, | ||
RZ_NONNULL const char * | fmt, | ||
int | n | ||
) |
...
b | ... |
buf | ... |
fmt | ... |
n | ... |
...
Definition at line 978 of file buf.c.
References b, buf_format(), dst, n, rz_buf_free(), rz_buf_new_with_pointers(), rz_return_val_if_fail, st64, and UT64_MAX.
Referenced by rz_bin_coff_init_hdr(), and rz_buf_fread_at().
RZ_API st64 rz_buf_fread_at | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | addr, | ||
RZ_NONNULL ut8 * | buf, | ||
RZ_NONNULL const char * | fmt, | ||
int | n | ||
) |
...
b | ... |
addr | ... |
buf | ... |
fmt | ... |
n | ... |
...
Definition at line 1001 of file buf.c.
References addr, b, n, rz_buf_fread(), rz_buf_seek(), RZ_BUF_SET, rz_buf_tell(), rz_return_val_if_fail, st64, and autogen_x86imm::tmp.
Referenced by art_header_load(), bin_pe_dotnet_init_metadata(), carve_deps_at_address(), check_buffer(), create_cache_bins(), entries(), estimate_slide(), get_rebase_info(), get_rebase_infos(), header(), init_items(), lmf_header_load(), load_buffer(), parse_chained_fixups(), parse_thread(), populate_cache_maps(), read_cache_accel(), read_cache_header(), read_cache_images(), read_cache_imgextra(), rz_axml_decode(), rz_bin_coff_init_hdr(), rz_bin_coff_init_opt_hdr(), rz_bin_coff_init_scn_hdr(), rz_bin_coff_init_symtable(), rz_coresym_cache_element_header_new(), rz_dyld_locsym_new(), rz_dyldcache_symbols_from_locsym(), sections(), and sep64_xtr_ctx_new().
Free all internal data hold by the buffer and the buffer.
b | ... |
...
Definition at line 1253 of file buf.c.
References b, free(), and rz_buf_fini().
Referenced by __close(), __open(), ar_close(), ar_open_all(), ar_open_file(), basefind_create_array_of_addresses(), bin_pe_dotnet_destroy_clr(), buf_ref_fini(), buf_sparse_fini(), build(), classes(), cmd_search_bin(), create(), destroy(), egg_patch_free(), extract(), get_gnu_debugdata_elf_symbols(), get_virtual_files(), gprobe_debugoff(), gprobe_debugon(), gprobe_getdeviceid(), gprobe_getinformation(), gprobe_read(), gprobe_reset(), gprobe_runcode(), gprobe_write(), handle_tmp_desc(), mach0_free(), msf_stream_directory_free(), msf_stream_free(), nso_free(), oneshot_buffer(), parse_classes(), rabin_do_operation(), rz_analysis_il_vm_free(), rz_analysis_il_vm_new(), rz_analysis_reflines_str(), rz_asm_massemble(), rz_asm_pseudo_incbin(), rz_axml_decode(), rz_bflt_free(), rz_bin_coff_free(), rz_bin_dex_free(), rz_bin_dmp64_free(), rz_bin_elf_free(), rz_bin_fatmach0_free(), rz_bin_file_compute_hashes(), rz_bin_file_free(), rz_bin_file_set_bytes(), rz_bin_mdmp_free(), rz_bin_mdmp_init_pe_bins(), rz_bin_mz_free(), rz_bin_open_io(), rz_bin_pdb_free(), rz_bin_pdb_parse_from_file(), rz_bin_pe_free(), rz_bin_pemixed_free(), rz_bin_pemixed_init_native(), rz_bin_te_free(), rz_bin_virtual_file_free(), rz_bin_wasm_destroy(), rz_bin_xtrdata_free(), rz_bin_zimg_new_buf(), rz_buf_fread(), rz_buf_fwrite(), rz_cf_value_data_free(), rz_cmd_debug(), rz_core_bin_whole_strings(), rz_core_fini(), rz_core_flirt_convert_file(), rz_core_flirt_create_file(), rz_core_flirt_dump_file(), rz_debug_dmp_init(), rz_dyldcache_free(), rz_egg_encode(), rz_egg_finalize(), rz_egg_free(), rz_egg_reset(), rz_file_deflate(), rz_file_inflate(), rz_il_mem_free(), rz_io_def_mmap_free(), rz_io_zip_free_zipfileobj(), rz_kernel_cache_free(), rz_main_rz_bin(), rz_sign_flirt_apply(), rz_sign_flirt_parse_compressed_pattern_from_buffer(), rz_sign_flirt_write_compressed_pattern_to_buffer(), sep64_xtr_ctx_get_slice(), sigdb_signature_resolve_details(), socket_http_answer(), virtual_files(), and xnu_generate_corefile().
RZ_API ut64 rz_buf_fwd_scan | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | start, | ||
ut64 | amount, | ||
RZ_NONNULL RzBufferFwdScan | fwd_scan, | ||
RZ_NULLABLE void * | user | ||
) |
Scans buffer linearly in chunks calling fwd_scan
for each chunk.
b | RzBuffer to read |
start | Start address |
amount | Amount of bytes to read |
fwd_scan | Function to call for each chunk |
user | User data to pass to fwd_scan |
Definition at line 1303 of file buf.c.
References addr, b, buf_size, test_evm::end, free(), malloc(), read(), rz_buf_read_at(), rz_buf_size(), RZ_MIN, rz_return_val_if_fail, start, ut64(), UT64_ADD_OVFCHK, and UT64_MAX.
Referenced by bin_pe_compute_authentihash(), bin_pe_get_actual_checksum(), find_go_build_info(), and rz_bin_file_compute_hashes().
RZ_API st64 rz_buf_fwrite | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const ut8 * | buf, | ||
RZ_NONNULL const char * | fmt, | ||
int | n | ||
) |
...
b | ... |
addr | ... |
buf | ... |
fmt | ... |
n | ... |
...
Definition at line 1033 of file buf.c.
References b, buf_format(), n, rz_buf_free(), rz_buf_new_with_pointers(), rz_return_val_if_fail, src, st64, and UT64_MAX.
Referenced by rz_buf_fwrite_at().
RZ_API st64 rz_buf_fwrite_at | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | addr, | ||
RZ_NONNULL const ut8 * | buf, | ||
RZ_NONNULL const char * | fmt, | ||
int | n | ||
) |
...
b | ... |
addr | ... |
buf | ... |
fmt | ... |
n | ... |
...
Definition at line 1056 of file buf.c.
References addr, b, n, rz_buf_fwrite(), rz_buf_seek(), RZ_BUF_SET, rz_buf_tell(), rz_return_val_if_fail, st64, and autogen_x86imm::tmp.
Get a string with a max length from the buffer.
b | RzBuffer pointer |
addr | The address of the string |
size | The max length authorized |
Return an heap-allocated string read from the RzBuffer b at address addr. The length depends on the first '\0' found and the arguments size in the buffer. If there is no '\0' in the buffer, there is no string, thus NULL is returned.
Definition at line 585 of file buf.c.
References addr, b, count, GET_STRING_BUFFER_SIZE, NULL, r, rz_buf_read_at(), rz_return_val_if_fail, rz_str_nlen(), rz_strbuf_append_n(), rz_strbuf_drain(), rz_strbuf_free(), rz_strbuf_new(), st64, and autogen_x86imm::tmp.
Referenced by parse_note_file(), and rz_buf_get_string().
RZ_API RZ_OWN char* rz_buf_get_string | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | addr | ||
) |
Get a string from the buffer.
b | RzBuffer pointer |
addr | The address of the string |
Return an heap-allocated string read from the RzBuffer b at address addr. The length depends on the first '\0' found in the buffer. If there is no '\0' in the buffer, there is no string, thus NULL is returned.
Definition at line 628 of file buf.c.
References addr, b, NULL, rz_buf_get_nstring(), rz_buf_size(), and rz_return_val_if_fail.
Referenced by mach_headerfields(), parse_dbi_stream_ex_header(), parse_gdata_global(), rz_bin_pe_get_clr_symbols(), and rz_dyldcache_symbols_from_locsym().
RZ_API st64 rz_buf_insert_bytes | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | addr, | ||
RZ_NONNULL const ut8 * | buf, | ||
ut64 | length | ||
) |
Insert an array of bytes in the buffer.
b | A buffer with write permission. |
addr | ... |
buf | ... |
length | ... |
...
Definition at line 1087 of file buf.c.
References addr, b, buf_move_back(), length, rz_buf_write_at(), rz_return_val_if_fail, and st64.
Referenced by rz_buf_prepend_bytes().
Creates a new empty buffer with a predefined size;.
len | The length in byte of the new buffer. |
The function creates a new buffer of the specified length in memory, filled with \0.
Definition at line 285 of file buf.c.
References buf_bytes_user::data_steal, free(), len, buf_bytes_user::length, new_buffer(), NULL, RZ_BUFFER_BYTES, RZ_NEWS0, and buf_bytes_user::steal.
Referenced by get_gnu_debugdata_elf_symbols(), get_virtual_files(), rz_sign_flirt_write_compressed_pattern_to_buffer(), and virtual_files().
Creates a new buffer from a file.
file | The filename used to create the new buffer. |
perm | Same meaning than the symbolic constants defined in sys/stat.h. |
mode | Same meaning than the symbolic constants use with open (fcntl.h). |
The function creates a new buffer synchronized with the file content, opening it with rz_sys_open and using regular read/write operations to change its content.
Definition at line 317 of file buf.c.
References file, buf_file_user::file, buf_file_user::mode, new_buffer(), buf_file_user::perm, and RZ_BUFFER_FILE.
Referenced by ar_open_all(), ar_open_file(), rz_bin_open_io(), rz_cmd_debug(), rz_core_flirt_convert_file(), rz_core_flirt_create_file(), rz_file_deflate(), rz_file_inflate(), rz_io_def_mmap_create_new_file(), and sigdb_signature_resolve_details().
Creates a new buffer from a file using rz_file_mmap.
file | The filename used to create the new buffer. |
perm | Same meaning than the symbolic constants defined in sys/stat.h. |
mode | Same meaning than the symbolic constants use with open (fcntl.h). |
The function creates a new buffer synchronized with the file content, using mmap to access the file.
Definition at line 339 of file buf.c.
References buf_mmap_user::filename, buf_mmap_user::mode, new_buffer(), NULL, buf_mmap_user::perm, RZ_BUFFER_MMAP, and rz_return_val_if_fail.
Referenced by rz_io_def_mmap_create_new_file().
Creates a new buffer from a slice of another buffer.
b | The source buffer used to create the sub buffer. |
offset | The starting offset in the source buffer. |
size | The number of bytes that will be extract from the source buffer. |
The function creates a new buffer which shows just a slice of another one, passed as argument. The allocated buffer will reference the source buffer. So both buffer are synchronized.
Definition at line 364 of file buf.c.
References b, new_buffer(), buf_ref_user::offset, buf_ref_user::parent, RZ_BUFFER_REF, and buf_ref_user::size.
Referenced by bin_pe_dotnet_init_metadata(), cmd_search_bin(), get_gnu_debugdata_elf_symbols(), rz_bin_fatmach0_extract(), rz_bin_open_io(), and sep64_xtr_ctx_get_slice().
Creates a new buffer from a file.
file | The filename used to create the new buffer. |
The function creates a new buffer in memory, initializing it with the whole content of the specified file.
Definition at line 384 of file buf.c.
References buf_bytes_user::data_steal, len, buf_bytes_user::length, new_buffer(), NULL, RZ_BUFFER_BYTES, rz_file_slurp(), buf_bytes_user::steal, autogen_x86imm::tmp, and ut64().
Referenced by rz_bin_pdb_parse_from_file(), rz_core_flirt_convert_file(), rz_core_flirt_dump_file(), and rz_sign_flirt_apply().
Creates a sparse buffer.
Oxff | The byte used to fill unpopulated bytes. |
The function creates a new allocated buffer using the RZ_BUFFER_SPARSE back end. Creates a new sparse RzBuffer where unpopulated bytes are filled with Oxff parameter.
Definition at line 408 of file buf.c.
References b, new_buffer(), NULL, and RZ_BUFFER_SPARSE.
Referenced by __open().
RZ_API RZ_OWN RzBuffer* rz_buf_new_sparse_overlay | ( | RzBuffer * | b, |
RzBufferSparseWriteMode | write_mode | ||
) |
Creates a sparse buffer from a already populated buffer.
b | The source buffer used to create the sub buffer. |
write_mode | Defined how byte are written to the buffer. |
The function creates a new allocated buffer using the RZ_BUFFER_SPARSE back end. Creates a new sparse RzBuffer where unpopulated bytes are taken as-is from b
Definition at line 426 of file buf.c.
References b, sparse_init_config_t::base, new_buffer(), NULL, RZ_BUFFER_SPARSE, and rz_return_val_if_fail.
Referenced by bflt_patch_relocs(), patch_relocs(), and rz_coff_get_patched_buf().
Creates a new buffer from a source buffer.
b | The source buffer used to create the sub buffer. |
The function creates a new allocated buffer using the RZ_BUFFER_BYTES back end. WARNING: this function doesn't use reference counting, this can lead to a lot of memory overhead.
Definition at line 448 of file buf.c.
References b, get_whole_buf(), rz_buf_new_with_bytes(), autogen_x86imm::tmp, and ut64().
Referenced by rabin_do_operation(), rz_bin_mz_new_buf(), rz_bin_pemixed_init_native(), and rz_bin_te_new_buf().
Creates a new buffer with a bytes array.
bytes | The bytes array used to initialized the buffer. |
len | The length of the bytes array. |
The function creates a new buffer in memory, initializing it with the bytes passed as argument. The bytes parameter can be NULL, but the length should be set to 0.
Definition at line 465 of file buf.c.
References bytes, buf_bytes_user::data, len, buf_bytes_user::length, new_buffer(), NULL, RZ_BUFFER_BYTES, and rz_return_val_if_fail.
Referenced by build(), create(), dex_create_relocations(), gprobe_debugoff(), gprobe_debugon(), gprobe_getdeviceid(), gprobe_getinformation(), gprobe_read(), gprobe_reset(), gprobe_runcode(), gprobe_write(), handle_tmp_desc(), rz_analysis_reflines_str(), rz_bin_fatmach0_from_bytes_new(), rz_bin_fatmach0_new(), rz_bin_file_set_bytes(), rz_bin_mdmp_init_pe_bins(), rz_bin_mz_new(), rz_bin_pemixed_from_bytes_new(), rz_bin_pemixed_init_dos(), rz_bin_te_new(), rz_buf_new_with_buf(), rz_buf_new_with_string(), rz_core_cmd_subst_i(), rz_core_init(), rz_egg_finalize(), rz_egg_new(), rz_egg_patch(), rz_egg_reset(), rz_io_zip_create_new_file(), rz_io_zip_slurp_file(), rz_main_rz_gg(), socket_http_answer(), and xnu_generate_corefile().
RZ_API RZ_OWN RzBuffer* rz_buf_new_with_io | ( | RZ_NONNULL void * | iob | ) |
Creates a new buffer wrapping the memory map exposed by RzIOBind.
iob | Pointer to RzIOBind structure. |
This buffer will use rz_io_read_at()
/rz_io_write_at()
as implemented by the RzIOBind given.
Definition at line 509 of file buf.c.
References buf_io_fd_user::iob, new_buffer(), NULL, RZ_BUFFER_IO, and rz_return_val_if_fail.
Referenced by rz_analysis_il_vm_new(), and rz_debug_dmp_init().
RZ_API RZ_OWN RzBuffer* rz_buf_new_with_io_fd | ( | RZ_NONNULL void * | iob, |
int | fd | ||
) |
Creates a new buffer wrapping a file descriptor accessed through RzIOBind.
iob | Pointer to RzIOBind structure. |
fd | File descriptor to wrap in the buffer. |
The function creates a new buffer wrapping access to a file descriptor through the RzIOBind methods specified in librz/io.
Definition at line 490 of file buf.c.
References fd, buf_io_fd_user::fd, buf_io_fd_user::iob, new_buffer(), NULL, RZ_BUFFER_IO_FD, and rz_return_val_if_fail.
Referenced by basefind_new_bin_file(), cmd_search_bin(), rz_bin_file_compute_hashes(), rz_bin_open_io(), and rz_core_bin_whole_strings().
RZ_API RZ_OWN RzBuffer* rz_buf_new_with_methods | ( | RZ_NONNULL const RzBufferMethods * | methods, |
void * | init_user | ||
) |
Creates a new buffer with a specific back end.
methods | A struct holding the list of methods to use. |
init_user | Some implementation specific information. |
The function creates a new allocated buffer using a custom back end. This function should only be used when no other back end are appropriate.
Definition at line 525 of file buf.c.
References b, buf_init(), free(), NULL, and RZ_NEW0.
Referenced by new_buffer(), new_rebasing_and_stripping_buf(), rz_dyldcache_new_rebasing_buf(), and rz_xnu_kernelcache_new_rebasing_buf().
Creates a new buffer with a bytes array.
bytes | The bytes array used to initialized the buffer. |
len | The length of the bytes array. |
steal | If the boolean is true the function take the ownership of the data. |
The function creates a new buffer in memory. The argument bytes
is used as the memory backend if steal
is true, otherwise a new buffer is allocated and its content is initialized with the one from bytes
.
Definition at line 552 of file buf.c.
References bytes, buf_bytes_user::data_steal, len, buf_bytes_user::length, new_buffer(), RZ_BUFFER_BYTES, and buf_bytes_user::steal.
Referenced by extract_slice(), load_buffer(), pdb7_extract_msf_stream_directory(), pdb7_extract_streams(), rz_axml_decode(), rz_bin_file_set_bytes(), rz_buf_fread(), rz_buf_fwrite(), rz_cf_value_data_new(), and rz_sign_flirt_parse_compressed_pattern_from_buffer().
RZ_API RZ_OWN RzBuffer* rz_buf_new_with_string | ( | RZ_NONNULL const char * | msg | ) |
Creates a new buffer from a string.
msg | The source string used to create the buffer. |
The function creates a new buffer in memory, initializing it with the string passed as argument.
Definition at line 570 of file buf.c.
References msg, rz_buf_new_with_bytes(), and ut64().
Referenced by rz_asm_pseudo_incbin().
RZ_API bool rz_buf_prepend_bytes | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const ut8 * | buf, | ||
ut64 | length | ||
) |
Prepend an array of bytes to the buffer.
b | A buffer with write permission. |
buf | ... |
length | ... |
...
Definition at line 846 of file buf.c.
References b, length, rz_buf_insert_bytes(), and rz_return_val_if_fail.
Referenced by gprobe_frame_sp(), rz_egg_prepend_bytes(), and rz_egg_raw_prepend().
RZ_API st64 rz_buf_read | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL ut8 RZ_OUT * | buf, | ||
ut64 | len | ||
) |
Read len bytes of the buffer at the cursor.
b | ... |
buf | ... |
len | ... |
...
Definition at line 1111 of file buf.c.
References b, buf_read(), len, memset(), rz_return_val_if_fail, and st64.
Referenced by buf_format(), rz_buf_read8(), rz_buf_read_at(), rz_buf_sleb128(), and rz_buf_uleb128().
RZ_API bool rz_buf_read8 | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL RZ_OUT ut8 * | result | ||
) |
Read a byte at the cursor in the buffer.
b | ... |
result | ... |
...
Definition at line 860 of file buf.c.
References b, rz_buf_read(), rz_return_val_if_fail, and ut8.
Referenced by bin_pe_dotnet_read_method_header(), consume_init_expr_r(), consumeBuffer(), has_non_padding(), java_attribute_set_code(), java_constant_pool_new(), parse_gdata_global(), parse_type_bitfield(), parse_type_mfunction(), parse_type_numeric(), parse_type_procedure(), parse_type_string(), showBuffer(), and skip_padding().
Read a byte at the specified address in the buffer.
b | ... |
addr | ... |
result | ... |
Definition at line 876 of file buf.c.
References addr, b, rz_buf_read_at(), rz_return_val_if_fail, and ut8.
Referenced by __read_nonnull_str_at(), bin_pe_get_actual_checksum(), bin_pe_read_metadata_string(), build(), check_buffer(), check_pe32_buf(), check_pe64_buf(), jmp(), jmp_dest(), le_read_nonnull_str_at(), lua_parse_body_53(), lua_parse_body_54(), lua_parse_const_entry(), lua_parse_debug(), lua_parse_header_53(), lua_parse_header_54(), lua_parse_string(), lua_parse_szint(), lua_parse_upvalue_entry(), mach_headerfields(), rjmp(), rjmp_dest(), rz_bin_le_get_relocs(), rz_bin_ne_get_imports(), rz_bin_ne_get_symbols(), rz_core_meta_pascal_string_add(), and rz_core_yank_as_string().
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.
b | ... |
addr | ... |
buf | ... |
len | ... |
...
Definition at line 1136 of file buf.c.
References addr, b, len, rz_buf_read(), rz_buf_seek(), RZ_BUF_SET, rz_buf_tell(), rz_return_val_if_fail, st64, and autogen_x86imm::tmp.
Referenced by __dumpSections(), __ne_get_resources(), __read(), __read_nonnull_str_at(), _parse_resource_directory(), ar_read_at(), bflt_init_hdr(), bin_pe_dotnet_init_metadata(), bin_pe_get_actual_checksum(), bin_pe_init_security(), bin_pe_parse_imports(), binsym(), bootimg_header_load(), buf_move_back(), buf_read(), buf_ref_read(), buf_sparse_read(), carve_deps_at_address(), carve_kexts(), check_buffer(), check_mingw(), check_msvcseh(), check_pe32_buf(), check_pe64_buf(), check_unknow(), checkEntrypointBuffer(), checkHeader(), classes(), create_cache_bins(), create_path_to_index(), decompress(), entries(), extract_binobj(), extract_slice(), get_category_t(), get_class_name(), get_class_ro_t(), get_class_t(), get_entrypoint(), get_filetype(), get_import_addr_mips(), get_ivar_list_t(), get_lib_name(), get_main(), get_main_offset_mips(), get_main_offset_x86_pie(), get_method_list_t(), get_objc_property_list(), get_protocol_list_t(), get_rebase_info(), get_relocs(), get_section_bytes(), get_whole_buf(), gprobe_read(), header(), info(), init_hdr(), init_items(), io_read_va_at(), is_compressed_pdb(), iterate_rebase_list(), kexts_from_load_commands(), knownHeaderBuffer(), le_get_entries(), le_init_header(), le_read_nonnull_str_at(), load_buffer(), lua_load_block(), lua_parse_string(), mach0_info_new(), mach_headerfields(), parse_classes(), parse_dylib(), parse_dysymtab(), parse_function_starts(), parse_go_build_info(), parse_note_prstatus(), parse_relocation_info(), parse_segments(), parse_signature(), parse_symbol_table(), parse_symtab(), parse_thread(), parseCodeDirectory(), parseDragons(), parseHeader(), parseMetadata(), Pe_r_bin_pe_parse_string(), Pe_r_bin_pe_parse_string_file_info(), Pe_r_bin_pe_parse_string_table(), Pe_r_bin_pe_parse_var(), Pe_r_bin_pe_parse_var_file_info(), Pe_r_bin_pe_parse_version_info(), process_constructors(), process_kmod_init_term(), rabin_dump_symbols(), read_and_follow_jump(), read_elf_intrp(), read_image_section_header(), read_le_header_aux(), read_n_bits(), read_ptr_pa(), read_str(), read_xbe_header(), read_xbe_lib(), read_xbe_section(), readString(), rebase_buffer(), reconstruct_chained_fixup(), resolve_mig_subsystem(), resolve_syscalls(), rz_axml_decode(), rz_bin_dmp64_init_bmp_header(), rz_bin_dmp64_init_header(), rz_bin_dmp64_init_memory_runs(), rz_bin_elf_get_compiler(), rz_bin_elf_get_ehdr(), rz_bin_elf_get_main_offset(), rz_bin_elf_strtab_new(), rz_bin_fatmach0_init(), rz_bin_le_get_relocs(), rz_bin_mdmp_init_directory_entry(), rz_bin_mdmp_init_pe_bins(), rz_bin_mz_get_main_vaddr(), rz_bin_mz_init_hdr(), rz_bin_ne_buf_init(), rz_bin_ne_get_imports(), rz_bin_ne_get_relocs(), rz_bin_ne_get_symbols(), rz_bin_pe_get_debug_data(), rz_bin_pe_get_exports(), rz_bin_pe_get_imports(), rz_bin_pe_get_libs(), rz_bin_pe_get_sections(), rz_bin_pemixed_init_dos(), rz_bin_te_get_main_paddr(), rz_bin_te_init_sections(), rz_bin_zimg_new_buf(), rz_buf_append_buf_slice(), rz_buf_fwd_scan(), rz_buf_get_nstring(), rz_buf_read8_at(), rz_buf_to_string(), rz_cf_value_dict_parse(), rz_coff_symbol_name(), rz_core_yank_paste(), rz_core_yank_print(), rz_core_yank_print_hexdump(), rz_core_yank_print_string(), rz_coresym_cache_element_new(), rz_il_mem_load(), rz_io_zip_read(), rz_rebase_info_new_from_mach0(), rz_scan_strings(), sections(), shared_data_read_at(), size(), socket_http_answer(), string_scan_range_cfstring(), symbols(), symbols_from_stubs(), trycatch(), vf_read(), and walk_exports().
Increment the reference count of the buffer.
b | RzBuffer to reference |
b
The function increment the reference count of the buffer
Definition at line 668 of file buf.c.
References b.
Referenced by buf_ref_init(), buf_sparse_init(), load_buffer(), rz_bflt_init(), rz_bin_coff_init(), rz_bin_dmp64_new_buf(), rz_bin_elf_new_buf(), rz_bin_fatmach0_from_buffer_new(), rz_bin_file_new_from_buffer(), rz_bin_file_object_new_from_xtr_data(), rz_bin_mdmp_new_buf(), rz_bin_pe_new_buf(), rz_bin_wasm_init(), rz_bin_xtrdata_new(), rz_bin_zimg_new_buf(), rz_dyldcache_new_buf(), and rz_il_mem_new().
RZ_API bool rz_buf_resize | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | newsize | ||
) |
Resize the buffer size.
b | ... |
newsize | ... |
...
Definition at line 890 of file buf.c.
References b, buf_resize(), and rz_return_val_if_fail.
Referenced by __resize(), buf_bytes_write(), buf_move_back(), buf_resize(), rz_buf_append_nbytes(), rz_buf_set_bytes(), rz_io_def_mmap_truncate(), rz_io_zip_realloc_buf(), rz_io_zip_truncate_buf(), and vf_resize().
Modify the current cursor position in the buffer.
b | ... |
addr | ... |
whence | The relative position of the address. |
...
Definition at line 1166 of file buf.c.
References addr, b, buf_seek(), and rz_return_val_if_fail.
Referenced by __lseek(), __read(), __write(), ar_parse_header(), bin_pe_dotnet_read_method_header(), consume_r(), consumeBuffer(), dex_class_def_new(), dex_parse(), entries(), get_entries_from_section(), get_entrypoint(), has_non_padding(), java_attribute_set_code(), java_attribute_set_unknown(), java_constant_pool_new(), parse_code_entry(), parse_data_entry(), parse_dbi_stream(), parse_dbi_stream_ex_header(), parse_gdata_global(), parse_gdata_stream(), parse_type_string(), parse_v5_header(), pdb7_extract_msf_stream_directory(), pdb7_extract_streams(), read_desc(), read_entry(), read_hdr(), read_image_clr_header(), read_image_debug_directory_entry(), read_image_delay_import_directory(), read_image_export_directory(), read_image_import_directory(), read_image_metadata_tilde_header(), read_image_resource_data_entry(), read_image_resource_directory(), read_image_resource_directory_entry(), read_memory64_list(), read_module(), read_tls_directory(), rz_bin_dmp64_init_triage(), rz_bin_dmp64_init_triage_datablocks(), rz_bin_dmp64_init_triage_drivers(), rz_bin_reload(), rz_bin_wasm_get_custom_name_entries(), rz_bin_wasm_get_sections(), rz_bin_wasm_get_start(), rz_buf_append_bytes(), rz_buf_fread_at(), rz_buf_fwrite_at(), rz_buf_read_at(), rz_buf_set_bytes(), rz_buf_sleb128_at(), rz_buf_tell(), rz_buf_uleb128_at(), rz_buf_write_at(), rz_egg_compile(), rz_io_def_mmap_seek(), rz_io_zip_lseek(), rz_io_zip_read(), rz_io_zip_write(), rz_main_rz_gg(), showBuffer(), skip_padding(), and symbols().
RZ_API bool rz_buf_set_bytes | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const ut8 * | buf, | ||
ut64 | length | ||
) |
Replace the content of the buffer with the bytes array.
b | A buffer with write permission. |
buf | ... |
length | ... |
...
Definition at line 905 of file buf.c.
References b, length, rz_buf_append_bytes(), rz_buf_resize(), rz_buf_seek(), RZ_BUF_SET, and rz_return_val_if_fail.
Referenced by build(), rz_bin_fatmach0_from_bytes_new(), rz_bin_fatmach0_new(), rz_bin_mz_new(), rz_bin_te_new(), rz_core_yank_set(), and rz_io_zip_slurp_file().
RZ_API void rz_buf_set_overflow_byte | ( | RZ_NONNULL RzBuffer * | b, |
ut8 | Oxff | ||
) |
Change the overflow byte used in the RZ_BUFFER_SPARSE.
b | ... |
Oxff | The new byte filling value. |
Set the content that bytes read outside the buffer bounds should have.
Definition at line 1272 of file buf.c.
References b, and rz_return_if_fail.
RZ_API ut64 rz_buf_size | ( | RZ_NONNULL RzBuffer * | b | ) |
Return the size of the buffer.
b | ... |
...
Definition at line 1225 of file buf.c.
References b, buf_get_size(), and rz_return_val_if_fail.
Referenced by __dumpSections(), ar_open_all(), ar_open_file(), art_header_load(), bin_pe_compute_authentihash(), bin_pe_dotnet_init_metadata(), bin_pe_init_imports(), bootimg_header_load(), buf_get_size(), buf_move_back(), buf_ref_init(), buf_ref_resize(), buf_seek(), buf_sparse_size(), build(), check_buffer(), check_buffer_jmp(), check_buffer_rjmp(), checkEntrypointBuffer(), checkHeader(), consume_init_expr_r(), consume_limits_r(), consume_locals_r(), consume_r(), consume_str_r(), consumeBuffer(), create(), dex_parse(), entries(), get_elf_intrp(), get_entries_from_section(), get_main_offset_arm_glibc_thumb(), get_section(), get_whole_buf(), gprobe_read(), handle_tmp_desc(), is_eob(), java_class_parse(), kexts_from_load_commands(), knownHeaderBuffer(), lmf_header_load(), load_buffer(), MACH0_(), mach_headerfields(), make_string(), maps(), parse_header(), parse_omap_stream(), parse_pe_stream(), parse_signature(), parseDragons(), rz_asm_massemble(), rz_bflt_init(), rz_bin_coff_init(), rz_bin_dmp64_init_triage(), rz_bin_dmp64_new_buf(), rz_bin_elf_new_buf(), rz_bin_fatmach0_from_buffer_new(), rz_bin_file_compute_hashes(), rz_bin_file_new_from_buffer(), rz_bin_file_xtr_load_buffer(), rz_bin_mdmp_init_directory_entry(), rz_bin_mdmp_new_buf(), rz_bin_mz_get_segments(), rz_bin_mz_new_buf(), rz_bin_ne_get_relocs(), rz_bin_object_new(), rz_bin_open_io(), rz_bin_pdb_parse_from_buf(), rz_bin_pe_get_debug_data(), rz_bin_pe_new_buf(), rz_bin_te_new_buf(), rz_bin_wasm_get_custom_name_entries(), rz_bin_wasm_get_sections(), rz_bin_wasm_get_start(), rz_bin_wasm_init(), rz_bin_zimg_new_buf(), rz_buf_append_nbytes(), rz_buf_fwd_scan(), rz_buf_get_string(), rz_buf_to_string(), rz_core_cmd_subst_i(), rz_core_yank_as_string(), rz_core_yank_dump(), rz_core_yank_paste(), rz_core_yank_print(), rz_core_yank_print_hexdump(), rz_core_yank_print_string(), rz_coresym_cache_element_new(), rz_egg_finalize(), rz_io_open_buffer(), rz_io_zip_lseek(), rz_io_zip_read(), rz_io_zip_write(), rz_sign_flirt_parse_compressed_pattern_from_buffer(), rz_xnu_kernelcache_buf_is_kernelcache(), sections(), sep64_xtr_ctx_get_slice(), showBuffer(), size(), trycatch(), and vf_lseek().
RZ_API st64 rz_buf_sleb128 | ( | RZ_NONNULL RzBuffer * | buffer, |
RZ_NONNULL st64 * | value | ||
) |
Decodes SLEB128 from RzBuffer.
buffer | Buffer used to decode the SLEB128. |
value | Decoded value. |
Definition at line 1384 of file buf.c.
References rz_buf_read(), rz_return_val_if_fail, shift(), st64, ut64(), and value.
Referenced by rz_buf_sleb128_at().
RZ_API ut64 rz_buf_tell | ( | RZ_NONNULL RzBuffer * | b | ) |
Return the current cursor position.
b | ... |
...
Definition at line 1238 of file buf.c.
References b, RZ_BUF_CUR, rz_buf_seek(), and rz_return_val_if_fail.
Referenced by ar_parse_header(), consume_init_expr_r(), consume_limits_r(), consume_locals_r(), consume_r(), consume_str_r(), dex_new_encoded_field(), dex_new_encoded_method(), dex_parse(), get_code_object(), get_entries_from_section(), is_eob(), java_class_parse(), java_field_new(), java_method_new(), parse_code_entry(), parse_data_entry(), parse_dbi_stream_ex_header(), parse_element_entry(), parse_gdata_global(), parse_gdata_stream(), parse_type_entry(), rz_bin_wasm_get_custom_name_entries(), rz_bin_wasm_get_sections(), rz_bin_wasm_get_start(), rz_buf_fread_at(), rz_buf_fwrite_at(), rz_buf_read_at(), rz_buf_write_at(), rz_io_zip_lseek(), rz_io_zip_realloc_buf(), rz_io_zip_write(), and rz_sign_flirt_parse_compressed_pattern_from_buffer().
RZ_API RZ_OWN char* rz_buf_to_string | ( | RZ_NONNULL RzBuffer * | b | ) |
Stringify the buffer.
b | RzBuffer pointer |
The string is guaranteed to be NULL terminated even if the buffer doesn't have any NULL bytes.
Definition at line 642 of file buf.c.
References b, free(), NULL, rz_buf_read_at(), rz_buf_size(), RZ_NEWS, rz_return_val_if_fail, and ut64().
Referenced by gprobe_getdeviceid(), rz_analysis_reflines_str(), rz_asm_massemble(), rz_egg_assemble_asm(), rz_egg_get_assembly(), rz_egg_get_source(), and rz_egg_to_string().
RZ_API st64 rz_buf_uleb128 | ( | RZ_NONNULL RzBuffer * | buffer, |
RZ_NONNULL ut64 * | value | ||
) |
Decodes ULEB128 from RzBuffer.
buffer | Buffer used to decode the ULEB128. |
value | Decoded value. |
Definition at line 1353 of file buf.c.
References rz_buf_read(), rz_return_val_if_fail, shift(), ut64(), and value.
Referenced by dex_class_def_new(), dex_new_encoded_field(), dex_new_encoded_method(), dex_string_new(), and rz_buf_uleb128_at().
RZ_API st64 rz_buf_write | ( | RZ_NONNULL RzBuffer * | b, |
RZ_NONNULL const ut8 * | buf, | ||
ut64 | len | ||
) |
Write len bytes of the buffer at the cursor.
b | A buffer with write permission. |
buf | ... |
len | ... |
...
Definition at line 1181 of file buf.c.
References b, buf_write(), len, and rz_return_val_if_fail.
Referenced by buf_format(), rz_buf_append_bytes(), rz_buf_write8(), rz_buf_write_at(), and rz_io_def_mmap_write().
RZ_API bool rz_buf_write8 | ( | RZ_NONNULL RzBuffer * | b, |
ut8 | value | ||
) |
Write a byte at the cursor in the buffer.
b | ... |
result | ... |
...
Definition at line 931 of file buf.c.
References b, rz_buf_write(), rz_return_val_if_fail, ut8, and value.
Write a byte at the specified address in the buffer.
b | ... |
addr | ... |
value | ... |
...
Definition at line 948 of file buf.c.
References addr, b, rz_buf_write_at(), rz_return_val_if_fail, ut8, and value.
RZ_API st64 rz_buf_write_at | ( | RZ_NONNULL RzBuffer * | b, |
ut64 | addr, | ||
RZ_NONNULL const ut8 * | buf, | ||
ut64 | len | ||
) |
Write len bytes of the buffer at the specified address.
b | A buffer with write permission. |
addr | ... |
buf | ... |
len | ... |
...
Definition at line 1197 of file buf.c.
References addr, b, len, rz_buf_seek(), RZ_BUF_SET, rz_buf_tell(), rz_buf_write(), rz_return_val_if_fail, st64, and autogen_x86imm::tmp.
Referenced by __open(), __write(), _patch_reloc(), ar_write_at(), buf_move_back(), buf_sparse_write(), buf_write(), build(), fill_level(), ihex_parse(), patch_reloc_cb(), rz_analysis_reflines_str(), rz_bin_pemixed_init_native(), rz_buf_insert_bytes(), rz_buf_write8_at(), rz_core_bin_whole_strings(), rz_core_yank_set_str(), rz_egg_finalize(), rz_il_mem_store(), rz_io_zip_write(), srecord_parse(), vf_write(), write_image_section_header(), and write_n_bits().