Rizin
unix-like reverse engineering framework and cli tools
esil_stats.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_analysis.h>
5 
6 static int hook_flag_read(RzAnalysisEsil *esil, const char *flag, ut64 *num) {
7  sdb_array_add(esil->stats, "flg.read", flag, 0);
8  return 0;
9 }
10 
11 static int hook_command(RzAnalysisEsil *esil, const char *op) {
12  sdb_array_add(esil->stats, "ops.list", op, 0);
13  return 0;
14 }
15 
16 static int hook_mem_read(RzAnalysisEsil *esil, ut64 addr, ut8 *buf, int len) {
17  sdb_array_add_num(esil->stats, "mem.read", addr, 0);
18  return 0;
19 }
20 
21 static int hook_mem_write(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len) {
22  sdb_array_add_num(esil->stats, "mem.write", addr, 0);
23  return 0;
24 }
25 
26 static int hook_reg_read(RzAnalysisEsil *esil, const char *name, ut64 *res, int *size) {
27  const char *key = (*name >= '0' && *name <= '9') ? "num.load" : "reg.read";
28  sdb_array_add(esil->stats, key, name, 0);
29  return 0;
30 }
31 
32 static int hook_reg_write(RzAnalysisEsil *esil, const char *name, ut64 *val) {
33  sdb_array_add(esil->stats, "reg.write", name, 0);
34  return 0;
35 }
36 
37 static int hook_NOP_mem_write(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len) {
38  RZ_LOG_DEBUG("esil: NOP write at 0x%08" PFMT64x "\n", addr);
39  return 1; // override
40 }
41 
42 RZ_API void rz_analysis_esil_mem_ro(RzAnalysisEsil *esil, int mem_readonly) {
43  if (mem_readonly) {
45  } else {
46  esil->cb.hook_mem_write = NULL;
47  }
48 }
49 
50 RZ_API void rz_analysis_esil_stats(RzAnalysisEsil *esil, int enable) {
51  if (enable) {
52  if (esil->stats) {
53  sdb_reset(esil->stats);
54  } else {
55  esil->stats = sdb_new0();
56  }
57  // reset sdb->stats
64  } else {
65  esil->cb.hook_mem_write = NULL;
66  esil->cb.hook_flag_read = NULL;
67  esil->cb.hook_command = NULL;
68  sdb_free(esil->stats);
69  esil->stats = NULL;
70  }
71 }
size_t len
Definition: 6502dis.c:15
ut16 val
Definition: armass64_const.h:6
RZ_API int sdb_array_add_num(Sdb *s, const char *key, ut64 val, ut32 cas)
Definition: array.c:211
RZ_API int sdb_array_add(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: array.c:224
#define RZ_API
#define NULL
Definition: cris-opc.c:27
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 key
Definition: sflib.h:118
RZ_API void rz_analysis_esil_mem_ro(RzAnalysisEsil *esil, int mem_readonly)
Definition: esil_stats.c:42
static int hook_reg_read(RzAnalysisEsil *esil, const char *name, ut64 *res, int *size)
Definition: esil_stats.c:26
static int hook_mem_read(RzAnalysisEsil *esil, ut64 addr, ut8 *buf, int len)
Definition: esil_stats.c:16
static int hook_flag_read(RzAnalysisEsil *esil, const char *flag, ut64 *num)
Definition: esil_stats.c:6
static int hook_reg_write(RzAnalysisEsil *esil, const char *name, ut64 *val)
Definition: esil_stats.c:32
static int hook_NOP_mem_write(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len)
Definition: esil_stats.c:37
RZ_API void rz_analysis_esil_stats(RzAnalysisEsil *esil, int enable)
Definition: esil_stats.c:50
static int hook_mem_write(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len)
Definition: esil_stats.c:21
static int hook_command(RzAnalysisEsil *esil, const char *op)
Definition: esil_stats.c:11
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
#define RZ_LOG_DEBUG(fmtstr,...)
Definition: rz_log.h:49
#define PFMT64x
Definition: rz_types.h:393
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RZ_API void sdb_reset(Sdb *s)
Definition: sdb.c:433
Definition: z80asm.h:102
int(* hook_mem_read)(ANALYSIS_ESIL *esil, ut64 addr, ut8 *buf, int len)
Definition: rz_analysis.h:1032
int(* hook_command)(ANALYSIS_ESIL *esil, const char *op)
Definition: rz_analysis.h:1031
int(* hook_reg_read)(ANALYSIS_ESIL *esil, const char *name, ut64 *res, int *size)
Definition: rz_analysis.h:1036
int(* hook_mem_write)(ANALYSIS_ESIL *esil, ut64 addr, const ut8 *buf, int len)
Definition: rz_analysis.h:1034
int(* hook_flag_read)(ANALYSIS_ESIL *esil, const char *flag, ut64 *num)
Definition: rz_analysis.h:1030
RzAnalysisEsilHookRegWriteCB hook_reg_write
Definition: rz_analysis.h:1038
RzAnalysisEsilCallbacks cb
Definition: rz_analysis.h:1078
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58