Rizin
unix-like reverse engineering framework and cli tools
pe_rsrc.c File Reference
#include "pe.h"
#include <ht_uu.h>

Go to the source code of this file.

Macros

#define align32(x)   x = (((x)&0x3) == 0) ? (x) : ((x) & ~0x3) + 0x4;
 
#define EXIT_ON_OVERFLOW(S)
 

Functions

static void _free_resource (rz_pe_resource *rs)
 
static bool read_image_resource_directory_aux (RzBuffer *b, Pe_image_resource_directory *dir)
 
static int read_image_resource_directory (RzBuffer *b, ut64 addr, Pe_image_resource_directory *dir)
 
int PE_() bin_pe_init_resource (RzBinPEObj *bin)
 
static void free_Var (Var *var)
 
static void free_VarFileInfo (VarFileInfo *varFileInfo)
 
static void free_String (String *string)
 
static void free_StringTable (StringTable *stringTable)
 
static void free_StringFileInfo (StringFileInfo *stringFileInfo)
 
static void free_VS_VERSIONINFO (PE_VS_VERSIONINFO *vs_VersionInfo)
 
static VarPe_r_bin_pe_parse_var (RzBinPEObj *bin, PE_DWord *curAddr)
 
static VarFileInfoPe_r_bin_pe_parse_var_file_info (RzBinPEObj *bin, PE_DWord *curAddr)
 
static StringPe_r_bin_pe_parse_string (RzBinPEObj *bin, PE_DWord *curAddr)
 
static StringTablePe_r_bin_pe_parse_string_table (RzBinPEObj *bin, PE_DWord *curAddr)
 
static StringFileInfoPe_r_bin_pe_parse_string_file_info (RzBinPEObj *bin, PE_DWord *curAddr)
 
static PE_VS_VERSIONINFOPe_r_bin_pe_parse_version_info (RzBinPEObj *bin, PE_DWord version_info_paddr)
 
static SdbPe_r_bin_store_var (Var *var)
 
static SdbPe_r_bin_store_var_file_info (VarFileInfo *varFileInfo)
 
static SdbPe_r_bin_store_string (String *string)
 
static SdbPe_r_bin_store_string_table (StringTable *stringTable)
 
static SdbPe_r_bin_store_string_file_info (StringFileInfo *stringFileInfo)
 
static SdbPe_r_bin_store_fixed_file_info (PE_VS_FIXEDFILEINFO *vs_fixedFileInfo)
 
static SdbPe_r_bin_store_resource_version_info (PE_VS_VERSIONINFO *vs_VersionInfo)
 
static char * _known_product_ids (int id)
 
void PE_() bin_pe_init_rich_info (RzBinPEObj *bin)
 
static char * _resource_lang_str (int id)
 
static char * _resource_type_str (int type)
 
static int read_image_resource_directory_entry (RzBuffer *b, ut64 addr, Pe_image_resource_directory_entry *entry)
 
static int read_image_resource_data_entry (RzBuffer *b, ut64 addr, Pe_image_resource_data_entry *entry)
 
static void _parse_resource_directory (RzBinPEObj *bin, Pe_image_resource_directory *dir, ut64 offDir, int type, int id, HtUU *dirs, const char *resource_name)
 
static void _store_resource_sdb (RzBinPEObj *bin)
 
RZ_API void PE_() bin_pe_parse_resource (RzBinPEObj *bin)
 

Macro Definition Documentation

◆ align32

#define align32 (   x)    x = (((x)&0x3) == 0) ? (x) : ((x) & ~0x3) + 0x4;

Definition at line 132 of file pe_rsrc.c.

◆ EXIT_ON_OVERFLOW

#define EXIT_ON_OVERFLOW (   S)
Value:
if (curAddr > bin->size || curAddr + (S) > bin->size) { \
goto out_error; \
}
Definition: malloc.c:26
#define S
Definition: zip_err_str.c:9

Definition at line 552 of file pe_rsrc.c.

Function Documentation

◆ _free_resource()

static void _free_resource ( rz_pe_resource rs)
static

Definition at line 9 of file pe_rsrc.c.

9  {
10  if (rs) {
11  free(rs->name);
12  free(rs->timestr);
13  free(rs->data);
14  free(rs->type);
15  free(rs->language);
16  free(rs);
17  }
18 }
#define rs()
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), and rs.

Referenced by bin_pe_init_resource().

◆ _known_product_ids()

static char* _known_product_ids ( int  id)
static

Definition at line 849 of file pe_rsrc.c.

849  {
850  switch (id) {
851  case 0: return "Unknown";
852  case 1: return "Import0";
853  case 2: return "Linker510";
854  case 3: return "Cvtomf510";
855  case 4: return "Linker600";
856  case 5: return "Cvtomf600";
857  case 6: return "Cvtres500";
858  case 7: return "Utc11_Basic";
859  case 8: return "Utc11_C";
860  case 9: return "Utc12_Basic";
861  case 10: return "Utc12_C";
862  case 11: return "Utc12_CPP";
863  case 12: return "AliasObj60";
864  case 13: return "VisualBasic60";
865  case 14: return "Masm613";
866  case 15: return "Masm710";
867  case 16: return "Linker511";
868  case 17: return "Cvtomf511";
869  case 18: return "Masm614";
870  case 19: return "Linker512";
871  case 20: return "Cvtomf512";
872  case 21: return "Utc12_C_Std";
873  case 22: return "Utc12_CPP_Std";
874  case 23: return "Utc12_C_Book";
875  case 24: return "Utc12_CPP_Book";
876  case 25: return "Implib700";
877  case 26: return "Cvtomf700";
878  case 27: return "Utc13_Basic";
879  case 28: return "Utc13_C";
880  case 29: return "Utc13_CPP";
881  case 30: return "Linker610";
882  case 31: return "Cvtomf610";
883  case 32: return "Linker601";
884  case 33: return "Cvtomf601";
885  case 34: return "Utc12_1_Basic";
886  case 35: return "Utc12_1_C";
887  case 36: return "Utc12_1_CPP";
888  case 37: return "Linker620";
889  case 38: return "Cvtomf620";
890  case 39: return "AliasObj70";
891  case 40: return "Linker621";
892  case 41: return "Cvtomf621";
893  case 42: return "Masm615";
894  case 43: return "Utc13_LTCG_C";
895  case 44: return "Utc13_LTCG_CPP";
896  case 45: return "Masm620";
897  case 46: return "ILAsm100";
898  case 47: return "Utc12_2_Basic";
899  case 48: return "Utc12_2_C";
900  case 49: return "Utc12_2_CPP";
901  case 50: return "Utc12_2_C_Std";
902  case 51: return "Utc12_2_CPP_Std";
903  case 52: return "Utc12_2_C_Book";
904  case 53: return "Utc12_2_CPP_Book";
905  case 54: return "Implib622";
906  case 55: return "Cvtomf622";
907  case 56: return "Cvtres501";
908  case 57: return "Utc13_C_Std";
909  case 58: return "Utc13_CPP_Std";
910  case 59: return "Cvtpgd1300";
911  case 60: return "Linker622";
912  case 61: return "Linker700";
913  case 62: return "Export622";
914  case 63: return "Export700";
915  case 64: return "Masm700";
916  case 65: return "Utc13_POGO_I_C";
917  case 66: return "Utc13_POGO_I_CPP";
918  case 67: return "Utc13_POGO_O_C";
919  case 68: return "Utc13_POGO_O_CPP";
920  case 69: return "Cvtres700";
921  case 70: return "Cvtres710p";
922  case 71: return "Linker710p";
923  case 72: return "Cvtomf710p";
924  case 73: return "Export710p";
925  case 74: return "Implib710p";
926  case 75: return "Masm710p";
927  case 76: return "Utc1310p_C";
928  case 77: return "Utc1310p_CPP";
929  case 78: return "Utc1310p_C_Std";
930  case 79: return "Utc1310p_CPP_Std";
931  case 80: return "Utc1310p_LTCG_C";
932  case 81: return "Utc1310p_LTCG_CPP";
933  case 82: return "Utc1310p_POGO_I_C";
934  case 83: return "Utc1310p_POGO_I_CPP";
935  case 84: return "Utc1310p_POGO_O_C";
936  case 85: return "Utc1310p_POGO_O_CPP";
937  case 86: return "Linker624";
938  case 87: return "Cvtomf624";
939  case 88: return "Export624";
940  case 89: return "Implib624";
941  case 90: return "Linker710";
942  case 91: return "Cvtomf710";
943  case 92: return "Export710";
944  case 93: return "Implib710";
945  case 94: return "Cvtres710";
946  case 95: return "Utc1310_C";
947  case 96: return "Utc1310_CPP";
948  case 97: return "Utc1310_C_Std";
949  case 98: return "Utc1310_CPP_Std";
950  case 99: return "Utc1310_LTCG_C";
951  case 100: return "Utc1310_LTCG_CPP";
952  case 101: return "Utc1310_POGO_I_C";
953  case 102: return "Utc1310_POGO_I_CPP";
954  case 103: return "Utc1310_POGO_O_C";
955  case 104: return "Utc1310_POGO_O_CPP";
956  case 105: return "AliasObj710";
957  case 106: return "AliasObj710p";
958  case 107: return "Cvtpgd1310";
959  case 108: return "Cvtpgd1310p";
960  case 109: return "Utc1400_C";
961  case 110: return "Utc1400_CPP";
962  case 111: return "Utc1400_C_Std";
963  case 112: return "Utc1400_CPP_Std";
964  case 113: return "Utc1400_LTCG_C";
965  case 114: return "Utc1400_LTCG_CPP";
966  case 115: return "Utc1400_POGO_I_C";
967  case 116: return "Utc1400_POGO_I_CPP";
968  case 117: return "Utc1400_POGO_O_C";
969  case 118: return "Utc1400_POGO_O_CPP";
970  case 119: return "Cvtpgd1400";
971  case 120: return "Linker800";
972  case 121: return "Cvtomf800";
973  case 122: return "Export800";
974  case 123: return "Implib800";
975  case 124: return "Cvtres800";
976  case 125: return "Masm800";
977  case 126: return "AliasObj800";
978  case 127: return "PhoenixPrerelease";
979  case 128: return "Utc1400_CVTCIL_C";
980  case 129: return "Utc1400_CVTCIL_CPP";
981  case 130: return "Utc1400_LTCG_MSIL";
982  case 131: return "Utc1500_C";
983  case 132: return "Utc1500_CPP";
984  case 133: return "Utc1500_C_Std";
985  case 134: return "Utc1500_CPP_Std";
986  case 135: return "Utc1500_CVTCIL_C";
987  case 136: return "Utc1500_CVTCIL_CPP";
988  case 137: return "Utc1500_LTCG_C";
989  case 138: return "Utc1500_LTCG_CPP";
990  case 139: return "Utc1500_LTCG_MSIL";
991  case 140: return "Utc1500_POGO_I_C";
992  case 141: return "Utc1500_POGO_I_CPP";
993  case 142: return "Utc1500_POGO_O_C";
994  case 143: return "Utc1500_POGO_O_CPP";
995 
996  case 144: return "Cvtpgd1500";
997  case 145: return "Linker900";
998  case 146: return "Export900";
999  case 147: return "Implib900";
1000  case 148: return "Cvtres900";
1001  case 149: return "Masm900";
1002  case 150: return "AliasObj900";
1003  case 151: return "Resource900";
1004 
1005  case 152: return "AliasObj1000";
1006  case 154: return "Cvtres1000";
1007  case 155: return "Export1000";
1008  case 156: return "Implib1000";
1009  case 157: return "Linker1000";
1010  case 158: return "Masm1000";
1011 
1012  case 170: return "Utc1600_C";
1013  case 171: return "Utc1600_CPP";
1014  case 172: return "Utc1600_CVTCIL_C";
1015  case 173: return "Utc1600_CVTCIL_CPP";
1016  case 174: return "Utc1600_LTCG_C ";
1017  case 175: return "Utc1600_LTCG_CPP";
1018  case 176: return "Utc1600_LTCG_MSIL";
1019  case 177: return "Utc1600_POGO_I_C";
1020  case 178: return "Utc1600_POGO_I_CPP";
1021  case 179: return "Utc1600_POGO_O_C";
1022  case 180: return "Utc1600_POGO_O_CPP";
1023 
1024  case 183: return "Linker1010";
1025  case 184: return "Export1010";
1026  case 185: return "Implib1010";
1027  case 186: return "Cvtres1010";
1028  case 187: return "Masm1010";
1029  case 188: return "AliasObj1010";
1030 
1031  case 199: return "AliasObj1100";
1032  case 201: return "Cvtres1100";
1033  case 202: return "Export1100";
1034  case 203: return "Implib1100";
1035  case 204: return "Linker1100";
1036  case 205: return "Masm1100";
1037 
1038  case 206: return "Utc1700_C";
1039  case 207: return "Utc1700_CPP";
1040  case 208: return "Utc1700_CVTCIL_C";
1041  case 209: return "Utc1700_CVTCIL_CPP";
1042  case 210: return "Utc1700_LTCG_C ";
1043  case 211: return "Utc1700_LTCG_CPP";
1044  case 212: return "Utc1700_LTCG_MSIL";
1045  case 213: return "Utc1700_POGO_I_C";
1046  case 214: return "Utc1700_POGO_I_CPP";
1047  case 215: return "Utc1700_POGO_O_C";
1048  case 216: return "Utc1700_POGO_O_CPP";
1049 
1050  case 219: return "Cvtres1200";
1051  case 220: return "Export1200";
1052  case 221: return "Implib1200";
1053  case 222: return "Linker1200";
1054  case 223:
1055  return "Masm1200";
1056  // Speculation
1057  case 224: return "AliasObj1200";
1058 
1059  case 237: return "Cvtres1210";
1060  case 238: return "Export1210";
1061  case 239: return "Implib1210";
1062  case 240: return "Linker1210";
1063  case 241:
1064  return "Masm1210";
1065  // Speculation
1066  case 242: return "Utc1810_C";
1067  case 243: return "Utc1810_CPP";
1068  case 244: return "Utc1810_CVTCIL_C";
1069  case 245: return "Utc1810_CVTCIL_CPP";
1070  case 246: return "Utc1810_LTCG_C ";
1071  case 247: return "Utc1810_LTCG_CPP";
1072  case 248: return "Utc1810_LTCG_MSIL";
1073  case 249: return "Utc1810_POGO_I_C";
1074  case 250: return "Utc1810_POGO_I_CPP";
1075  case 251: return "Utc1810_POGO_O_C";
1076  case 252: return "Utc1810_POGO_O_CPP";
1077 
1078  case 255: return "Cvtres1400";
1079  case 256: return "Export1400";
1080  case 257: return "Implib1400";
1081  case 258: return "Linker1400";
1082  case 259: return "Masm1400";
1083 
1084  case 260: return "Utc1900_C";
1085  case 261:
1086  return "Utc1900_CPP";
1087  // Speculation
1088  case 262: return "Utc1900_CVTCIL_C";
1089  case 263: return "Utc1900_CVTCIL_CPP";
1090  case 264: return "Utc1900_LTCG_C ";
1091  case 265: return "Utc1900_LTCG_CPP";
1092  case 266: return "Utc1900_LTCG_MSIL";
1093  case 267: return "Utc1900_POGO_I_C";
1094  case 268: return "Utc1900_POGO_I_CPP";
1095  case 269: return "Utc1900_POGO_O_C";
1096  case 270: return "Utc1900_POGO_O_CPP";
1097  default: return "Unknown";
1098  }
1099 }

Referenced by bin_pe_init_rich_info().

◆ _parse_resource_directory()

static void _parse_resource_directory ( RzBinPEObj bin,
Pe_image_resource_directory dir,
ut64  offDir,
int  type,
int  id,
HtUU *  dirs,
const char *  resource_name 
)
static

Definition at line 1357 of file pe_rsrc.c.

1357  {
1358  char *resourceEntryName = NULL;
1359  int index = 0;
1360  ut32 totalRes = dir->NumberOfNamedEntries + dir->NumberOfIdEntries;
1361  ut64 rsrc_base = bin->resource_directory_offset;
1362  ut64 off;
1363  if (totalRes > RZ_PE_MAX_RESOURCES) {
1364  return;
1365  }
1366  for (index = 0; index < totalRes; index++) {
1368  off = rsrc_base + offDir + sizeof(*dir) + index * sizeof(entry);
1369  if (ht_uu_find(dirs, off, NULL)) {
1370  break;
1371  }
1372  ht_uu_insert(dirs, off, 1);
1373  if (off > bin->size || off + sizeof(entry) > bin->size) {
1374  break;
1375  }
1377  RZ_LOG_ERROR("read resource entry\n");
1378  break;
1379  }
1380  if (entry.u1.Name >> 31) {
1381  int i;
1382  ut16 buf;
1383  ut32 NameOffset = entry.u1.Name & 0x7fffffff;
1384  if (rz_buf_read_at(bin->b, bin->resource_directory_offset + NameOffset, (ut8 *)&buf, sizeof(ut16)) != sizeof(ut16)) {
1385  break;
1386  }
1387  ut16 resourceEntryNameLength = rz_read_le16(&buf);
1388  resourceEntryName = calloc(resourceEntryNameLength + 1, 1);
1389  if (resourceEntryName) {
1390  for (i = 0; i < resourceEntryNameLength; i++) { /* Convert Unicode to ASCII */
1391  ut8 byte;
1392  int r = rz_buf_read_at(bin->b, bin->resource_directory_offset + NameOffset + 2 + (i * 2), &byte, sizeof(ut8));
1393  if (r != sizeof(ut8) || !byte) {
1394  RZ_FREE(resourceEntryName);
1395  break;
1396  }
1397  resourceEntryName[i] = byte;
1398  }
1399  }
1400  }
1401  if (entry.u2.OffsetToData >> 31) {
1402  // detect here malicious file trying to making us infinite loop
1403  Pe_image_resource_directory identEntry;
1404  ut32 OffsetToDirectory = entry.u2.OffsetToData & 0x7fffffff;
1405  off = rsrc_base + OffsetToDirectory;
1406  int len = read_image_resource_directory(bin->b, off, &identEntry);
1407  if (len < 1 || len != sizeof(Pe_image_resource_directory)) {
1408  RZ_LOG_ERROR("parsing resource directory\n");
1409  }
1410  _parse_resource_directory(bin, &identEntry, OffsetToDirectory, type, entry.u1.Name & 0xffff, dirs, resourceEntryName);
1411  RZ_FREE(resourceEntryName);
1412  continue;
1413  }
1414  RZ_FREE(resourceEntryName);
1415 
1417  if (!data) {
1418  break;
1419  }
1420  off = rsrc_base + entry.u2.OffsetToData;
1421  if (off > bin->size || off + sizeof(*data) > bin->size) {
1422  free(data);
1423  break;
1424  }
1425  if (read_image_resource_data_entry(bin->b, off, data) != sizeof(*data)) {
1426  RZ_LOG_ERROR("read (resource data entry)\n");
1427  free(data);
1428  break;
1429  }
1431  char key[64];
1432  int counter = 0;
1433  Sdb *sdb = sdb_new0();
1434  if (!sdb) {
1435  free(data);
1436  sdb_free(sdb);
1437  continue;
1438  }
1439  PE_DWord data_paddr = PE_(bin_pe_rva_to_paddr)(bin, data->OffsetToData);
1440  if (!data_paddr) {
1441  RZ_LOG_INFO("bad RVA in resource data entry\n");
1442  free(data);
1443  sdb_free(sdb);
1444  continue;
1445  }
1446  PE_DWord cur_paddr = data_paddr;
1447  if ((cur_paddr & 0x3) != 0) {
1448  RZ_LOG_INFO("not aligned version info address\n");
1449  free(data);
1450  sdb_free(sdb);
1451  continue;
1452  }
1453  while (cur_paddr < (data_paddr + data->Size) && cur_paddr < bin->size) {
1454  PE_VS_VERSIONINFO *vs_VersionInfo = Pe_r_bin_pe_parse_version_info(bin, cur_paddr);
1455  if (vs_VersionInfo) {
1456  snprintf(key, 30, "VS_VERSIONINFO%d", counter++);
1457  sdb_ns_set(sdb, key, Pe_r_bin_store_resource_version_info(vs_VersionInfo));
1458  } else {
1459  break;
1460  }
1461  if (vs_VersionInfo->wLength < 1) {
1462  // Invalid version length
1463  break;
1464  }
1465  cur_paddr += vs_VersionInfo->wLength;
1466  free_VS_VERSIONINFO(vs_VersionInfo);
1467  align32(cur_paddr);
1468  }
1469  sdb_ns_set(bin->kv, "vs_version_info", sdb);
1470  }
1472  if (!rs) {
1473  free(data);
1474  break;
1475  }
1476  /* Compare compileTimeStamp to resource timestamp to figure out if DOS date or POSIX date */
1477  if (rz_time_stamp_is_dos_format((ut32)sdb_num_get(bin->kv, "image_file_header.TimeDateStamp", 0), dir->TimeDateStamp)) {
1479  } else {
1480  rs->timestr = rz_time_stamp_to_str(dir->TimeDateStamp);
1481  }
1482  rs->type = _resource_type_str(type);
1483  rs->language = strdup(_resource_lang_str(entry.u1.Name & 0x3ff));
1484  rs->data = data;
1485  if (resource_name) {
1486  rs->name = strdup(resource_name);
1487  } else {
1488  rs->name = rz_str_newf("%d", id);
1489  }
1490  rz_list_append(bin->resources, rs);
1491  }
1492 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
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
uint16_t ut16
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
uint8_t ut8
Definition: lh5801.h:11
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
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 type
Definition: mipsasm.c:17
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
int off
Definition: pal.c:13
PE_DWord PE_() bin_pe_rva_to_paddr(RzBinPEObj *bin, PE_DWord rva)
Definition: pe.c:15
static void free_VS_VERSIONINFO(PE_VS_VERSIONINFO *vs_VersionInfo)
Definition: pe_rsrc.c:134
static int read_image_resource_directory(RzBuffer *b, ut64 addr, Pe_image_resource_directory *dir)
Definition: pe_rsrc.c:29
static int read_image_resource_directory_entry(RzBuffer *b, ut64 addr, Pe_image_resource_directory_entry *entry)
Definition: pe_rsrc.c:1321
static Sdb * Pe_r_bin_store_resource_version_info(PE_VS_VERSIONINFO *vs_VersionInfo)
Definition: pe_rsrc.c:828
#define align32(x)
Definition: pe_rsrc.c:132
static char * _resource_type_str(int type)
Definition: pe_rsrc.c:1250
static PE_VS_VERSIONINFO * Pe_r_bin_pe_parse_version_info(RzBinPEObj *bin, PE_DWord version_info_paddr)
Definition: pe_rsrc.c:556
static void _parse_resource_directory(RzBinPEObj *bin, Pe_image_resource_directory *dir, ut64 offDir, int type, int id, HtUU *dirs, const char *resource_name)
Definition: pe_rsrc.c:1357
static char * _resource_lang_str(int id)
Definition: pe_rsrc.c:1151
static int read_image_resource_data_entry(RzBuffer *b, ut64 addr, Pe_image_resource_data_entry *entry)
Definition: pe_rsrc.c:1342
#define PE_(name)
Definition: pe_specs.h:23
#define RZ_PE_MAX_RESOURCES
Definition: pe_specs.h:509
#define PE_RESOURCE_ENTRY_VERSION
Definition: pe_specs.h:523
#define PE_DWord
Definition: pe_specs.h:27
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API bool rz_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp)
Verifies that the timestamp is in dos format.
Definition: time.c:225
RZ_API RZ_OWN char * rz_time_stamp_to_str(ut32 timestamp)
Converts an unix epoch timestamp to string.
Definition: time.c:143
RZ_API ut32 rz_time_dos_time_stamp_to_posix(ut32 timestamp)
Converts dos timestamp to posix timestamp.
Definition: time.c:190
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
Definition: pe_specs.h:501
ut32 Size
Definition: pe_specs.h:503
ut32 OffsetToData
Definition: pe_specs.h:502
Definition: pe_specs.h:469
Definition: zipcmp.c:77
Definition: sdb.h:63
int64_t counter
Definition: main.c:4
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References _resource_lang_str(), _resource_type_str(), align32, bin_pe_rva_to_paddr(), calloc(), counter, free(), free_VS_VERSIONINFO(), i, key, len, NULL, Pe_image_resource_directory::NumberOfIdEntries, Pe_image_resource_directory::NumberOfNamedEntries, off, Pe_image_resource_data_entry::OffsetToData, PE_, PE_DWord, Pe_r_bin_pe_parse_version_info(), Pe_r_bin_store_resource_version_info(), PE_RESOURCE_ENTRY_VERSION, r, read_image_resource_data_entry(), read_image_resource_directory(), read_image_resource_directory_entry(), rs, rz_buf_read_at(), RZ_FREE, rz_list_append(), RZ_LOG_ERROR, RZ_LOG_INFO, RZ_NEW0, RZ_PE_MAX_RESOURCES, rz_read_le16(), rz_str_newf(), rz_time_dos_time_stamp_to_posix(), rz_time_stamp_is_dos_format(), rz_time_stamp_to_str(), sdb_free(), sdb_new0(), sdb_ns_set(), sdb_num_get(), Pe_image_resource_data_entry::Size, snprintf, strdup(), Pe_image_resource_directory::TimeDateStamp, type, ut64(), and PE_VS_VERSIONINFO::wLength.

Referenced by bin_pe_parse_resource().

◆ _resource_lang_str()

static char* _resource_lang_str ( int  id)
static

Definition at line 1151 of file pe_rsrc.c.

1151  {
1152  switch (id) {
1153  case 0x00: return "LANG_NEUTRAL";
1154  case 0x7f: return "LANG_INVARIANT";
1155  case 0x36: return "LANG_AFRIKAANS";
1156  case 0x1c: return "LANG_ALBANIAN ";
1157  case 0x01: return "LANG_ARABIC";
1158  case 0x2b: return "LANG_ARMENIAN";
1159  case 0x4d: return "LANG_ASSAMESE";
1160  case 0x2c: return "LANG_AZERI";
1161  case 0x2d: return "LANG_BASQUE";
1162  case 0x23: return "LANG_BELARUSIAN";
1163  case 0x45: return "LANG_BENGALI";
1164  case 0x02: return "LANG_BULGARIAN";
1165  case 0x03: return "LANG_CATALAN";
1166  case 0x04: return "LANG_CHINESE";
1167  case 0x1a: return "LANG_CROATIAN";
1168  case 0x05: return "LANG_CZECH";
1169  case 0x06: return "LANG_DANISH";
1170  case 0x65: return "LANG_DIVEHI";
1171  case 0x13: return "LANG_DUTCH";
1172  case 0x09: return "LANG_ENGLISH";
1173  case 0x25: return "LANG_ESTONIAN";
1174  case 0x38: return "LANG_FAEROESE";
1175  case 0x29: return "LANG_FARSI";
1176  case 0x0b: return "LANG_FINNISH";
1177  case 0x0c: return "LANG_FRENCH";
1178  case 0x56: return "LANG_GALICIAN";
1179  case 0x37: return "LANG_GEORGIAN";
1180  case 0x07: return "LANG_GERMAN";
1181  case 0x08: return "LANG_GREEK";
1182  case 0x47: return "LANG_GUJARATI";
1183  case 0x0d: return "LANG_HEBREW";
1184  case 0x39: return "LANG_HINDI";
1185  case 0x0e: return "LANG_HUNGARIAN";
1186  case 0x0f: return "LANG_ICELANDIC";
1187  case 0x21: return "LANG_INDONESIAN";
1188  case 0x10: return "LANG_ITALIAN";
1189  case 0x11: return "LANG_JAPANESE";
1190  case 0x4b: return "LANG_KANNADA";
1191  case 0x60: return "LANG_KASHMIRI";
1192  case 0x3f: return "LANG_KAZAK";
1193  case 0x57: return "LANG_KONKANI";
1194  case 0x12: return "LANG_KOREAN";
1195  case 0x40: return "LANG_KYRGYZ";
1196  case 0x26: return "LANG_LATVIAN";
1197  case 0x27: return "LANG_LITHUANIAN";
1198  case 0x2f: return "LANG_MACEDONIAN";
1199  case 0x3e: return "LANG_MALAY";
1200  case 0x4c: return "LANG_MALAYALAM";
1201  case 0x58: return "LANG_MANIPURI";
1202  case 0x4e: return "LANG_MARATHI";
1203  case 0x50: return "LANG_MONGOLIAN";
1204  case 0x61: return "LANG_NEPALI";
1205  case 0x14: return "LANG_NORWEGIAN";
1206  case 0x48: return "LANG_ORIYA";
1207  case 0x15: return "LANG_POLISH";
1208  case 0x16: return "LANG_PORTUGUESE";
1209  case 0x46: return "LANG_PUNJABI";
1210  case 0x18: return "LANG_ROMANIAN";
1211  case 0x19: return "LANG_RUSSIAN";
1212  case 0x4f: return "LANG_SANSKRIT";
1213  case 0x59: return "LANG_SINDHI";
1214  case 0x1b: return "LANG_SLOVAK";
1215  case 0x24: return "LANG_SLOVENIAN";
1216  case 0x0a: return "LANG_SPANISH ";
1217  case 0x41: return "LANG_SWAHILI";
1218  case 0x1d: return "LANG_SWEDISH";
1219  case 0x5a: return "LANG_SYRIAC";
1220  case 0x49: return "LANG_TAMIL";
1221  case 0x44: return "LANG_TATAR";
1222  case 0x4a: return "LANG_TELUGU";
1223  case 0x1e: return "LANG_THAI";
1224  case 0x1f: return "LANG_TURKISH";
1225  case 0x22: return "LANG_UKRAINIAN";
1226  case 0x20: return "LANG_URDU";
1227  case 0x43: return "LANG_UZBEK";
1228  case 0x2a: return "LANG_VIETNAMESE";
1229  case 0x3c: return "LANG_GAELIC";
1230  case 0x3a: return "LANG_MALTESE";
1231  case 0x28: return "LANG_MAORI";
1232  case 0x17: return "LANG_RHAETO_ROMANCE";
1233  case 0x3b: return "LANG_SAAMI";
1234  case 0x2e: return "LANG_SORBIAN";
1235  case 0x30: return "LANG_SUTU";
1236  case 0x31: return "LANG_TSONGA";
1237  case 0x32: return "LANG_TSWANA";
1238  case 0x33: return "LANG_VENDA";
1239  case 0x34: return "LANG_XHOSA";
1240  case 0x35: return "LANG_ZULU";
1241  case 0x8f: return "LANG_ESPERANTO";
1242  case 0x90: return "LANG_WALON";
1243  case 0x91: return "LANG_CORNISH";
1244  case 0x92: return "LANG_WELSH";
1245  case 0x93: return "LANG_BRETON";
1246  default: return "UNKNOWN";
1247  }
1248 }

Referenced by _parse_resource_directory().

◆ _resource_type_str()

static char* _resource_type_str ( int  type)
static

Definition at line 1250 of file pe_rsrc.c.

1250  {
1251  const char *typeName;
1252  switch (type) {
1253  case 1:
1254  typeName = "CURSOR";
1255  break;
1256  case 2:
1257  typeName = "BITMAP";
1258  break;
1259  case 3:
1260  typeName = "ICON";
1261  break;
1262  case 4:
1263  typeName = "MENU";
1264  break;
1265  case 5:
1266  typeName = "DIALOG";
1267  break;
1268  case 6:
1269  typeName = "STRING";
1270  break;
1271  case 7:
1272  typeName = "FONTDIR";
1273  break;
1274  case 8:
1275  typeName = "FONT";
1276  break;
1277  case 9:
1278  typeName = "ACCELERATOR";
1279  break;
1280  case 10:
1281  typeName = "RCDATA";
1282  break;
1283  case 11:
1284  typeName = "MESSAGETABLE";
1285  break;
1286  case 12:
1287  typeName = "GROUP_CURSOR";
1288  break;
1289  case 14:
1290  typeName = "GROUP_ICON";
1291  break;
1292  case 16:
1293  typeName = "VERSION";
1294  break;
1295  case 17:
1296  typeName = "DLGINCLUDE";
1297  break;
1298  case 19:
1299  typeName = "PLUGPLAY";
1300  break;
1301  case 20:
1302  typeName = "VXD";
1303  break;
1304  case 21:
1305  typeName = "ANICURSOR";
1306  break;
1307  case 22:
1308  typeName = "ANIICON";
1309  break;
1310  case 23:
1311  typeName = "HTML";
1312  break;
1313  case 24:
1314  typeName = "MANIFEST";
1315  break;
1316  default: return rz_str_newf("UNKNOWN (%d)", type);
1317  }
1318  return strdup(typeName);
1319 }

References rz_str_newf(), strdup(), and type.

Referenced by _parse_resource_directory().

◆ _store_resource_sdb()

static void _store_resource_sdb ( RzBinPEObj bin)
static

Definition at line 1494 of file pe_rsrc.c.

1494  {
1495  RzListIter *iter;
1496  rz_pe_resource *rs;
1497  int index = 0;
1498  ut64 vaddr = 0;
1499  char *key;
1500  Sdb *sdb = sdb_new0();
1501  if (!sdb) {
1502  return;
1503  }
1504  rz_list_foreach (bin->resources, iter, rs) {
1505  key = sdb_fmt("resource.%d.timestr", index);
1506  sdb_set(sdb, key, rs->timestr, 0);
1507  key = sdb_fmt("resource.%d.vaddr", index);
1508  vaddr = PE_(bin_pe_rva_to_va)(bin, rs->data->OffsetToData);
1509  sdb_num_set(sdb, key, vaddr, 0);
1510  key = sdb_fmt("resource.%d.name", index);
1511  sdb_set(sdb, key, rs->name, 0);
1512  key = sdb_fmt("resource.%d.size", index);
1513  sdb_num_set(sdb, key, rs->data->Size, 0);
1514  key = sdb_fmt("resource.%d.type", index);
1515  sdb_set(sdb, key, rs->type, 0);
1516  key = sdb_fmt("resource.%d.language", index);
1517  sdb_set(sdb, key, rs->language, 0);
1518  index++;
1519  }
1520  sdb_ns_set(bin->kv, "pe_resource", sdb);
1521 }
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
PE_DWord PE_() bin_pe_rva_to_va(RzBinPEObj *bin, PE_DWord rva)
Definition: pe.c:28
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611

References bin_pe_rva_to_va(), key, PE_, rs, sdb_fmt(), sdb_new0(), sdb_ns_set(), sdb_num_set(), sdb_set(), and ut64().

Referenced by bin_pe_parse_resource().

◆ bin_pe_init_resource()

int PE_() bin_pe_init_resource ( RzBinPEObj bin)

Definition at line 50 of file pe_rsrc.c.

