Rizin
unix-like reverse engineering framework and cli tools
serialize_io.c File Reference
#include <rz_util/rz_serialize.h>
#include <rz_io.h>
#include <errno.h>

Go to the source code of this file.

Classes

struct  RzIODescasd
 
struct  PCacheSaveCtx
 

Macros

#define SUB(ns, call)   RZ_SERIALIZE_SUB_DO(db, subdb, res, ns, call, goto beach;)
 

Functions

static bool pcache_save_cb (void *user, const ut64 k, const void *v)
 
static bool file_save_cb (void *user, void *data, ut32 id)
 
RZ_API void rz_serialize_io_files_save (RZ_NONNULL Sdb *db, RZ_NONNULL RzIO *io)
 
RZ_API bool rz_serialize_io_files_load (RZ_NONNULL Sdb *db, RZ_NONNULL RzIO *io, RZ_NULLABLE RzSerializeResultInfo *res)
 
RZ_API void rz_serialize_io_save (RZ_NONNULL Sdb *db, RZ_NONNULL RzIO *io)
 
RZ_API bool rz_serialize_io_load (RZ_NONNULL Sdb *db, RZ_NONNULL RzIO *io, RZ_NULLABLE RzSerializeResultInfo *res)
 

Macro Definition Documentation

◆ SUB

#define SUB (   ns,
  call 
)    RZ_SERIALIZE_SUB_DO(db, subdb, res, ns, call, goto beach;)

Function Documentation

◆ file_save_cb()

static bool file_save_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 49 of file serialize_io.c.

49  {
50  Sdb *db = user;
51  RzIODesc *desc = (RzIODesc *)data;
52 
53  char key[0x20];
54  if (snprintf(key, sizeof(key), "%d", desc->fd) < 0) {
55  return false;
56  }
57 
58  PJ *j = pj_new();
59  if (!j) {
60  return false;
61  }
62  pj_o(j);
63 
64  pj_ki(j, "perm", desc->perm);
65  // obsz is irrelevant (never written, always 0)
66  pj_ks(j, "uri", desc->uri);
67  pj_ks(j, "name", desc->name);
68  if (desc->referer) {
69  pj_ks(j, "referer", desc->referer);
70  }
71  // TODO: plugin
72 
73  pj_end(j);
74  sdb_set(db, key, pj_string(j), 0);
75  pj_free(j);
76 
77  if (desc->cache->count) {
78  PCacheSaveCtx ctx = {
79  .fd = desc->fd,
80  .db = sdb_ns(db, "pcache", true)
81  };
82  ht_up_foreach(desc->cache, pcache_save_cb, &ctx);
83  }
84  return true;
85 }
const char * desc
Definition: bin_vsf.c:19
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
snprintf
Definition: kernel.h:364
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
static bool pcache_save_cb(void *user, const ut64 k, const void *v)
Definition: serialize_io.c:37
Definition: rz_pj.h:12
Definition: sdb.h:63

References desc, key, pcache_save_cb(), pj_end(), pj_free(), pj_ki(), pj_ks(), pj_new(), pj_o(), pj_string(), sdb_ns(), sdb_set(), and snprintf.

Referenced by rz_serialize_io_files_save().

◆ pcache_save_cb()

static bool pcache_save_cb ( void *  user,
const ut64  k,
const void *  v 
)
static

Definition at line 37 of file serialize_io.c.

37  {
38  PCacheSaveCtx *ctx = user;
39  const RzIODescCache *cache = v;
40  char key[0x30];
41  if (snprintf(key, sizeof(key), "%d.0x%" PFMT64x, ctx->fd, k) < 0) {
42  return false;
43  }
44  char val[RZ_IO_DESC_CACHE_SIZE * 4 + 1];
46  return true;
47 }
ut16 val
Definition: armass64_const.h:6
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
RZ_API size_t rz_base64_encode(char *bout, const ut8 *bin, size_t sz)
Definition: ubase64.c:81
#define RZ_IO_DESC_CACHE_SIZE
Definition: rz_io.h:169
#define PFMT64x
Definition: rz_types.h:393
ut8 cdata[RZ_IO_DESC_CACHE_SIZE]
Definition: rz_io.h:172

References rz_io_desc_cache_t::cdata, k, key, PFMT64x, rz_base64_encode(), RZ_IO_DESC_CACHE_SIZE, snprintf, v, and val.

Referenced by file_save_cb().

◆ rz_serialize_io_files_load()

RZ_API bool rz_serialize_io_files_load ( RZ_NONNULL Sdb db,
RZ_NONNULL RzIO io,
RZ_NULLABLE RzSerializeResultInfo res 
)

Definition at line 92 of file serialize_io.c.

92  {
93  // TODO
94  return true;
95 }

Referenced by rz_serialize_io_load().

◆ rz_serialize_io_files_save()

RZ_API void rz_serialize_io_files_save ( RZ_NONNULL Sdb db,
RZ_NONNULL RzIO io 
)

Definition at line 87 of file serialize_io.c.

87  {
88  sdb_ns(db, "pcache", true);
89  rz_id_storage_foreach(io->files, file_save_cb, db);
90 }
RZ_API bool rz_id_storage_foreach(RzIDStorage *storage, RzIDStorageForeachCb cb, void *user)
Definition: idpool.c:254
static bool file_save_cb(void *user, void *data, ut32 id)
Definition: serialize_io.c:49

References file_save_cb(), rz_id_storage_foreach(), and sdb_ns().

Referenced by rz_serialize_io_save().

◆ rz_serialize_io_load()

RZ_API bool rz_serialize_io_load ( RZ_NONNULL Sdb db,
RZ_NONNULL RzIO io,
RZ_NULLABLE RzSerializeResultInfo res 
)

Definition at line 101 of file serialize_io.c.

101  {
102  // TODO: purge RzIO?
103  bool ret = false;
104  Sdb *subdb;
105 #define SUB(ns, call) RZ_SERIALIZE_SUB_DO(db, subdb, res, ns, call, goto beach;)
106  SUB("files", rz_serialize_io_files_load(subdb, io, res));
107 #undef SUB
108  ret = true;
109 beach:
110  return ret;
111 }
RZ_API bool rz_serialize_io_files_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzIO *io, RZ_NULLABLE RzSerializeResultInfo *res)
Definition: serialize_io.c:92
#define SUB(ns, call)

References rz_serialize_io_files_load(), and SUB.

◆ rz_serialize_io_save()

RZ_API void rz_serialize_io_save ( RZ_NONNULL Sdb db,
RZ_NONNULL RzIO io 
)

Definition at line 97 of file serialize_io.c.

97  {
98  rz_serialize_io_files_save(sdb_ns(db, "files", true), io);
99 }
RZ_API void rz_serialize_io_files_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzIO *io)
Definition: serialize_io.c:87

References rz_serialize_io_files_save(), and sdb_ns().