Rizin
unix-like reverse engineering framework and cli tools
esil_sources.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2018 condret <condr3t@protonmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_analysis.h>
5 #include <rz_util.h>
6 #include <rz_lib.h>
7 
9  if (esil && !esil->sources) {
10  esil->sources = rz_id_storage_new(1, 0xffffffff); // 0 is reserved for stuff from plugins
11  }
12 }
13 
17 
19  src->content = rz_lib_dl_open(path);
20  if (!src->content) {
21  RZ_LOG_ERROR("esil: cannot load library (no content)\n");
22  free(src);
23  return 0;
24  }
25 
27  if (!rz_id_storage_add(esil->sources, src, &src->id)) {
28  RZ_LOG_ERROR("esil: cannot add to id storage\n");
29  rz_lib_dl_close(src->content);
30  free(src);
31  return 0;
32  }
33 
34  return src->id;
35 }
36 
38  if (!esil || !esil->sources) {
39  return NULL;
40  }
41  return (RzAnalysisEsilSource *)rz_id_storage_get(esil->sources, src_id);
42 }
43 
45  RzAnalysisEsilSource *src = _get_source(esil, src_id);
46 
47  return src ? src->content : NULL;
48 }
49 
51  RzAnalysisEsilSource *src = _get_source(esil, src_id);
52 
53  if (src) {
54  src->claimed++;
55  return true;
56  }
57  return false;
58 }
59 
61  RzAnalysisEsilSource *src = _get_source(esil, src_id);
62 
63  if (!src) {
64  return;
65  }
66  if (src->claimed <= 1) {
67  rz_id_storage_delete(esil->sources, src_id);
68  rz_lib_dl_close(src->content);
69  free(src);
70  } else {
71  src->claimed--;
72  }
73 }
74 
75 static bool _free_source_cb(void *user, void *data, ut32 id) {
77 
78  if (src) {
79  rz_lib_dl_close(src->content);
80  }
81  free(src);
82  return true;
83 }
84 
86  if (esil) {
89  }
90 }
lzma_index * src
Definition: index.h:567
#define RZ_API
#define NULL
Definition: cris-opc.c:27
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
uint32_t ut32
RZ_API void rz_analysis_esil_sources_init(RzAnalysisEsil *esil)
Definition: esil_sources.c:8
RZ_API void rz_analysis_esil_release_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:60
RZ_API void * rz_analysis_esil_get_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:44
RZ_API void rz_analysis_esil_sources_fini(RzAnalysisEsil *esil)
Definition: esil_sources.c:85
static RzAnalysisEsilSource * _get_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:37
RZ_API bool rz_analysis_esil_claim_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:50
static bool _free_source_cb(void *user, void *data, ut32 id)
Definition: esil_sources.c:75
RZ_API ut32 rz_analysis_esil_load_source(RzAnalysisEsil *esil, const char *path)
Definition: esil_sources.c:14
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RzIDStorage * rz_id_storage_new(ut32 start_id, ut32 last_id)
Definition: idpool.c:80
RZ_API void rz_id_storage_free(RzIDStorage *storage)
Definition: idpool.c:270
RZ_API void * rz_id_storage_get(RzIDStorage *storage, ut32 id)
Definition: idpool.c:162
RZ_API bool rz_id_storage_foreach(RzIDStorage *storage, RzIDStorageForeachCb cb, void *user)
Definition: idpool.c:254
RZ_API void rz_id_storage_delete(RzIDStorage *storage, ut32 id)
Definition: idpool.c:221
RZ_API bool rz_id_storage_add(RzIDStorage *storage, void *data, ut32 *id)
Definition: idpool.c:155
RZ_API void * rz_lib_dl_open(const char *libname)
Definition: lib.c:54
RZ_API int rz_lib_dl_close(void *handler)
Definition: lib.c:104
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
#define RZ_NEW0(x)
Definition: rz_types.h:284
RzIDStorage * sources
Definition: rz_analysis.h:1073