Skip to content

Commit

Permalink
TE: 16 bit for _TEXT_RE and fixes for virtual addresses calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Mar 29, 2013
1 parent 0f807f1 commit e62e837
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libr/bin/format/te/te.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "te_specs.h"
#include "te.h"

ut64 r_bin_te_get_stripped_delta(struct r_bin_te_obj_t *bin) {
return bin->header->StrippedSize - sizeof(TE_image_file_header);
}

ut64 r_bin_te_get_main_offset(struct r_bin_te_obj_t *bin) {
struct r_bin_te_addr_t *entry = r_bin_te_get_entrypoint (bin);
ut64 addr = 0LL;
Expand Down Expand Up @@ -128,7 +132,7 @@ struct r_bin_te_addr_t* r_bin_te_get_entrypoint(struct r_bin_te_obj_t* bin) {
perror("malloc (entrypoint)");
return NULL;
}
entry->rva = bin->header->AddressOfEntryPoint;
entry->rva = bin->header->AddressOfEntryPoint - r_bin_te_get_stripped_delta(bin);
if (entry->rva == 0) // in TE if EP = 0 then EP = baddr
entry->rva = bin->header->ImageBase;
entry->offset = r_bin_te_rva_to_offset(bin, entry->rva);
Expand Down Expand Up @@ -277,10 +281,10 @@ struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin) {
for (i = 0; i < sections_count; i++) {
memcpy (sections[i].name, shdr[i].Name, TE_IMAGE_SIZEOF_NAME);
sections[i].name[TE_IMAGE_SIZEOF_NAME] = '\0';
sections[i].rva = shdr[i].VirtualAddress;
sections[i].rva = shdr[i].VirtualAddress - r_bin_te_get_stripped_delta(bin);
sections[i].size = shdr[i].SizeOfRawData;
sections[i].vsize = shdr[i].VirtualSize;
sections[i].offset = shdr[i].PointerToRawData;
sections[i].offset = shdr[i].PointerToRawData - r_bin_te_get_stripped_delta(bin);
sections[i].flags = shdr[i].Characteristics;
sections[i].last = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions libr/bin/p/bin_te.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ static RList* sections(RBinArch *arch) {
ptr->srwx |= 0x4;
if (R_BIN_TE_SCN_IS_SHAREABLE (sections[i].flags))
ptr->srwx |= 0x8;
/* All TE files have _TEXT_RE section, which is 16-bit, because of
* CPU start in this mode */
if (!strncmp(ptr->name, "_TEXT_RE", 8))
ptr->bits = 16;
r_list_append (ret, ptr);
}
free (sections);
Expand Down

0 comments on commit e62e837

Please sign in to comment.