9 return bin->nt_headers->optional_header.AddressOfEntryPoint & 1;
13 switch (
bin->nt_headers->file_header.Machine) {
27 if (
bin &&
bin->nt_headers) {
28 switch (
bin->nt_headers->file_header.Machine) {
62 default: machine =
"unknown";
71 if (!
bin || !
bin->nt_headers) {
74 switch (
bin->nt_headers->optional_header.Subsystem) {
104 if (
bin &&
bin->nt_headers) {
105 switch (
bin->nt_headers->optional_header.Magic) {
108 default:
return strdup(
"Unknown");
116 if (!
bin || !
bin->nt_headers) {
119 switch (
bin->nt_headers->file_header.Machine) {
160 char *subsystem =
NULL;
161 if (
bin &&
bin->nt_headers) {
162 switch (
bin->nt_headers->optional_header.Subsystem) {
164 subsystem =
"Native";
167 subsystem =
"Windows GUI";
170 subsystem =
"Windows CUI";
173 subsystem =
"POSIX CUI";
176 subsystem =
"Windows CE GUI";
179 subsystem =
"EFI Application";
182 subsystem =
"EFI Boot Service Driver";
185 subsystem =
"EFI Runtime Driver";
188 subsystem =
"EFI ROM";
194 subsystem =
"Unknown";
202 if (
bin &&
bin->nt_headers) {
207 switch (
bin->nt_headers->optional_header.Magic) {
212 switch (
bin->nt_headers->optional_header.Magic) {
222 if (!
bin || !
bin->optional_header) {
225 return bin->optional_header->CheckSum;
235 ut64 computed_cs = *
ctx->computed_cs;
237 for (
i = 0;
i <
size;
i += 4) {
240 computed_cs = (computed_cs & 0xFFFFFFFF) + cur + (computed_cs >> 32);
241 if (computed_cs >> 32) {
242 computed_cs = (computed_cs & 0xFFFFFFFF) + (computed_cs >> 32);
245 *
ctx->computed_cs = computed_cs;
250 size_t i, j, checksum_offset = 0;
251 ut64 computed_cs = 0;
255 if (!
bin || !
bin->nt_header_offset) {
258 const size_t buf_sz = 0x1000;
267 checksum_offset =
bin->nt_header_offset + 4 +
sizeof(
PE_(image_file_header)) + 0x40;
273 remaining_bytes =
bin->size % 4;
274 i =
bin->size - remaining_bytes;
275 if (remaining_bytes != 0) {
283 for (j = 1; j < remaining_bytes; j++,
shift += 8) {
289 computed_cs = (computed_cs & 0xFFFFFFFF) + cur + (computed_cs >> 32);
290 if (computed_cs >> 32) {
291 computed_cs = (computed_cs & 0xFFFFFFFF) + (computed_cs >> 32);
296 computed_cs = (computed_cs & 0xFFFF) + (computed_cs >> 16);
297 computed_cs = (computed_cs) + (computed_cs >> 16);
298 computed_cs = (computed_cs & 0xFFFF);
301 computed_cs +=
bin->size;
308 if (
bin &&
bin->nt_headers) {
312 switch (
bin->nt_headers->optional_header.Magic) {
322 #define HASCHR(x) (bin->nt_headers->file_header.Characteristics & (x))
325 if (!
bin || !
bin->nt_headers) {
332 if (!
bin || !
bin->nt_headers) {
337 BOOL aslr = inh->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
339 BOOL dep = inh->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
345 if (!
bin || !
bin->nt_headers) {
348 arch =
bin->nt_headers->file_header.Machine;
357 if (!
bin || !
bin->nt_headers) {
364 if (!
bin || !
bin->nt_headers) {
371 if (!
bin || !
bin->nt_headers) {
378 if (!
bin || !
bin->nt_headers) {
390 PE_(image_import_directory)
392 PE_(image_delay_import_directory)
393 curr_delay_import_dir;
395 HtPP *lib_map =
NULL;
406 if (
bin->import_directory_offset +
bin->import_directory_size >
bin->size) {
407 RZ_LOG_INFO(
"import directory offset bigger than file\n");
411 off =
bin->import_directory_offset;
412 if (off < bin->
size &&
off > 0) {
416 if (
off +
sizeof(
PE_(image_import_directory)) >
bin->size) {
422 while (
r ==
sizeof(curr_import_dir) &&
off + (iidi + 1) *
sizeof(curr_import_dir) <=
last && (curr_import_dir.FirstThunk || curr_import_dir.Name || curr_import_dir.TimeDateStamp || curr_import_dir.Characteristics || curr_import_dir.ForwarderChain)) {
432 libs[index].name[
len - 1] =
'\0';
436 libs[index++].last = 0;
437 if (index >= max_libs) {
454 off =
bin->delay_import_directory_offset;
455 if (off < bin->
size &&
off > 0) {
457 if (
off +
sizeof(
PE_(image_delay_import_directory)) >
bin->size) {
461 if (
r !=
sizeof(curr_delay_import_dir)) {
464 while (
r ==
sizeof(curr_delay_import_dir) &&
465 curr_delay_import_dir.Name != 0 && curr_delay_import_dir.DelayImportNameTable != 0) {
475 libs[index].name[
len - 1] =
'\0';
479 libs[index++].last = 0;
480 if (index >= max_libs) {
493 &curr_delay_import_dir);
497 libs[index].last = 1;
506 return bin->nt_headers->optional_header.SizeOfImage;
511 static bool debug =
false;
514 if (!
bin || !
bin->optional_header) {
521 PE_DWord pe_entry =
bin->optional_header->AddressOfEntryPoint;
525 entry->haddr =
bin->dos_header->e_lfanew + 4 +
sizeof(
PE_(image_file_header)) + 16;
532 "trying to fix it but i do not promise nothing\n");
534 for (
i = 0;
i <
bin->num_sections;
i++) {
544 for (
i = 0;
i <
bin->num_sections;
i++) {
555 int sa =
RZ_MAX(
bin->optional_header->SectionAlignment, 0x1000);
556 entry->paddr = pe_entry & ((sa << 1) - 1);
566 for (
i = 0;
i <
bin->num_sections;
i++) {
578 if (
entry->paddr & 1) {
590 if (!
bin || !
bin->nt_headers) {
593 imageBase =
bin->nt_headers->optional_header.ImageBase;
611 entry->paddr += jmp_dst;
612 entry->vaddr += jmp_dst;
618 entry->paddr += dst_offset;
619 entry->vaddr += dst_offset;
640 if (
b[0] == 0xe8 &&
b[5] == 0xe9) {
646 ut32 imageBase =
bin->nt_headers->optional_header.ImageBase;
647 for (
n = 0;
n <
sizeof(
b) - 6;
n++) {
649 if (
b[
n] == 0x68 && tmp_imgbase == imageBase &&
b[
n + 5] == 0xe8) {
660 for (
n = 0;
n <
sizeof(
b) - 6;
n++) {
661 if (
b[
n] == 0x50 &&
b[
n + 1] == 0xff &&
b[
n + 3] == 0xff &&
b[
n + 5] == 0xe8) {
671 for (
n = 0;
n <
sizeof(
b) - 20;
n++) {
672 if (
b[
n] == 0x50 &&
b[
n + 1] == 0xff &&
b[
n + 7] == 0xff &&
b[
n + 13] == 0xe8) {
682 for (
n = 0;
n <
sizeof(
b) - 5;
n++) {
683 if (
b[
n] == 0x50 &&
b[
n + 1] == 0x57 &&
b[
n + 2] == 0xff &&
b[
n + 4] == 0xe8) {
693 for (
n = 0;
n <
sizeof(
b) - 5;
n++) {
694 if (
b[
n] == 0x57 &&
b[
n + 1] == 0x56 &&
b[
n + 2] == 0xff &&
b[
n + 4] == 0xe8) {
718 for (
n = 0;
n <
sizeof(
b) - 17;
n++) {
724 if (
b[
n] == 0xe8 && !memcmp(
b +
n + 5,
"\x83\xc4\x04", 3) &&
b[
n + 8] == 0xe8 &&
b[
n + 13] == 0x89 &&
b[
n + 16] == 0xe8) {
727 for (j = 0; j <
sizeof(
b) - 4; j++) {
744 for (
i = 0;
i <
sizeof(
b) - 14;
i++) {
745 if (
b[
i] == 0x48 &&
b[
i + 1] == 0x83 &&
b[
i + 2] == 0xEC) {
749 bool found_caller =
false;
750 if (
b[
i + 13] == 0xe9) {
770 if (
b[0x129] == 0xe8) {
787 for (
n = 0;
n <
sizeof(
b) - 13;
n++) {
788 if (
b[
n] == 0x4c &&
b[
n + 3] == 0x48 &&
b[
n + 6] == 0x8b &&
b[
n + 8] == 0xe8) {
791 }
else if (
b[
n] == 0x4c &&
b[
n + 5] == 0x48 &&
b[
n + 10] == 0x8b &&
b[
n + 14] == 0xe8) {
808 if (
b[188] == 0x50 &&
b[201] == 0xe8) {
813 if (
b[292] == 0x50 &&
b[303] == 0xe8) {
844 if (
b[0] == 0x55 &&
b[1] == 0x89 &&
b[3] == 0x83 &&
b[6] == 0xc7 &&
b[13] == 0xff &&
b[19] == 0xe8) {
851 if (
b[0] == 0x83 &&
b[3] == 0xc7 &&
b[10] == 0xff &&
b[16] == 0xe8) {
859 if (
b[0] == 0x83 &&
b[3] == 0xc7 &&
b[13] == 0xe8 &&
b[18] == 0x83 &&
b[21] == 0xe9) {
868 for (
n = 0;
n <
sizeof(
b) - 12;
n++) {
869 if (
b[
n] == 0xa1 &&
b[
n + 5] == 0x89 &&
b[
n + 8] == 0xe8) {
897 if (
b[367] == 0xe8) {
902 for (
i = 0;
i < 512 - 16;
i++) {
904 if (!memcmp(
b +
i,
"\xff\x15", 2)) {
905 if (
b[
i + 6] == 0x50) {
906 if (
b[
i + 7] == 0xe8) {
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
static RzList * libs(RzBinFile *bf)
RzList * sections(RzBinFile *bf)
int bits(struct state *s, int need)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
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")
PE_DWord PE_() bin_pe_rva_to_paddr(RzBinPEObj *bin, PE_DWord rva)
PE_DWord PE_() bin_pe_rva_to_va(RzBinPEObj *bin, PE_DWord rva)
int PE_() read_image_delay_import_directory(RzBuffer *b, ut64 addr, PE_(image_delay_import_directory) *directory)
int PE_() read_image_import_directory(RzBuffer *b, ut64 addr, PE_(image_import_directory) *import_dir)
int PE_() rz_bin_pe_is_stripped_debug(RzBinPEObj *bin)
struct rz_bin_pe_addr_t *PE_() check_unknow(RzBinPEObj *bin)
int PE_() rz_bin_pe_get_image_size(RzBinPEObj *bin)
int PE_() rz_bin_pe_is_pie(RzBinPEObj *bin)
int PE_() rz_bin_pe_is_big_endian(RzBinPEObj *bin)
struct rz_bin_pe_addr_t *PE_() rz_bin_pe_get_main_vaddr(RzBinPEObj *bin)
static ut64 buf_fwd_checksum(const ut8 *buf, ut64 size, void *user)
static bool read_and_follow_jump(struct rz_bin_pe_addr_t *entry, RzBuffer *buf, ut8 *b, int len, bool big_endian)
struct rz_bin_pe_addr_t *PE_() rz_bin_pe_get_entrypoint(RzBinPEObj *bin)
int PE_() rz_bin_pe_is_stripped_local_syms(RzBinPEObj *bin)
char *PE_() rz_bin_pe_get_subsystem(RzBinPEObj *bin)
char *PE_() rz_bin_pe_get_machine(RzBinPEObj *bin)
char *PE_() rz_bin_pe_get_arch(RzBinPEObj *bin)
int PE_() bin_pe_get_claimed_checksum(RzBinPEObj *bin)
static int is_thumb(RzBinPEObj *bin)
struct rz_bin_pe_lib_t *PE_() rz_bin_pe_get_libs(RzBinPEObj *bin)
int PE_() bin_pe_get_actual_checksum(RzBinPEObj *bin)
ut64 PE_() rz_bin_pe_get_image_base(RzBinPEObj *bin)
char *PE_() rz_bin_pe_get_cc(RzBinPEObj *bin)
static bool follow_offset(struct rz_bin_pe_addr_t *entry, RzBuffer *buf, ut8 *b, int len, bool big_endian, size_t instr_off)
int PE_() rz_bin_pe_is_stripped_relocs(RzBinPEObj *bin)
char *PE_() rz_bin_pe_get_os(RzBinPEObj *bin)
char *PE_() rz_bin_pe_get_class(RzBinPEObj *bin)
int PE_() rz_bin_pe_is_dll(RzBinPEObj *bin)
struct rz_bin_pe_addr_t *PE_() check_msvcseh(RzBinPEObj *bin)
static int is_arm(RzBinPEObj *bin)
int PE_() rz_bin_pe_get_bits(RzBinPEObj *bin)
int PE_() rz_bin_pe_is_stripped_line_nums(RzBinPEObj *bin)
struct rz_bin_pe_addr_t *PE_() check_mingw(RzBinPEObj *bin)
#define PE_IMAGE_FILE_DEBUG_STRIPPED
#define PE_IMAGE_FILE_MACHINE_CEE
#define PE_IMAGE_FILE_MACHINE_SH5
#define PE_IMAGE_SUBSYSTEM_EFI_ROM
#define PE_IMAGE_FILE_MACHINE_IA64
#define PE_IMAGE_FILE_MACHINE_M68K
#define PE_IMAGE_FILE_MACHINE_MIPSFPU16
#define PE_IMAGE_SCN_MEM_EXECUTE
#define PE_IMAGE_FILE_MACHINE_R10000
#define PE_IMAGE_FILE_MACHINE_ARMNT
#define PE_IMAGE_FILE_MACHINE_ARM
#define PE_IMAGE_SUBSYSTEM_POSIX_CUI
#define PE_IMAGE_FILE_MACHINE_ALPHA
#define PE_IMAGE_FILE_MACHINE_RISCV64
#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
#define PE_IMAGE_FILE_MACHINE_THUMB
#define PE_IMAGE_FILE_MACHINE_SH3E
#define PE_IMAGE_FILE_MACHINE_SH4
#define PE_IMAGE_FILE_TYPE_PE32
#define PE_IMAGE_SUBSYSTEM_XBOX
#define PE_IMAGE_FILE_MACHINE_CEF
#define PE_IMAGE_FILE_MACHINE_R4000
#define PE_IMAGE_FILE_MACHINE_AM33
#define PE_IMAGE_FILE_MACHINE_AMD64
#define PE_IMAGE_FILE_TYPE_PE32PLUS
#define PE_IMAGE_FILE_BYTES_REVERSED_HI
#define PE_IMAGE_SCN_MEM_WRITE
#define PE_IMAGE_FILE_MACHINE_ARM64
#define PE_IMAGE_FILE_MACHINE_EBC
#define PE_IMAGE_SUBSYSTEM_NATIVE
#define PE_IMAGE_FILE_MACHINE_RISCV128
#define PE_IMAGE_FILE_LOCAL_SYMS_STRIPPED
#define PE_IMAGE_FILE_MACHINE_RISCV32
#define PE_IMAGE_FILE_MACHINE_TRICORE
#define PE_IMAGE_FILE_MACHINE_R3000
#define PE_IMAGE_FILE_RELOCS_STRIPPED
#define PE_IMAGE_FILE_MACHINE_SH3
#define PE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
#define PE_IMAGE_FILE_MACHINE_WCEMIPSV2
#define PE_IMAGE_FILE_LINE_NUMS_STRIPPED
#define PE_IMAGE_FILE_MACHINE_MIPS16
#define PE_IMAGE_SUBSYSTEM_EFI_APPLICATION
#define PE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
#define PE_IMAGE_FILE_DLL
#define PE_IMAGE_FILE_MACHINE_M32R
#define PE_IMAGE_SUBSYSTEM_WINDOWS_CUI
#define PE_IMAGE_FILE_MACHINE_SH3DSP
#define PE_IMAGE_FILE_MACHINE_I386
#define PE_IMAGE_SUBSYSTEM_WINDOWS_GUI
#define PE_IMAGE_FILE_MACHINE_MIPSFPU
#define PE_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
#define PE_IMAGE_FILE_MACHINE_POWERPC
#define PE_IMAGE_FILE_MACHINE_POWERPCFP
#define PE_IMAGE_FILE_MACHINE_ALPHA64
#define rz_return_val_if_fail(expr, val)
RZ_API bool rz_buf_read8_at(RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the specified address in the buffer.
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.
RZ_API ut64 rz_buf_fwd_scan(RZ_NONNULL RzBuffer *b, ut64 start, ut64 amount, RZ_NONNULL RzBufferFwdScan fwd_scan, RZ_NULLABLE void *user)
Scans buffer linearly in chunks calling fwd_scan for each chunk.
static ut32 rz_read_ble32(const void *src, bool big_endian)
static ut32 rz_read_at_ble32(const void *src, size_t offset, bool big_endian)
#define RZ_LOG_INFO(fmtstr,...)
RZ_API void rz_str_case(char *str, bool up)
RZ_API char * sdb_ht_find(HtPP *ht, const char *key, bool *found)
RZ_API HtPP * sdb_ht_new(void)
RZ_API void sdb_ht_free(HtPP *ht)
RZ_API bool sdb_ht_insert(HtPP *ht, const char *key, const char *value)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()