diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfObsoleteRecord.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfObsoleteRecord.java index d3f9698b0c..7af5fa1aa2 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfObsoleteRecord.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfObsoleteRecord.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,20 +18,23 @@ package ghidra.app.util.bin.format.omf; import java.io.IOException; import ghidra.app.util.bin.BinaryReader; -import ghidra.app.util.bin.format.omf.omf.OmfRecordTypes; import ghidra.program.model.data.DataType; import ghidra.util.exception.DuplicateNameException; public class OmfObsoleteRecord extends OmfRecord { + private Class recordTypesClass; + /** * Create a new {@link OmfObsoleteRecord} * * @param reader A {@link BinaryReader} positioned at the start of the record + * @param recordTypesClass The class that contains accessible OMF type fields * @throws IOException If an IO-related error occurred */ - public OmfObsoleteRecord(BinaryReader reader) throws IOException { + public OmfObsoleteRecord(BinaryReader reader, Class recordTypesClass) throws IOException { super(reader); + this.recordTypesClass = recordTypesClass; } @Override @@ -41,6 +44,7 @@ public class OmfObsoleteRecord extends OmfRecord { @Override public DataType toDataType() throws DuplicateNameException, IOException { - return OmfUtils.toOmfRecordDataType(this, OmfRecordTypes.getName(recordType)); + return OmfUtils.toOmfRecordDataType(this, + OmfUtils.getRecordName(recordType, recordTypesClass)); } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUnknownRecord.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUnknownRecord.java index 57c9f6040e..f487bf7a8e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUnknownRecord.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUnknownRecord.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,7 +18,6 @@ package ghidra.app.util.bin.format.omf; import java.io.IOException; import ghidra.app.util.bin.BinaryReader; -import ghidra.app.util.bin.format.omf.omf.OmfRecordTypes; import ghidra.program.model.data.DataType; import ghidra.util.exception.DuplicateNameException; @@ -27,14 +26,18 @@ import ghidra.util.exception.DuplicateNameException; */ public class OmfUnknownRecord extends OmfRecord { + private Class recordTypesClass; + /** * Create a new {@link OmfUnknownRecord} * * @param reader A {@link BinaryReader} positioned at the start of the record + * @param recordTypesClass The class that contains accessible OMF type fields * @throws IOException If an IO-related error occurred */ - public OmfUnknownRecord(BinaryReader reader) throws IOException { + public OmfUnknownRecord(BinaryReader reader, Class recordTypesClass) throws IOException { super(reader); + this.recordTypesClass = recordTypesClass; } @Override @@ -44,6 +47,7 @@ public class OmfUnknownRecord extends OmfRecord { @Override public DataType toDataType() throws DuplicateNameException, IOException { - return OmfUtils.toOmfRecordDataType(this, OmfRecordTypes.getName(recordType)); + return OmfUtils.toOmfRecordDataType(this, + OmfUtils.getRecordName(recordType, recordTypesClass)); } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUtils.java index ea1c3468f6..a93cff8ed9 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUtils.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/OmfUtils.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.stream.Stream; import ghidra.app.util.bin.BinaryReader; +import ghidra.app.util.importer.MessageLog; import ghidra.program.model.data.*; /** @@ -126,19 +127,29 @@ public class OmfUtils { * {@link AbstractOmfRecordFactory} * * @param factory The {@link AbstractOmfRecordFactory} + * @param log The log * @return A {@link List} of read {@link OmfRecord records} * @throws IOException if there was an IO-related error * @throws OmfException if there was a problem with the OMF specification */ - public static List readRecords(AbstractOmfRecordFactory factory) + public static List readRecords(AbstractOmfRecordFactory factory, MessageLog log) throws OmfException, IOException { List records = new ArrayList<>(); factory.reset(); while (true) { - OmfRecord rec = factory.readNextRecord(); - records.add(rec); - if (rec.getRecordType() == factory.getEndRecordType()) { + try { + OmfRecord rec = factory.readNextRecord(); + if (!rec.validCheckSum()) { + log.appendMsg("OMF record [%s] has an invalid checksum".formatted(rec)); + } + records.add(rec); + if (rec.getRecordType() == factory.getEndRecordType()) { + break; + } + } + catch (IOException e) { + log.appendException(e); break; } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf/OmfRecordFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf/OmfRecordFactory.java index 83d2a9c21d..3feb08e926 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf/OmfRecordFactory.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf/OmfRecordFactory.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -91,7 +91,7 @@ public class OmfRecordFactory extends AbstractOmfRecordFactory { case LIBNAM: case LIBLOC: case LIBDIC: - yield new OmfObsoleteRecord(reader); + yield new OmfObsoleteRecord(reader, OmfRecordTypes.class); case LOCSYM: case TYPDEF: case COMDAT: @@ -104,7 +104,7 @@ public class OmfRecordFactory extends AbstractOmfRecordFactory { case VENDEXT: yield new OmfUnsupportedRecord(reader, OmfRecordTypes.class); default: - yield new OmfUnknownRecord(reader); + yield new OmfUnknownRecord(reader, OmfRecordTypes.class); }; record.parseData(); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf51/Omf51RecordFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf51/Omf51RecordFactory.java index b8efb24aa3..ab4abd3d0a 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf51/Omf51RecordFactory.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/omf/omf51/Omf51RecordFactory.java @@ -82,7 +82,7 @@ public class Omf51RecordFactory extends AbstractOmfRecordFactory { case DebugItem: yield new OmfUnsupportedRecord(reader, Omf51RecordTypes.class); default: - yield new OmfUnknownRecord(reader); + yield new OmfUnknownRecord(reader, Omf51RecordTypes.class); }; record.parseData(); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/Omf51Loader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/Omf51Loader.java index c7cdf19171..107136e35d 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/Omf51Loader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/Omf51Loader.java @@ -82,7 +82,7 @@ public class Omf51Loader extends AbstractProgramWrapperLoader { MemoryBlockUtils.createFileBytes(program, settings.provider(), monitor); AbstractOmfRecordFactory factory = new Omf51RecordFactory(settings.provider()); try { - List records = OmfUtils.readRecords(factory); + List records = OmfUtils.readRecords(factory, settings.log()); Map segmentToAddr = processMemoryBlocks(program, fileBytes, records, log, monitor); Map extIdToAddr =