mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GP-1024 fix "Extract and Import" to not produce tmp files with bad names
Temp files were named using memory block name and string rep of the min and max address, which would cause problems if address representation contained a ":" (seg:offset) and the user was on a windows platform.
This commit is contained in:
parent
54bbbcf44b
commit
eb24c51b51
5 changed files with 52 additions and 14 deletions
|
@ -125,6 +125,9 @@ public class MemoryByteProvider implements ByteProvider {
|
|||
}
|
||||
return bytes;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ public class FileSystemService {
|
|||
* @return true if local, false if the path points to an embedded file in a container.
|
||||
*/
|
||||
public boolean isLocal(FSRL fsrl) {
|
||||
return fsrl.getFS().hasContainer() == false;
|
||||
return localFS.isSameFS(fsrl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -519,6 +519,25 @@ public class FileSystemService {
|
|||
return fileCache.createCacheEntryBuilder(sizeHint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link ByteProvider} for the specified {@link FileCacheEntry}, using the
|
||||
* specified filename.
|
||||
* <p>
|
||||
* The returned ByteProvider's FSRL will be decorative and does not allow returning to
|
||||
* the same ByteProvider at a later time.
|
||||
*
|
||||
* @param tempFileCacheEntry {@link FileCacheEntry} (returned by {@link #createTempFile(long)})
|
||||
* @param name desired name
|
||||
* @return new {@link ByteProvider} with decorative {@link FSRL}
|
||||
* @throws IOException if io error
|
||||
*/
|
||||
public ByteProvider getNamedTempFile(FileCacheEntry tempFileCacheEntry, String name)
|
||||
throws IOException {
|
||||
FSRL resultFSRL = FSRLRoot.makeRoot("tmp")
|
||||
.withPathMD5(FSUtilities.appendPath("/", name), tempFileCacheEntry.getMD5());
|
||||
return tempFileCacheEntry.asByteProvider(resultFSRL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the resources used by caching the specified file to be released.
|
||||
*
|
||||
|
|
|
@ -65,7 +65,7 @@ public class LocalFileSystem implements GFileSystem, GFileHashProvider {
|
|||
this.fsFSRL = fsrl;
|
||||
}
|
||||
|
||||
private boolean isSameFS(FSRL fsrl) {
|
||||
boolean isSameFS(FSRL fsrl) {
|
||||
return fsFSRL.equals(fsrl.getFS());
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ package ghidra.plugin.importer;
|
|||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import docking.ActionContext;
|
||||
|
@ -29,8 +30,13 @@ import ghidra.app.context.ListingActionContext;
|
|||
import ghidra.app.events.ProgramActivatedPluginEvent;
|
||||
import ghidra.app.plugin.PluginCategoryNames;
|
||||
import ghidra.app.services.*;
|
||||
import ghidra.app.util.bin.ByteProvider;
|
||||
import ghidra.app.util.importer.LibrarySearchPathManager;
|
||||
import ghidra.app.util.opinion.LoaderMap;
|
||||
import ghidra.app.util.opinion.LoaderService;
|
||||
import ghidra.formats.gfilesystem.FSRL;
|
||||
import ghidra.formats.gfilesystem.FileCache.FileCacheEntry;
|
||||
import ghidra.formats.gfilesystem.FileCache.FileCacheEntryBuilder;
|
||||
import ghidra.formats.gfilesystem.FileSystemService;
|
||||
import ghidra.framework.main.*;
|
||||
import ghidra.framework.main.datatree.DomainFolderNode;
|
||||
|
@ -385,20 +391,30 @@ public class ImporterPlugin extends Plugin
|
|||
return;
|
||||
}
|
||||
|
||||
Memory memory = program.getMemory();
|
||||
MemoryBlock block = memory.getBlock(range.getMinAddress());
|
||||
String tempFileName =
|
||||
block.getName() + "_[" + range.getMinAddress() + "," + range.getMaxAddress() + "]_";
|
||||
try {
|
||||
File tempFile = File.createTempFile(tempFileName, ".tmp");
|
||||
try (OutputStream outputStream = new FileOutputStream(tempFile)) {
|
||||
Memory memory = program.getMemory();
|
||||
FileSystemService fsService = FileSystemService.getInstance();
|
||||
|
||||
// create a tmp ByteProvider that contains the bytes from the selected region
|
||||
FileCacheEntry tmpFile;
|
||||
try (FileCacheEntryBuilder tmpFileBuilder =
|
||||
fsService.createTempFile(range.getLength())) {
|
||||
byte[] bytes = new byte[(int) range.getLength()];
|
||||
memory.getBytes(range.getMinAddress(), bytes);
|
||||
outputStream.write(bytes);
|
||||
tmpFileBuilder.write(bytes);
|
||||
tmpFile = tmpFileBuilder.finish();
|
||||
}
|
||||
|
||||
DomainFolder folder = AppInfo.getActiveProject().getProjectData().getRootFolder();
|
||||
importFile(folder, tempFile);
|
||||
MemoryBlock block = memory.getBlock(range.getMinAddress());
|
||||
String rangeName =
|
||||
block.getName() + "[" + range.getMinAddress() + "," + range.getMaxAddress() + "]";
|
||||
ByteProvider bp =
|
||||
fsService.getNamedTempFile(tmpFile, program.getName() + " " + rangeName);
|
||||
LoaderMap loaderMap = LoaderService.getAllSupportedLoadSpecs(bp);
|
||||
|
||||
ImporterDialog importerDialog =
|
||||
new ImporterDialog(tool, programManager, loaderMap, bp, null);
|
||||
tool.showDialog(importerDialog);
|
||||
}
|
||||
catch (IOException e) {
|
||||
Msg.showError(this, null, "I/O Error Occurred", e.getMessage(), e);
|
||||
|
|
|
@ -462,9 +462,9 @@ public interface Memory extends AddressSetView {
|
|||
* @param destIndex the offset into dest to place the bytes.
|
||||
* @param size the number of bytes to get.
|
||||
* @return the number of bytes put into dest. May be less than
|
||||
* size if the requested number extends beyond available memory.
|
||||
* size if the requested number extends beyond initialized / available memory.
|
||||
* @throws MemoryAccessException if the starting address is
|
||||
* not contained in any memory block.
|
||||
* not contained in any memory block or is an uninitialized location.
|
||||
*/
|
||||
public int getBytes(Address addr, byte[] dest, int destIndex, int size)
|
||||
throws MemoryAccessException;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue