Rizin
unix-like reverse engineering framework and cli tools
bytes_diff.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 RizinOrg <info@rizin.re>
2 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 /* Helpers for handling bytes */
6 #define DIFF_IS_BYTES_METHOD(x) (x.elem_at == methods_bytes.elem_at)
7 
8 static const void *byte_elem_at(const ut8 *array, ut32 index) {
9  return &array[index];
10 }
11 
12 static int byte_compare(const ut8 *a_elem, const ut8 *b_elem) {
13  return ((int)b_elem[0]) - ((int)a_elem[0]);
14 }
15 
16 static ut32 byte_hash(const char *elem) {
17  return elem[0];
18 }
19 
20 static void byte_stringify(const ut8 *a_elem, RzStrBuf *sb) {
21  rz_strbuf_setf(sb, "%02x", *a_elem);
22 }
23 
26  .elem_hash = (RzDiffMethodElemHash)byte_hash,
27  .compare /* */ = (RzDiffMethodCompare)byte_compare,
29  .ignore /* */ = fake_ignore,
30  .free /* */ = NULL,
31 };
static SblHeader sb
Definition: bin_mbn.c:26
static ut32 byte_hash(const char *elem)
Definition: bytes_diff.c:16
static const void * byte_elem_at(const ut8 *array, ut32 index)
Definition: bytes_diff.c:8
static void byte_stringify(const ut8 *a_elem, RzStrBuf *sb)
Definition: bytes_diff.c:20
static int byte_compare(const ut8 *a_elem, const ut8 *b_elem)
Definition: bytes_diff.c:12
static const MethodsInternal methods_bytes
Definition: bytes_diff.c:24
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
static bool fake_ignore(const void *value)
Definition: diff.c:118
uint8_t ut8
Definition: lh5801.h:11
const void *(* RzDiffMethodElemAt)(RZ_BORROW const void *array, ut32 index)
Definition: rz_diff.h:36
ut32(* RzDiffMethodElemHash)(RZ_BORROW const void *elem)
Definition: rz_diff.h:37
void(* RzDiffMethodStringify)(RZ_BORROW const void *elem, RZ_BORROW RzStrBuf *sb)
Definition: rz_diff.h:40
int(* RzDiffMethodCompare)(RZ_BORROW const void *a_elem, RZ_BORROW const void *b_elem)
Definition: rz_diff.h:38
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
static int
Definition: sfsocketcall.h:114
RzDiffMethodElemAt elem_at
Definition: diff.c:81