diff --git a/Ghidra/Features/Base/src/main/help/help/topics/ExporterPlugin/exporter.htm b/Ghidra/Features/Base/src/main/help/help/topics/ExporterPlugin/exporter.htm index 4a8ff89bdd..78f8e89da5 100644 --- a/Ghidra/Features/Base/src/main/help/help/topics/ExporterPlugin/exporter.htm +++ b/Ghidra/Features/Base/src/main/help/help/topics/ExporterPlugin/exporter.htm @@ -22,15 +22,17 @@ @@ -238,17 +240,6 @@ -

Binary

- -
-

Creates a binary file containing only the bytes from each memory block in the program. - If the program was originally created using the Binary Importer, then this - exporter allows recreation of the original file.

- -

Only initialized memory blocks - are included in the output file.

-
-

C/C++

@@ -284,22 +275,8 @@
- -

ELF

-
-

Writes an ELF program that was imported with the ELF loader back to its original file - layout. Any file-backed bytes that were modified by the user in the program database will - be reflected in the new file.

- -

Writing back a modified Memory - Map is not supported.

- -

Relocation bytes are always - restored to their original values, even if the user modifies them.

-
- -

Ghidra Zip File (.gzf)

+

Ghidra Zip File (.gzf)

Creates a zip file from a program in your project. You may want to create a zip file @@ -321,7 +298,7 @@ the ASCII Options.

-

Intel Hex

+

Intel Hex

The Intel Hex format, a printable file representing memory images, was originally @@ -345,18 +322,57 @@

-

PE

+

Original File

-

Writes a PE program that was imported with the PE loader back to its original file - layout. Any file-backed bytes that were modified by the user in the program database will - be reflected in the new file.

+

Writes a program back to its original file layout. By default, any file-backed bytes + that were modified by the user in the program database will be reflected in the new file. + Optionally, the program can be written back to its unmodified file bytes, discarding all + user modifications. +

+ +

Original File Options

+ + + + +

This exporter is only + operational when the program has at least one file-backed byte source. This will be + reflected in the Memory Map's + Byte Source column, which entries that begin with File:

Writing back a modified Memory Map is not supported.

Relocation bytes are always restored to their original values, even if the user modifies them.

+ +

Programs written to disk with + this exporter may be runnable on your native platform. Use caution when exporting + potentially malicious programs.

+
+ +

Raw Bytes

+ +
+

Creates a binary file containing only the raw bytes from each memory block in the + program. If there are multiple memory blocks, their bytes will be concatenated in the + exported binary file. If the program was originally created using the Binary + Importer and there is only one memory block, then this exporter allows recreation of + the original file.

+ +

Only initialized memory blocks + are included in the output file.

XML

diff --git a/Ghidra/Features/Base/src/main/help/help/topics/MemoryMapPlugin/Memory_Map.htm b/Ghidra/Features/Base/src/main/help/help/topics/MemoryMapPlugin/Memory_Map.htm index 14bc73febb..4b68fc957e 100644 --- a/Ghidra/Features/Base/src/main/help/help/topics/MemoryMapPlugin/Memory_Map.htm +++ b/Ghidra/Features/Base/src/main/help/help/topics/MemoryMapPlugin/Memory_Map.htm @@ -116,7 +116,7 @@ block. If the bytes were originally imported from a file, then this will indicate which file and the offset into that file. If the bytes are mapped to another region of memory, it will provide the address for the mapping. Blocks may consist of regions that have different - sources. In that case, source information about the first several regions will be d + sources. In that case, source information about the first several regions will be displayed.

Source - Description of block origination.

diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/AbstractLoaderExporter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/AbstractLoaderExporter.java deleted file mode 100644 index 3bb1c77102..0000000000 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/exporter/AbstractLoaderExporter.java +++ /dev/null @@ -1,169 +0,0 @@ -/* ### - * IP: GHIDRA - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ghidra.app.util.exporter; - -import java.io.*; -import java.nio.file.*; -import java.util.List; - -import ghidra.app.util.DomainObjectService; -import ghidra.app.util.Option; -import ghidra.app.util.opinion.Loader; -import ghidra.framework.model.DomainObject; -import ghidra.program.database.mem.AddressSourceInfo; -import ghidra.program.database.mem.FileBytes; -import ghidra.program.model.address.Address; -import ghidra.program.model.address.AddressSetView; -import ghidra.program.model.listing.Program; -import ghidra.program.model.mem.Memory; -import ghidra.program.model.mem.MemoryBlockSourceInfo; -import ghidra.program.model.reloc.Relocation; -import ghidra.util.Conv; -import ghidra.util.HelpLocation; -import ghidra.util.task.TaskMonitor; -import utilities.util.FileUtilities; - -/** - * An {@link Exporter} that can export programs imported with a particular {@link Loader} - */ -public abstract class AbstractLoaderExporter extends Exporter { - - /** - * Creates a new {@link AbstractLoaderExporter} - * - * @param name The display name of this exporter - * @param help The {@link HelpLocation} for this exporter - */ - protected AbstractLoaderExporter(String name, HelpLocation help) { - super(name, "", help); - } - - /** - * Checks to see if the given file format is supported by this exporter - * - * @param fileFormat The file format (loader name) of the program to export - * @return True if the given file format is supported by this exporter; otherwise, false - */ - protected abstract boolean supportsFileFormat(String fileFormat); - - @Override - public boolean export(File file, DomainObject domainObj, AddressSetView addrSet, - TaskMonitor monitor) throws IOException, ExporterException { - - if (!(domainObj instanceof Program)) { - log.appendMsg("Unsupported type: " + domainObj.getClass().getSimpleName()); - return false; - } - - Program program = (Program) domainObj; - Memory memory = program.getMemory(); - - String fileFormat = program.getExecutableFormat(); - if (!supportsFileFormat(fileFormat)) { - log.appendMsg("Unsupported file format: " + fileFormat); - return false; - } - - List fileBytes = memory.getAllFileBytes(); - if (fileBytes.isEmpty()) { - log.appendMsg("Exporting a program with no file source bytes is not supported"); - return false; - } - if (fileBytes.size() > 1) { - log.appendMsg("Exporting a program with more than 1 file source is not supported"); - return false; - } - - // Write source program's file bytes to a temp file - File tempFile = File.createTempFile("ghidra_export_", null); - try (OutputStream out = new FileOutputStream(tempFile, false)) { - FileUtilities.copyStreamToStream(new FileBytesInputStream(fileBytes.get(0)), out, - monitor); - } - - // Undo relocations in the temp file - // NOTE: not all relocations are file-backed, and some are only partially file-backed - try (RandomAccessFile fout = new RandomAccessFile(tempFile, "rw")) { - Iterable relocs = () -> program.getRelocationTable().getRelocations(); - for (Relocation reloc : relocs) { - Address addr = reloc.getAddress(); - AddressSourceInfo addrSourceInfo = memory.getAddressSourceInfo(addr); - if (addrSourceInfo == null) { - continue; - } - long offset = addrSourceInfo.getFileOffset(); - if (offset >= 0) { - MemoryBlockSourceInfo memSourceInfo = addrSourceInfo.getMemoryBlockSourceInfo(); - byte[] bytes = reloc.getBytes(); - int len = Math.min(bytes.length, - (int) memSourceInfo.getMaxAddress().subtract(addr) + 1); - fout.seek(offset); - fout.write(bytes, 0, len); - } - } - } - catch (Exception e) { - if (!tempFile.delete()) { - log.appendMsg("Failed to delete malformed file: " + tempFile); - } - return false; - } - - // Move temp file to desired output file - Path from = Paths.get(tempFile.toURI()); - Path to = Paths.get(file.toURI()); - Files.move(from, to, StandardCopyOption.REPLACE_EXISTING); - return true; - } - - @Override - public List