31 for (
size_t i = 0;
i < 4;
i++) {
45 for (
size_t i = 0;
i < 10;
i++) {
125 if (!(
bin->dos_header =
malloc(
sizeof(
PE_(image_dos_header))))) {
134 sdb_set(
bin->kv,
"pe_dos_header.format",
"[2]zwwwwwwwwwwwww[4]www[10]wx"
135 " e_magic e_cblp e_cp e_crlc e_cparhdr e_minalloc e_maxalloc"
136 " e_ss e_sp e_csum e_ip e_cs e_lfarlc e_ovno e_res e_oemid"
137 " e_oeminfo e_res2 e_lfanew",
139 if (
bin->dos_header->e_lfanew > (
unsigned int)
bin->size) {
143 if (!(
bin->nt_headers =
malloc(
sizeof(
PE_(image_nt_headers))))) {
147 bin->nt_header_offset =
bin->dos_header->e_lfanew;
152 sdb_set(
bin->kv,
"pe_magic.cparse",
"enum pe_magic { IMAGE_NT_OPTIONAL_HDR32_MAGIC=0x10b, IMAGE_NT_OPTIONAL_HDR64_MAGIC=0x20b, IMAGE_ROM_OPTIONAL_HDR_MAGIC=0x107 };", 0);
153 sdb_set(
bin->kv,
"pe_subsystem.cparse",
"enum pe_subsystem { IMAGE_SUBSYSTEM_UNKNOWN=0, IMAGE_SUBSYSTEM_NATIVE=1, IMAGE_SUBSYSTEM_WINDOWS_GUI=2, "
154 " IMAGE_SUBSYSTEM_WINDOWS_CUI=3, IMAGE_SUBSYSTEM_OS2_CUI=5, IMAGE_SUBSYSTEM_POSIX_CUI=7, IMAGE_SUBSYSTEM_WINDOWS_CE_GUI=9, "
155 " IMAGE_SUBSYSTEM_EFI_APPLICATION=10, IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER=11, IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER=12, "
156 " IMAGE_SUBSYSTEM_EFI_ROM=13, IMAGE_SUBSYSTEM_XBOX=14, IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION=16 };",
158 sdb_set(
bin->kv,
"pe_dllcharacteristics.cparse",
"enum pe_dllcharacteristics { IMAGE_LIBRARY_PROCESS_INIT=0x0001, IMAGE_LIBRARY_PROCESS_TERM=0x0002, "
159 " IMAGE_LIBRARY_THREAD_INIT=0x0004, IMAGE_LIBRARY_THREAD_TERM=0x0008, IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA=0x0020, "
160 " IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE=0x0040, IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY=0x0080, "
161 " IMAGE_DLLCHARACTERISTICS_NX_COMPAT=0x0100, IMAGE_DLLCHARACTERISTICS_NO_ISOLATION=0x0200,IMAGE_DLLCHARACTERISTICS_NO_SEH=0x0400, "
162 " IMAGE_DLLCHARACTERISTICS_NO_BIND=0x0800, IMAGE_DLLCHARACTERISTICS_APPCONTAINER=0x1000, IMAGE_DLLCHARACTERISTICS_WDM_DRIVER=0x2000, "
163 " IMAGE_DLLCHARACTERISTICS_GUARD_CF=0x4000, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE=0x8000};",
166 sdb_num_set(
bin->kv,
"pe_nt_image_headers64.offset",
bin->dos_header->e_lfanew, 0);
167 sdb_set(
bin->kv,
"pe_nt_image_headers64.format",
"[4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header64)optionalHeader", 0);
168 sdb_set(
bin->kv,
"pe_image_optional_header64.format",
"[2]Ebbxxxxxqxxwwwwwwxxxx[2]E[2]Bqqqqxx[16]?"
169 " (pe_magic)magic majorLinkerVersion minorLinkerVersion sizeOfCode sizeOfInitializedData"
170 " sizeOfUninitializedData addressOfEntryPoint baseOfCode imageBase"
171 " sectionAlignment fileAlignment majorOperatingSystemVersion minorOperatingSystemVersion"
172 " majorImageVersion minorImageVersion majorSubsystemVersion minorSubsystemVersion"
173 " win32VersionValue sizeOfImage sizeOfHeaders checkSum (pe_subsystem)subsystem (pe_dllcharacteristics)dllCharacteristics"
174 " sizeOfStackReserve sizeOfStackCommit sizeOfHeapReserve sizeOfHeapCommit loaderFlags"
175 " numberOfRvaAndSizes (pe_image_data_directory)dataDirectory",
178 sdb_num_set(
bin->kv,
"pe_nt_image_headers32.offset",
bin->dos_header->e_lfanew, 0);
179 sdb_set(
bin->kv,
"pe_nt_image_headers32.format",
"[4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header32)optionalHeader", 0);
180 sdb_set(
bin->kv,
"pe_image_optional_header32.format",
"[2]Ebbxxxxxxxxxwwwwwwxxxx[2]E[2]Bxxxxxx[16]?"
181 " (pe_magic)magic majorLinkerVersion minorLinkerVersion sizeOfCode sizeOfInitializedData"
182 " sizeOfUninitializedData addressOfEntryPoint baseOfCode baseOfData imageBase"
183 " sectionAlignment fileAlignment majorOperatingSystemVersion minorOperatingSystemVersion"
184 " majorImageVersion minorImageVersion majorSubsystemVersion minorSubsystemVersion"
185 " win32VersionValue sizeOfImage sizeOfHeaders checkSum (pe_subsystem)subsystem (pe_dllcharacteristics)dllCharacteristics"
186 " sizeOfStackReserve sizeOfStackCommit sizeOfHeapReserve sizeOfHeapCommit loaderFlags numberOfRvaAndSizes"
187 " (pe_image_data_directory)dataDirectory",
190 sdb_set(
bin->kv,
"pe_machine.cparse",
"enum pe_machine { IMAGE_FILE_MACHINE_I386=0x014c, IMAGE_FILE_MACHINE_IA64=0x0200, IMAGE_FILE_MACHINE_AMD64=0x8664 };", 0);
191 sdb_set(
bin->kv,
"pe_characteristics.cparse",
"enum pe_characteristics { "
192 " IMAGE_FILE_RELOCS_STRIPPED=0x0001, IMAGE_FILE_EXECUTABLE_IMAGE=0x0002, IMAGE_FILE_LINE_NUMS_STRIPPED=0x0004, "
193 " IMAGE_FILE_LOCAL_SYMS_STRIPPED=0x0008, IMAGE_FILE_AGGRESIVE_WS_TRIM=0x0010, IMAGE_FILE_LARGE_ADDRESS_AWARE=0x0020, "
194 " IMAGE_FILE_BYTES_REVERSED_LO=0x0080, IMAGE_FILE_32BIT_MACHINE=0x0100, IMAGE_FILE_DEBUG_STRIPPED=0x0200, "
195 " IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP=0x0400, IMAGE_FILE_NET_RUN_FROM_SWAP=0x0800, IMAGE_FILE_SYSTEM=0x1000, "
196 " IMAGE_FILE_DLL=0x2000, IMAGE_FILE_UP_SYSTEM_ONLY=0x4000, IMAGE_FILE_BYTES_REVERSED_HI=0x8000 };",
198 sdb_set(
bin->kv,
"pe_image_file_header.format",
"[2]Ewtxxw[2]B"
199 " (pe_machine)machine numberOfSections timeDateStamp pointerToSymbolTable"
200 " numberOfSymbols sizeOfOptionalHeader (pe_characteristics)characteristics",
202 sdb_set(
bin->kv,
"pe_image_data_directory.format",
"xx virtualAddress size", 0);
206 sdb_num_set(
bin->kv,
"image_file_header.TimeDateStamp",
bin->nt_headers->file_header.TimeDateStamp, 0);
208 sdb_set_owned(
bin->kv,
"image_file_header.TimeDateStamp_string", timestr, 0);
210 bin->optional_header = &
bin->nt_headers->optional_header;
211 bin->data_directory = (
PE_(image_data_directory *)) &
bin->optional_header->DataDirectory;
213 if (
bin->dos_header->e_magic != 0x5a4d ||
214 (
bin->nt_headers->Signature != 0x4550 &&
216 bin->nt_headers->Signature != 0x4c50)) {
void * malloc(size_t size)
#define header(is_bt, len_min, ret_op)
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
bool PE_() read_nt_headers(RzBuffer *buf, ut64 addr, PE_(image_nt_headers) *headers)
int PE_() bin_pe_init_hdr(RzBinPEObj *bin)
static bool read_dos_header_aux(RzBuffer *buf, ut64 *offset, PE_(image_dos_header) *header)
static bool read_nt_headers_aux(RzBuffer *buf, ut64 *offset, PE_(image_nt_headers) *headers)
bool PE_() read_dos_header(RzBuffer *buf, PE_(image_dos_header) *header)
#define PE_IMAGE_DIRECTORY_ENTRIES
#define rz_buf_read_le16_offset(b, offset, result)
#define rz_buf_read_le64_offset(b, offset, result)
#define rz_buf_read_le32_offset(b, offset, result)
#define rz_buf_read8_offset(b, offset, result)
#define RZ_LOG_INFO(fmtstr,...)
RZ_API RZ_OWN char * rz_time_stamp_to_str(ut32 timestamp)
Converts an unix epoch timestamp to string.
RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas)
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
if(dbg->bits==RZ_SYS_BITS_64)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()