Rizin
unix-like reverse engineering framework and cli tools
snap.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015-2020 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2015-2020 rkx1209 <rkx1209dev@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_debug.h>
6 
8  if (snap) {
9  free(snap->name);
10  free(snap->data);
11  RZ_FREE(snap);
12  }
13 }
14 
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 }
45 
47  return (snap->addr <= addr && addr >= snap->addr_end);
48 }
49 
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 }
57 
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 }
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RzDebug * dbg
Definition: desil.c:30
size_t map(int syms, int left, int len)
Definition: enough.c:237
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
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
ut32 RzHashSize
Definition: rz_hash.h:24
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_FREE(x)
Definition: rz_types.h:369
#define PFMT64x
Definition: rz_types.h:393
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
RZ_API bool rz_debug_snap_is_equal(RzDebug *dbg, RzDebugSnap *a, RzDebugSnap *b)
Definition: snap.c:58
RZ_API bool rz_debug_snap_contains(RzDebugSnap *snap, ut64 addr)
Definition: snap.c:46
RZ_API RzDebugSnap * rz_debug_snap_map(RzDebug *dbg, RzDebugMap *map)
Definition: snap.c:15
RZ_API ut8 * rz_debug_snap_get_hash(RzDebug *dbg, RzDebugSnap *snap, RzHashSize *size)
Definition: snap.c:50
RZ_API void rz_debug_snap_free(RzDebugSnap *snap)
Definition: snap.c:7
RzHash * hash
Definition: rz_debug.h:303
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58