1/* 2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25package sun.jvm.hotspot.debugger.win32.coff; 26 27public class TestParser { 28 public static void main(String[] args) { 29 if (args.length != 1) { 30 System.err.println("usage: java TestParser [file name]"); 31 System.err.println("File name may be an .exe, .dll or .obj"); 32 System.exit(1); 33 } 34 35 try { 36 COFFFile file = COFFFileParser.getParser().parse(args[0]); 37 if (file.isImage()) { 38 System.out.println("PE Image detected."); 39 } else { 40 System.out.println("PE Image NOT detected, assuming object file."); 41 } 42 COFFHeader header = file.getHeader(); 43 int numSections = header.getNumberOfSections(); 44 System.out.println(numSections + " sections detected."); 45 for (int i = 1; i <= numSections; i++) { 46 SectionHeader secHeader = header.getSectionHeader(i); 47 System.out.println(secHeader.getName()); 48 } 49 50 // FIXME: the DLL exports are not contained in the COFF symbol 51 // table. Instead, they are in the Export Table, one of the 52 // Optional Header Data Directories available from the Optional 53 // Header. Must implement that next. 54 55 /* 56 int numSymbols = header.getNumberOfSymbols(); 57 System.out.println(numSymbols + " symbols detected."); 58 System.out.println("Symbol dump:"); 59 for (int i = 0; i < header.getNumberOfSymbols(); i++) { 60 COFFSymbol sym = header.getCOFFSymbol(i); 61 System.out.println(" " + sym.getName()); 62 } 63 */ 64 65 // OK, let's give the exported symbols a shot 66 OptionalHeader optHdr = header.getOptionalHeader(); 67 OptionalHeaderDataDirectories ddirs = optHdr.getDataDirectories(); 68 ExportDirectoryTable exports = ddirs.getExportDirectoryTable(); 69 System.out.println("Export flags (should be 0): " + exports.getExportFlags()); 70 System.out.println("DLL name (from export directory table): " + 71 exports.getDLLName()); 72 int numSymbols = exports.getNumberOfNamePointers(); 73 System.out.println(numSymbols + " exported symbols detected:"); 74 for (int i = 0; i < numSymbols; i++) { 75 System.out.println(" " + exports.getExportName(i)); 76 } 77 } catch (Exception e) { 78 e.printStackTrace(); 79 } 80 } 81} 82