Rizin
unix-like reverse engineering framework and cli tools
rz_pdb.h File Reference
#include <rz_util.h>
#include <rz_type.h>
#include <rz_cmd.h>

Go to the source code of this file.

Classes

struct  dbi_stream_header_t
 
struct  RzPdbRzPdbDbiStreamDbgHeader
 
struct  dbi_stream_t
 
struct  RzPdbGDataStream
 
struct  RzPdbOmapStream
 
struct  RzPdbPeStream
 
struct  tpi_stream_header_t
 
struct  tpi_types
 
struct  tpi_stream_t
 
struct  RzPdbGuid
 
struct  RzRzPdbStreamHeader
 
struct  RzPdbStream
 
struct  RzPdbMsfSuperBlock
 MSF file format header https://llvm.org/docs/PDB/MsfFile.html#the-superblock. More...
 
struct  RzPdbMsfStream
 
struct  RzPdbMsfStreamDirectory
 
struct  rz_pdb_t
 

Macros

#define CAB_SIGNATURE   "MSCF"
 
#define PDB_SIGNATURE   "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00"
 
#define PDB_SIGNATURE_LEN   32
 
#define GET_BF(value, start, len)   (((value) >> (start)) & ((1 << len) - 1))
 

Typedefs

typedef struct dbi_stream_header_t RzPdbRzPdbDbiStreamHdr
 
typedef struct dbi_stream_t RzPdbDbiStream
 
typedef struct tpi_stream_header_t RzPdbTpiStreamHeader
 
typedef struct tpi_types RzPdbTpiType
 
typedef struct tpi_stream_t RzPdbTpiStream
 
typedef enum pdb_stream_index_t RzRzPdbStreamIndex
 
typedef struct rz_pdb_t RzPdb
 

Enumerations

enum  RzPdbTpiCallingConvention {
  NEAR_C = 0x00000000 , FAR_C = 0x00000001 , NEAR_PASCAL = 0x00000002 , FAR_PASCAL = 0x00000003 ,
  NEAR_FAST = 0x00000004 , FAR_FAST = 0x00000005 , SKIPPED = 0x00000006 , NEAR_STD = 0x00000007 ,
  FAR_STD = 0x00000008 , NEAR_SYS = 0x00000009 , FAR_SYS = 0x0000000A , THISCALL = 0x0000000B ,
  MIPSCALL = 0x0000000C , GENERIC = 0x0000000D , ALPHACALL = 0x0000000E , PPCCALL = 0x0000000F ,
  SHCALL = 0x00000010 , ARMCALL = 0x00000011 , AM33CALL = 0x00000012 , TRICALL = 0x00000013 ,
  SH5CALL = 0x00000014 , M32RCALL = 0x00000015 , CLRCALL = 0x00000016 , INLINECALL = 0x00000017 ,
  NEAR_VEC = 0X00000018 , RESERVED = 0x00000019 , MAX_CV_CALL
}
 
enum  RzPdbTpiStreamVersion {
  V40 = 19950410 , V41 = 19951122 , V50 = 19961031 , V70 = 19990903 ,
  V80 = 20040203
}
 
enum  pdb_stream_index_t {
  PDB_STREAM_ROOT = 0 , PDB_STREAM_PDB , PDB_STREAM_TPI , PDB_STREAM_DBI ,
  PDB_STREAM_GSYM , PDB_STREAM_SECT_HDR , PDB_STREAM_SECT__HDR_ORIG , PDB_STREAM_OMAP_TO_SRC ,
  PDB_STREAM_OMAP_FROM_SRC , PDB_STREAM_FPO , PDB_STREAM_FPO_NEW , PDB_STREAM_XDATA ,
  PDB_STREAM_PDATA , PDB_STREAM_TOKEN_RID_MAP , PDB_STREAM_MAX
}
 
enum  pdb_stream_version {
  VC2 = 19941610 , VC4 = 19950623 , VC41 = 19950814 , VC50 = 19960307 ,
  VC98 = 19970604 , VC70Dep = 19990604 , VC70 = 20000404 , VC80 = 20030901 ,
  VC110 = 20091201 , VC140 = 20140508
}
 

Functions

RZ_API bool rz_bin_pdb_extract_in_folder (RZ_NONNULL const char *file_cab, RZ_NONNULL const char *output_dir)
 Extracts compressed PDB files into a folder. More...
 
RZ_API RZ_OWN RzPdbrz_bin_pdb_parse_from_file (RZ_NONNULL const char *filename)
 Parse PDB file given the path. More...
 
RZ_API RZ_OWN RzPdbrz_bin_pdb_parse_from_buf (RZ_NONNULL const RzBuffer *buf)
 Parse PDB from the buffer. More...
 
RZ_API void rz_bin_pdb_free (RzPdb *pdb)
 Free PDB instance. More...
 
RZ_API RZ_BORROW RzPdbTpiTyperz_bin_pdb_get_type_by_index (RZ_NONNULL RzPdbTpiStream *stream, ut32 index)
 Get RzPdbTpiType that matches tpi stream index. More...
 
RZ_API RZ_OWN char * rz_bin_pdb_calling_convention_as_string (RZ_NONNULL RzPdbTpiCallingConvention idx)
 Parses calling convention type as string. More...
 
RZ_API bool rz_bin_pdb_type_is_fwdref (RZ_NONNULL RzPdbTpiType *t)
 Return true if type is forward definition. More...
 
RZ_API RZ_BORROW RzListrz_bin_pdb_get_type_members (RZ_NONNULL RzPdbTpiStream *stream, RzPdbTpiType *t)
 Get the RzPdbTpiType member list. More...
 
