21 #define macro_str(s) #s
22 #define rz_buf_read_le8_at(a, b, c) \
23 (rz_buf_read_at(a, b, (ut8 *)c, sizeof(ut8)) == 1)
24 #define parse_header_value(off, bits, key) \
26 if (!rz_buf_read_le##bits##_at(bin->b, off, &bin->header->key)) { \
27 RZ_LOG_ERROR("Cannot read TE_image_file_header." macro_str(key) "\n"); \
36 }
else if (!
bin->kv) {
58 sdb_set(
bin->kv,
"te_machine.cparse",
"enum te_machine { TE_IMAGE_FILE_MACHINE_UNKNOWN=0x0, TE_IMAGE_FILE_MACHINE_ALPHA=0x184, "
59 "TE_IMAGE_FILE_MACHINE_ALPHA64=0x284, TE_IMAGE_FILE_MACHINE_AM33=0x1d3, TE_IMAGE_FILE_MACHINE_AMD64=0x8664, "
60 "TE_IMAGE_FILE_MACHINE_ARM=0x1c0, TE_IMAGE_FILE_MACHINE_AXP64=0x184, TE_IMAGE_FILE_MACHINE_CEE=0xc0ee, "
61 "TE_IMAGE_FILE_MACHINE_CEF=0x0cef, TE_IMAGE_FILE_MACHINE_EBC=0x0ebc, TE_IMAGE_FILE_MACHINE_I386=0x014c, "
62 "TE_IMAGE_FILE_MACHINE_IA64=0x0200, TE_IMAGE_FILE_MACHINE_M32R=0x9041, TE_IMAGE_FILE_MACHINE_M68K=0x0268, "
63 "TE_IMAGE_FILE_MACHINE_MIPS16=0x0266, TE_IMAGE_FILE_MACHINE_MIPSFPU=0x0366, TE_IMAGE_FILE_MACHINE_MIPSFPU16=0x0466, "
64 "TE_IMAGE_FILE_MACHINE_POWERPC=0x01f0, TE_IMAGE_FILE_MACHINE_POWERPCFP=0x01f1, TE_IMAGE_FILE_MACHINE_R10000=0x0168, "
65 "TE_IMAGE_FILE_MACHINE_R3000=0x0162, TE_IMAGE_FILE_MACHINE_R4000=0x0166, TE_IMAGE_FILE_MACHINE_SH3=0x01a2, "
66 "TE_IMAGE_FILE_MACHINE_SH3DSP=0x01a3, TE_IMAGE_FILE_MACHINE_SH3E=0x01a4, TE_IMAGE_FILE_MACHINE_SH4=0x01a6, "
67 "TE_IMAGE_FILE_MACHINE_SH5=0x01a8, TE_IMAGE_FILE_MACHINE_THUMB=0x01c2, TE_IMAGE_FILE_MACHINE_TRICORE=0x0520, "
68 "TE_IMAGE_FILE_MACHINE_WCEMIPSV2=0x0169};",
70 sdb_set(
bin->kv,
"te_subsystem.cparse",
"enum te_subsystem { TE_IMAGE_SUBSYSTEM_UNKNOWN=0, TE_IMAGE_SUBSYSTEM_NATIVE=1, "
71 "TE_IMAGE_SUBSYSTEM_WINDOWS_GUI=2, TE_IMAGE_SUBSYSTEM_WINDOWS_CUI=3, "
72 "TE_IMAGE_SUBSYSTEM_POSIX_CUI=7, TE_IMAGE_SUBSYSTEM_WINDOWS_CE_GU=9, "
73 "TE_IMAGE_SUBSYSTEM_EFI_APPLICATION=10, TE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER=11, TE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER=12, "
74 "TE_IMAGE_SUBSYSTEM_EFI_ROM=13, TE_IMAGE_SUBSYSTEM_XBOX=14};",
77 sdb_set(
bin->kv,
"te_header.format",
"[2]z[2]Eb[1]Ewxxq"
78 " Signature (te_machine)Machine NumberOfSections (te_subsystem)Subsystem StrippedSize AddressOfEntryPoint BaseOfCode ImageBase",
81 sdb_set(
bin->kv,
"te_directory1_header.format",
"xx"
82 " VirtualAddress Size",
85 sdb_set(
bin->kv,
"te_directory2_header.format",
"xx"
86 " VirtualAddress Size",
89 if (strncmp((
char *)&
bin->header->Signature,
"VZ", 2)) {
103 eprintf(
"Error: read (entry)\n");
105 if (
buf[367] == 0xe8) {
124 for (
i = 0;
i <
bin->header->NumberOfSections;
i++) {
125 section_base =
bin->section_header[
i].VirtualAddress;
126 section_size =
bin->section_header[
i].VirtualSize;
127 if (vaddr >= section_base && vaddr < section_base + section_size) {
128 return bin->section_header[
i].PointerToRawData + (vaddr - section_base);
136 if (sections_size >
bin->size) {
137 eprintf(
"Invalid NumberOfSections value\n");
140 if (!(
bin->section_header =
malloc(sections_size))) {
141 perror(
"malloc (sections headers)");
145 (
ut8 *)
bin->section_header, sections_size) == -1) {
146 eprintf(
"Error: read (sections headers)\n");
157 eprintf(
"Warning: File is not TE\n");
161 eprintf(
"Warning: Cannot initialize sections\n");
172 switch (
bin->header->Machine) {
207 if (!
bin || !
bin->header) {
211 perror(
"malloc (entrypoint)");
215 if (
entry->vaddr == 0) {
216 entry->vaddr =
bin->header->ImageBase;
224 return (
ut64)
bin->header->ImageBase;
234 switch (
bin->header->Machine) {
236 machine =
strdup(
"Alpha");
239 machine =
strdup(
"Alpha 64");
245 machine =
strdup(
"AMD 64");
272 machine =
strdup(
"Mips 16");
275 machine =
strdup(
"Mips FPU");
278 machine =
strdup(
"Mips FPU 16");
281 machine =
strdup(
"PowerPC");
284 machine =
strdup(
"PowerPC FP");
287 machine =
strdup(
"R10000");
290 machine =
strdup(
"R3000");
293 machine =
strdup(
"R4000");
299 machine =
strdup(
"SH3DSP");
311 machine =
strdup(
"Thumb");
314 machine =
strdup(
"Tricore");
317 machine =
strdup(
"WCE Mips V2");
320 machine =
strdup(
"unknown");
331 switch (
bin->header->Subsystem) {
362 int i, sections_count;
366 shdr =
bin->section_header;
367 sections_count =
bin->header->NumberOfSections;
370 perror(
"malloc (sections)");
373 for (
i = 0;
i < sections_count;
i++) {
394 switch (
bin->header->Subsystem) {
396 subsystem =
strdup(
"Native");
399 subsystem =
strdup(
"Windows GUI");
402 subsystem =
strdup(
"Windows CUI");
405 subsystem =
strdup(
"POSIX CUI");
408 subsystem =
strdup(
"Windows CE GUI");
411 subsystem =
strdup(
"EFI Application");
414 subsystem =
strdup(
"EFI Boot Service Driver");
417 subsystem =
strdup(
"EFI Runtime Driver");
420 subsystem =
strdup(
"EFI ROM");
423 subsystem =
strdup(
"XBOX");
426 subsystem =
strdup(
"Unknown");
RzList * sections(RzBinFile *bf)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, 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")
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_buf(RzBuffer *b)
Creates a new buffer from a source 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 void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
RZ_API bool rz_buf_set_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Replace the content of the buffer with the bytes array.
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
RZ_API Sdb * sdb_new0(void)
ut64 rz_bin_te_get_image_base(struct rz_bin_te_obj_t *bin)
static int rz_bin_te_init_sections(struct rz_bin_te_obj_t *bin)
struct rz_bin_te_section_t * rz_bin_te_get_sections(struct rz_bin_te_obj_t *bin)
struct rz_bin_te_obj_t * rz_bin_te_new(const char *file)
ut64 rz_bin_te_get_main_paddr(struct rz_bin_te_obj_t *bin)
static int rz_bin_te_init_hdr(struct rz_bin_te_obj_t *bin)
char * rz_bin_te_get_os(struct rz_bin_te_obj_t *bin)
char * rz_bin_te_get_arch(struct rz_bin_te_obj_t *bin)
char * rz_bin_te_get_subsystem(struct rz_bin_te_obj_t *bin)
struct rz_bin_te_obj_t * rz_bin_te_new_buf(RzBuffer *buf)
RzBinAddr * rz_bin_te_get_entrypoint(struct rz_bin_te_obj_t *bin)
ut64 rz_bin_te_get_stripped_delta(struct rz_bin_te_obj_t *bin)
char * rz_bin_te_get_machine(struct rz_bin_te_obj_t *bin)
void * rz_bin_te_free(struct rz_bin_te_obj_t *bin)
#define parse_header_value(off, bits, key)
static int rz_bin_te_init(struct rz_bin_te_obj_t *bin)
int rz_bin_te_get_bits(struct rz_bin_te_obj_t *bin)
static TE_DWord rz_bin_te_vaddr_to_paddr(struct rz_bin_te_obj_t *bin, TE_DWord vaddr)
#define TE_IMAGE_FILE_MACHINE_POWERPC
#define TE_IMAGE_FILE_MACHINE_R3000
#define TE_IMAGE_FILE_MACHINE_MIPSFPU
#define TE_IMAGE_FILE_MACHINE_THUMB
#define TE_IMAGE_FILE_MACHINE_ARM
#define TE_IMAGE_SUBSYSTEM_WINDOWS_GUI
#define TE_IMAGE_FILE_MACHINE_I386
#define TE_IMAGE_FILE_MACHINE_ALPHA64
#define TE_IMAGE_FILE_MACHINE_SH3DSP
#define TE_IMAGE_FILE_MACHINE_CEF
#define TE_IMAGE_FILE_MACHINE_EBC
#define TE_IMAGE_FILE_MACHINE_MIPS16
#define TE_IMAGE_FILE_MACHINE_M68K
#define TE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
#define TE_IMAGE_FILE_MACHINE_R4000
#define TE_IMAGE_SUBSYSTEM_NATIVE
#define TE_IMAGE_SUBSYSTEM_POSIX_CUI
#define TE_IMAGE_SUBSYSTEM_WINDOWS_CUI
#define TE_IMAGE_FILE_MACHINE_IA64
#define TE_IMAGE_SUBSYSTEM_EFI_APPLICATION
#define TE_IMAGE_FILE_MACHINE_SH5
#define TE_IMAGE_SUBSYSTEM_EFI_ROM
#define TE_IMAGE_FILE_MACHINE_POWERPCFP
#define TE_IMAGE_SIZEOF_NAME
#define TE_IMAGE_FILE_MACHINE_SH4
#define TE_IMAGE_FILE_MACHINE_ALPHA
#define TE_IMAGE_SUBSYSTEM_XBOX
#define TE_IMAGE_FILE_MACHINE_M32R
#define TE_IMAGE_FILE_MACHINE_CEE
#define TE_IMAGE_FILE_MACHINE_AMD64
#define TE_IMAGE_FILE_MACHINE_AM33
#define TE_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
#define TE_IMAGE_FILE_MACHINE_SH3
#define TE_IMAGE_FILE_MACHINE_TRICORE
#define TE_IMAGE_FILE_MACHINE_R10000
#define TE_IMAGE_FILE_MACHINE_WCEMIPSV2
#define TE_IMAGE_FILE_MACHINE_MIPSFPU16
#define TE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
#define TE_IMAGE_FILE_MACHINE_SH3E
if(dbg->bits==RZ_SYS_BITS_64)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()