50  {
51  PE_(image_data_directory) *resource_dir = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_RESOURCE];
52  PE_DWord resource_dir_paddr = PE_(bin_pe_rva_to_paddr)(bin, resource_dir->VirtualAddress);
53  if (!resource_dir_paddr) {
54  return false;
55  }
56 
58  if (!bin->resources) {
59  return false;
60  }
61  if (!(bin->resource_directory = malloc(sizeof(*bin->resource_directory)))) {
62  rz_sys_perror("malloc (resource directory)");
63  return false;
64  }
65  if (read_image_resource_directory(bin->b, resource_dir_paddr, bin->resource_directory) < 0) {
66  RZ_LOG_INFO("read (resource directory)\n");
67  RZ_FREE(bin->resource_directory);
68  return false;
69  }
70  bin->resource_directory_offset = resource_dir_paddr;
71  return true;
72 }
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
void * malloc(size_t size)
Definition: malloc.c:123
static void _free_resource(rz_pe_resource *rs)
Definition: pe_rsrc.c:9
#define PE_IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pe_specs.h:145
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define rz_sys_perror(x)
Definition: rz_types.h:336

References _free_resource(), bin_pe_rva_to_paddr(), malloc(), PE_, PE_DWord, PE_IMAGE_DIRECTORY_ENTRY_RESOURCE, read_image_resource_directory(), RZ_FREE, rz_list_newf(), RZ_LOG_INFO, and rz_sys_perror.

Referenced by bin_pe_init().

◆ bin_pe_init_rich_info()

void PE_() bin_pe_init_rich_info ( RzBinPEObj bin)

Definition at line 1101 of file pe_rsrc.c.

1101  {
1102  if (!bin->rich_entries) {
1103  bin->rich_entries = rz_list_newf(free);
1104  }
1105  bin->rich_header_offset = bin->nt_header_offset;
1106  ut64 off = bin->nt_header_offset - sizeof(ut32);
1107  ut32 magic = 0x68636952; // Rich
1108  if (off % sizeof(ut32)) {
1109  return;
1110  }
1111 
1112  ut32 tmp;
1113  while (rz_buf_read_le32_at(bin->b, off, &tmp) && tmp != magic && off) {
1114  off -= sizeof(ut32);
1115  }
1116 
1117  if (!off) {
1118  return;
1119  }
1120 
1121  ut32 mask;
1122  if (!rz_buf_read_le32_at(bin->b, off + sizeof(ut32), &mask)) {
1123  return;
1124  }
1125 
1126  magic = 0x536E6144; // DanS
1127  off -= sizeof(ut32);
1128 
1129  ut32 data;
1130  while (rz_buf_read_le32_at(bin->b, off, &data) && data != magic && data ^ mask && off > 0x80) {
1132  if (!entry) {
1133  return;
1134  }
1135  entry->timesUsed = data ^ mask;
1136  off -= sizeof(ut32);
1137  if (!rz_buf_read_le32_at(bin->b, off, &data)) {
1138  free(entry);
1139  return;
1140  }
1141  data ^= mask;
1142  entry->productId = data >> 16;
1143  entry->minVersion = data & 0xFFFF;
1144  entry->productName = _known_product_ids(entry->productId);
1145  off -= sizeof(ut32);
1146  rz_list_append(bin->rich_entries, entry);
1147  }
1148  bin->rich_header_offset = off + sizeof(ut32);
1149 }
#define mask()
static char * _known_product_ids(int id)
Definition: pe_rsrc.c:849
#define rz_buf_read_le32_at(b, addr, result)
Definition: rz_buf.h:271
Definition: pe_specs.h:345

References _known_product_ids(), free(), mask, off, rz_buf_read_le32_at, rz_list_append(), rz_list_newf(), RZ_NEW0, autogen_x86imm::tmp, and ut64().

Referenced by bin_pe_init().

◆ bin_pe_parse_resource()

RZ_API void PE_() bin_pe_parse_resource ( RzBinPEObj bin)

Definition at line 1523 of file pe_rsrc.c.

1523  {
1524  int index = 0;
1525  ut64 off = 0, rsrc_base = bin->resource_directory_offset;
1526  Pe_image_resource_directory *rs_directory = bin->resource_directory;
1527  ut32 curRes = 0;
1528  int totalRes = 0;
1529  HtUUOptions opt = { 0 };
1530  HtUU *dirs = ht_uu_new_opt(&opt); // to avoid infinite loops
1531  if (!dirs) {
1532  return;
1533  }
1534  if (!rs_directory) {
1535  ht_uu_free(dirs);
1536  return;
1537  }
1538  curRes = rs_directory->NumberOfNamedEntries;
1539  totalRes = curRes + rs_directory->NumberOfIdEntries;
1540  if (totalRes > RZ_PE_MAX_RESOURCES) {
1541  RZ_LOG_ERROR("Cannot parse resource directory\n");
1542  ht_uu_free(dirs);
1543  return;
1544  }
1545  for (index = 0; index < totalRes; index++) {
1547  off = rsrc_base + sizeof(*rs_directory) + index * sizeof(typeEntry);
1548  ht_uu_insert(dirs, off, 1);
1549  if (off > bin->size || off + sizeof(typeEntry) > bin->size) {
1550  break;
1551  }
1552  if (read_image_resource_directory_entry(bin->b, off, &typeEntry) < 0) {
1553  RZ_LOG_ERROR("read resource directory entry\n");
1554  break;
1555  }
1556  if (typeEntry.u2.OffsetToData >> 31) {
1557  Pe_image_resource_directory identEntry;
1558  ut32 OffsetToDirectory = typeEntry.u2.OffsetToData & 0x7fffffff;
1559  off = rsrc_base + OffsetToDirectory;
1560  int len = read_image_resource_directory(bin->b, off, &identEntry);
1561  if (len != sizeof(identEntry)) {
1562  RZ_LOG_ERROR("parsing resource directory\n");
1563  }
1564  (void)_parse_resource_directory(bin, &identEntry, OffsetToDirectory, typeEntry.u1.Name & 0xffff, 0, dirs, NULL);
1565  }
1566  }
1567  ht_uu_free(dirs);
1569 }
static void _store_resource_sdb(RzBinPEObj *bin)
Definition: pe_rsrc.c:1494
ut32 Name
Definition: pe_specs.h:476
ut32 OffsetToData
Definition: pe_specs.h:483
union Pe_image_resource_directory_entry::@191 u1
union Pe_image_resource_directory_entry::@192 u2

References _parse_resource_directory(), _store_resource_sdb(), len, Pe_image_resource_directory_entry::Name, NULL, Pe_image_resource_directory::NumberOfIdEntries, Pe_image_resource_directory::NumberOfNamedEntries, off, Pe_image_resource_directory_entry::OffsetToData, read_image_resource_directory(), read_image_resource_directory_entry(), RZ_LOG_ERROR, RZ_PE_MAX_RESOURCES, Pe_image_resource_directory_entry::u1, Pe_image_resource_directory_entry::u2, and ut64().

Referenced by bin_pe_init().

◆ free_String()

static void free_String ( String string)
static

Definition at line 96 of file pe_rsrc.c.

96  {
97  if (string) {
98  free(string->szKey);
99  free(string->Value);
100  free(string);
101  }
102 }
ut16 * Value
Definition: pe_specs.h:561
ut16 * szKey
Definition: pe_specs.h:559

References free(), String::szKey, and String::Value.

Referenced by free_StringTable(), and Pe_r_bin_pe_parse_string().

◆ free_StringFileInfo()

static void free_StringFileInfo ( StringFileInfo stringFileInfo)
static

Definition at line 118 of file pe_rsrc.c.

118  {
119  if (stringFileInfo) {
120  free(stringFileInfo->szKey);
121  if (stringFileInfo->Children) {
122  ut32 childrenSFI = 0;
123  for (; childrenSFI < stringFileInfo->numOfChildren; childrenSFI++) {
124  free_StringTable(stringFileInfo->Children[childrenSFI]);
125  }
126  free(stringFileInfo->Children);
127  }
128  free(stringFileInfo);
129  }
130 }
static void free_StringTable(StringTable *stringTable)
Definition: pe_rsrc.c:104
ut32 numOfChildren
Definition: pe_specs.h:583
ut16 * szKey
Definition: pe_specs.h:581
StringTable ** Children
Definition: pe_specs.h:584

References StringFileInfo::Children, free(), free_StringTable(), StringFileInfo::numOfChildren, and StringFileInfo::szKey.

Referenced by free_VS_VERSIONINFO(), and Pe_r_bin_pe_parse_string_file_info().

◆ free_StringTable()

static void free_StringTable ( StringTable stringTable)
static

Definition at line 104 of file pe_rsrc.c.

104  {
105  if (stringTable) {
106  free(stringTable->szKey);
107  if (stringTable->Children) {
108  ut32 childrenST = 0;
109  for (; childrenST < stringTable->numOfChildren; childrenST++) {
110  free_String(stringTable->Children[childrenST]);
111  }
112  free(stringTable->Children);
113  }
114  free(stringTable);
115  }
116 }
static void free_String(String *string)
Definition: pe_rsrc.c:96
ut32 numOfChildren
Definition: pe_specs.h:573
ut16 * szKey
Definition: pe_specs.h:568
String ** Children
Definition: pe_specs.h:574

References StringTable::Children, free(), free_String(), StringTable::numOfChildren, and StringTable::szKey.

Referenced by free_StringFileInfo(), and Pe_r_bin_pe_parse_string_table().

◆ free_Var()

static void free_Var ( Var var)
static

Definition at line 74 of file pe_rsrc.c.

74  {
75  if (var) {
76  free(var->szKey);
77  free(var->Value);
78  free(var);
79  }
80 }
ut16 * szKey
Definition: pe_specs.h:591
ut32 * Value
Definition: pe_specs.h:594

References free(), Var::szKey, and Var::Value.

Referenced by free_VarFileInfo(), and Pe_r_bin_pe_parse_var().

◆ free_VarFileInfo()

static void free_VarFileInfo ( VarFileInfo varFileInfo)
static

Definition at line 82 of file pe_rsrc.c.

82  {
83  if (varFileInfo) {
84  free(varFileInfo->szKey);
85  if (varFileInfo->Children) {
86  ut32 children = 0;
87  for (; children < varFileInfo->numOfChildren; children++) {
88  free_Var(varFileInfo->Children[children]);
89  }
90  free(varFileInfo->Children);
91  }
92  free(varFileInfo);
93  }
94 }
static void free_Var(Var *var)
Definition: pe_rsrc.c:74
ut16 * szKey
Definition: pe_specs.h:601
Var ** Children
Definition: pe_specs.h:604
ut32 numOfChildren
Definition: pe_specs.h:603

References VarFileInfo::Children, free(), free_Var(), VarFileInfo::numOfChildren, and VarFileInfo::szKey.

Referenced by free_VS_VERSIONINFO(), and Pe_r_bin_pe_parse_var_file_info().

◆ free_VS_VERSIONINFO()

static void free_VS_VERSIONINFO ( PE_VS_VERSIONINFO vs_VersionInfo)
static

Definition at line 134 of file pe_rsrc.c.

134  {
135  if (vs_VersionInfo) {
136  free(vs_VersionInfo->szKey);
137  free(vs_VersionInfo->Value);
138  free_VarFileInfo(vs_VersionInfo->varFileInfo);
139  free_StringFileInfo(vs_VersionInfo->stringFileInfo);
140  free(vs_VersionInfo);
141  }
142 }
static void free_VarFileInfo(VarFileInfo *varFileInfo)
Definition: pe_rsrc.c:82
static void free_StringFileInfo(StringFileInfo *stringFileInfo)
Definition: pe_rsrc.c:118
VarFileInfo * varFileInfo
Definition: pe_specs.h:680
StringFileInfo * stringFileInfo
Definition: pe_specs.h:681
PE_VS_FIXEDFILEINFO * Value
Definition: pe_specs.h:678

References free(), free_StringFileInfo(), free_VarFileInfo(), PE_VS_VERSIONINFO::stringFileInfo, PE_VS_VERSIONINFO::szKey, PE_VS_VERSIONINFO::Value, and PE_VS_VERSIONINFO::varFileInfo.

Referenced by _parse_resource_directory(), and Pe_r_bin_pe_parse_version_info().

