From 8e86135a3414d2fbb1fad64da6885c831a67107b Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Thu, 13 Apr 2023 19:16:35 +0100 Subject: [PATCH] Add GNU PE64 binary parser for MinGW GCC toolchain Part of #361 --- .../META-INF/MANIFEST.MF | 2 +- .../schema/ManagedBuildTools.exsd | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../plugin.xml | 2 +- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- core/org.eclipse.cdt.core/plugin.properties | 1 + core/org.eclipse.cdt.core/plugin.xml | 10 +++ .../coff/parser/GNUPEBinaryArchive64.java | 40 ++++++++++ .../coff/parser/GNUPEBinaryExecutable64.java | 30 ++++++++ .../coff/parser/GNUPEBinaryObject64.java | 65 +++++++++++++++++ .../coff/parser/GNUPEBinaryShared64.java | 30 ++++++++ .../cdt/utils/coff/parser/GNUPEParser64.java | 73 +++++++++++++++++++ 12 files changed, 254 insertions(+), 5 deletions(-) create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryArchive64.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryExecutable64.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryObject64.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryShared64.java create mode 100644 core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEParser64.java diff --git a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF index 658b91a6297..b03bcd50a0a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.core; singleton:=true -Bundle-Version: 9.5.0.qualifier +Bundle-Version: 9.5.100.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/ManagedBuildTools.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/ManagedBuildTools.exsd index ae7409bbe1d..0f52be5c6fc 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/ManagedBuildTools.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/ManagedBuildTools.exsd @@ -514,7 +514,7 @@ Additional special types exist to flag options of special relevance to the build - Set this to the ID of the binary parser for the output format of your target. Currently there are only 2 choices: org.eclipse.cdt.core.ELF for *nix targets, and "org.eclipse.cdt.core.PE64" for targets that build for Windows, like Cygwin. + Set this to the ID of the binary parser for the output format of your target. Currently there are ELF parsers for *nix and many embedded targets, and PE64 parsers for Windows targets. Alternative versions of these parsers provide additional capabilities for GNU toolchains only. diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF index c8ed22135cd..b1ba548d3bb 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.gnu.ui; singleton:=true -Bundle-Version: 8.5.0.qualifier +Bundle-Version: 8.5.100.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml index 345b44f4a0c..b2f7a94ff49 100644 --- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml @@ -2388,7 +2388,7 @@ diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index be1c6d64c08..ca6823a44b9 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 8.1.100.qualifier +Bundle-Version: 8.2.0.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties index b19f168c1a8..696efa230de 100644 --- a/core/org.eclipse.cdt.core/plugin.properties +++ b/core/org.eclipse.cdt.core/plugin.properties @@ -45,6 +45,7 @@ ElfParser.name=Elf Parser GNUElfParser.name=GNU Elf Parser PEWindowsParser.name=PE Windows Parser (Deprecated) PE64WindowsParser.name=PE64 Windows Parser +GNUPE64WindowsParser.name=GNU PE64 Windows Parser CygwinPEParser.name=Cygwin PE Parser (Deprecated) CygwinPE64Parser.name=Cygwin PE64 Parser XCOFF32Parser.name=AIX XCOFF32 Parser diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 278bc5c8f0a..2d752bec2cc 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -72,6 +72,16 @@ + + + + + + children2) { + for (int i = 0; i < headers.length; i++) { + IBinaryObject bin = new GNUPEBinaryObject64(getBinaryParser(), getPath(), headers[i]); + children.add(bin); + } + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryExecutable64.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryExecutable64.java new file mode 100644 index 00000000000..ae957fe132f --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryExecutable64.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004, 2023 Space Codesign Systems and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Space Codesign Systems - Initial API and implementation + * QNX Software Systems - Initial CygwinPEBinaryExecutable class + * John Dallaway - Initial GNUPEBinaryExecutable64 class (#361) + *******************************************************************************/ +package org.eclipse.cdt.utils.coff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.core.runtime.IPath; + +/** @since 8.2 */ +public class GNUPEBinaryExecutable64 extends GNUPEBinaryObject64 implements IBinaryExecutable { + + public GNUPEBinaryExecutable64(IBinaryParser parser, IPath path, int executable) { + super(parser, path, IBinaryFile.EXECUTABLE); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryObject64.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryObject64.java new file mode 100644 index 00000000000..d1112e05f72 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryObject64.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 2023 Space Codesign Systems and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Space Codesign Systems - Initial API and implementation + * QNX Software Systems - Initial CygwinPEBinaryObject class + * John Dallaway - Initial GNUPEBinaryObject64 class (#361) + *******************************************************************************/ +package org.eclipse.cdt.utils.coff.parser; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.utils.AR.ARHeader; +import org.eclipse.cdt.utils.IGnuToolFactory; +import org.eclipse.cdt.utils.Objdump; +import org.eclipse.core.runtime.IPath; + +/** @since 8.2 */ +public class GNUPEBinaryObject64 extends PEBinaryObject64 { + + public GNUPEBinaryObject64(IBinaryParser parser, IPath path, ARHeader header) { + super(parser, path, header); + } + + public GNUPEBinaryObject64(IBinaryParser parser, IPath path, int type) { + super(parser, path, type); + } + + @Override + public InputStream getContents() throws IOException { + InputStream stream = null; + Objdump objdump = getObjdump(); + if (objdump != null) { + try { + byte[] contents = objdump.getOutput(); + stream = new ByteArrayInputStream(contents); + } catch (IOException e) { + // Nothing + } + } + if (stream == null) { + stream = super.getContents(); + } + return stream; + } + + protected Objdump getObjdump() { + IGnuToolFactory factory = getBinaryParser().getAdapter(IGnuToolFactory.class); + if (factory != null) { + return factory.getObjdump(getPath()); + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryShared64.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryShared64.java new file mode 100644 index 00000000000..4a8be641328 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryShared64.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2004, 2023 Space Codesign Systems and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Space Codesign Systems - Initial API and implementation + * QNX Software Systems - Initial CygwinPEBinaryShared class + * John Dallaway - Initial GNUPEBinaryShared64 class (#361) + *******************************************************************************/ +package org.eclipse.cdt.utils.coff.parser; + +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; +import org.eclipse.core.runtime.IPath; + +/** @since 8.2 */ +public class GNUPEBinaryShared64 extends GNUPEBinaryObject64 implements IBinaryShared { + + protected GNUPEBinaryShared64(IBinaryParser parser, IPath path) { + super(parser, path, IBinaryFile.SHARED); + } + +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEParser64.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEParser64.java new file mode 100644 index 00000000000..bbcfba7793e --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEParser64.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2000, 2023 Space Codesign Systems and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Space Codesign Systems - Initial API and implementation + * QNX Software Systems - Initial CygwinPEParser class + * John Dallaway - Initial GNUPEParser64 class (#361) + *******************************************************************************/ +package org.eclipse.cdt.utils.coff.parser; + +import java.io.IOException; + +import org.eclipse.cdt.utils.DefaultGnuToolFactory; +import org.eclipse.cdt.utils.IGnuToolFactory; +import org.eclipse.core.runtime.IPath; + +/** @since 8.2 */ +public class GNUPEParser64 extends PEParser64 { + + private IGnuToolFactory toolFactory; + + @Override + public String getFormat() { + return "GNU PE"; //$NON-NLS-1$ + } + + @Override + protected IBinaryArchive createBinaryArchive(IPath path) throws IOException { + return new GNUPEBinaryArchive64(this, path); + } + + @Override + protected IBinaryExecutable createBinaryExecutable(IPath path) { + return new GNUPEBinaryExecutable64(this, path, IBinaryFile.EXECUTABLE); + } + + @Override + protected IBinaryObject createBinaryCore(IPath path) { + return new GNUPEBinaryObject64(this, path, IBinaryFile.CORE); + } + + @Override + protected IBinaryObject createBinaryObject(IPath path) { + return new GNUPEBinaryObject64(this, path, IBinaryFile.OBJECT); + } + + @Override + protected IBinaryShared createBinaryShared(IPath path) { + return new GNUPEBinaryShared64(this, path); + } + + protected IGnuToolFactory createToolFactory() { + return new DefaultGnuToolFactory(this); + } + + @Override + public T getAdapter(Class adapter) { + if (adapter.isAssignableFrom(IGnuToolFactory.class)) { + if (toolFactory == null) { + toolFactory = createToolFactory(); + } + return adapter.cast(toolFactory); + } + return super.getAdapter(adapter); + } +}