mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-3064 fixing importing to be cancellable
This commit is contained in:
parent
70757b658e
commit
33c5feac44
22 changed files with 279 additions and 252 deletions
|
@ -108,8 +108,6 @@ public class MemoryBlockUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new bit mapped memory block. (A bit mapped block is a block where each byte value
|
||||
* is either 1 or 0 and the value is taken from a bit in a byte at some other address in memory)
|
||||
|
@ -279,12 +277,12 @@ public class MemoryBlockUtils {
|
|||
MemoryBlock block;
|
||||
try {
|
||||
try {
|
||||
block = memory.createInitializedBlock(name, start, dataInput, dataLength,
|
||||
monitor, isOverlay);
|
||||
block = memory.createInitializedBlock(name, start, dataInput, dataLength, monitor,
|
||||
isOverlay);
|
||||
}
|
||||
catch (MemoryConflictException e) {
|
||||
block = memory.createInitializedBlock(name, start, dataInput, dataLength,
|
||||
monitor, true);
|
||||
block = memory.createInitializedBlock(name, start, dataInput, dataLength, monitor,
|
||||
true);
|
||||
}
|
||||
}
|
||||
catch (LockException | DuplicateNameException | MemoryConflictException e) {
|
||||
|
@ -325,11 +323,12 @@ public class MemoryBlockUtils {
|
|||
* @param program the program in which to create a new FileBytes object
|
||||
* @param provider the ByteProvider from which to get the bytes.
|
||||
* @return the newly created FileBytes object.
|
||||
* @param monitor the monitor for canceling this potentially long running operation.
|
||||
* @throws IOException if an IOException occurred.
|
||||
*/
|
||||
public static FileBytes createFileBytes(Program program, ByteProvider provider)
|
||||
throws IOException {
|
||||
return createFileBytes(program, provider, 0, provider.length());
|
||||
public static FileBytes createFileBytes(Program program, ByteProvider provider,
|
||||
TaskMonitor monitor) throws IOException, CancelledException {
|
||||
return createFileBytes(program, provider, 0, provider.length(), monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,14 +337,16 @@ public class MemoryBlockUtils {
|
|||
* @param provider the ByteProvider from which to get the bytes.
|
||||
* @param offset the offset into the ByteProvider from which to start loading bytes.
|
||||
* @param length the number of bytes to load
|
||||
* @param monitor the monitor for canceling this potentially long running operation.
|
||||
* @return the newly created FileBytes object.
|
||||
* @throws IOException if an IOException occurred.
|
||||
* @throws CancelledException if the user cancelled the operation
|
||||
*/
|
||||
public static FileBytes createFileBytes(Program program, ByteProvider provider, long offset,
|
||||
long length) throws IOException {
|
||||
long length, TaskMonitor monitor) throws IOException, CancelledException {
|
||||
Memory memory = program.getMemory();
|
||||
try (InputStream fis = provider.getInputStream(offset)) {
|
||||
return memory.createFileBytes(provider.getName(), offset, length, fis);
|
||||
return memory.createFileBytes(provider.getName(), offset, length, fis, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ public class BinaryLoader extends AbstractProgramLoader {
|
|||
@Override
|
||||
protected boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec,
|
||||
List<Option> options, MessageLog log, Program prog, TaskMonitor monitor)
|
||||
throws IOException {
|
||||
throws IOException, CancelledException {
|
||||
long length = getLength(options);
|
||||
//File file = provider.getFile();
|
||||
long fileOffset = getFileOffset(options);
|
||||
|
@ -312,7 +312,8 @@ public class BinaryLoader extends AbstractProgramLoader {
|
|||
|
||||
length = clipToMemorySpace(length, log, prog);
|
||||
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(prog, provider, fileOffset, length);
|
||||
FileBytes fileBytes =
|
||||
MemoryBlockUtils.createFileBytes(prog, provider, fileOffset, length, monitor);
|
||||
try {
|
||||
AddressSpace space = prog.getAddressFactory().getDefaultAddressSpace();
|
||||
if (baseAddr == null) {
|
||||
|
|
|
@ -38,8 +38,7 @@ import ghidra.program.model.mem.*;
|
|||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.program.model.util.CodeUnitInsertionException;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
import ghidra.util.exception.NotFoundException;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
public class CoffLoader extends AbstractLibrarySupportLoader {
|
||||
|
@ -183,7 +182,8 @@ public class CoffLoader extends AbstractLibrarySupportLoader {
|
|||
|
||||
@Override
|
||||
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
|
||||
Program program, TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
Program program, TaskMonitor monitor, MessageLog log)
|
||||
throws IOException, CancelledException {
|
||||
|
||||
boolean performFakeLinking = performFakeLinking(options);
|
||||
|
||||
|
@ -193,7 +193,7 @@ public class CoffLoader extends AbstractLibrarySupportLoader {
|
|||
Map<CoffSectionHeader, Address> sectionsMap = new HashMap<>();
|
||||
Map<CoffSymbol, Symbol> symbolsMap = new HashMap<>();
|
||||
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider);
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
|
||||
|
||||
int id = program.startTransaction("loading program from COFF");
|
||||
boolean success = false;
|
||||
|
|
|
@ -49,7 +49,6 @@ public class DyldCacheLoader extends AbstractLibrarySupportLoader {
|
|||
/** Default value for loader option to create memory blocks for DYLIB sections */
|
||||
static final boolean CREATE_DYLIB_SECTIONS_OPTION_DEFAULT = false;
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws IOException {
|
||||
List<LoadSpec> loadSpecs = new ArrayList<>();
|
||||
|
@ -84,8 +83,8 @@ public class DyldCacheLoader extends AbstractLibrarySupportLoader {
|
|||
|
||||
try {
|
||||
DyldCacheProgramBuilder.buildProgram(program, provider,
|
||||
MemoryBlockUtils.createFileBytes(program, provider), shouldProcessSymbols(options),
|
||||
shouldCreateDylibSections(options), log, monitor);
|
||||
MemoryBlockUtils.createFileBytes(program, provider, monitor),
|
||||
shouldProcessSymbols(options), shouldCreateDylibSections(options), log, monitor);
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
return;
|
||||
|
|
|
@ -120,7 +120,7 @@ class ElfProgramBuilder extends MemorySectionResolver implements ElfLoadHelper {
|
|||
ByteProvider byteProvider = elf.getReader().getByteProvider();
|
||||
try (InputStream fileIn = byteProvider.getInputStream(0)) {
|
||||
fileBytes = program.getMemory().createFileBytes(byteProvider.getName(), 0,
|
||||
byteProvider.length(), fileIn);
|
||||
byteProvider.length(), fileIn, monitor);
|
||||
}
|
||||
|
||||
// process headers and define "section" within memory elfProgramBuilder
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MachoLoader extends AbstractLibrarySupportLoader {
|
|||
Program program, TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
|
||||
try {
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider);
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
|
||||
|
||||
// A Mach-O file may contain PRELINK information. If so, we use a special
|
||||
// program builder that knows how to deal with it.
|
||||
|
|
|
@ -87,9 +87,9 @@ public class MzLoader extends AbstractLibrarySupportLoader {
|
|||
|
||||
@Override
|
||||
public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program prog,
|
||||
TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
TaskMonitor monitor, MessageLog log) throws IOException, CancelledException {
|
||||
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(prog, provider);
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(prog, provider, monitor);
|
||||
AddressFactory af = prog.getAddressFactory();
|
||||
if (!(af.getDefaultAddressSpace() instanceof SegmentedAddressSpace)) {
|
||||
throw new IOException("Selected Language must have a segmented address space.");
|
||||
|
|
|
@ -40,8 +40,7 @@ import ghidra.program.model.symbol.*;
|
|||
import ghidra.program.model.util.CodeUnitInsertionException;
|
||||
import ghidra.util.Conv;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
/**
|
||||
|
@ -84,7 +83,7 @@ public class NeLoader extends AbstractLibrarySupportLoader {
|
|||
|
||||
@Override
|
||||
public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program prog,
|
||||
TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
TaskMonitor monitor, MessageLog log) throws IOException, CancelledException {
|
||||
|
||||
if (monitor.isCancelled()) {
|
||||
return;
|
||||
|
@ -98,7 +97,7 @@ public class NeLoader extends AbstractLibrarySupportLoader {
|
|||
// We don't use the file bytes to create block because the bytes are manipulated before
|
||||
// forming the block. Creating the FileBytes anyway in case later we want access to all
|
||||
// the original bytes.
|
||||
MemoryBlockUtils.createFileBytes(prog, provider);
|
||||
MemoryBlockUtils.createFileBytes(prog, provider, monitor);
|
||||
|
||||
NewExecutable ne = new NewExecutable(factory, provider);
|
||||
WindowsHeader wh = ne.getWindowsHeader();
|
||||
|
|
|
@ -34,6 +34,7 @@ import ghidra.program.model.mem.*;
|
|||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.program.model.util.CodeUnitInsertionException;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
import ghidra.util.task.TaskMonitorAdapter;
|
||||
|
@ -107,7 +108,8 @@ public class OmfLoader extends AbstractLibrarySupportLoader {
|
|||
|
||||
@Override
|
||||
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
|
||||
Program program, TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
Program program, TaskMonitor monitor, MessageLog log)
|
||||
throws IOException, CancelledException {
|
||||
|
||||
OmfFileHeader header = null;
|
||||
BinaryReader reader = OmfFileHeader.createReader(provider);
|
||||
|
@ -127,7 +129,7 @@ public class OmfLoader extends AbstractLibrarySupportLoader {
|
|||
// We don't use the file bytes to create block because the bytes are manipulated before
|
||||
// forming the block. Creating the FileBytes anyway in case later we want access to all
|
||||
// the original bytes.
|
||||
MemoryBlockUtils.createFileBytes(program, provider);
|
||||
MemoryBlockUtils.createFileBytes(program, provider, monitor);
|
||||
|
||||
int id = program.startTransaction("loading program from OMF");
|
||||
boolean success = false;
|
||||
|
|
|
@ -44,8 +44,7 @@ import ghidra.program.model.symbol.*;
|
|||
import ghidra.program.model.util.AddressSetPropertyMap;
|
||||
import ghidra.program.model.util.CodeUnitInsertionException;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
import ghidra.util.exception.InvalidInputException;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
/**
|
||||
|
@ -94,7 +93,8 @@ public class PeLoader extends AbstractPeDebugLoader {
|
|||
|
||||
@Override
|
||||
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
|
||||
Program program, TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
Program program, TaskMonitor monitor, MessageLog log)
|
||||
throws IOException, CancelledException {
|
||||
|
||||
if (monitor.isCancelled()) {
|
||||
return;
|
||||
|
@ -112,7 +112,7 @@ public class PeLoader extends AbstractPeDebugLoader {
|
|||
FileHeader fileHeader = ntHeader.getFileHeader();
|
||||
|
||||
monitor.setMessage("Completing PE header parsing...");
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider);
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
|
||||
try {
|
||||
Map<Integer, Address> sectionNumberToAddress =
|
||||
processMemoryBlocks(pe, program, fileBytes, monitor, log);
|
||||
|
|
|
@ -33,6 +33,7 @@ import ghidra.program.model.listing.Data;
|
|||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.mem.MemoryBlock;
|
||||
import ghidra.program.model.symbol.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
public class PefLoader extends AbstractLibrarySupportLoader {
|
||||
|
@ -68,9 +69,10 @@ public class PefLoader extends AbstractLibrarySupportLoader {
|
|||
|
||||
@Override
|
||||
public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
|
||||
Program program, TaskMonitor monitor, MessageLog log) throws IOException {
|
||||
Program program, TaskMonitor monitor, MessageLog log)
|
||||
throws IOException, CancelledException {
|
||||
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider);
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, monitor);
|
||||
|
||||
ImportStateCache importState = null;
|
||||
try {
|
||||
|
@ -258,7 +260,8 @@ public class PefLoader extends AbstractLibrarySupportLoader {
|
|||
}
|
||||
|
||||
if (symbolIndex % 100 == 0) {
|
||||
monitor.setMessage("Processing import " + symbolIndex + " of " + symbols.size());
|
||||
monitor.setMessage(
|
||||
"Processing import " + symbolIndex + " of " + symbols.size());
|
||||
}
|
||||
++symbolIndex;
|
||||
|
||||
|
@ -291,8 +294,8 @@ public class PefLoader extends AbstractLibrarySupportLoader {
|
|||
private void addExternalReference(Program program, Address start, String libraryName,
|
||||
String symbolName, MessageLog log) {
|
||||
try {
|
||||
program.getReferenceManager().addExternalReference(start, libraryName, symbolName,
|
||||
null, SourceType.IMPORTED, 0, RefType.DATA);
|
||||
program.getReferenceManager().addExternalReference(start, libraryName, symbolName, null,
|
||||
SourceType.IMPORTED, 0, RefType.DATA);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.appendMsg(e.getMessage());
|
||||
|
@ -332,8 +335,8 @@ public class PefLoader extends AbstractLibrarySupportLoader {
|
|||
return;
|
||||
}
|
||||
if (relocationIndex % 100 == 0) {
|
||||
monitor.setMessage("Processing relocation " + relocationIndex + " of " +
|
||||
relocations.size());
|
||||
monitor.setMessage(
|
||||
"Processing relocation " + relocationIndex + " of " + relocations.size());
|
||||
}
|
||||
++relocationIndex;
|
||||
|
||||
|
|
|
@ -114,8 +114,8 @@ class MyTestMemory extends AddressSet implements Memory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is)
|
||||
throws IOException {
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is,
|
||||
TaskMonitor monitor) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ public class PrelinkFileSystem extends GFileSystemBase implements GFileSystemPro
|
|||
boolean success = false;
|
||||
try {
|
||||
FileBytes fileBytes = MemoryBlockUtils.createFileBytes(program, provider, offset,
|
||||
provider.length() - offset);
|
||||
provider.length() - offset, monitor);
|
||||
ByteProvider providerWrapper =
|
||||
new ByteProviderWrapper(provider, offset, provider.length() - offset);
|
||||
MachoProgramBuilder.buildProgram(program, providerWrapper, fileBytes, new MessageLog(),
|
||||
|
|
|
@ -328,8 +328,8 @@ public class MemoryTestDummy extends AddressSet implements Memory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is)
|
||||
throws IOException {
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is,
|
||||
TaskMonitor monitor) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,18 +15,19 @@
|
|||
*/
|
||||
package ghidra.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import ghidra.util.exception.IOCancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* An InputStream which utilizes a TaskMonitor to indicate input progress and
|
||||
* allows the operation to be cancelled via the TaskMonitor.
|
||||
*/
|
||||
public class MonitoredInputStream extends InputStream {
|
||||
|
||||
private final static int PROGRESS_INCREMENT = 32*1024;
|
||||
private final static int PROGRESS_INCREMENT = 32 * 1024;
|
||||
|
||||
protected InputStream in;
|
||||
private TaskMonitor monitor;
|
||||
|
@ -64,12 +64,13 @@ public class MonitoredInputStream extends InputStream {
|
|||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (monitor.isCancelled()) {
|
||||
throw new IOCancelledException();
|
||||
}
|
||||
int n = in.read();
|
||||
if (n != -1) {
|
||||
++smallCount;
|
||||
if (smallCount >= PROGRESS_INCREMENT) {
|
||||
if (monitor.isCancelled())
|
||||
throw new IOCancelledException();
|
||||
count += smallCount;
|
||||
smallCount = 0;
|
||||
monitor.setProgress(count);
|
||||
|
@ -121,11 +122,12 @@ public class MonitoredInputStream extends InputStream {
|
|||
*/
|
||||
@Override
|
||||
public int read(byte b[], int off, int len) throws IOException {
|
||||
if (monitor.isCancelled()) {
|
||||
throw new IOCancelledException();
|
||||
}
|
||||
int n = in.read(b, off, len);
|
||||
smallCount += n;
|
||||
if (smallCount >= PROGRESS_INCREMENT) {
|
||||
if (monitor.isCancelled())
|
||||
throw new IOCancelledException();
|
||||
count += smallCount;
|
||||
smallCount = 0;
|
||||
monitor.setProgress(count);
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.InputStream;
|
|||
import java.util.*;
|
||||
|
||||
import db.*;
|
||||
import ghidra.util.exception.IOCancelledException;
|
||||
import ghidra.util.exception.VersionException;
|
||||
|
||||
/**
|
||||
|
@ -158,9 +159,18 @@ class FileBytesAdapterV0 extends FileBytesAdapter {
|
|||
}
|
||||
buffers[bufCount - 1] = handle.createBuffer(sizeLastBuf);
|
||||
|
||||
try {
|
||||
for (DBBuffer buffer : buffers) {
|
||||
buffer.fill(is);
|
||||
}
|
||||
}
|
||||
catch (IOCancelledException e) {
|
||||
for (DBBuffer buffer : buffers) {
|
||||
buffer.delete();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return buffers;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,8 +494,10 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
return newBlock;
|
||||
}
|
||||
catch (IOCancelledException e) {
|
||||
// TODO: this could leave things in a bad state.
|
||||
// Canceling requires additional improvements (see GT-3064)
|
||||
// this assumes the adapter has already cleaned up any partially created buffers.
|
||||
if (overlay) {
|
||||
checkRemoveAddressSpace(start.getAddressSpace());
|
||||
}
|
||||
throw new CancelledException();
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
@ -2022,14 +2024,18 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is)
|
||||
throws IOException {
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is,
|
||||
TaskMonitor monitor) throws IOException, CancelledException {
|
||||
lock.acquire();
|
||||
try {
|
||||
// TODO: this should accept task monitor to permit cancellation although
|
||||
// canceling requires additional improvements (see GT-3064)
|
||||
if (monitor != null && is != null) {
|
||||
is = new MonitoredInputStream(is, monitor);
|
||||
}
|
||||
return fileBytesAdapter.createFileBytes(filename, offset, size, is);
|
||||
}
|
||||
catch (IOCancelledException e) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
finally {
|
||||
lock.release();
|
||||
}
|
||||
|
|
|
@ -148,6 +148,8 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
|
|||
@Override
|
||||
MemoryBlockDB createInitializedBlock(String name, Address startAddr, InputStream is,
|
||||
long length, int permissions) throws AddressOverflowException, IOException {
|
||||
|
||||
// TODO verify that it is necessary to pre-define all segments in the address map
|
||||
updateAddressMapForAllAddresses(startAddr, length);
|
||||
|
||||
List<SubMemoryBlock> subBlocks = new ArrayList<>();
|
||||
|
@ -171,7 +173,7 @@ public class MemoryMapDBAdapterV3 extends MemoryMapDBAdapter {
|
|||
Collections.sort(memoryBlocks);
|
||||
return newBlock;
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOCancelledException e) {
|
||||
// clean up any created DBBufferss
|
||||
for (SubMemoryBlock subMemoryBlock : subBlocks) {
|
||||
BufferSubMemoryBlock bufferSubMemoryBlock = (BufferSubMemoryBlock) subMemoryBlock;
|
||||
|
|
|
@ -729,11 +729,14 @@ public interface Memory extends AddressSetView {
|
|||
* @param offset the offset into the file for the first byte in the input stream.
|
||||
* @param size the number of bytes to store from the input stream.
|
||||
* @param is the input stream that will supply the bytes to store in the program.
|
||||
* @param monitor
|
||||
* @return a FileBytes that was created to access the bytes.
|
||||
* @throws IOException if there was an IOException saving the bytes to the program database.
|
||||
* @throws CancelledException if the user cancelled this operation. Note: the database will
|
||||
* be stable, but the buffers may contain 0s instead of the actual bytes.
|
||||
*/
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is)
|
||||
throws IOException;
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is,
|
||||
TaskMonitor monitor) throws IOException, CancelledException;
|
||||
|
||||
/**
|
||||
* Returns a list of all the stored original file bytes objects
|
||||
|
|
|
@ -469,8 +469,8 @@ public class MemoryStub implements Memory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is)
|
||||
throws IOException {
|
||||
public FileBytes createFileBytes(String filename, long offset, long size, InputStream is,
|
||||
TaskMonitor monitor) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class FileBytesTest extends AbstractGenericTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testStoreAndRetrieveFileBytes() throws IOException {
|
||||
public void testStoreAndRetrieveFileBytes() throws Exception {
|
||||
int dataSize = MAX_BUFFER_SIZE_FOR_TESTING / 2;
|
||||
FileBytes fileBytes = createFileBytes("testFile", dataSize);
|
||||
|
||||
|
@ -186,13 +186,13 @@ public class FileBytesTest extends AbstractGenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
private FileBytes createFileBytes(String name, int size) throws IOException {
|
||||
private FileBytes createFileBytes(String name, int size) throws Exception {
|
||||
byte[] bytes = new byte[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
bytes[i] = (byte) i;
|
||||
}
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) {
|
||||
return mem.createFileBytes(name, 0, size, is);
|
||||
return mem.createFileBytes(name, 0, size, is, TaskMonitor.DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package ghidra.program.database.mem;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.*;
|
||||
|
@ -282,7 +281,8 @@ public class MemBlockDBTest extends AbstractGenericTest {
|
|||
@Test
|
||||
public void testCreateFileBytesBlockOutSideRange() throws Exception {
|
||||
byte[] bytes = new byte[256];
|
||||
FileBytes fileBytes = mem.createFileBytes("test", 0, 100, new ByteArrayInputStream(bytes));
|
||||
FileBytes fileBytes =
|
||||
mem.createFileBytes("test", 0, 100, new ByteArrayInputStream(bytes), TaskMonitor.DUMMY);
|
||||
try {
|
||||
mem.createInitializedBlock("test", addr(100), fileBytes, 10, 100, false);
|
||||
fail(
|
||||
|
@ -379,7 +379,6 @@ public class MemBlockDBTest extends AbstractGenericTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testJoinFileBytesBlockAndBufferBlock() throws Exception {
|
||||
FileBytes fileBytes = createFileBytes();
|
||||
|
@ -695,7 +694,6 @@ public class MemBlockDBTest extends AbstractGenericTest {
|
|||
assertEquals(2, ranges.getRangeCount()); // we have two sublocks so two distinct ranges
|
||||
assertEquals(10, ranges.get(0).getSize() + ranges.get(1).getSize());
|
||||
|
||||
|
||||
ByteSourceRange range = ranges.get(0);
|
||||
assertEquals(10, range.getStart().getOffset());
|
||||
assertEquals(15, range.getEnd().getOffset());
|
||||
|
@ -919,12 +917,13 @@ public class MemBlockDBTest extends AbstractGenericTest {
|
|||
false);
|
||||
}
|
||||
|
||||
private FileBytes createFileBytes() throws IOException {
|
||||
private FileBytes createFileBytes() throws Exception {
|
||||
byte[] bytes = new byte[256];
|
||||
for (int i = 0; i < 256; i++) {
|
||||
bytes[i] = (byte) i;
|
||||
}
|
||||
FileBytes fileBytes = mem.createFileBytes("test", 0, 100, new ByteArrayInputStream(bytes));
|
||||
FileBytes fileBytes =
|
||||
mem.createFileBytes("test", 0, 100, new ByteArrayInputStream(bytes), TaskMonitor.DUMMY);
|
||||
return fileBytes;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue