Rizin
unix-like reverse engineering framework and cli tools
pdb_downloader.h File Reference
#include <rz_types.h>
#include <rz_bin.h>

Go to the source code of this file.

Classes

struct  SPDBOptions
 
struct  SPDBDownloaderOpt
 
struct  SPDBDownloader
 

Typedefs

typedef struct SPDBOptions SPDBOptions
 
typedef struct SPDBDownloaderOpt SPDBDownloaderOpt
 
typedef struct SPDBDownloader SPDBDownloader
 

Functions

RZ_API int rz_bin_pdb_download (RZ_NONNULL RzBin *bin, RZ_NULLABLE PJ *pj, int isradjson, RZ_NONNULL SPDBOptions *options)
 Download PDB file for currently opened RzBin file. More...
 
RZ_API RZ_OWN char * rz_bin_symserver_download (RZ_NONNULL const SPDBDownloaderOpt *options)
 downloads file from symbol server More...
 

Typedef Documentation

◆ SPDBDownloader

◆ SPDBDownloaderOpt

◆ SPDBOptions

typedef struct SPDBOptions SPDBOptions

Function Documentation

◆ rz_bin_pdb_download()

RZ_API int rz_bin_pdb_download ( RZ_NONNULL RzBin bin,
RZ_NULLABLE PJ pj,
int  isradjson,
RZ_NONNULL SPDBOptions options 
)

Download PDB file for currently opened RzBin file.

Parameters
binRzBin instance
pjOptional PJ instance for json output
isradjsonUse pj for json output
optionssymbol server options for downloading the PDB file

Definition at line 171 of file pdb_downloader.c.

171  {
173  SPDBDownloaderOpt opt;
175 
176  if (!info || !info->debug_file_name) {
177  RZ_LOG_ERROR("Can't find debug filename\n");
178  return 1;
179  }
180 
181  if (!is_valid_guid(info->guid)) {
182  RZ_LOG_ERROR("Invalid GUID for file\n");
183  return 1;
184  }
185 
186  if (!options->symbol_server || !options->symbol_store_path) {
187  RZ_LOG_ERROR("Can't retrieve pdb configurations\n");
188  return 1;
189  }
190 
192  opt.guid = info->guid;
193  opt.symbol_server = options->symbol_server;
194  opt.symbol_store_path = options->symbol_store_path;
195  opt.extract = options->extract;
196 
197  char *path = rz_bin_symserver_download(&opt);
198 
199  if (isradjson) {
200  pj_ko(pj, "pdb");
201  pj_ks(pj, "file", opt.dbg_file);
202  pj_ks(pj, "guid", opt.guid);
203  pj_ks(pj, "path", path);
204  pj_kb(pj, "download", (bool)path);
205  pj_end(pj);
206  } else {
207  rz_cons_printf("PDB \"%s\" download %s\n",
208  opt.dbg_file, path ? "success" : "failed");
209  }
210  free(path);
211  return !path;
212 }
RZ_DEPRECATE RZ_API RZ_BORROW RzBinInfo * rz_bin_get_info(RzBin *bin)
Definition: bin.c:585
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
RZ_API RZ_OWN char * rz_bin_symserver_download(RZ_NONNULL const SPDBDownloaderOpt *options)
downloads file from symbol server
static bool is_valid_guid(const char *guid)
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API const char * rz_file_dos_basename(RZ_BORROW RZ_NONNULL const char *path)
Definition: file.c:102
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API PJ * pj_ko(PJ *j, const char *k)
Definition: pj.c:156
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
const char * dbg_file
const char * symbol_server
const char * symbol_store_path
const char * guid
Definition: malloc.c:26
char * guid
Definition: rz_bin.h:222
char * debug_file_name
Definition: rz_bin.h:223

References SPDBDownloaderOpt::dbg_file, rz_bin_info_t::debug_file_name, SPDBDownloaderOpt::extract, free(), SPDBDownloaderOpt::guid, rz_bin_info_t::guid, info(), is_valid_guid(), options, path, pj_end(), pj_kb(), pj_ko(), pj_ks(), rz_bin_get_info(), rz_bin_symserver_download(), rz_cons_printf(), rz_file_dos_basename(), RZ_LOG_ERROR, rz_return_val_if_fail, SPDBDownloaderOpt::symbol_server, and SPDBDownloaderOpt::symbol_store_path.

Referenced by download_pdb(), GetHeapGlobalsOffset(), rz_cmd_info_pdb_download_handler(), and rz_main_rz_bin().

◆ rz_bin_symserver_download()

RZ_API RZ_OWN char* rz_bin_symserver_download ( RZ_NONNULL const SPDBDownloaderOpt options)

downloads file from symbol server

Parameters
optionsoptions for downloading file
Returns
char* is the path that file was downloaded to or NULL in case of failure

Definition at line 219 of file pdb_downloader.c.

219  {
221  SPDBDownloader downloader;
222  SPDBDownloaderOpt opt = *options;
223  char *path = NULL;
224  char *symbol_server = strdup(options->symbol_server);
225  char *server = strtok(symbol_server, ";");
226  while (server && !path) {
227  opt.symbol_server = server;
228  init_pdb_downloader(&opt, &downloader);
229  if (!downloader.download) {
230  break;
231  }
232  path = downloader.download(&downloader);
233  deinit_pdb_downloader(&downloader);
234  server = strtok(NULL, ";");
235  }
236  free(symbol_server);
237  return path;
238 }
#define NULL
Definition: cris-opc.c:27
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")
void deinit_pdb_downloader(SPDBDownloader *pd)
deinitialization of PDB downloader
void init_pdb_downloader(SPDBDownloaderOpt *opt, SPDBDownloader *pd)
initialization of pdb downloader by SPDBDownloaderOpt
char *(* download)(struct SPDBDownloader *pdb_downloader)

References deinit_pdb_downloader(), SPDBDownloader::download, free(), init_pdb_downloader(), NULL, options, path, rz_return_val_if_fail, strdup(), and SPDBDownloaderOpt::symbol_server.

Referenced by rz_bin_pdb_download(), and winkd_download_module_and_pdb().