◆ Pe_r_bin_pe_parse_string()

static String* Pe_r_bin_pe_parse_string ( RzBinPEObj bin,
PE_DWord curAddr 
)
static

Definition at line 295 of file pe_rsrc.c.

295  {
296  String *string = calloc(1, sizeof(*string));
297  PE_DWord begAddr = *curAddr;
298  int len_value = 0;
299  int i = 0;
300  if (!string) {
301  RZ_LOG_INFO("calloc (String)\n");
302  return NULL;
303  }
304  if (begAddr > bin->size || begAddr + sizeof(string->wLength) > bin->size) {
305  free_String(string);
306  return NULL;
307  }
308  if (!rz_buf_read_le16_at(bin->b, *curAddr, &string->wLength)) {
309  RZ_LOG_INFO("read (String wLength)\n");
310  goto out_error;
311  }
312  *curAddr += sizeof(string->wLength);
313  if (*curAddr > bin->size || *curAddr + sizeof(string->wValueLength) > bin->size) {
314  goto out_error;
315  }
316  if (!rz_buf_read_le16_at(bin->b, *curAddr, &string->wValueLength)) {
317  RZ_LOG_INFO("read (String wValueLength)\n");
318  goto out_error;
319  }
320  *curAddr += sizeof(string->wValueLength);
321 
322  if (*curAddr > bin->size || *curAddr + sizeof(string->wType) > bin->size) {
323  goto out_error;
324  }
325  if (!rz_buf_read_le16_at(bin->b, *curAddr, &string->wType)) {
326  RZ_LOG_INFO("read (String wType)\n");
327  goto out_error;
328  }
329  *curAddr += sizeof(string->wType);
330  if (string->wType != 0 && string->wType != 1) {
331  RZ_LOG_INFO("check (String wType)\n");
332  goto out_error;
333  }
334 
335  for (i = 0; *curAddr < begAddr + string->wLength; i++, *curAddr += sizeof(ut16)) {
336  ut16 utf16_char;
337  ut16 *tmpKey;
338  if (*curAddr > bin->size || *curAddr + sizeof(ut16) > bin->size) {
339  goto out_error;
340  }
341  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)&utf16_char, sizeof(ut16)) != sizeof(ut16)) {
342  RZ_LOG_INFO("check (String szKey)\n");
343  goto out_error;
344  }
345  tmpKey = (ut16 *)realloc(string->szKey, (i + 1) * sizeof(ut16));
346  if (!tmpKey) {
347  RZ_LOG_INFO("realloc (String szKey)\n");
348  goto out_error;
349  }
350  string->szKey = tmpKey;
351  string->szKey[i] = utf16_char;
352  string->wKeyLen += sizeof(ut16);
353  if (!utf16_char) {
354  *curAddr += sizeof(ut16);
355  break;
356  }
357  }
358  align32(*curAddr);
359  len_value = RZ_MIN(string->wValueLength * 2, string->wLength - (*curAddr - begAddr));
360  string->wValueLength = len_value;
361  if (len_value < 0) {
362  len_value = 0;
363  }
364  string->Value = (ut16 *)calloc(len_value + 1, 1);
365  if (!string->Value) {
366  RZ_LOG_INFO("malloc (String Value)\n");
367  goto out_error;
368  }
369  if (*curAddr > bin->size || *curAddr + len_value > bin->size) {
370  goto out_error;
371  }
372  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)string->Value, len_value) != len_value) {
373  RZ_LOG_INFO("read (String Value)\n");
374  goto out_error;
375  }
376  *curAddr += len_value;
377  return string;
378 out_error:
379  free_String(string);
380  return NULL;
381 }
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
#define rz_buf_read_le16_at(b, addr, result)
Definition: rz_buf.h:270
#define RZ_MIN(x, y)
ut16 wValueLength
Definition: pe_specs.h:556
ut16 wType
Definition: pe_specs.h:557
ut16 wLength
Definition: pe_specs.h:555

References align32, calloc(), free_String(), i, NULL, PE_DWord, realloc(), rz_buf_read_at(), rz_buf_read_le16_at, RZ_LOG_INFO, RZ_MIN, String::szKey, String::Value, String::wLength, String::wType, and String::wValueLength.

Referenced by Pe_r_bin_pe_parse_string_table().

◆ Pe_r_bin_pe_parse_string_file_info()

static StringFileInfo* Pe_r_bin_pe_parse_string_file_info ( RzBinPEObj bin,
PE_DWord curAddr 
)
static

Definition at line 462 of file pe_rsrc.c.

462  {
463  StringFileInfo *stringFileInfo = calloc(1, sizeof(*stringFileInfo));
464  if (!stringFileInfo) {
465  RZ_LOG_INFO("calloc (StringFileInfo)\n");
466  return NULL;
467  }
468 
469  PE_DWord startAddr = *curAddr;
470 
471  if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringFileInfo->wLength)) {
472  RZ_LOG_INFO("read (StringFileInfo wLength)\n");
473  free_StringFileInfo(stringFileInfo);
474  return NULL;
475  }
476  *curAddr += sizeof(stringFileInfo->wLength);
477 
478  if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringFileInfo->wValueLength)) {
479  RZ_LOG_INFO("read (StringFileInfo wValueLength)\n");
480  free_StringFileInfo(stringFileInfo);
481  return NULL;
482  }
483  *curAddr += sizeof(stringFileInfo->wValueLength);
484 
485  if (stringFileInfo->wValueLength) {
486  RZ_LOG_INFO("check (StringFileInfo wValueLength)\n");
487  free_StringFileInfo(stringFileInfo);
488  return NULL;
489  }
490 
491  if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringFileInfo->wType)) {
492  RZ_LOG_INFO("read (StringFileInfo wType)\n");
493  free_StringFileInfo(stringFileInfo);
494  return NULL;
495  }
496  *curAddr += sizeof(stringFileInfo->wType);
497 
498  if (stringFileInfo->wType && stringFileInfo->wType != 1) {
499  RZ_LOG_INFO("check (StringFileInfo wType)\n");
500  free_StringFileInfo(stringFileInfo);
501  return NULL;
502  }
503 
504  stringFileInfo->szKey = (ut16 *)malloc(UT16_ALIGN(STRINGFILEINFO_UTF_16_LEN)); // L"StringFileInfo"
505  if (!stringFileInfo->szKey) {
506  RZ_LOG_INFO("malloc (StringFileInfo szKey)\n");
507  free_StringFileInfo(stringFileInfo);
508  return NULL;
509  }
510 
511  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)stringFileInfo->szKey, STRINGFILEINFO_UTF_16_LEN) != STRINGFILEINFO_UTF_16_LEN) {
512  RZ_LOG_INFO("read (StringFileInfo szKey)\n");
513  free_StringFileInfo(stringFileInfo);
514  return NULL;
515  }
516  *curAddr += STRINGFILEINFO_UTF_16_LEN;
517 
518  if (memcmp(stringFileInfo->szKey, STRINGFILEINFO_UTF_16, STRINGFILEINFO_UTF_16_LEN) != 0) {
519  RZ_LOG_INFO("check (StringFileInfo szKey)\n");
520  free_StringFileInfo(stringFileInfo);
521  return NULL;
522  }
523 
524  align32(*curAddr);
525 
526  while (startAddr + stringFileInfo->wLength > *curAddr) {
527  StringTable **tmp = (StringTable **)realloc(stringFileInfo->Children, (stringFileInfo->numOfChildren + 1) * sizeof(*stringFileInfo->Children));
528  if (!tmp) {
529  RZ_LOG_INFO("realloc (StringFileInfo Children)\n");
530  free_StringFileInfo(stringFileInfo);
531  return NULL;
532  }
533  stringFileInfo->Children = tmp;
534  if (!(stringFileInfo->Children[stringFileInfo->numOfChildren] = Pe_r_bin_pe_parse_string_table(bin, curAddr))) {
535  RZ_LOG_INFO("bad parsing StringTable\n");
536  free_StringFileInfo(stringFileInfo);
537  return NULL;
538  }
539  stringFileInfo->numOfChildren++;
540  align32(*curAddr);
541  }
542 
543  if (!stringFileInfo->numOfChildren) {
544  RZ_LOG_INFO("check (StringFileInfo numOfChildren)\n");
545  free_StringFileInfo(stringFileInfo);
546  return NULL;
547  }
548 
549  return stringFileInfo;
550 }
static StringTable * Pe_r_bin_pe_parse_string_table(RzBinPEObj *bin, PE_DWord *curAddr)
Definition: pe_rsrc.c:383
#define STRINGFILEINFO_UTF_16
Definition: pe_specs.h:544
#define STRINGFILEINFO_UTF_16_LEN
Definition: pe_specs.h:549
#define UT16_ALIGN(x)
ut16 wValueLength
Definition: pe_specs.h:579

References align32, calloc(), StringFileInfo::Children, free_StringFileInfo(), malloc(), NULL, StringFileInfo::numOfChildren, PE_DWord, Pe_r_bin_pe_parse_string_table(), realloc(), rz_buf_read_at(), rz_buf_read_le16_at, RZ_LOG_INFO, STRINGFILEINFO_UTF_16, STRINGFILEINFO_UTF_16_LEN, StringFileInfo::szKey, autogen_x86imm::tmp, UT16_ALIGN, StringFileInfo::wLength, StringFileInfo::wType, and StringFileInfo::wValueLength.

Referenced by Pe_r_bin_pe_parse_version_info().

◆ Pe_r_bin_pe_parse_string_table()

static StringTable* Pe_r_bin_pe_parse_string_table ( RzBinPEObj bin,
PE_DWord curAddr 
)
static

Definition at line 383 of file pe_rsrc.c.

383  {
384  StringTable *stringTable = calloc(1, sizeof(*stringTable));
385  if (!stringTable) {
386  RZ_LOG_INFO("calloc (stringTable)\n");
387  return NULL;
388  }
389 
390  PE_DWord startAddr = *curAddr;
391  if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringTable->wLength)) {
392  RZ_LOG_INFO("read (StringTable wLength)\n");
393  free_StringTable(stringTable);
394  return NULL;
395  }
396  *curAddr += sizeof(stringTable->wLength);
397 
398  if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringTable->wValueLength)) {
399  RZ_LOG_INFO("read (StringTable wValueLength)\n");
400  free_StringTable(stringTable);
401  return NULL;
402  }
403  *curAddr += sizeof(stringTable->wValueLength);
404 
405  if (stringTable->wValueLength) {
406  RZ_LOG_INFO("check (StringTable wValueLength)\n");
407  free_StringTable(stringTable);
408  return NULL;
409  }
410 
411  if (!rz_buf_read_le16_at(bin->b, *curAddr, &stringTable->wType)) {
412  RZ_LOG_INFO("read (StringTable wType)\n");
413  free_StringTable(stringTable);
414  return NULL;
415  }
416  *curAddr += sizeof(stringTable->wType);
417  if (stringTable->wType && stringTable->wType != 1) {
418  RZ_LOG_INFO("check (StringTable wType)\n");
419  free_StringTable(stringTable);
420  return NULL;
421  }
422  stringTable->szKey = (ut16 *)malloc(UT16_ALIGN(EIGHT_HEX_DIG_UTF_16_LEN)); // EIGHT_HEX_DIG_UTF_16_LEN
423  if (!stringTable->szKey) {
424  RZ_LOG_INFO("malloc (stringTable szKey)\n");
425  free_StringTable(stringTable);
426  return NULL;
427  }
428 
429  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)stringTable->szKey, EIGHT_HEX_DIG_UTF_16_LEN) != EIGHT_HEX_DIG_UTF_16_LEN) {
430  RZ_LOG_INFO("read (StringTable szKey)\n");
431  free_StringTable(stringTable);
432  return NULL;
433  }
434  *curAddr += EIGHT_HEX_DIG_UTF_16_LEN;
435  align32(*curAddr);
436  while (startAddr + stringTable->wLength > *curAddr) {
437  String **tmp = (String **)realloc(stringTable->Children, (stringTable->numOfChildren + 1) * sizeof(*stringTable->Children));
438  if (!tmp) {
439  RZ_LOG_INFO("realloc (StringTable Children)\n");
440  free_StringTable(stringTable);
441  return NULL;
442  }
443  stringTable->Children = tmp;
444  if (!(stringTable->Children[stringTable->numOfChildren] = Pe_r_bin_pe_parse_string(bin, curAddr))) {
445  RZ_LOG_INFO("bad parsing String\n");
446  free_StringTable(stringTable);
447  return NULL;
448  }
449  stringTable->numOfChildren++;
450  align32(*curAddr);
451  }
452 
453  if (!stringTable->numOfChildren) {
454  RZ_LOG_INFO("check (StringTable numOfChildren)\n");
455  free_StringTable(stringTable);
456  return NULL;
457  }
458 
459  return stringTable;
460 }
static String * Pe_r_bin_pe_parse_string(RzBinPEObj *bin, PE_DWord *curAddr)
Definition: pe_rsrc.c:295
#define EIGHT_HEX_DIG_UTF_16_LEN
Definition: pe_specs.h:542
ut16 wValueLength
Definition: pe_specs.h:566
ut16 wType
Definition: pe_specs.h:567
ut16 wLength
Definition: pe_specs.h:565

