Skip to content

Commit

Permalink
Fix for parsing non-existant ExportOrdinalTable like in Petna sample
Browse files Browse the repository at this point in the history
  • Loading branch information
struppigel committed Jul 5, 2017
1 parent 5e637f8 commit 7c0c0ec
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/github/katjahahn/parser/PELoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.Reporter;

import com.github.katjahahn.parser.coffheader.COFFFileHeader;
import com.github.katjahahn.parser.msdos.MSDOSHeader;
import com.github.katjahahn.parser.optheader.OptionalHeader;
import com.github.katjahahn.parser.optheader.WindowsEntryKey;
import com.github.katjahahn.parser.sections.SectionLoader;
import com.github.katjahahn.parser.sections.SectionTable;
import com.github.katjahahn.tools.DiffReportCreator;
import com.github.katjahahn.tools.ReportCreator;
Expand Down Expand Up @@ -286,9 +288,10 @@ private OptionalHeader loadOptionalHeader(PESignature pesig,
public static void main(String[] args) throws IOException, AWTException {
logger.entry();

File file = new File("/home/katja/samples/corruptedPortex");
ReportCreator reporter = ReportCreator.newInstance(file);
System.out.println(reporter.resourcesReport());
File file = new File("/home/katja/samples/petna");
ReportCreator r = ReportCreator.newInstance(file);
System.out.println(r.exportsReport());

// File file2 = new File("/home/katja/samples/tesla2");
// List<File> list = new ArrayList<>();
// list.add(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.github.katjahahn.parser.MemoryMappedPE
import ExportOrdinalTable.entrySize
import com.github.katjahahn.parser.FileFormatException

class ExportOrdinalTable private (
class ExportOrdinalTable (
val ordinals: List[Int],
val base: Int,
val fileOffset: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,10 @@ object ExportSection {
val rva = edataTable(ORDINAL_TABLE_RVA)
val entries = edataTable(NR_OF_NAME_POINTERS)
val ordTableFileOffset = edataOffset + rva - virtualAddress
if(ordTableFileOffset <= 0) {
throw new FileFormatException("Offset for ordinal export entries invalid!");
if(ordTableFileOffset <= 0 || entries < 0) {
// create empty ExportOrdinalTable
return new ExportOrdinalTable(List.empty[Int], base.toInt, 0L)
}
if(entries < 0) {
throw new FileFormatException("Number of name pointer entries is < 0!");
}
ExportOrdinalTable(mmBytes, base.toInt, rva, entries.toInt, virtualAddress, ordTableFileOffset)
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/katjahahn/tools/PortExAnalyzer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import java.awt.Color
*/
object PortExAnalyzer {

private val version = """version: 0.6.6
private val version = """version: 0.6.7
|author: Karsten Hahn
|last update: 10. Mai 2017""".stripMargin
|last update: 05. July 2017""".stripMargin

private val title = """PortEx Analyzer""" + NL

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/github/katjahahn/tools/ReportCreator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,13 @@ class ReportCreator(private val data: PEData) {
val loader = new SectionLoader(data)
val maybeExports = loader.maybeLoadExportSection()
if (maybeExports.isPresent && !maybeExports.get.isEmpty) {
println("not empty")
val edata = maybeExports.get
val buf = new StringBuffer()
buf.append(title("Exports") + NL)
val exports = edata.getExportEntries.asScala
println("retrieving export entry")
for (export <- exports) {
buf.append(export + NL)
}
println("exports done")
buf.toString + NL
} else ""
}
Expand Down

0 comments on commit 7c0c0ec

Please sign in to comment.