Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bin.ne endian #23043

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading