Rizin
unix-like reverse engineering framework and cli tools
rz_bitvector.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 heersin <teablearcher@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef RZ_BITVECTOR_H
5 #define RZ_BITVECTOR_H
6 
7 #include <rz_types.h>
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
19 typedef struct bitvector_t {
20  union {
23  } bits;
27 
28 // init
35  RZ_NONNULL const RzBitVector *src, ut32 src_start_pos,
36  RZ_NONNULL RzBitVector *dst, ut32 dst_start_pos,
37  ut32 nbit);
40 // read and write to a bit
50 // logic operations
53 RZ_API bool rz_bv_lshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit);
54 RZ_API bool rz_bv_rshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit);
58 #define rz_bv_neg rz_bv_complement_2
59 #define rz_bv_not rz_bv_complement_1
62 
63 // Module 2 arithmetic operations
71 
77 
80 
81 // some convert functions
86 // misc
100 
105 #define rz_bv_new_zero(l) rz_bv_new(l)
106 #define rz_bv_new_one(l) rz_bv_new_from_ut64(l, 1)
107 #define rz_bv_new_two(l) rz_bv_new_from_ut64(l, 2)
108 #define rz_bv_new_minus_one(l) rz_bv_new_from_st64(l, -1)
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif // RZ_IL_BITVECTOR_H
lzma_index * src
Definition: index.h:567
static int value
Definition: cmd_api.c:93
#define RZ_API
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 static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
uint16_t ut16
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
char * dst
Definition: lz4.h:724
int x
Definition: mipsasm.c:20
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
RZ_API RZ_OWN RzBitVector * rz_bv_add(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y, RZ_NULLABLE bool *carry)
Definition: bitvector.c:683
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:167
RZ_API bool rz_bv_lsb(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:1012
RZ_API ut32 rz_bv_ctz(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:1123
RZ_API ut32 rz_bv_copy(RZ_NONNULL const RzBitVector *src, RZ_NONNULL RzBitVector *dst)
Definition: bitvector.c:186
RZ_API RZ_OWN RzBitVector * rz_bv_prepend_zero(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
Definition: bitvector.c:236
RZ_API RZ_OWN RzBitVector * rz_bv_or(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:573
RZ_API bool rz_bv_set_from_ut64(RZ_NONNULL RzBitVector *bv, ut64 value)
Definition: bitvector.c:1222
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
Definition: bitvector.c:85
RZ_API bool rz_bv_ule(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1052
RZ_API bool rz_bv_lshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit)
Definition: bitvector.c:469
RZ_API bool rz_bv_cmp(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1086
RZ_API void rz_bv_set_from_bytes_le(RZ_NONNULL RzBitVector *bv, RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
Definition: bitvector.c:1265
struct bitvector_t RzBitVector
RZ_API void rz_bv_fini(RZ_NONNULL RzBitVector *bv)
Clear a RzBitVector structure.
Definition: bitvector.c:58
RZ_API void rz_bv_set_to_bytes_le(RZ_NONNULL const RzBitVector *bv, RZ_OUT RZ_NONNULL ut8 *buf)
Set the buffer contents from the given bitvector's bits in little endian format.
Definition: bitvector.c:1318
RZ_API bool rz_bv_sle(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1064
RZ_API ut64 rz_bv_to_ut64(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1454
RZ_API ut32 rz_bv_len(RZ_NONNULL const RzBitVector *bv)
Definition: bitvector.c:1140
RZ_API bool rz_bv_toggle(RZ_NONNULL RzBitVector *bv, ut32 pos)
Definition: bitvector.c:396
RZ_API bool rz_bv_is_zero_vector(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1021
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_st64(ut32 length, st64 value)
Definition: bitvector.c:1179
RZ_API RZ_OWN RzBitVector * rz_bv_mod(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:865
RZ_API bool rz_bv_set_all(RZ_NONNULL RzBitVector *bv, bool b)
Definition: bitvector.c:367
RZ_API bool rz_bv_lshift(RZ_NONNULL RzBitVector *bv, ut32 size)
Definition: bitvector.c:446
RZ_API ut32 rz_bv_to_ut32(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1435
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
Definition: bitvector.c:1161
RZ_API ut8 rz_bv_to_ut8(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1397
RZ_API RZ_OWN char * rz_bv_as_string(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:98
RZ_API void rz_bv_set_from_bytes_be(RZ_NONNULL RzBitVector *bv, RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
Set the bitvector's contents from the given bits. The bitvector's size is unchanged....
Definition: bitvector.c:1296
RZ_API bool rz_bv_toggle_all(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:410
RZ_API RZ_OWN RzBitVector * rz_bv_cut_tail(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
Definition: bitvector.c:303
RZ_API ut32 rz_bv_hash(RZ_NULLABLE RzBitVector *x)
Definition: bitvector.c:1372
RZ_API ut32 rz_bv_len_bytes(RZ_NONNULL const RzBitVector *bv)
Definition: bitvector.c:1150
RZ_API RZ_OWN RzBitVector * rz_bv_complement_2(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:652
RZ_API bool rz_bv_rshift(RZ_NONNULL RzBitVector *bv, ut32 size)
Definition: bitvector.c:457
RZ_API RZ_OWN RzBitVector * rz_bv_xor(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:600
RZ_API RZ_OWN RzBitVector * rz_bv_append(RZ_NONNULL RzBitVector *bv1, RZ_NONNULL RzBitVector *bv2)
Definition: bitvector.c:326
RZ_API RZ_OWN RzBitVector * rz_bv_mul(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:734
RZ_API bool rz_bv_msb(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:1003
RZ_API RZ_OWN RzBitVector * rz_bv_and(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:546
RZ_API bool rz_bv_get(RZ_NONNULL const RzBitVector *bv, ut32 pos)
Definition: bitvector.c:429
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_bytes_be(RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
Definition: bitvector.c:1207
RZ_API RZ_OWN RzBitVector * rz_bv_new(ut32 length)
Definition: bitvector.c:71
RZ_API ut16 rz_bv_to_ut16(RZ_NONNULL const RzBitVector *x)
Definition: bitvector.c:1416
RZ_API ut32 rz_bv_clz(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:1107
RZ_API bool rz_bv_set(RZ_NONNULL RzBitVector *bv, ut32 pos, bool b)
Definition: bitvector.c:341
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_bytes_le(RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
Definition: bitvector.c:1194
RZ_API RZ_OWN RzBitVector * rz_bv_sub(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y, RZ_NULLABLE bool *borrow)
Definition: bitvector.c:715
RZ_API RZ_OWN RzBitVector * rz_bv_complement_1(RZ_NONNULL RzBitVector *bv)
Definition: bitvector.c:625
RZ_API bool rz_bv_rshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit)
Definition: bitvector.c:508
RZ_API RZ_OWN RzBitVector * rz_bv_sdiv(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:893
RZ_API void rz_bv_set_to_bytes_be(RZ_NONNULL const RzBitVector *bv, RZ_OUT RZ_NONNULL ut8 *buf)
Set the buffer contents from the given bitvector's bits in big endian format.
Definition: bitvector.c:1349
RZ_API RZ_OWN RzBitVector * rz_bv_smod(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:952
RZ_API RZ_OWN RzBitVector * rz_bv_append_zero(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
Definition: bitvector.c:258
RZ_API bool rz_bv_init(RZ_NONNULL RzBitVector *bv, ut32 length)
Initialize a RzBitVector structure.
Definition: bitvector.c:38
RZ_API bool rz_bv_set_from_st64(RZ_NONNULL RzBitVector *bv, st64 value)
Definition: bitvector.c:1243
RZ_API ut32 rz_bv_copy_nbits(RZ_NONNULL const RzBitVector *src, ut32 src_start_pos, RZ_NONNULL RzBitVector *dst, ut32 dst_start_pos, ut32 nbit)
Definition: bitvector.c:210
RZ_API RZ_OWN RzBitVector * rz_bv_cut_head(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
Definition: bitvector.c:281
RZ_API bool rz_bv_eq(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:1041
RZ_API RZ_OWN RzBitVector * rz_bv_div(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
Definition: bitvector.c:808
RZ_API RZ_OWN char * rz_bv_as_hex_string(RZ_NONNULL RzBitVector *bv, bool pad)
Definition: bitvector.c:121
#define RZ_IN
Definition: rz_types.h:50
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_OUT
Definition: rz_types.h:51
#define RZ_NONNULL
Definition: rz_types.h:64
#define st64
Definition: rz_types_base.h:10
#define b(i)
Definition: sha256.c:42
structure for bitvector
Definition: rz_bitvector.h:19
union bitvector_t::@303 bits
ut32 len
number of bits – virtual / logical
Definition: rz_bitvector.h:25
ut8 * large_a
little endian array of bytes for bitvectors > 64 bits whose size is defined in _elem_len
Definition: rz_bitvector.h:21
ut64 small_u
value of the bitvector when the size is <= 64 bits
Definition: rz_bitvector.h:22
ut32 _elem_len
length of ut8 array (bits.large_a) – real / physical
Definition: rz_bitvector.h:24
int pos
Definition: main.c:11
ut64(WINAPI *w32_GetEnabledXStateFeatures)()