mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-02 07:00:38 +08:00
GP-3586 corrected inappropriate ELF Header warniing for non-ELF binary
import
This commit is contained in:
@@ -15,11 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.app.util.bin.format.elf;
|
package ghidra.app.util.bin.format.elf;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import ghidra.app.util.bin.*;
|
import ghidra.app.util.bin.*;
|
||||||
import ghidra.app.util.bin.format.elf.ElfRelocationTable.TableFormat;
|
import ghidra.app.util.bin.format.elf.ElfRelocationTable.TableFormat;
|
||||||
import ghidra.app.util.bin.format.elf.extend.ElfExtensionFactory;
|
import ghidra.app.util.bin.format.elf.extend.ElfExtensionFactory;
|
||||||
@@ -136,21 +135,19 @@ public class ElfHeader implements StructConverter {
|
|||||||
protected void initElfHeader() throws ElfException {
|
protected void initElfHeader() throws ElfException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (!Arrays.equals(ElfConstants.MAGIC_BYTES,
|
||||||
|
provider.readBytes(0, ElfConstants.MAGIC_BYTES.length))) {
|
||||||
|
throw new ElfException("Not a valid ELF executable.");
|
||||||
|
}
|
||||||
|
e_ident_magic_num = ElfConstants.MAGIC_NUM;
|
||||||
|
e_ident_magic_str = ElfConstants.MAGIC_STR;
|
||||||
|
|
||||||
determineHeaderEndianess();
|
determineHeaderEndianess();
|
||||||
|
|
||||||
// reader uses unbounded provider wrapper to allow handling of missing/truncated headers
|
// reader uses unbounded provider wrapper to allow handling of missing/truncated headers
|
||||||
reader = new BinaryReader(new UnlimitedByteProviderWrapper(provider),
|
reader = new BinaryReader(new UnlimitedByteProviderWrapper(provider),
|
||||||
hasLittleEndianHeaders);
|
hasLittleEndianHeaders);
|
||||||
|
reader.setPointerIndex(ElfConstants.MAGIC_BYTES.length);
|
||||||
e_ident_magic_num = reader.readNextByte();
|
|
||||||
e_ident_magic_str = reader.readNextAsciiString(ElfConstants.MAGIC_STR_LEN);
|
|
||||||
|
|
||||||
boolean magicMatch = ElfConstants.MAGIC_NUM == e_ident_magic_num &&
|
|
||||||
ElfConstants.MAGIC_STR.equalsIgnoreCase(e_ident_magic_str);
|
|
||||||
|
|
||||||
if (!magicMatch) {
|
|
||||||
throw new ElfException("Not a valid ELF executable.");
|
|
||||||
}
|
|
||||||
|
|
||||||
e_ident_class = reader.readNextByte();
|
e_ident_class = reader.readNextByte();
|
||||||
e_ident_data = reader.readNextByte();
|
e_ident_data = reader.readNextByte();
|
||||||
|
|||||||
Reference in New Issue
Block a user