Skip to content

Commit

Permalink
Fix crash with ELF format crc32 check
Browse files Browse the repository at this point in the history
  • Loading branch information
djipi committed Aug 23, 2022
1 parent 080ab2e commit 004e4b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions jiffi2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Supported formats of the Atari Jaguar.
- ROM


Version 1.0.1 - 08-23-2022
- Fix crash with ELF format crc32 check.


Version 1.0.0 - 02-28-2021
- Work based on JiFFI v1.43 which is based on the v1.42, written in GFA Basic, released by ggn.
-- Follow the same set of features
Expand Down
21 changes: 21 additions & 0 deletions src/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ int detect_file_format(void)
//ElfMem = (Elf*)ptr;
if (((((((Elf32_Ehdr*)ptrload)->e_machine) & 0xFF) == EM_68K) && ((((Elf32_Ehdr*)ptrload)->e_type) == ET_EXEC)) || (!endianess && (((((Elf32_Ehdr*)ptrload)->e_machine) & 0xFF00) == (EM_68K << 8)) && ((((Elf32_Ehdr*)ptrload)->e_type) == (ET_EXEC << 8))))
{
unsigned char* ptr = NULL;
size_t NbrSect;
Elf* ElfMem = elf_memory((char*)ptrload, linj);
if (!elf_getshdrnum(ElfMem, &NbrSect))
Expand All @@ -235,22 +236,42 @@ int detect_file_format(void)
PtrGElfShdr = gelf_getshdr(PtrElfScn, &GElfShdr);
switch (PtrGElfShdr->sh_type)
{
// Program data
case SHT_PROGBITS:
if ((PtrGElfShdr->sh_flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR)))
{
if (PtrGElfShdr->sh_addr < loadadr)
{
loadadr = PtrGElfShdr->sh_addr;
if (ptr < (ptrload + PtrGElfShdr->sh_offset))
{
ptr = (ptrload + PtrGElfShdr->sh_offset);
}
}
}
else
{
linj -= PtrGElfShdr->sh_size;
}
break;
// Symbol table
case SHT_SYMTAB:
// String table
case SHT_STRTAB:
// Section header table entry unused
case SHT_NULL:
// Program space with no data (bss)
case SHT_NOBITS:
// reduce the size with the section's size
default:
linj -= PtrGElfShdr->sh_size;
break;
}
}
// get run address
//runadr = !endianess ? (uint32_t)PtrGElfEhdr->e_entry : ((((uint32_t)PtrGElfEhdr->e_entry & 0xff000000) >> 24) | (((uint32_t)PtrGElfEhdr->e_entry & 0x00ff0000) >> 8) | (((uint32_t)PtrGElfEhdr->e_entry & 0x0000ff00) << 8) | (((uint32_t)PtrGElfEhdr->e_entry & 0x000000ff) << 24));
runadr = (uint32_t)PtrGElfEhdr->e_entry;
memcpy(imageadr, ptr, linj);
detected_format = format_ELF;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// Release Information
#define MAJOR 1 // Major version number
#define MINOR 0 // Minor version number
#define PATCH 0 // Patch release number
#define PATCH 1 // Patch release number

#endif // __VERSION_H__

0 comments on commit 004e4b4

Please sign in to comment.