Skip to content

Commit

Permalink
dumper: Fix 32-bit Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Oct 12, 2024
1 parent 766c4e0 commit 68bf49d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions dumper/format/elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,20 @@ void dump_elf_coredump64(adbg_object_t *o, Elf64_Phdr *phdr) {
// NOTE: 8-byte aligned
// NOTE: A note program segment contains multiple notes

void *nbuffer = malloc(phdr.p_filesz);
void *nbuffer = malloc(cast(size_t)phdr.p_filesz);
if (nbuffer == null)
panic_crt();
scope(exit) free(nbuffer);

if (adbg_object_read_at(o, phdr.p_offset, nbuffer, phdr.p_filesz))
if (adbg_object_read_at(o, phdr.p_offset, nbuffer, cast(size_t)phdr.p_filesz))
panic_adbg();

uint index;
void *current = nbuffer;
void *maxlength = nbuffer + phdr.p_filesz;
for (; current < maxlength; ) {
Elf64_Nhdr *note = cast(Elf64_Nhdr*)current;
if (adbg_bits_ptrbounds(note, Elf64_Nhdr.sizeof, nbuffer, phdr.p_filesz))
if (adbg_bits_ptrbounds(note, Elf64_Nhdr.sizeof, nbuffer, cast(size_t)phdr.p_filesz))
panic(2, "Elf64_Nhdr header does not fit note");

// NOTE: Note names
Expand All @@ -249,7 +249,7 @@ void dump_elf_coredump64(adbg_object_t *o, Elf64_Phdr *phdr) {
return;

const(char)* name = cast(const(char)*)note + Elf64_Nhdr.sizeof;
if (adbg_bits_ptrbounds(cast(void*)name, note.n_namesz, nbuffer, phdr.p_filesz))
if (adbg_bits_ptrbounds(cast(void*)name, note.n_namesz, nbuffer, cast(size_t)phdr.p_filesz))
panic(2, "Elf64_Nhdr:n_namesz points outside of note bounds");

print_section(++index, name, note.n_namesz);
Expand All @@ -263,7 +263,7 @@ void dump_elf_coredump64(adbg_object_t *o, Elf64_Phdr *phdr) {

switch (note.n_type) {
case ELF_NT_PRSTATUS:
if (adbg_bits_ptrbounds(data, elf_prstatus64.sizeof, nbuffer, phdr.p_filesz))
if (adbg_bits_ptrbounds(data, elf_prstatus64.sizeof, nbuffer, cast(size_t)phdr.p_filesz))
return;
elf_prstatus64 *prstatus = cast(elf_prstatus64*)data;
print_u32("pr_info.si_signo", prstatus.pr_info.si_signo);
Expand Down Expand Up @@ -315,7 +315,7 @@ void dump_elf_coredump64(adbg_object_t *o, Elf64_Phdr *phdr) {
break;
case ELF_NT_PRPSINFO:
elf_prpsinfo64 *prpsinfo = cast(elf_prpsinfo64*)data;
if (adbg_bits_ptrbounds(data, elf_prpsinfo64.sizeof + prpsinfo.pr_sname, nbuffer, phdr.p_filesz))
if (adbg_bits_ptrbounds(data, elf_prpsinfo64.sizeof + prpsinfo.pr_sname, nbuffer, cast(size_t)phdr.p_filesz))
return;
char[4] pr_sname = void;
int l = realchar(pr_sname.ptr, 4, prpsinfo.pr_sname);
Expand All @@ -337,7 +337,7 @@ void dump_elf_coredump64(adbg_object_t *o, Elf64_Phdr *phdr) {
// NOTE: SI_MAX_SIZE is defined with 128, must be same size
goto default;
case ELF_NT_FPREGSET:
if (adbg_bits_ptrbounds(data, user_i387_struct64.sizeof, nbuffer, phdr.p_filesz))
if (adbg_bits_ptrbounds(data, user_i387_struct64.sizeof, nbuffer, cast(size_t)phdr.p_filesz))
return;
user_i387_struct64 *fregset = cast(user_i387_struct64*)data;
print_x16("cwd", fregset.cwd);
Expand Down Expand Up @@ -548,11 +548,11 @@ void dump_elf_disasm(adbg_object_t *o) {
case ELF_CLASS_64:
for (Elf64_Shdr *s = void; (s = adbg_object_elf_shdr64(o, i)) != null; ++i) {
if (all || s.sh_flags & ELF_SHF_EXECINSTR) {
buffer = malloc(s.sh_size);
buffer = malloc(cast(size_t)s.sh_size);
if (buffer == null)
panic_crt();

if (adbg_object_read_at(o, s.sh_offset, buffer, s.sh_size))
if (adbg_object_read_at(o, s.sh_offset, buffer, cast(size_t)s.sh_size))
panic_adbg();

dump_disassemble_object(o,
Expand Down

0 comments on commit 68bf49d

Please sign in to comment.