References align32, calloc(), StringTable::Children, EIGHT_HEX_DIG_UTF_16_LEN, free_StringTable(), malloc(), NULL, StringTable::numOfChildren, PE_DWord, Pe_r_bin_pe_parse_string(), realloc(), rz_buf_read_at(), rz_buf_read_le16_at, RZ_LOG_INFO, StringTable::szKey, autogen_x86imm::tmp, UT16_ALIGN, StringTable::wLength, StringTable::wType, and StringTable::wValueLength.

Referenced by Pe_r_bin_pe_parse_string_file_info().

◆ Pe_r_bin_pe_parse_var()

static Var* Pe_r_bin_pe_parse_var ( RzBinPEObj bin,
PE_DWord curAddr 
)
static

Definition at line 148 of file pe_rsrc.c.

148  {
149  Var *var = calloc(1, sizeof(*var));
150  if (!var) {
151  RZ_LOG_INFO("calloc (Var)\n");
152  return NULL;
153  }
154  if (!rz_buf_read_le16_at(bin->b, *curAddr, &var->wLength)) {
155  RZ_LOG_INFO("read (Var wLength)\n");
156  free_Var(var);
157  return NULL;
158  }
159  *curAddr += sizeof(var->wLength);
160  if (!rz_buf_read_le16_at(bin->b, *curAddr, &var->wValueLength)) {
161  RZ_LOG_INFO("read (Var wValueLength)\n");
162  free_Var(var);
163  return NULL;
164  }
165  *curAddr += sizeof(var->wValueLength);
166  if (!rz_buf_read_le16_at(bin->b, *curAddr, &var->wType)) {
167  RZ_LOG_INFO("read (Var wType)\n");
168  free_Var(var);
169  return NULL;
170  }
171  *curAddr += sizeof(var->wType);
172  if (var->wType != 0 && var->wType != 1) {
173  RZ_LOG_INFO("check (Var wType)\n");
174  free_Var(var);
175  return NULL;
176  }
177 
178  var->szKey = (ut16 *)malloc(UT16_ALIGN(TRANSLATION_UTF_16_LEN)); // L"Translation"
179  if (!var->szKey) {
180  RZ_LOG_INFO("malloc (Var szKey)\n");
181  free_Var(var);
182  return NULL;
183  }
184  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)var->szKey, TRANSLATION_UTF_16_LEN) < 1) {
185  RZ_LOG_INFO("read (Var szKey)\n");
186  free_Var(var);
187  return NULL;
188  }
189  *curAddr += TRANSLATION_UTF_16_LEN;
190  if (memcmp(var->szKey, TRANSLATION_UTF_16, TRANSLATION_UTF_16_LEN)) {
191  RZ_LOG_INFO("check (Var szKey)\n");
192  free_Var(var);
193  return NULL;
194  }
195  align32(*curAddr);
196  var->numOfValues = var->wValueLength / 4;
197  if (!var->numOfValues) {
198  RZ_LOG_INFO("check (Var numOfValues)\n");
199  free_Var(var);
200  return NULL;
201  }
202  var->Value = (ut32 *)malloc(var->wValueLength);
203  if (!var->Value) {
204  RZ_LOG_INFO("malloc (Var Value)\n");
205  free_Var(var);
206  return NULL;
207  }
208  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)var->Value, var->wValueLength) != var->wValueLength) {
209  RZ_LOG_INFO("read (Var Value)\n");
210  free_Var(var);
211  return NULL;
212  }
213  *curAddr += var->wValueLength;
214  return var;
215 }
#define TRANSLATION_UTF_16
Definition: pe_specs.h:545
#define TRANSLATION_UTF_16_LEN
Definition: pe_specs.h:550
Definition: pe_specs.h:587
ut16 wLength
Definition: pe_specs.h:588
ut32 numOfValues
Definition: pe_specs.h:593
ut16 wValueLength
Definition: pe_specs.h:589
ut16 wType
Definition: pe_specs.h:590

References align32, calloc(), free_Var(), malloc(), NULL, Var::numOfValues, rz_buf_read_at(), rz_buf_read_le16_at, RZ_LOG_INFO, Var::szKey, TRANSLATION_UTF_16, TRANSLATION_UTF_16_LEN, UT16_ALIGN, Var::Value, Var::wLength, Var::wType, and Var::wValueLength.

Referenced by Pe_r_bin_pe_parse_var_file_info().

◆ Pe_r_bin_pe_parse_var_file_info()

static VarFileInfo* Pe_r_bin_pe_parse_var_file_info ( RzBinPEObj bin,
PE_DWord curAddr 
)
static

Definition at line 217 of file pe_rsrc.c.

217  {
218  VarFileInfo *varFileInfo = calloc(1, sizeof(*varFileInfo));
219  if (!varFileInfo) {
220  RZ_LOG_INFO("calloc (VarFileInfo)\n");
221  return NULL;
222  }
223  PE_DWord startAddr = *curAddr;
224  if (!rz_buf_read_le16_at(bin->b, *curAddr, &varFileInfo->wLength)) {
225  RZ_LOG_INFO("read (VarFileInfo wLength)\n");
226  free_VarFileInfo(varFileInfo);
227  return NULL;
228  }
229  *curAddr += sizeof(varFileInfo->wLength);
230 
231  if (!rz_buf_read_le16_at(bin->b, *curAddr, &varFileInfo->wValueLength)) {
232  RZ_LOG_INFO("read (VarFileInfo wValueLength)\n");
233  free_VarFileInfo(varFileInfo);
234  return NULL;
235  }
236  *curAddr += sizeof(varFileInfo->wValueLength);
237 
238  if (varFileInfo->wValueLength != 0) {
239  RZ_LOG_INFO("check (VarFileInfo wValueLength)\n");
240  free_VarFileInfo(varFileInfo);
241  return NULL;
242  }
243 
244  if (!rz_buf_read_le16_at(bin->b, *curAddr, &varFileInfo->wType)) {
245  RZ_LOG_INFO("read (VarFileInfo wType)\n");
246  free_VarFileInfo(varFileInfo);
247  return NULL;
248  }
249  *curAddr += sizeof(varFileInfo->wType);
250  if (varFileInfo->wType && varFileInfo->wType != 1) {
251  RZ_LOG_INFO("check (VarFileInfo wType)\n");
252  free_VarFileInfo(varFileInfo);
253  return NULL;
254  }
255 
256  varFileInfo->szKey = (ut16 *)malloc(UT16_ALIGN(VARFILEINFO_UTF_16_LEN)); // L"VarFileInfo"
257  if (!varFileInfo->szKey) {
258  RZ_LOG_INFO("malloc (VarFileInfo szKey)\n");
259  free_VarFileInfo(varFileInfo);
260  return NULL;
261  }
262 
263  if (rz_buf_read_at(bin->b, *curAddr, (ut8 *)varFileInfo->szKey, VARFILEINFO_UTF_16_LEN) != VARFILEINFO_UTF_16_LEN) {
264  RZ_LOG_INFO("read (VarFileInfo szKey)\n");
265  free_VarFileInfo(varFileInfo);
266  return NULL;
267  }
268  *curAddr += VARFILEINFO_UTF_16_LEN;
269 
270  if (memcmp(varFileInfo->szKey, VARFILEINFO_UTF_16, VARFILEINFO_UTF_16_LEN)) {
271  RZ_LOG_INFO("check (VarFileInfo szKey)\n");
272  free_VarFileInfo(varFileInfo);
273  return NULL;
274  }
275  align32(*curAddr);
276  while (startAddr + varFileInfo->wLength > *curAddr) {
277  Var **tmp = (Var **)realloc(varFileInfo->Children, (varFileInfo->numOfChildren + 1) * sizeof(*varFileInfo->Children));
278  if (!tmp) {
279  RZ_LOG_INFO("realloc (VarFileInfo Children)\n");
280  free_VarFileInfo(varFileInfo);
281  return NULL;
282  }
283  varFileInfo->Children = tmp;
284  if (!(varFileInfo->Children[varFileInfo->numOfChildren] = Pe_r_bin_pe_parse_var(bin, curAddr))) {
285  RZ_LOG_INFO("bad parsing Var\n");
286  free_VarFileInfo(varFileInfo);
287  return NULL;
288  }
289  varFileInfo->numOfChildren++;
290  align32(*curAddr);
291  }
292  return varFileInfo;
293 }
static Var * Pe_r_bin_pe_parse_var(RzBinPEObj *bin, PE_DWord *curAddr)
Definition: pe_rsrc.c:148
#define VARFILEINFO_UTF_16
Definition: pe_specs.h:546
#define VARFILEINFO_UTF_16_LEN
Definition: pe_specs.h:551
ut16 wLength
Definition: pe_specs.h:598
ut16 wType
Definition: pe_specs.h:600
ut16 wValueLength
Definition: pe_specs.h:599

References align32, calloc(), VarFileInfo::Children, free_VarFileInfo(), malloc(), NULL, VarFileInfo::numOfChildren, PE_DWord, Pe_r_bin_pe_parse_var(), realloc(), rz_buf_read_at(), rz_buf_read_le16_at, RZ_LOG_INFO, VarFileInfo::szKey, autogen_x86imm::tmp, UT16_ALIGN, VARFILEINFO_UTF_16, VARFILEINFO_UTF_16_LEN, VarFileInfo::wLength, VarFileInfo::wType, and VarFileInfo::wValueLength.

Referenced by Pe_r_bin_pe_parse_version_info().

◆ Pe_r_bin_pe_parse_version_info()

static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info ( RzBinPEObj bin,
PE_DWord  version_info_paddr 
)
static

Definition at line 556 of file pe_rsrc.c.

556  {
557  ut32 sz;
558  PE_VS_VERSIONINFO *vs_VersionInfo = calloc(1, sizeof(PE_VS_VERSIONINFO));
559  if (!vs_VersionInfo) {
560  return NULL;
561  }
562  PE_DWord startAddr = version_info_paddr;
563  PE_DWord curAddr = version_info_paddr;
564  // align32(curAddr); // XXX: do we really need this? Because in msdn
565  // wLength is The length, in bytes, of the VS_VERSIONINFO structure.
566  // This length does not include any padding that aligns any subsequent
567  // version resource data on a 32-bit boundary.
568  // Mb we are in subsequent version resource data and not aligned.
569  sz = sizeof(ut16);
570  EXIT_ON_OVERFLOW(sz);
571  if (!rz_buf_read_le16_at(bin->b, curAddr, &vs_VersionInfo->wLength)) {
572  RZ_LOG_INFO("read (VS_VERSIONINFO wLength)\n");
573  goto out_error;
574  }
575  curAddr += sz;
576  EXIT_ON_OVERFLOW(sz);
577  if (!rz_buf_read_le16_at(bin->b, curAddr, &vs_VersionInfo->wValueLength)) {
578  RZ_LOG_INFO("read (VS_VERSIONINFO wValueLength)\n");
579  goto out_error;
580  }
581  curAddr += sz;
582  EXIT_ON_OVERFLOW(sz);
583  if (!rz_buf_read_le16_at(bin->b, curAddr, &vs_VersionInfo->wType)) {
584  RZ_LOG_INFO("read (VS_VERSIONINFO wType)\n");
585  goto out_error;
586  }
587  curAddr += sz;
588  if (vs_VersionInfo->wType && vs_VersionInfo->wType != 1) {
589  RZ_LOG_INFO("check (VS_VERSIONINFO wType)\n");
590  goto out_error;
591  }
592 
593  vs_VersionInfo->szKey = (ut16 *)malloc(UT16_ALIGN(VS_VERSION_INFO_UTF_16_LEN)); // L"VS_VERSION_INFO"
594  if (!vs_VersionInfo->szKey) {
595  RZ_LOG_INFO("malloc (VS_VERSIONINFO szKey)\n");
596  goto out_error;
597  }
599  EXIT_ON_OVERFLOW(sz);
600  if (rz_buf_read_at(bin->b, curAddr, (ut8 *)vs_VersionInfo->szKey, sz) != sz) {
601  RZ_LOG_INFO("read (VS_VERSIONINFO szKey)\n");
602  goto out_error;
603  }
604  curAddr += sz;
605  if (memcmp(vs_VersionInfo->szKey, VS_VERSION_INFO_UTF_16, sz)) {
606  goto out_error;
607  }
608  align32(curAddr);
609  if (vs_VersionInfo->wValueLength) {
610  if (vs_VersionInfo->wValueLength != sizeof(*vs_VersionInfo->Value)) {
611  RZ_LOG_INFO("check (VS_VERSIONINFO wValueLength != sizeof PE_VS_FIXEDFILEINFO)\n");
612  goto out_error;
613  }
614 
615  PE_VS_FIXEDFILEINFO *ffi = vs_VersionInfo->Value = (PE_VS_FIXEDFILEINFO *)malloc(sizeof(*vs_VersionInfo->Value));
616  if (!ffi) {
617  RZ_LOG_INFO("malloc (VS_VERSIONINFO Value)\n");
618  goto out_error;
619  }
620  sz = sizeof(PE_VS_FIXEDFILEINFO);
621  EXIT_ON_OVERFLOW(sz);
622  if (!rz_buf_read_le32_at(bin->b, curAddr, &ffi->dwSignature) ||
623  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32), &ffi->dwStrucVersion) ||
624  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 2, &ffi->dwFileVersionMS) ||
625  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 3, &ffi->dwFileVersionLS) ||
626  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 4, &ffi->dwProductVersionMS) ||
627  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 5, &ffi->dwProductVersionLS) ||
628  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 6, &ffi->dwFileFlagsMask) ||
629  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 7, &ffi->dwFileFlags) ||
630  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 8, &ffi->dwFileOS) ||
631  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 9, &ffi->dwFileType) ||
632  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 10, &ffi->dwFileSubtype) ||
633  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 11, &ffi->dwFileDateMS) ||
634  !rz_buf_read_le32_at(bin->b, curAddr + sizeof(ut32) * 12, &ffi->dwFileDateLS)) {
635  RZ_LOG_INFO("read (VS_VERSIONINFO Value)\n");
636  goto out_error;
637  }
638  if (ffi->dwSignature != 0xFEEF04BD) {
639  RZ_LOG_INFO("check (PE_VS_FIXEDFILEINFO signature) 0x%08x\n", ffi->dwSignature);
640  goto out_error;
641  }
642  curAddr += sz;
643  align32(curAddr);
644  }
645 
646  if (startAddr + vs_VersionInfo->wLength > curAddr) {
647  char t = '\0';
648  if (curAddr + 3 * sizeof(ut16) > bin->size || curAddr + 3 + sizeof(ut64) + 1 > bin->size) {
649  goto out_error;
650  }
651  if (rz_buf_read_at(bin->b, curAddr + 3 * sizeof(ut16), (ut8 *)&t, 1) != 1) {
652  RZ_LOG_INFO("read (VS_VERSIONINFO Children V or S)\n");
653  goto out_error;
654  }
655  if (!(t == 'S' || t == 'V')) {
656  RZ_LOG_INFO("bad type (VS_VERSIONINFO Children)\n");
657  goto out_error;
658  }
659  if (t == 'S') {
660  if (!(vs_VersionInfo->stringFileInfo = Pe_r_bin_pe_parse_string_file_info(bin, &curAddr))) {
661  RZ_LOG_INFO("bad parsing (VS_VERSIONINFO StringFileInfo)\n");
662  goto out_error;
663  }
664  }
665  if (t == 'V') {
666  if (!(vs_VersionInfo->varFileInfo = Pe_r_bin_pe_parse_var_file_info(bin, &curAddr))) {
667  RZ_LOG_INFO("bad parsing (VS_VERSIONINFO VarFileInfo)\n");
668  goto out_error;
669  }
670  }
671 
672  align32(curAddr);
673 
674  if (startAddr + vs_VersionInfo->wLength > curAddr) {
675  if (t == 'V') {
676  if (!(vs_VersionInfo->stringFileInfo = Pe_r_bin_pe_parse_string_file_info(bin, &curAddr))) {
677  RZ_LOG_INFO("bad parsing (VS_VERSIONINFO StringFileInfo)\n");
678  goto out_error;
679  }
680  } else if (t == 'S') {
681  if (!(vs_VersionInfo->varFileInfo = Pe_r_bin_pe_parse_var_file_info(bin, &curAddr))) {
682  RZ_LOG_INFO("bad parsing (VS_VERSIONINFO VarFileInfo)\n");
683  goto out_error;
684  }
685  }
686  if (startAddr + vs_VersionInfo->wLength > curAddr) {
687  RZ_LOG_INFO("bad parsing (VS_VERSIONINFO wLength left)\n");
688  goto out_error;
689  }
690  }
691  }
692  return vs_VersionInfo;
693 out_error:
694  free_VS_VERSIONINFO(vs_VersionInfo);
695  return NULL;
696 }
static VarFileInfo * Pe_r_bin_pe_parse_var_file_info(RzBinPEObj *bin, PE_DWord *curAddr)
Definition: pe_rsrc.c:217
static StringFileInfo * Pe_r_bin_pe_parse_string_file_info(RzBinPEObj *bin, PE_DWord *curAddr)
Definition: pe_rsrc.c:462
#define EXIT_ON_OVERFLOW(S)
Definition: pe_rsrc.c:552
#define VS_VERSION_INFO_UTF_16_LEN
Definition: pe_specs.h:552
#define VS_VERSION_INFO_UTF_16
Definition: pe_specs.h:547

References align32, calloc(), PE_VS_FIXEDFILEINFO::dwFileDateLS, PE_VS_FIXEDFILEINFO::dwFileDateMS, PE_VS_FIXEDFILEINFO::dwFileFlags, PE_VS_FIXEDFILEINFO::dwFileFlagsMask, PE_VS_FIXEDFILEINFO::dwFileOS, PE_VS_FIXEDFILEINFO::dwFileSubtype, PE_VS_FIXEDFILEINFO::dwFileType, PE_VS_FIXEDFILEINFO::dwFileVersionLS, PE_VS_FIXEDFILEINFO::dwFileVersionMS, PE_VS_FIXEDFILEINFO::dwProductVersionLS, PE_VS_FIXEDFILEINFO::dwProductVersionMS, PE_VS_FIXEDFILEINFO::dwSignature, PE_VS_FIXEDFILEINFO::dwStrucVersion, EXIT_ON_OVERFLOW, free_VS_VERSIONINFO(), malloc(), NULL, PE_DWord, Pe_r_bin_pe_parse_string_file_info(), Pe_r_bin_pe_parse_var_file_info(), rz_buf_read_at(), rz_buf_read_le16_at, rz_buf_read_le32_at, RZ_LOG_INFO, PE_VS_VERSIONINFO::stringFileInfo, PE_VS_VERSIONINFO::szKey, UT16_ALIGN, ut64(), PE_VS_VERSIONINFO::Value, PE_VS_VERSIONINFO::varFileInfo, VS_VERSION_INFO_UTF_16, VS_VERSION_INFO_UTF_16_LEN, PE_VS_VERSIONINFO::wLength, PE_VS_VERSIONINFO::wType, and PE_VS_VERSIONINFO::wValueLength.

Referenced by _parse_resource_directory().

◆ Pe_r_bin_store_fixed_file_info()

static Sdb* Pe_r_bin_store_fixed_file_info ( PE_VS_FIXEDFILEINFO vs_fixedFileInfo)
static

Definition at line 803 of file pe_rsrc.c.

803  {
804  Sdb *sdb = NULL;
805  if (!vs_fixedFileInfo) {
806  return NULL;
807  }
808  sdb = sdb_new0();
809  if (!sdb) {
810  return NULL;
811  }
812  sdb_num_set(sdb, "Signature", vs_fixedFileInfo->dwSignature, 0);
813  sdb_num_set(sdb, "StrucVersion", vs_fixedFileInfo->dwStrucVersion, 0);
814  sdb_num_set(sdb, "FileVersionMS", vs_fixedFileInfo->dwFileVersionMS, 0);
815  sdb_num_set(sdb, "FileVersionLS", vs_fixedFileInfo->dwFileVersionLS, 0);
816  sdb_num_set(sdb, "ProductVersionMS", vs_fixedFileInfo->dwProductVersionMS, 0);
817  sdb_num_set(sdb, "ProductVersionLS", vs_fixedFileInfo->dwProductVersionLS, 0);
818  sdb_num_set(sdb, "FileFlagsMask", vs_fixedFileInfo->dwFileFlagsMask, 0);
819  sdb_num_set(sdb, "FileFlags", vs_fixedFileInfo->dwFileFlags, 0);
820  sdb_num_set(sdb, "FileOS", vs_fixedFileInfo->dwFileOS, 0);
821  sdb_num_set(sdb, "FileType", vs_fixedFileInfo->dwFileType, 0);
822  sdb_num_set(sdb, "FileSubtype", vs_fixedFileInfo->dwFileSubtype, 0);
823  sdb_num_set(sdb, "FileDateMS", vs_fixedFileInfo->dwFileDateMS, 0);
824  sdb_num_set(sdb, "FileDateLS", vs_fixedFileInfo->dwFileDateLS, 0);
825  return sdb;
826 }

References PE_VS_FIXEDFILEINFO::dwFileDateLS, PE_VS_FIXEDFILEINFO::dwFileDateMS, PE_VS_FIXEDFILEINFO::dwFileFlags, PE_VS_FIXEDFILEINFO::dwFileFlagsMask, PE_VS_FIXEDFILEINFO::dwFileOS, PE_VS_FIXEDFILEINFO::dwFileSubtype, PE_VS_FIXEDFILEINFO::dwFileType, PE_VS_FIXEDFILEINFO::dwFileVersionLS, PE_VS_FIXEDFILEINFO::dwFileVersionMS, PE_VS_FIXEDFILEINFO::dwProductVersionLS, PE_VS_FIXEDFILEINFO::dwProductVersionMS, PE_VS_FIXEDFILEINFO::dwSignature, PE_VS_FIXEDFILEINFO::dwStrucVersion, NULL, sdb_new0(), and sdb_num_set().

Referenced by Pe_r_bin_store_resource_version_info().

◆ Pe_r_bin_store_resource_version_info()

static Sdb* Pe_r_bin_store_resource_version_info ( PE_VS_VERSIONINFO vs_VersionInfo)
static