RZ_API RZ_BORROW char * rz_bin_pdb_get_type_name (RZ_NONNULL RzPdbTpiType *type)
 Get the name of the type. More...
 
RZ_API ut64 rz_bin_pdb_get_type_val (RZ_NONNULL RzPdbTpiType *type)
 Get the numeric value inside the type. More...
 
RZ_API int rz_bin_pdb_omap_remap (RZ_NONNULL RzPdbOmapStream *omap_stream, int address)
 return remapped symbol address More...
 

Macro Definition Documentation

◆ CAB_SIGNATURE

#define CAB_SIGNATURE   "MSCF"

Definition at line 15 of file rz_pdb.h.

◆ GET_BF

#define GET_BF (   value,
  start,
  len 
)    (((value) >> (start)) & ((1 << len) - 1))

Definition at line 19 of file rz_pdb.h.

◆ PDB_SIGNATURE

#define PDB_SIGNATURE   "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00"

Definition at line 16 of file rz_pdb.h.

◆ PDB_SIGNATURE_LEN

#define PDB_SIGNATURE_LEN   32

Definition at line 17 of file rz_pdb.h.

Typedef Documentation

◆ RzPdb

typedef struct rz_pdb_t RzPdb

◆ RzPdbDbiStream

typedef struct dbi_stream_t RzPdbDbiStream

◆ RzPdbRzPdbDbiStreamHdr

◆ RzPdbTpiStream

typedef struct tpi_stream_t RzPdbTpiStream

◆ RzPdbTpiStreamHeader

◆ RzPdbTpiType

typedef struct tpi_types RzPdbTpiType

◆ RzRzPdbStreamIndex

Enumeration Type Documentation

◆ pdb_stream_index_t

Enumerator
PDB_STREAM_ROOT 
PDB_STREAM_PDB 
PDB_STREAM_TPI 
PDB_STREAM_DBI 
PDB_STREAM_GSYM 
PDB_STREAM_SECT_HDR 
PDB_STREAM_SECT__HDR_ORIG 
PDB_STREAM_OMAP_TO_SRC 
PDB_STREAM_OMAP_FROM_SRC 
PDB_STREAM_FPO 
PDB_STREAM_FPO_NEW 
PDB_STREAM_XDATA 
PDB_STREAM_PDATA 
PDB_STREAM_TOKEN_RID_MAP 
PDB_STREAM_MAX 

Definition at line 161 of file rz_pdb.h.

