forked from eclipse-cdt/cdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GNU PE64 binary parser for MinGW GCC toolchain
Part of eclipse-cdt#361
- Loading branch information
Showing
10 changed files
with
252 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryArchive64.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* 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 CygwinPEBinaryArchive class | ||
* John Dallaway - Initial GNUPEBinaryArchive64 class (#361) | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.utils.coff.parser; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; | ||
import org.eclipse.cdt.utils.AR.ARHeader; | ||
import org.eclipse.core.runtime.IPath; | ||
|
||
/** @since 8.2 */ | ||
public class GNUPEBinaryArchive64 extends PEBinaryArchive64 { | ||
|
||
public GNUPEBinaryArchive64(PEParser64 parser, IPath path) throws IOException { | ||
super(parser, path); | ||
} | ||
|
||
@Override | ||
protected void addArchiveMembers(ARHeader[] headers, ArrayList<IBinaryObject> children2) { | ||
for (int i = 0; i < headers.length; i++) { | ||
IBinaryObject bin = new GNUPEBinaryObject64(getBinaryParser(), getPath(), headers[i]); | ||
children.add(bin); | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryExecutable64.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryObject64.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEBinaryShared64.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/parser/GNUPEParser64.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 DefaultGnuToolFactory 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 DefaultGnuToolFactory createToolFactory() { | ||
return new DefaultGnuToolFactory(this); | ||
} | ||
|
||
@Override | ||
public <T> T getAdapter(Class<T> adapter) { | ||
if (adapter.isAssignableFrom(IGnuToolFactory.class)) { | ||
if (toolFactory == null) { | ||
toolFactory = createToolFactory(); | ||
} | ||
return adapter.cast(toolFactory); | ||
} | ||
return super.getAdapter(adapter); | ||
} | ||
} |