1 /* 2 * Copyright (c) 2001, 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 25 package sun.jvm.hotspot.debugger.win32.coff; 26 27 public class DumpExports { 28 private static void usage() { 29 System.err.println("usage: java DumpExports [.dll name]"); 30 System.exit(1); 31 } 32 33 public static void main(String[] args) { 34 if (args.length != 1) { 35 usage(); 36 } 37 38 String filename = args[0]; 39 COFFFile file = COFFFileParser.getParser().parse(filename); 40 41 // get common point for both things we want to dump 42 OptionalHeaderDataDirectories dataDirs = file.getHeader().getOptionalHeader(). 43 getDataDirectories(); 44 45 // dump the header data directory for the Export Table: 46 DataDirectory dir = dataDirs.getExportTable(); 47 System.out.println("Export table: RVA = " + dir.getRVA() + "/0x" + 48 Integer.toHexString(dir.getRVA()) + ", size = " + dir.getSize() + "/0x" + 49 Integer.toHexString(dir.getSize())); 50 51 System.out.println(file.getHeader().getNumberOfSections() + " sections in file"); 52 for (int i = 1; i <= file.getHeader().getNumberOfSections(); i++) { 53 SectionHeader sec = file.getHeader().getSectionHeader(i); 54 System.out.println(" Section " + i + ":"); 55 System.out.println(" Name = '" + sec.getName() + "'"); 56 System.out.println(" VirtualSize = " + sec.getSize() + "/0x" + 57 Integer.toHexString(sec.getSize())); 58 System.out.println(" VirtualAddress = " + sec.getVirtualAddress() + "/0x" + 59 Integer.toHexString(sec.getVirtualAddress())); 60 System.out.println(" SizeOfRawData = " + sec.getSizeOfRawData() + "/0x" + 61 Integer.toHexString(sec.getSizeOfRawData())); 62 System.out.println(" PointerToRawData = " + sec.getPointerToRawData() + "/0x" + 63 Integer.toHexString(sec.getPointerToRawData())); 64 } 65 66 ExportDirectoryTable exports = dataDirs.getExportDirectoryTable(); 67 if (exports == null) { 68 System.out.println("No exports found."); 69 } else { 70 System.out.println("DLL name: " + exports.getDLLName()); 71 System.out.println("Time/date stamp 0x" + Integer.toHexString(exports.getTimeDateStamp())); 72 System.out.println("Major version 0x" + Integer.toHexString(exports.getMajorVersion() & 0xFFFF)); 73 System.out.println("Minor version 0x" + Integer.toHexString(exports.getMinorVersion() & 0xFFFF)); 74 System.out.println(exports.getNumberOfNamePointers() + " exports found"); 75 for (int i = 0; i < exports.getNumberOfNamePointers(); i++) { 76 short ordinal = exports.getExportOrdinal(i); 77 System.out.print("[" + i + "] '" + exports.getExportName(i) + "': [" + 78 ordinal + "] = 0x" + Integer.toHexString(exports.getExportAddress(ordinal))); 79 System.out.println(exports.isExportAddressForwarder(ordinal) 80 ? " Forwarded to '" + exports.getExportAddressForwarder(ordinal) + "'" 81 : ""); 82 } 83 } 84 } 85 }