Definition at line 828 of file pe_rsrc.c.

828  {
829  Sdb *sdb = NULL;
830  if (!vs_VersionInfo) {
831  return NULL;
832  }
833  sdb = sdb_new0();
834  if (!sdb) {
835  return NULL;
836  }
837  if (vs_VersionInfo->Value) {
838  sdb_ns_set(sdb, "fixed_file_info", Pe_r_bin_store_fixed_file_info(vs_VersionInfo->Value));
839  }
840  if (vs_VersionInfo->varFileInfo) {
841  sdb_ns_set(sdb, "var_file_info", Pe_r_bin_store_var_file_info(vs_VersionInfo->varFileInfo));
842  }
843  if (vs_VersionInfo->stringFileInfo) {
844  sdb_ns_set(sdb, "string_file_info", Pe_r_bin_store_string_file_info(vs_VersionInfo->stringFileInfo));
845  }
846  return sdb;
847 }
static Sdb * Pe_r_bin_store_fixed_file_info(PE_VS_FIXEDFILEINFO *vs_fixedFileInfo)
Definition: pe_rsrc.c:803
static Sdb * Pe_r_bin_store_string_file_info(StringFileInfo *stringFileInfo)
Definition: pe_rsrc.c:785
static Sdb * Pe_r_bin_store_var_file_info(VarFileInfo *varFileInfo)
Definition: pe_rsrc.c:714

References NULL, Pe_r_bin_store_fixed_file_info(), Pe_r_bin_store_string_file_info(), Pe_r_bin_store_var_file_info(), sdb_new0(), sdb_ns_set(), PE_VS_VERSIONINFO::stringFileInfo, PE_VS_VERSIONINFO::Value, and PE_VS_VERSIONINFO::varFileInfo.

Referenced by _parse_resource_directory().

◆ Pe_r_bin_store_string()

static Sdb* Pe_r_bin_store_string ( String string)
static

Definition at line 731 of file pe_rsrc.c.

731  {
732  Sdb *sdb = NULL;
733  char *encodedVal = NULL, *encodedKey = NULL;
734  if (!string) {
735  return NULL;
736  }
737  sdb = sdb_new0();
738  if (!sdb) {
739  return NULL;
740  }
741  encodedKey = sdb_encode((unsigned char *)string->szKey, string->wKeyLen);
742  if (!encodedKey) {
743  sdb_free(sdb);
744  return NULL;
745  }
746  encodedVal = sdb_encode((unsigned char *)string->Value, string->wValueLength);
747  if (!encodedVal) {
748  free(encodedKey);
749  sdb_free(sdb);
750  return NULL;
751  }
752  sdb_set(sdb, "key", encodedKey, 0);
753  sdb_set(sdb, "value", encodedVal, 0);
754  free(encodedKey);
755  free(encodedVal);
756  return sdb;
757 }
RZ_API char * sdb_encode(const ut8 *bin, int len)
Definition: base64.c:18
ut16 wKeyLen
Definition: pe_specs.h:558

References free(), NULL, sdb_encode(), sdb_free(), sdb_new0(), sdb_set(), String::szKey, String::Value, String::wKeyLen, and String::wValueLength.

Referenced by Pe_r_bin_store_string_table().

◆ Pe_r_bin_store_string_file_info()

static Sdb* Pe_r_bin_store_string_file_info ( StringFileInfo stringFileInfo)
static

Definition at line 785 of file pe_rsrc.c.

785  {
786  char key[30];
787  int i = 0;
788  Sdb *sdb = NULL;
789  if (!stringFileInfo) {
790  return NULL;
791  }
792  sdb = sdb_new0();
793  if (!sdb) {
794  return NULL;
795  }
796  for (; i < stringFileInfo->numOfChildren; i++) {
797  snprintf(key, 30, "stringtable%d", i);
798  sdb_ns_set(sdb, key, Pe_r_bin_store_string_table(stringFileInfo->Children[i]));
799  }
800  return sdb;
801 }
static Sdb * Pe_r_bin_store_string_table(StringTable *stringTable)
Definition: pe_rsrc.c:759

References StringFileInfo::Children, i, key, NULL, StringFileInfo::numOfChildren, Pe_r_bin_store_string_table(), sdb_new0(), sdb_ns_set(), and snprintf.

Referenced by Pe_r_bin_store_resource_version_info().

◆ Pe_r_bin_store_string_table()

static Sdb* Pe_r_bin_store_string_table ( StringTable stringTable)
static

Definition at line 759 of file pe_rsrc.c.

759  {
760  char key[20];
761  char *encodedKey = NULL;
762  int i = 0;
763  Sdb *sdb = NULL;
764  if (!stringTable) {
765  return NULL;
766  }
767  sdb = sdb_new0();
768  if (!sdb) {
769  return NULL;
770  }
771  encodedKey = sdb_encode((unsigned char *)stringTable->szKey, EIGHT_HEX_DIG_UTF_16_LEN);
772  if (!encodedKey) {
773  sdb_free(sdb);
774  return NULL;
775  }
776  sdb_set(sdb, "key", encodedKey, 0);
777  free(encodedKey);
778  for (; i < stringTable->numOfChildren; i++) {
779  snprintf(key, 20, "string%d", i);
780  sdb_ns_set(sdb, key, Pe_r_bin_store_string(stringTable->Children[i]));
781  }
782  return sdb;
783 }
static Sdb * Pe_r_bin_store_string(String *string)
Definition: pe_rsrc.c:731

References StringTable::Children, EIGHT_HEX_DIG_UTF_16_LEN, free(), i, key, NULL, StringTable::numOfChildren, Pe_r_bin_store_string(), sdb_encode(), sdb_free(), sdb_new0(), sdb_ns_set(), sdb_set(), snprintf, and StringTable::szKey.

Referenced by Pe_r_bin_store_string_file_info().

◆ Pe_r_bin_store_var()

static Sdb* Pe_r_bin_store_var ( Var var)
static

Definition at line 698 of file pe_rsrc.c.

698  {
699  unsigned int i = 0;
700  char key[20];
701  Sdb *sdb = NULL;
702  if (var) {
703  sdb = sdb_new0();
704  if (sdb) {
705  for (; i < var->numOfValues; i++) {
706  snprintf(key, 20, "%d", i);
707  sdb_num_set(sdb, key, var->Value[i], 0);
708  }
709  }
710  }
711  return sdb;
712 }

References i, key, NULL, Var::numOfValues, sdb_new0(), sdb_num_set(), snprintf, and Var::Value.

Referenced by Pe_r_bin_store_var_file_info().

◆ Pe_r_bin_store_var_file_info()

static Sdb* Pe_r_bin_store_var_file_info ( VarFileInfo varFileInfo)
static

Definition at line 714 of file pe_rsrc.c.

714  {
715  char key[20];
716  unsigned int i = 0;
717  if (!varFileInfo) {
718  return NULL;
719  }
720  Sdb *sdb = sdb_new0();
721  if (!sdb) {
722  return NULL;
723  }
724  for (; i < varFileInfo->numOfChildren; i++) {
725  snprintf(key, 20, "var%d", i);
726  sdb_ns_set(sdb, key, Pe_r_bin_store_var(varFileInfo->Children[i]));
727  }
728  return sdb;
729 }
static Sdb * Pe_r_bin_store_var(Var *var)
Definition: pe_rsrc.c:698

References VarFileInfo::Children, i, key, NULL, VarFileInfo::numOfChildren, Pe_r_bin_store_var(), sdb_new0(), sdb_ns_set(), and snprintf.

Referenced by Pe_r_bin_store_resource_version_info().

◆ read_image_resource_data_entry()

static int read_image_resource_data_entry ( RzBuffer b,
ut64  addr,
Pe_image_resource_data_entry entry 
)
static

Definition at line 1342 of file pe_rsrc.c.

1342  {
1343  st64 o_addr = rz_buf_seek(b, 0, RZ_BUF_CUR);
1344  if (rz_buf_seek(b, addr, RZ_BUF_SET) < 0) {
1345  return -1;
1346  }
1353  rz_buf_seek(b, o_addr, RZ_BUF_SET);
1354  return sizeof(Pe_image_resource_data_entry);
1355 }
#define PE_READ_STRUCT_FIELD(var, struct_type, field, size)
Definition: pe.h:177
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
#define RZ_BUF_CUR
Definition: rz_buf.h:15
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
#define st64
Definition: rz_types_base.h:10
#define b(i)
Definition: sha256.c:42
static int addr
Definition: z80asm.c:58

References addr, b, PE_READ_STRUCT_FIELD, RZ_BUF_CUR, rz_buf_read(), rz_buf_seek(), RZ_BUF_SET, and st64.

Referenced by _parse_resource_directory().

◆ read_image_resource_directory()

static int read_image_resource_directory ( RzBuffer b,
ut64  addr,
Pe_image_resource_directory dir 
)
static

Definition at line 29 of file pe_rsrc.c.

29  {
31  if (tmp < 0) {
32  return -1;
33  }
34 
35  if (rz_buf_seek(b, addr, RZ_BUF_SET) < 0) {
36  return -1;
37  }
38 
40  return -1;
41  }
42 
43  if (rz_buf_seek(b, tmp, RZ_BUF_SET) < 0) {
44  return -1;
45  }
46 
47  return sizeof(Pe_image_resource_directory);
48 }
static bool read_image_resource_directory_aux(RzBuffer *b, Pe_image_resource_directory *dir)
Definition: pe_rsrc.c:20

References addr, b, read_image_resource_directory_aux(), RZ_BUF_CUR, rz_buf_seek(), RZ_BUF_SET, st64, and autogen_x86imm::tmp.

Referenced by _parse_resource_directory(), bin_pe_init_resource(), and bin_pe_parse_resource().

◆ read_image_resource_directory_aux()

static bool read_image_resource_directory_aux ( RzBuffer b,
Pe_image_resource_directory dir 
)
static

Definition at line 20 of file pe_rsrc.c.

20  {
21  return rz_buf_read_le32(b, &dir->Characteristics) &&
27 }
#define rz_buf_read_le16(b, result)
Read a big endian or little endian (ut16, ut32, ut64) at the specified offset in the buffer and shift...
Definition: rz_buf.h:266
#define rz_buf_read_le32(b, result)
Definition: rz_buf.h:267

References b, Pe_image_resource_directory::Characteristics, Pe_image_resource_directory::MajorVersion, Pe_image_resource_directory::MinorVersion, Pe_image_resource_directory::NumberOfIdEntries, Pe_image_resource_directory::NumberOfNamedEntries, rz_buf_read_le16, rz_buf_read_le32, and Pe_image_resource_directory::TimeDateStamp.

Referenced by read_image_resource_directory().

◆ read_image_resource_directory_entry()

static int read_image_resource_directory_entry ( RzBuffer b,
ut64  addr,
Pe_image_resource_directory_entry entry 
)
static

Definition at line 1321 of file pe_rsrc.c.

1321  {
1322  st64 tmp = rz_buf_seek(b, 0, RZ_BUF_CUR);
1323  if (tmp < 0) {
1324  return -1;
1325  }
1326 
1327  if (rz_buf_seek(b, addr, RZ_BUF_SET) < 0) {
1328  return -1;
1329  }
1330 
1331  if (!rz_buf_read_le32(b, &entry->u1.Name) || !rz_buf_read_le32(b, &entry->u2.OffsetToData)) {
1332  return -1;
1333  }
1334 
1335  if (rz_buf_seek(b, tmp, RZ_BUF_SET) < 0) {
1336  return -1;
1337  }
1338 
1339  return sizeof(Pe_image_resource_directory_entry);
1340 }

References addr, b, RZ_BUF_CUR, rz_buf_read_le32, rz_buf_seek(), RZ_BUF_SET, st64, and autogen_x86imm::tmp.

Referenced by _parse_resource_directory(), and bin_pe_parse_resource().