Rizin
unix-like reverse engineering framework and cli tools
snap.c File Reference
#include <rz_debug.h>

Go to the source code of this file.

Functions

RZ_API void rz_debug_snap_free (RzDebugSnap *snap)
 
RZ_API RzDebugSnaprz_debug_snap_map (RzDebug *dbg, RzDebugMap *map)
 
RZ_API bool rz_debug_snap_contains (RzDebugSnap *snap, ut64 addr)
 
RZ_API ut8rz_debug_snap_get_hash (RzDebug *dbg, RzDebugSnap *snap, RzHashSize *size)
 
RZ_API bool rz_debug_snap_is_equal (RzDebug *dbg, RzDebugSnap *a, RzDebugSnap *b)
 

Function Documentation

◆ rz_debug_snap_contains()

RZ_API bool rz_debug_snap_contains ( RzDebugSnap snap,
ut64  addr 
)

Definition at line 46 of file snap.c.

46  {
47  return (snap->addr <= addr && addr >= snap->addr_end);
48 }
static int addr
Definition: z80asm.c:58

References addr, rz_debug_snap_t::addr, and rz_debug_snap_t::addr_end.

◆ rz_debug_snap_free()

RZ_API void rz_debug_snap_free ( RzDebugSnap snap)

Definition at line 7 of file snap.c.

7  {
8  if (snap) {
9  free(snap->name);
10  free(snap->data);
11  RZ_FREE(snap);
12  }
13 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define RZ_FREE(x)
Definition: rz_types.h:369

References rz_debug_snap_t::data, free(), rz_debug_snap_t::name, and RZ_FREE.

Referenced by deserialize_checkpoints_cb(), rz_debug_add_checkpoint(), rz_debug_session_list_memory(), and rz_debug_snap_map().

◆ rz_debug_snap_get_hash()

RZ_API ut8* rz_debug_snap_get_hash ( RzDebug dbg,
RzDebugSnap snap,
RzHashSize size 
)

Definition at line 50 of file snap.c.

50  {
51  ut8 *digest = rz_hash_cfg_calculate_small_block(dbg->hash, "sha256", snap->data, snap->size, size);
52  if (!digest) {
53  return NULL;
54  }
55  return digest;
56 }
#define NULL
Definition: cris-opc.c:27
RzDebug * dbg
Definition: desil.c:30
RZ_API RZ_OWN ut8 * rz_hash_cfg_calculate_small_block(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NONNULL RzHashSize *osize)
Returns the digest size of the requested algorithm name.
Definition: hash.c:529
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RzHash * hash
Definition: rz_debug.h:303

References rz_debug_snap_t::data, dbg, rz_debug_t::hash, NULL, rz_hash_cfg_calculate_small_block(), and rz_debug_snap_t::size.

Referenced by rz_debug_session_list_memory(), and rz_debug_snap_is_equal().

◆ rz_debug_snap_is_equal()

RZ_API bool rz_debug_snap_is_equal ( RzDebug dbg,
RzDebugSnap a,
RzDebugSnap b 
)

Definition at line 58 of file snap.c.

58  {
59  RzHashSize digest_size = 0;
60  ut8 *a_dgst = rz_debug_snap_get_hash(dbg, a, &digest_size);
61  ut8 *b_dgst = rz_debug_snap_get_hash(dbg, b, NULL);
62 
63  bool ret = a_dgst && b_dgst && !memcmp(a_dgst, b_dgst, digest_size);
64  free(a_dgst);
65  free(b_dgst);
66  return ret;
67 }
ut32 RzHashSize
Definition: rz_hash.h:24
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
RZ_API ut8 * rz_debug_snap_get_hash(RzDebug *dbg, RzDebugSnap *snap, RzHashSize *size)
Definition: snap.c:50

References a, b, dbg, free(), NULL, and rz_debug_snap_get_hash().

◆ rz_debug_snap_map()

RZ_API RzDebugSnap* rz_debug_snap_map ( RzDebug dbg,
RzDebugMap map 
)

Definition at line 15 of file snap.c.

15  {
17  if (map->size < 1) {
18  eprintf("Invalid map size\n");
19  return NULL;
20  }
21 
23  if (!snap) {
24  return NULL;
25  }
26 
27  snap->name = strdup(map->name);
28  snap->addr = map->addr;
29  snap->addr_end = map->addr_end;
30  snap->size = map->size;
31  snap->perm = map->perm;
32  snap->user = map->user;
33  snap->shared = map->shared;
34 
35  snap->data = malloc(map->size);
36  if (!snap->data) {
37  rz_debug_snap_free(snap);
38  return NULL;
39  }
40  eprintf("Reading %d byte(s) from 0x%08" PFMT64x "...\n", snap->size, snap->addr);
41  dbg->iob.read_at(dbg->iob.io, snap->addr, snap->data, snap->size);
42 
43  return snap;
44 }
size_t map(int syms, int left, int len)
Definition: enough.c:237
void * malloc(size_t size)
Definition: malloc.c:123
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define eprintf(x, y...)
Definition: rlcc.c:7
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define PFMT64x
Definition: rz_types.h:393
RZ_API void rz_debug_snap_free(RzDebugSnap *snap)
Definition: snap.c:7
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232

References rz_debug_snap_t::addr, rz_debug_snap_t::addr_end, rz_debug_snap_t::data, dbg, eprintf, rz_io_bind_t::io, rz_debug_t::iob, malloc(), map(), rz_debug_snap_t::name, NULL, rz_debug_snap_t::perm, PFMT64x, rz_io_bind_t::read_at, rz_debug_snap_free(), RZ_NEW0, rz_return_val_if_fail, rz_debug_snap_t::shared, rz_debug_snap_t::size, strdup(), and rz_debug_snap_t::user.

Referenced by rz_debug_add_checkpoint(), and rz_debug_session_list_memory().