Skip to main content

idakit_sys/
bytes.rs

1//! Raw byte reads, item classification and linear navigation (`bytes.hpp`), binary pattern
2//! search, byte patching, and comment read/write.
3
4use std::ffi::{c_char, c_int, c_void};
5
6use crate::Address;
7
8// raw bytes
9unsafe extern "C" {
10    pub fn idakit_get_bytes(address: Address, buf: *mut c_void, size: usize) -> i64;
11}
12
13// binary pattern search (bytes.hpp). A compiled pattern is an opaque handle; `binpat_free`
14// releases it. `bin_search` returns BADADDR when the pattern is absent from [start, end).
15unsafe extern "C" {
16    pub fn idakit_binpat_compile(
17        address: Address,
18        pattern: *const c_char,
19        radix: c_int,
20        errbuf: *mut c_char,
21        errcap: usize,
22    ) -> *mut c_void;
23    pub fn idakit_binpat_from_bytes(bytes: *const u8, mask: *const u8, len: usize) -> *mut c_void;
24    pub fn idakit_binpat_free(pat: *mut c_void);
25    pub fn idakit_binpat_stats(pat: *const c_void, total: *mut usize, anchors: *mut usize);
26    pub fn idakit_bin_search(
27        start: Address,
28        end: Address,
29        pat: *const c_void,
30        flags: c_int,
31    ) -> Address;
32}
33
34/// `BIN_SEARCH_CASE` from `bytes.hpp` (IDA 9.3): match `"..."` string literals
35/// case-sensitively (the default is case-insensitive).
36pub const BIN_SEARCH_CASE: c_int = 0x01;
37/// `BIN_SEARCH_BITMASK` from `bytes.hpp` (IDA 9.3): match under a strict bit mask rather
38/// than byte-granular wildcards.
39pub const BIN_SEARCH_BITMASK: c_int = 0x20;
40
41/// Class mask over an address's flags word (`MS_CLS` in `bytes.hpp`); the masked value equals
42/// [`FF_CODE`] for an instruction or [`FF_DATA`] for data.
43pub const MS_CLS: u64 = 0x0000_0600;
44/// [`MS_CLS`]-masked flag value marking an address as the head of an instruction.
45pub const FF_CODE: u64 = 0x0000_0600;
46/// [`MS_CLS`]-masked flag value marking an address as the head of a data item.
47pub const FF_DATA: u64 = 0x0000_0400;
48
49// byte patching (bytes.hpp patch_bytes). Returns 0 without writing if any target byte is
50// unmapped, 1 on success.
51unsafe extern "C" {
52    pub fn idakit_patch_bytes(address: Address, buf: *const c_void, size: usize) -> c_int;
53}
54
55// comment write (plain libida `set_cmt`).
56unsafe extern "C" {
57    pub fn set_cmt(address: Address, comm: *const c_char, rptble: bool) -> bool;
58}