Skip to content

Commit

Permalink
Fix bin.ne endian
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl authored and trufae committed Jun 16, 2024
1 parent 0da877e commit b5cb854
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions libr/bin/format/ne/ne.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static bool __ne_get_resources(r_bin_ne_obj_t *bin) {
if (!res->entry) {
break;
}
r_buf_read_at (bin->buf, off, (ut8 *)&ti, sizeof (ti));
r_buf_fread_at (bin->buf, off, (ut8 *)&ti, "2si", 1);
if (!ti.rtTypeID) {
break;
} else if (ti.rtTypeID & 0x8000) {
Expand All @@ -300,7 +300,7 @@ static bool __ne_get_resources(r_bin_ne_obj_t *bin) {
if (!ren) {
break;
}
r_buf_read_at (bin->buf, off, (ut8 *)&ni, sizeof (NE_image_nameinfo_entry));
r_buf_fread_at (bin->buf, off, (ut8 *)&ni, "6s", 1);
ren->offset = ni.rnOffset << alignment;
ren->size = ni.rnLength;
if (ni.rnID & 0x8000) {
Expand Down Expand Up @@ -454,7 +454,7 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) {
if (!modref) {
return NULL;
}
r_buf_read_at (bin->buf, (ut64)bin->ne_header->ModRefTable + bin->header_offset, (ut8 *)modref, bin->ne_header->ModRefs * sizeof (ut16));
r_buf_fread_at (bin->buf, (ut64)bin->ne_header->ModRefTable + bin->header_offset, (ut8 *)modref, "s", bin->ne_header->ModRefs);

RList *relocs = r_list_newf (free);
if (!relocs) {
Expand All @@ -481,7 +481,7 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) {
while (off < start + length * sizeof (NE_image_reloc_item)) {
// && off + sizeof (NE_image_reloc_item) < buf_size)
NE_image_reloc_item rel = {0};
if (r_buf_read_at (bin->buf, off, (ut8 *)&rel, sizeof (rel)) < 1) {
if (r_buf_fread_at (bin->buf, off, (ut8 *)&rel, "2c3s", 1) < 1) {
return NULL;
}
RBinReloc *reloc = R_NEW0 (RBinReloc);
Expand Down Expand Up @@ -601,8 +601,7 @@ void __init(RBuffer *buf, r_bin_ne_obj_t *bin) {
return;
}
bin->buf = buf;
// XXX this is endian unsafe
if (r_buf_read_at (buf, bin->header_offset, (ut8 *)bin->ne_header, sizeof (NE_image_header)) < 1) {
if (r_buf_fread_at (buf, bin->header_offset, (ut8 *)bin->ne_header, "4c2si4c4si8si3s2c3s2c", 1) < 1) {
R_FREE (bin->ne_header);
return;
}
Expand Down Expand Up @@ -635,7 +634,7 @@ void __init(RBuffer *buf, r_bin_ne_obj_t *bin) {
if (!bin->segment_entries) {
return;
}
r_buf_read_at (buf, offset, (ut8 *)bin->segment_entries, size);
r_buf_fread_at (buf, offset, (ut8 *)bin->segment_entries, "4s", bin->ne_header->SegCount);
bin->entry_table = calloc (4, bin->ne_header->EntryTableLength);
if (!bin->entry_table) {
R_FREE (bin->segment_entries);
Expand Down

0 comments on commit b5cb854

Please sign in to comment.