161  {
162  PDB_STREAM_ROOT = 0, // PDB_ROOT_DIRECTORY
163  PDB_STREAM_PDB, // PDB STREAM INFO
164  PDB_STREAM_TPI, // TYPE INFO
165  PDB_STREAM_DBI, // DEBUG INFO
166 
enum pdb_stream_index_t RzRzPdbStreamIndex
@ PDB_STREAM_GSYM
Definition: rz_pdb.h:167
@ PDB_STREAM_SECT__HDR_ORIG
Definition: rz_pdb.h:169
@ PDB_STREAM_TPI
Definition: rz_pdb.h:164
@ PDB_STREAM_PDB
Definition: rz_pdb.h:163
@ PDB_STREAM_SECT_HDR
Definition: rz_pdb.h:168
@ PDB_STREAM_PDATA
Definition: rz_pdb.h:175
@ PDB_STREAM_OMAP_TO_SRC
Definition: rz_pdb.h:170
@ PDB_STREAM_FPO_NEW
Definition: rz_pdb.h:173
@ PDB_STREAM_MAX
Definition: rz_pdb.h:177
@ PDB_STREAM_TOKEN_RID_MAP
Definition: rz_pdb.h:176
@ PDB_STREAM_FPO
Definition: rz_pdb.h:172
@ PDB_STREAM_DBI
Definition: rz_pdb.h:165
@ PDB_STREAM_ROOT
Definition: rz_pdb.h:162
@ PDB_STREAM_XDATA
Definition: rz_pdb.h:174
@ PDB_STREAM_OMAP_FROM_SRC
Definition: rz_pdb.h:171

◆ pdb_stream_version

Enumerator
VC2 
VC4 
VC41 
VC50 
VC98 
VC70Dep 
VC70 
VC80 
VC110 
VC140 

Definition at line 180 of file rz_pdb.h.

180  {
181  VC2 = 19941610,
182  VC4 = 19950623,
183  VC41 = 19950814,
184  VC50 = 19960307,
185  VC98 = 19970604,
186  VC70Dep = 19990604,
187  VC70 = 20000404,
188  VC80 = 20030901,
189  VC110 = 20091201,
190  VC140 = 20140508,
191 };
@ VC70Dep
Definition: rz_pdb.h:186
@ VC80
Definition: rz_pdb.h:188
@ VC110
Definition: rz_pdb.h:189
@ VC50
Definition: rz_pdb.h:184
@ VC98
Definition: rz_pdb.h:185
@ VC41
Definition: rz_pdb.h:183
@ VC70
Definition: rz_pdb.h:187
@ VC4
Definition: rz_pdb.h:182
@ VC140
Definition: rz_pdb.h:190
@ VC2
Definition: rz_pdb.h:181

◆ RzPdbTpiCallingConvention

Enumerator
NEAR_C 
FAR_C 
NEAR_PASCAL 
FAR_PASCAL 
NEAR_FAST 
FAR_FAST 
SKIPPED 
NEAR_STD 
FAR_STD 
NEAR_SYS 
FAR_SYS 
THISCALL 
MIPSCALL 
GENERIC 
ALPHACALL 
PPCCALL 
SHCALL 
ARMCALL 
AM33CALL 
TRICALL 
SH5CALL 
M32RCALL 
CLRCALL 
INLINECALL 
NEAR_VEC 
RESERVED 
MAX_CV_CALL 

Definition at line 84 of file rz_pdb.h.

84  {
85  NEAR_C = 0x00000000,
86  FAR_C = 0x00000001,
87  NEAR_PASCAL = 0x00000002,
88  FAR_PASCAL = 0x00000003,
89  NEAR_FAST = 0x00000004,
90  FAR_FAST = 0x00000005,
91  SKIPPED = 0x00000006,
92  NEAR_STD = 0x00000007,
93  FAR_STD = 0x00000008,
94  NEAR_SYS = 0x00000009,
95  FAR_SYS = 0x0000000A,
96  THISCALL = 0x0000000B,
97  MIPSCALL = 0x0000000C,
98  GENERIC = 0x0000000D,
99  ALPHACALL = 0x0000000E,
100  PPCCALL = 0x0000000F,
101  SHCALL = 0x00000010,
102  ARMCALL = 0x00000011,
103  AM33CALL = 0x00000012,
104  TRICALL = 0x00000013,
105  SH5CALL = 0x00000014,
106  M32RCALL = 0x00000015,
107  CLRCALL = 0x00000016,
108  INLINECALL = 0x00000017,
109  NEAR_VEC = 0X00000018,
110  RESERVED = 0x00000019,
RzPdbTpiCallingConvention
Definition: rz_pdb.h:84
@ INLINECALL
Definition: rz_pdb.h:108
@ SH5CALL
Definition: rz_pdb.h:105
@ MAX_CV_CALL
Definition: rz_pdb.h:111
@ PPCCALL
Definition: rz_pdb.h:100
@ TRICALL
Definition: rz_pdb.h:104
@ THISCALL
Definition: rz_pdb.h:96
@ ALPHACALL
Definition: rz_pdb.h:99
@ CLRCALL
Definition: rz_pdb.h:107
@ MIPSCALL
Definition: rz_pdb.h:97
@ NEAR_PASCAL
Definition: rz_pdb.h:87
@ NEAR_FAST
Definition: rz_pdb.h:89
@ SKIPPED
Definition: rz_pdb.h:91
@ FAR_PASCAL
Definition: rz_pdb.h:88
@ ARMCALL
Definition: rz_pdb.h:102
@ FAR_FAST
Definition: rz_pdb.h:90
@ GENERIC
Definition: rz_pdb.h:98
@ NEAR_C
Definition: rz_pdb.h:85
@ NEAR_SYS
Definition: rz_pdb.h:94
@ NEAR_VEC
Definition: rz_pdb.h:109
@ FAR_C
Definition: rz_pdb.h:86
@ AM33CALL
Definition: rz_pdb.h:103
@ FAR_SYS
Definition: rz_pdb.h:95
@ NEAR_STD
Definition: rz_pdb.h:92
@ M32RCALL
Definition: rz_pdb.h:106
@ SHCALL
Definition: rz_pdb.h:101
@ FAR_STD
Definition: rz_pdb.h:93
@ RESERVED
Definition: rz_pdb.h:110

◆ RzPdbTpiStreamVersion

Enumerator
V40 
V41 
V50 
V70 
V80 

Definition at line 114 of file rz_pdb.h.

114  {
115  V40 = 19950410,
116  V41 = 19951122,
117  V50 = 19961031,
118  V70 = 19990903,
119  V80 = 20040203,
RzPdbTpiStreamVersion
Definition: rz_pdb.h:114
@ V80
Definition: rz_pdb.h:119
@ V41
Definition: rz_pdb.h:116
@ V70
Definition: rz_pdb.h:118
@ V50
Definition: rz_pdb.h:117
@ V40
Definition: rz_pdb.h:115

Function Documentation

◆ rz_bin_pdb_calling_convention_as_string()

RZ_API RZ_OWN char* rz_bin_pdb_calling_convention_as_string ( RZ_NONNULL RzPdbTpiCallingConvention  idx)

Parses calling convention type as string.

Parameters
idx

Definition at line 35 of file tpi.c.

35  {
36  switch (idx) {
37  case NEAR_C:
38  case FAR_C:
39  return strdup("__cdecl");
40  case NEAR_PASCAL:
41  case FAR_PASCAL:
42  return strdup("__pascal");
43  case NEAR_FAST:
44  case FAR_FAST:
45  return strdup("__fastcall");
46  case NEAR_STD:
47  case FAR_STD:
48  return strdup("__stdcall");
49  case NEAR_SYS:
50  case FAR_SYS:
51  return strdup("__syscall");
52  case THISCALL:
53  return strdup("__thiscall");
54  case NEAR_VEC:
55  return strdup("__vectorcall");
56  default:
57  return NULL;
58  }
59 }
#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")
int idx
Definition: setup.py:197

References FAR_C, FAR_FAST, FAR_PASCAL, FAR_STD, FAR_SYS, setup::idx, NEAR_C, NEAR_FAST, NEAR_PASCAL, NEAR_STD, NEAR_SYS, NEAR_VEC, NULL, strdup(), and THISCALL.

Referenced by parse_type_mfunction(), and parse_type_procedure().

◆ rz_bin_pdb_extract_in_folder()

RZ_API bool rz_bin_pdb_extract_in_folder ( RZ_NONNULL const char *  file_cab,
RZ_NONNULL const char *  output_dir 
)

Extracts compressed PDB files into a folder.

Parameters
file_cabThe file cab
output_dirThe output dir
Returns
On success returns true, otherwise false.

Definition at line 209 of file cab_extract.c.

209  {
210  rz_return_val_if_fail(file_cab && output_dir, false);
211 
212  if (!rz_file_exists(file_cab)) {
213  RZ_LOG_ERROR("%s is not a file or does not exist.\n", file_cab);
214  return false;
215  }
216 
217  if (!rz_file_is_directory(output_dir)) {
218  RZ_LOG_ERROR("%s is not a directory or does not exist.\n", output_dir);
219  return false;
220  }
221 
222  struct mscab_decompressor *cabd = NULL;
223  struct mscabd_cabinet *cab = NULL;
224 
226  RZ_LOG_ERROR("Cannot allocate mscab_decompressor.\n");
227  return false;
228  }
229 
230  if (!(cab = cabd->open(cabd, file_cab))) {
231  RZ_LOG_ERROR("Invalid compressed cab file: %s\n", file_cab);
233  return false;
234  }
235 
236  bool result = true;
237  bool is_unix = is_cab_using_unix_paths(cab->files);
238  for (struct mscabd_file *file = cab->files; file; file = file->next) {
239  char *new_name = sanitize_cab_filename(file, output_dir, is_unix);
240  if (!new_name) {
241  result = false;
242  break;
243  }
244  if (cabd->extract(cabd, file, new_name)) {
245  RZ_LOG_ERROR("cab_extract: %s: %s\n", new_name, cab_error(cabd));
246  free(new_name);
247  result = false;
248  break;
249  }
250  RZ_LOG_INFO("cab_extract: extracted %s\n", new_name);
251  free(new_name);
252  }
253 
254  cabd->close(cabd, cab);
256  return result;
257 }
static bool is_cab_using_unix_paths(struct mscabd_file *files)
Definition: cab_extract.c:11
static char * sanitize_cab_filename(struct mscabd_file *file, const char *output_dir, bool is_unix)
Definition: cab_extract.c:85
static const char * cab_error(struct mscab_decompressor *cd)
Definition: cab_extract.c:175
struct mscab_decompressor * cabd
Definition: cabextract.c:126
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void mspack_destroy_cab_decompressor(struct mscab_decompressor *base)
Definition: cabd.c:173
struct mscab_decompressor * mspack_create_cab_decompressor(struct mspack_system *sys)
Definition: cabd.c:140
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_file_is_directory(const char *str)
Definition: file.c:167
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
Definition: gzappend.c:170
z_const unsigned char * next
Definition: gzappend.c:175
struct mscabd_cabinet *(* open)(struct mscab_decompressor *self, const char *filename)
Definition: mspack.h:978
int(* extract)(struct mscab_decompressor *self, struct mscabd_file *file, const char *filename)
Definition: mspack.h:1138
void(* close)(struct mscab_decompressor *self, struct mscabd_cabinet *cab)
Definition: mspack.h:1010
struct mscabd_file * files
Definition: mspack.h:743

References cab_error(), cabd, mscab_decompressor::close, mscab_decompressor::extract, mscabd_cabinet::files, free(), is_cab_using_unix_paths(), mspack_create_cab_decompressor(), mspack_destroy_cab_decompressor(), file::next, NULL, mscab_decompressor::open, rz_file_exists(), rz_file_is_directory(), RZ_LOG_ERROR, RZ_LOG_INFO, rz_return_val_if_fail, and sanitize_cab_filename().

Referenced by download(), and rz_cmd_pdb_extract_handler().

◆ rz_bin_pdb_free()

RZ_API void rz_bin_pdb_free ( RzPdb pdb)

Free PDB instance.

Parameters
pdbPDB instance
Returns
void

Definition at line 366 of file pdb.c.

366  {
367  if (!pdb) {
368  return;
369  }
370  rz_buf_free(pdb->buf);
371  free(pdb->super_block);
372  rz_list_free(pdb->streams);
373  free(pdb->s_pdb);
374  free_dbi_stream(pdb->s_dbi);
376  free_omap_stream(pdb->s_omap);
377  free_tpi_stream(pdb->s_tpi);
378  free_pe_stream(pdb->s_pe);
379  free(pdb);
380 }
RZ_IPI void free_dbi_stream(RzPdbDbiStream *stream)
Definition: dbi.c:7
RZ_IPI void free_gdata_stream(RzPdbGDataStream *stream)
Definition: gdata.c:80
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_IPI void free_omap_stream(RzPdbOmapStream *stream)
Definition: omap.c:42
RZ_IPI void free_pe_stream(RzPdbPeStream *stream)
Definition: stream_pe.c:53
RZ_IPI void free_tpi_stream(RzPdbTpiStream *stream)
Definition: tpi.c:705
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RzPdbDbiStream * s_dbi
Definition: rz_pdb.h:246
RzPdbGDataStream * s_gdata
Definition: rz_pdb.h:248
RzPdbTpiStream * s_tpi
Definition: rz_pdb.h:247
RzList * streams
Definition: rz_pdb.h:244
RzPdbPeStream * s_pe
Definition: rz_pdb.h:250
RzPdbMsfSuperBlock * super_block
Definition: rz_pdb.h:243
RzPdbOmapStream * s_omap
Definition: rz_pdb.h:249
RzPdbStream * s_pdb
Definition: rz_pdb.h:245
RzBuffer * buf
Definition: rz_pdb.h:242

References rz_pdb_t::buf, free(), free_dbi_stream(), free_gdata_stream(), free_omap_stream(), free_pe_stream(), free_tpi_stream(), rz_buf_free(), rz_list_free(), rz_pdb_t::s_dbi, rz_pdb_t::s_gdata, rz_pdb_t::s_omap, rz_pdb_t::s_pdb, rz_pdb_t::s_pe, rz_pdb_t::s_tpi, rz_pdb_t::streams, and rz_pdb_t::super_block.

Referenced by GetHeapGlobalsOffset(), rz_bin_pdb_parse_from_buf(), rz_cmd_info_pdb_show_handler(), rz_core_bin_pdb_load(), and rz_core_bin_print().

◆ rz_bin_pdb_get_type_by_index()

RZ_API RZ_BORROW RzPdbTpiType* rz_bin_pdb_get_type_by_index ( RZ_NONNULL RzPdbTpiStream stream,
ut32  index 
)

Get RzPdbTpiType that matches tpi stream index.

Parameters
streamTPI Stream
indexTPI Stream Index

Definition at line 1844 of file tpi.c.

1844  {
1846  if (index == 0) {
1847  return NULL;
1848  }
1849 
1850  RBNode *node = rz_rbtree_find(stream->types, &index, tpi_type_node_cmp, NULL);
1851  if (!node) {
1852  if (!is_simple_type(stream, index)) {
1853  return NULL;
1854  } else {
1855  return parse_simple_type(stream, index);
1856  }
1857  }
1859  return type;
1860 }
voidpf stream
Definition: ioapi.h:138
int type
Definition: mipsasm.c:17
RZ_API RBNode * rz_rbtree_find(RBNode *root, void *data, RBComparator cmp, void *user)
Definition: rbtree.c:267
#define container_of(ptr, type, member)
Definition: rz_types.h:650
static bool is_simple_type(RzPdbTpiStream *stream, ut32 idx)
Definition: tpi.c:7
int tpi_type_node_cmp(const void *incoming, const RBNode *in_tree, void *user)
Definition: tpi.c:19
RZ_IPI RzPdbTpiType * parse_simple_type(RzPdbTpiStream *stream, ut32 idx)
Parses simple type if the idx represents one.
Definition: tpi.c:142

References container_of, is_simple_type(), NULL, parse_simple_type(), rz_rbtree_find(), rz_return_val_if_fail, tpi_type_node_cmp(), and type.

Referenced by parse_enum(), parse_structure(), parse_type_arglist(), parse_type_array(), parse_type_member(), parse_type_mfunction(), parse_type_modifier(), parse_type_nest(), parse_type_onemethod(), parse_type_pointer(), parse_type_procedure(), parse_type_static_member(), parse_union(), and rz_bin_pdb_get_type_members().

◆ rz_bin_pdb_get_type_members()

RZ_API RZ_BORROW RzList* rz_bin_pdb_get_type_members ( RZ_NONNULL RzPdbTpiStream stream,
RzPdbTpiType t 
)

Get the RzPdbTpiType member list.

Parameters
streamTPI stream
tRzPdbTpiType
Returns
RzList *

Definition at line 406 of file tpi.c.

406  {
408  RzPdbTpiType *tmp;
409  switch (t->leaf_type) {
410  case LF_FIELDLIST: {
411  Tpi_LF_FieldList *lf = t->type_data;
412  return lf->substructs;
413  }
414  case LF_UNION: {
416  Tpi_LF_FieldList *lf_union = tmp ? tmp->type_data : NULL;
417  return lf_union ? lf_union->substructs : NULL;
418  }
419  case LF_STRUCTURE:
420  case LF_CLASS: {
422  Tpi_LF_FieldList *lf_struct = tmp ? tmp->type_data : NULL;
423  return lf_struct ? lf_struct->substructs : NULL;
424  }
425  case LF_STRUCTURE_19:
426  case LF_CLASS_19: {
428  Tpi_LF_FieldList *lf_struct19 = tmp ? tmp->type_data : NULL;
429  return lf_struct19 ? lf_struct19->substructs : NULL;
430  }
431  case LF_ENUM: {
433  Tpi_LF_FieldList *lf_enum = tmp ? tmp->type_data : NULL;
434  return lf_enum ? lf_enum->substructs : NULL;
435  }
436  default:
437  return NULL;
438  }
439 }
RzList * substructs
Definition: tpi.h:581
ut16 leaf_type
Definition: rz_pdb.h:147
void * type_data
Definition: rz_pdb.h:149
RZ_API RZ_BORROW RzPdbTpiType * rz_bin_pdb_get_type_by_index(RZ_NONNULL RzPdbTpiStream *stream, ut32 index)
Get RzPdbTpiType that matches tpi stream index.
Definition: tpi.c:1844
@ LF_STRUCTURE_19
Definition: tpi.h:200
@ LF_CLASS
Definition: tpi.h:174
@ LF_UNION
Definition: tpi.h:176
@ LF_STRUCTURE
Definition: tpi.h:175
@ LF_CLASS_19
Definition: tpi.h:199
@ LF_FIELDLIST
Definition: tpi.h:146
@ LF_ENUM
Definition: tpi.h:177

References tpi_types::leaf_type, LF_CLASS, LF_CLASS_19, LF_ENUM, LF_FIELDLIST, LF_STRUCTURE, LF_STRUCTURE_19, LF_UNION, NULL, rz_bin_pdb_get_type_by_index(), rz_return_val_if_fail, Tpi_LF_FieldList::substructs, autogen_x86imm::tmp, and tpi_types::type_data.

Referenced by parse_enum(), parse_structure(), and parse_union().

◆ rz_bin_pdb_get_type_name()

RZ_API RZ_BORROW char* rz_bin_pdb_get_type_name ( RZ_NONNULL RzPdbTpiType type)

Get the name of the type.

Parameters
typeRzPdbTpiType *
Returns
char *

Definition at line 447 of file tpi.c.

447  {
449  switch (type->leaf_type) {
450  case LF_MEMBER: {
451  Tpi_LF_Member *lf_member = type->type_data;
452  return lf_member->name.name;
453  }
454  case LF_STMEMBER: {
455  Tpi_LF_StaticMember *lf_stmember = type->type_data;
456  return lf_stmember->name.name;
457  }
458  case LF_ONEMETHOD: {
459  Tpi_LF_OneMethod *lf_onemethod = type->type_data;
460  return lf_onemethod->name.name;
461  }
462  case LF_METHOD: {
463  Tpi_LF_Method *lf_method = type->type_data;
464  return lf_method->name.name;
465  }
466  case LF_NESTTYPE: {
467  Tpi_LF_NestType *lf_nesttype = type->type_data;
468  return lf_nesttype->name.name;
469  }
470  case LF_ENUM: {
471  Tpi_LF_Enum *lf_enum = type->type_data;
472  return lf_enum->name.name;
473  }
474  case LF_ENUMERATE: {
475  Tpi_LF_Enumerate *lf_enumerate = type->type_data;
476  return lf_enumerate->name.name;
477  }
478  case LF_CLASS:
479  case LF_STRUCTURE: {
480  Tpi_LF_Structure *lf_struct = type->type_data;
481  return lf_struct->name.name;
482  }
483  case LF_CLASS_19:
484  case LF_STRUCTURE_19: {
485  Tpi_LF_Structure_19 *lf_struct_19 = type->type_data;
486  return lf_struct_19->name.name;
487  }
488  case LF_ARRAY: {
489  Tpi_LF_Array *lf_array = type->type_data;
490  return lf_array->name.name;
491  }
492  case LF_UNION: {
493  Tpi_LF_Union *lf_union = type->type_data;
494  return lf_union->name.name;
495  }
496  default:
497  return NULL;
498  }
499 }
Tpi_Type_String name
Definition: tpi.h:438
Tpi_Type_String name
Definition: tpi.h:495
Tpi_Type_String name
Definition: tpi.h:503
Tpi_Type_String name
Definition: tpi.h:540
Tpi_Type_String name
Definition: tpi.h:521
Tpi_Type_String name
Definition: tpi.h:510
Tpi_Type_String name
Definition: tpi.h:561
Tpi_Type_String name
Definition: tpi.h:547
Tpi_Type_String name
Definition: tpi.h:462
Tpi_Type_String name
Definition: tpi.h:449
Tpi_Type_String name
Definition: tpi.h:472
char * name
Definition: tpi.h:424
@ LF_NESTTYPE
Definition: tpi.h:186
@ LF_MEMBER
Definition: tpi.h:183
@ LF_METHOD
Definition: tpi.h:185
@ LF_ONEMETHOD
Definition: tpi.h:187
@ LF_ENUMERATE
Definition: tpi.h:172
@ LF_STMEMBER
Definition: tpi.h:184
@ LF_ARRAY
Definition: tpi.h:173

References LF_ARRAY, LF_CLASS, LF_CLASS_19, LF_ENUM, LF_ENUMERATE, LF_MEMBER, LF_METHOD, LF_NESTTYPE, LF_ONEMETHOD, LF_STMEMBER, LF_STRUCTURE, LF_STRUCTURE_19, LF_UNION, Tpi_Type_String::name, Tpi_LF_Array::name, Tpi_LF_Structure::name, Tpi_LF_Structure_19::name, Tpi_LF_Union::name, Tpi_LF_Enum::name, Tpi_LF_Enumerate::name, Tpi_LF_NestType::name, Tpi_LF_Method::name, Tpi_LF_Member::name, Tpi_LF_StaticMember::name, Tpi_LF_OneMethod::name, NULL, rz_return_val_if_fail, and type.

Referenced by parse_enum(), parse_enumerate(), parse_struct_member(), parse_structure(), parse_type_nest(), parse_type_onemethod(), parse_union(), and parse_union_member().

◆ rz_bin_pdb_get_type_val()

RZ_API ut64 rz_bin_pdb_get_type_val ( RZ_NONNULL RzPdbTpiType type)

Get the numeric value inside the type.

Parameters
typeRzPdbTpiType *
Returns
ut64

Definition at line 507 of file tpi.c.

507  {
509  switch (type->leaf_type) {
510  case LF_ONEMETHOD: {
511  Tpi_LF_OneMethod *lf_onemethod = type->type_data;
512  return lf_onemethod->offset_in_vtable;
513  }
514  case LF_MEMBER: {
515  Tpi_LF_Member *lf_member = type->type_data;
516  return get_numeric_val(&lf_member->offset);
517  }
518  case LF_ENUMERATE: {
519  Tpi_LF_Enumerate *lf_enumerate = type->type_data;
520  return get_numeric_val(&lf_enumerate->enum_value);
521  }
522  case LF_CLASS:
523  case LF_STRUCTURE: {
524  Tpi_LF_Structure *lf_struct = type->type_data;
525  return get_numeric_val(&lf_struct->size);
526  }
527  case LF_CLASS_19:
528  case LF_STRUCTURE_19: {
529  Tpi_LF_Structure_19 *lf_struct_19 = type->type_data;
530  return get_numeric_val(&lf_struct_19->size);
531  }
532  case LF_ARRAY: {
533  Tpi_LF_Array *lf_array = type->type_data;
534  return get_numeric_val(&lf_array->size);
535  }
536  case LF_UNION: {
537  Tpi_LF_Union *lf_union = type->type_data;
538  return get_numeric_val(&lf_union->size);
539  }
540  case LF_INDEX: {
541  Tpi_LF_Index *lf_index = type->type_data;
542  return lf_index->index;
543  }
544  default:
545  return 0;
546  }
547 }
Tpi_Type_Numeric size
Definition: tpi.h:437
Tpi_Type_Numeric enum_value
Definition: tpi.h:502
ut32 index
Definition: tpi.h:553
Tpi_Type_Numeric offset
Definition: tpi.h:539
ut32 offset_in_vtable
Definition: tpi.h:560
Tpi_Type_Numeric size
Definition: tpi.h:461
Tpi_Type_Numeric size
Definition: tpi.h:448
Tpi_Type_Numeric size
Definition: tpi.h:471
static ut64 get_numeric_val(Tpi_Type_Numeric *numeric)
Definition: tpi.c:343
@ LF_INDEX
Definition: tpi.h:158

References Tpi_LF_Enumerate::enum_value, get_numeric_val(), Tpi_LF_Index::index, LF_ARRAY, LF_CLASS, LF_CLASS_19, LF_ENUMERATE, LF_INDEX, LF_MEMBER, LF_ONEMETHOD, LF_STRUCTURE, LF_STRUCTURE_19, LF_UNION, Tpi_LF_Member::offset, Tpi_LF_OneMethod::offset_in_vtable, rz_return_val_if_fail, Tpi_LF_Array::size, Tpi_LF_Structure::size, Tpi_LF_Structure_19::size, Tpi_LF_Union::size, and type.

Referenced by parse_enum(), parse_enumerate(), parse_struct_member(), parse_structure(), parse_type_array(), parse_union(), and parse_union_member().

◆ rz_bin_pdb_omap_remap()

RZ_API int rz_bin_pdb_omap_remap ( RZ_NONNULL RzPdbOmapStream omap_stream,
int  address 
)

return remapped symbol address

Parameters
omap_streamRzPdbOmapStream
addressWhere to remap
Returns
int

Definition at line 89 of file omap.c.

89  {
90  OmapEntry *omap_entry = 0;
91  RzListIter *it = 0;
92  int i = 0;
93  int pos = 0;
94  int len = 0;
95 
96  if (!omap_stream) {
97  return address;
98  }
99 
100  len = rz_list_length(omap_stream->entries);
101 
102  if (omap_stream->froms == 0) {
103  omap_stream->froms = (unsigned int *)malloc(4 * len);
104  if (!omap_stream->froms) {
105  return -1;
106  }
107  it = rz_list_iterator(omap_stream->entries);
108  while (rz_list_iter_next(it)) {
109  omap_entry = (OmapEntry *)rz_list_iter_get(it);
110  omap_stream->froms[i] = omap_entry->from;
111  i++;
112  }
113  }
114 
115  // mb (len -1) ???
116  pos = binary_search(omap_stream->froms, address, 0, (len));
117 
118  if (pos == -1) {
119  return -1;
120  }
121 
122  if (omap_stream->froms[pos] != address) {
123  pos -= 1;
124  }
125  omap_entry = (OmapEntry *)rz_list_get_n(omap_stream->entries, pos);
126  if (!omap_entry) {
127  return -1;
128  }
129  if (omap_entry->to == 0) {
130  return omap_entry->to;
131  }
132  return omap_entry->to + (address - omap_entry->from);
133 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
RZ_API RZ_BORROW RzListIter * rz_list_iterator(const RzList *list)
returns the first RzList iterator int the list
Definition: list.c:51
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
void * malloc(size_t size)
Definition: malloc.c:123
static int binary_search(unsigned int *A, int key, int imin, int imax)
Definition: omap.c:59
Definition: omap.h:9
ut32 from
Definition: omap.h:10
ut32 to
Definition: omap.h:11
int pos
Definition: main.c:11

References binary_search(), OmapEntry::from, i, len, malloc(), pos, rz_list_get_n(), rz_list_iterator(), rz_list_length(), and OmapEntry::to.

Referenced by pdb_set_symbols(), and rz_core_bin_pdb_gvars_as_string().

◆ rz_bin_pdb_parse_from_buf()

RZ_API RZ_OWN RzPdb* rz_bin_pdb_parse_from_buf ( RZ_NONNULL const RzBuffer buf)

Parse PDB from the buffer.

Parameters
bufmmap of the PDB file
Returns
RzPdb *

Definition at line 315 of file pdb.c.

315  {
317  RzPdb *pdb = RZ_NEW0(RzPdb);
318  if (!pdb) {
319  goto error;
320  }
321  pdb->buf = (RzBuffer *)buf;
324  if (len != PDB_SIGNATURE_LEN) {
325  RZ_LOG_ERROR("Wrong magic length!\n");
326  goto error;
327  }
329  RZ_LOG_ERROR("PDB Signature Error!\n");
330  goto error;
331  }
332  if (!rz_buf_read_le32(pdb->buf, &pdb->super_block->block_size) ||
334  !rz_buf_read_le32(pdb->buf, &pdb->super_block->num_blocks) ||
336  !rz_buf_read_le32(pdb->buf, &pdb->super_block->unknown) ||
338  goto error;
339  }
340  ut64 bufsize = rz_buf_size((RzBuffer *)buf); // length of whole PDB file
341  bool valid =
342  pdb->super_block->num_blocks > 0 &&
343  (ut64)pdb->super_block->num_blocks * pdb->super_block->block_size == bufsize &&
346  if (!valid) {
347  RZ_LOG_ERROR("Invalid MSF superblock!\n");
348  goto error;
349  }
350  if (!pdb7_parse(pdb)) {
351  goto error;
352  }
353  return pdb;
354 error:
355 
356  rz_bin_pdb_free(pdb);
357  return NULL;
358 }
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static bool pdb7_parse(RzPdb *pdb)
Definition: pdb.c:258
RZ_API void rz_bin_pdb_free(RzPdb *pdb)
Free PDB instance.
Definition: pdb.c:366
#define rz_buf_read_le32(b, result)
Definition: rz_buf.h:267
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define PDB_SIGNATURE
Definition: rz_pdb.h:16
#define PDB_SIGNATURE_LEN
Definition: rz_pdb.h:17
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define st64
Definition: rz_types_base.h:10
MSF file format header https://llvm.org/docs/PDB/MsfFile.html#the-superblock.
Definition: rz_pdb.h:218
ut32 num_directory_bytes
The size of the stream directory, in bytes.
Definition: rz_pdb.h:223
ut32 num_blocks
The total number of blocks in the file.
Definition: rz_pdb.h:222
ut32 block_size
The block size of the internal file system.
Definition: rz_pdb.h:220
ut32 block_map_addr
The index of a block within the MSF file.
Definition: rz_pdb.h:225
char file_magic[PDB_SIGNATURE_LEN]
Must be equal to "Microsoft C / C++ MSF 7.00\\r\\n" followed by the bytes 1A 44 53 00 00 00.
Definition: rz_pdb.h:219
ut32 free_block_map_block
The index of a block within the file, the data within that block is not used.
Definition: rz_pdb.h:221
bool valid
Definition: core.c:77
void error(const char *msg)
Definition: untgz.c:593
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References RzPdbMsfSuperBlock::block_map_addr, RzPdbMsfSuperBlock::block_size, rz_pdb_t::buf, error(), RzPdbMsfSuperBlock::file_magic, RzPdbMsfSuperBlock::free_block_map_block, if(), len, NULL, RzPdbMsfSuperBlock::num_blocks, RzPdbMsfSuperBlock::num_directory_bytes, pdb7_parse(), PDB_SIGNATURE, PDB_SIGNATURE_LEN, rz_bin_pdb_free(), rz_buf_read(), rz_buf_read_le32, rz_buf_size(), RZ_LOG_ERROR, RZ_NEW0, rz_return_val_if_fail, st64, rz_pdb_t::super_block, RzPdbMsfSuperBlock::unknown, ut64(), and valid.

Referenced by rz_bin_pdb_parse_from_file().

◆ rz_bin_pdb_parse_from_file()

RZ_API RZ_OWN RzPdb* rz_bin_pdb_parse_from_file ( RZ_NONNULL const char *  filename)

Parse PDB file given the path.

Parameters
filenamepath of the PDB file
Returns
RzPdb *

Definition at line 292 of file pdb.c.

292  {
295  if (!buf) {
296  RZ_LOG_ERROR("%s: Error reading file \"%s\"\n", __FUNCTION__, filename);
297  return false;
298  }
299 
300  if (is_compressed_pdb(buf)) {
301  rz_buf_free(buf);
302  RZ_LOG_ERROR("The pdb file %s seems to be compressed, please use idpx command to extract the contents.\n", filename);
303  return NULL;
304  }
305 
307 }
const char * filename
Definition: ioapi.h:137
bool is_compressed_pdb(RzBuffer *buf)
Definition: pdb.c:275
RZ_API RZ_OWN RzPdb * rz_bin_pdb_parse_from_buf(RZ_NONNULL const RzBuffer *buf)
Parse PDB from the buffer.
Definition: pdb.c:315
RZ_API RZ_OWN RzBuffer * rz_buf_new_slurp(const char *file)
Creates a new buffer from a file.
Definition: buf.c:384

References is_compressed_pdb(), NULL, rz_bin_pdb_parse_from_buf(), rz_buf_free(), rz_buf_new_slurp(), RZ_LOG_ERROR, and rz_return_val_if_fail.

Referenced by GetHeapGlobalsOffset(), and rz_core_pdb_load_info().

◆ rz_bin_pdb_type_is_fwdref()

RZ_API bool rz_bin_pdb_type_is_fwdref ( RZ_NONNULL RzPdbTpiType t)

Return true if type is forward definition.

Parameters
tRzPdbTpiType
Returns
bool

Definition at line 372 of file tpi.c.

372  {
373  rz_return_val_if_fail(t, false); // return val stands for we do nothing for it
374  switch (t->leaf_type) {
375  case LF_UNION: {
376  Tpi_LF_Union *lf = (Tpi_LF_Union *)t->type_data;
377  return lf->prop.bits.fwdref ? true : false;
378  }
379  case LF_STRUCTURE:
380  case LF_CLASS: {
381  Tpi_LF_Structure *lf = (Tpi_LF_Structure *)t->type_data;
382  return lf->prop.bits.fwdref ? true : false;
383  }
384  case LF_STRUCTURE_19:
385  case LF_CLASS_19: {
386  Tpi_LF_Structure_19 *lf = (Tpi_LF_Structure_19 *)t->type_data;
387  return lf->prop.bits.fwdref ? true : false;
388  }
389  case LF_ENUM: {
390  Tpi_LF_Enum *lf = (Tpi_LF_Enum *)t->type_data;
391  return lf->prop.bits.fwdref ? true : false;
392  }
393  default:
395  return false;
396  }
397 }
#define rz_warn_if_reached()
Definition: rz_assert.h:29
TpiCVProperty prop
Definition: tpi.h:492
TpiCVProperty prop
Definition: tpi.h:455
TpiCVProperty prop
Definition: tpi.h:444
TpiCVProperty prop
Definition: tpi.h:469
struct TpiCVProperty::@208 bits
ut16 fwdref
Definition: tpi.h:259

References TpiCVProperty::bits, TpiCVProperty::fwdref, LF_CLASS, LF_CLASS_19, LF_ENUM, LF_STRUCTURE, LF_STRUCTURE_19, LF_UNION, Tpi_LF_Structure::prop, Tpi_LF_Structure_19::prop, Tpi_LF_Union::prop, Tpi_LF_Enum::prop, rz_return_val_if_fail, and rz_warn_if_reached.

Referenced by parse_enum(), parse_structure(), and parse_union().