Skip to content

Commit

Permalink
Removed RZ_PACKED from le_specs.h
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Oct 20, 2022
1 parent 5006371 commit b83893c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
37 changes: 31 additions & 6 deletions librz/bin/format/le/le.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ static RzBinSymbol *le_get_symbol(rz_bin_le_obj_t *bin, ut64 *offset) {
return sym;
}

static bool read_le_entry_bundle_entry(RzBuffer *buf, ut64 addr, LE_entry_bundle_entry *e, LE_entry_bundle_type type) {
ut64 offset = addr;
switch (type) {
case ENTRY16:
return rz_buf_read8_offset(buf, &offset, &e->entry_16.flags) &&
rz_buf_read_le16_offset(buf, &offset, &e->entry_16.offset);
case CALLGATE:
return rz_buf_read8_offset(buf, &offset, &e->callgate.flags) &&
rz_buf_read_le16_offset(buf, &offset, &e->callgate.offset) &&
rz_buf_read_le16_offset(buf, &offset, &e->callgate.callgate_sel);
case ENTRY32:
return rz_buf_read8_offset(buf, &offset, &e->entry_32.flags) &&
rz_buf_read_le32_offset(buf, &offset, &e->entry_32.offset);
case FORWARDER:
return rz_buf_read8_offset(buf, &offset, &e->forwarder.flags) &&
rz_buf_read_le16_offset(buf, &offset, &e->forwarder.import_ord) &&
rz_buf_read_le32_offset(buf, &offset, &e->forwarder.offset);
default:
memset(e, 0, sizeof(LE_entry_bundle_entry));
return false;
}
}

RzList /*<char *>*/ *le_get_entries(rz_bin_le_obj_t *bin) {
ut64 offset = (ut64)bin->header->enttab + bin->headerOff;
RzList *l = rz_list_newf(free);
Expand Down Expand Up @@ -124,9 +147,10 @@ RzList /*<char *>*/ *le_get_entries(rz_bin_le_obj_t *bin) {
bool typeinfo = header.type & ENTRY_PARAMETER_TYPING_PRESENT;
int i;
for (i = 0; i < header.count; i++) {
ut64 entry = -1;
rz_buf_read_at(bin->buf, offset, (ut8 *)&e, sizeof(e));
switch (header.type & ~ENTRY_PARAMETER_TYPING_PRESENT) {
LE_entry_bundle_type bundle_type = header.type & ~ENTRY_PARAMETER_TYPING_PRESENT;
ut64 entry = UT64_MAX;
read_le_entry_bundle_entry(bin->buf, offset, &e, bundle_type);
switch (bundle_type) {
case ENTRY16:
if ((header.objnum - 1) < bin->header->objcnt) {
entry = (ut64)e.entry_16.offset + bin->objtbl[header.objnum - 1].reloc_base_addr;
Expand Down Expand Up @@ -157,6 +181,8 @@ RzList /*<char *>*/ *le_get_entries(rz_bin_le_obj_t *bin) {
case FORWARDER:
offset += sizeof(e.forwarder);
break;
default:
break;
}
if (entry != UT64_MAX) {
rz_list_append(l, rz_str_newf("0x%" PFMT64x, entry));
Expand Down Expand Up @@ -488,13 +514,12 @@ RzList /*<RzBinReloc *>*/ *rz_bin_le_get_relocs(rz_bin_le_obj_t *bin) {
break;
}
LE_fixup_record_header header;
int ret = rz_buf_read_at(bin->buf, offset, (ut8 *)&header, sizeof(header));
if (ret != sizeof(header)) {
if (!(rz_buf_read8_offset(bin->buf, &offset, &header.source) &&
rz_buf_read8_offset(bin->buf, &offset, &header.target))) {
RZ_LOG_WARN("Cannot read out of bounds relocation.\n");
free(rel);
break;
}
offset += sizeof(header);
switch (header.source & F_SOURCE_TYPE_MASK) {
case BYTEFIXUP:
rel->type = RZ_BIN_RELOC_8;
Expand Down
25 changes: 10 additions & 15 deletions librz/bin/format/le/le_specs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,26 @@ typedef struct LE_entry_bundle_header_s {
#define ENTRY_EXPORTED 0x01
#define ENTRY_PARAM_COUNT_MASK 0xF8

RZ_PACKED(typedef union LE_entry_bundle_entry_u {
RZ_PACKED(struct {
typedef union LE_entry_bundle_entry_u {
struct {
ut8 flags; // First bit set if exported, mask with 0xF8 to get parameters count
ut16 offset; // This is the offset in the object for the entry point defined at this ordinal number.
})
entry_16;
RZ_PACKED(struct {
} entry_16;
struct {
ut8 flags; // First bit set if exported, mask with 0xF8 to get parameters count
ut16 offset; // This is the offset in the object for the entry point defined at this ordinal number.
ut16 callgate_sel; // The callgate selector for references to ring 2 entry points.
})
callgate;
RZ_PACKED(struct {
} callgate;
struct {
ut8 flags; // First bit set if exported, mask with 0xF8 to get parameters count
ut32 offset; // This is the offset in the object for the entry point defined at this ordinal number.
})
entry_32;
RZ_PACKED(struct {
} entry_32;
struct {
ut8 flags; // First bit set if import by ordinal
ut16 import_ord; // This is the index into the Import Module Name Table for this forwarder.
ut32 offset; // If import by ordinal, is the ordinal number into the Entry Table of the target module, else is the offset into the Procedure Names Table of the target module.
})
forwarder;
})
LE_entry_bundle_entry;
} forwarder;
} LE_entry_bundle_entry;

#define F_SOURCE_TYPE_MASK 0xF
#define F_SOURCE_ALIAS 0x10
Expand Down

0 comments on commit b83893c

Please sign in to comment.