[Scummvm-cvs-logs] SF.net SVN: scummvm:[52550] scummvm/branches/gsoc2010-plugins/backends/ plugins
dhewg at users.sourceforge.net
dhewg at users.sourceforge.net
Sun Sep 5 14:38:38 CEST 2010
Revision: 52550
http://scummvm.svn.sourceforge.net/scummvm/?rev=52550&view=rev
Author: dhewg
Date: 2010-09-05 12:38:38 +0000 (Sun, 05 Sep 2010)
Log Message:
-----------
PLUGINS: Properly check the ELF header.
The ELFMAG is only 4 bytes, not 6. Properly check for endianess.
Modified Paths:
--------------
scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp
scummvm/branches/gsoc2010-plugins/backends/plugins/elf32.h
Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp 2010-09-05 12:38:18 UTC (rev 52549)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp 2010-09-05 12:38:38 UTC (rev 52550)
@@ -80,22 +80,57 @@
}
bool DLObject::readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) {
- // Start reading the elf header. Check for errors
+ // Start reading the elf header. Check for errors and magic
if (DLFile->read(ehdr, sizeof(*ehdr)) != sizeof(*ehdr) ||
- memcmp(ehdr->e_ident, ELFMAG, SELFMAG) || // Check MAGIC
- ehdr->e_type != ET_EXEC || // Check for executable
+ memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
+ warning("elfloader: No ELF file.");
+ return false;
+ }
+
+ if (ehdr->e_ident[EI_CLASS] != ELFCLASS32) {
+ warning("elfloader: Wrong ELF file class.");
+ return false;
+ }
+
+ if (ehdr->e_ident[EI_DATA] !=
+#ifdef SCUMM_BIG_ENDIAN
+ ELFDATA2MSB
+#else
+ ELFDATA2LSB
+#endif
+ ) {
+ warning("elfloader: Wrong ELF file endianess.");
+ return false;
+ }
+
+ if (ehdr->e_ident[EI_VERSION] != EV_CURRENT) {
+ warning("elfloader: Wrong ELF file version.");
+ return false;
+ }
+
+ if (ehdr->e_type != ET_EXEC) {
+ warning("elfloader: No executable ELF file.");
+ return false;
+ }
+
+ if (ehdr->e_machine !=
#ifdef ARM_TARGET
- ehdr->e_machine != EM_ARM || // Check for ARM machine type
+ EM_ARM
#endif
#ifdef MIPS_TARGET
- ehdr->e_machine != EM_MIPS || // Check for MIPS machine type
+ EM_MIPS
#endif
- ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header
- ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header
- warning("elfloader: Invalid file type.");
+ ) {
+ warning("elfloader: Wrong ELF file architecture.");
return false;
}
+ if (ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header
+ ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header
+ warning("elfloader: Invalid ELF structure sizes.");
+ return false;
+ }
+
debug(2, "elfloader: phoff = %d, phentsz = %d, phnum = %d",
ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum);
Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf32.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf32.h 2010-09-05 12:38:18 UTC (rev 52549)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf32.h 2010-09-05 12:38:38 UTC (rev 52550)
@@ -38,7 +38,7 @@
typedef Elf32_Half Elf32_Versym;
#define EI_NIDENT (16)
-#define SELFMAG 6
+#define SELFMAG 4
/* ELF File format structures. Look up ELF structure for more details */
@@ -61,8 +61,18 @@
} Elf32_Ehdr;
// Should be in e_ident
-#define ELFMAG "\177ELF\1\1" /* ELF Magic number */
+#define ELFMAG "\177ELF" /* ELF Magic number */
+#define EI_CLASS 4 /* File class byte index */
+#define ELFCLASS32 1 /* 32-bit objects */
+
+#define EI_DATA 5 /* Data encoding byte index */
+#define ELFDATA2LSB 1 /* 2's complement, little endian */
+#define ELFDATA2MSB 2 /* 2's complement, big endian */
+
+#define EI_VERSION 6
+#define EV_CURRENT 1 /* Current version */
+
// e_type values
#define ET_NONE 0 /* no file type */
#define ET_REL 1 /* relocatable */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list