GP-2624: Removing library support from a bunch of loaders that shouldn't

have it
This commit is contained in:
Ryan Kurtz 2022-10-04 03:40:04 -04:00
parent f7bb9e9e43
commit 56293636d0
10 changed files with 122 additions and 20 deletions

View File

@ -0,0 +1,112 @@
/* ###
* 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.opinion;
import java.io.IOException;
import java.util.List;
import ghidra.app.util.Option;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.importer.MessageLog;
import ghidra.framework.model.DomainFolder;
import ghidra.program.model.address.Address;
import ghidra.program.model.lang.*;
import ghidra.program.model.listing.Program;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
/**
* An abstract {@link Loader} that provides a convenience wrapper around
* {@link AbstractProgramLoader}, minimizing the amount of work a subclass needs to do to load a
* {@link Program}
*/
public abstract class AbstractProgramWrapperLoader extends AbstractProgramLoader {
/**
* Loads bytes in a particular format into the given {@link Program}.
*
* @param provider The bytes to load.
* @param loadSpec The {@link LoadSpec} to use during load.
* @param options The load options.
* @param program The {@link Program} to load into.
* @param monitor A cancelable task monitor.
* @param log The message log.
* @throws IOException if there was an IO-related problem loading.
* @throws CancelledException if the user cancelled the load.
*/
protected abstract void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
Program program, TaskMonitor monitor, MessageLog log)
throws CancelledException, IOException;
@Override
protected List<LoadedProgram> loadProgram(ByteProvider provider, String programName,
DomainFolder programFolder, LoadSpec loadSpec, List<Option> options, MessageLog log,
Object consumer, TaskMonitor monitor) throws CancelledException, IOException {
LanguageCompilerSpecPair pair = loadSpec.getLanguageCompilerSpec();
Language language = getLanguageService().getLanguage(pair.languageID);
CompilerSpec compilerSpec = language.getCompilerSpecByID(pair.compilerSpecID);
Address imageBaseAddr = language.getAddressFactory()
.getDefaultAddressSpace()
.getAddress(loadSpec.getDesiredImageBase());
Program program = createProgram(provider, programName, imageBaseAddr, getName(), language,
compilerSpec, consumer);
int transactionID = program.startTransaction("Loading");
boolean success = false;
try {
load(provider, loadSpec, options, program, monitor, log);
createDefaultMemoryBlocks(program, language, log);
success = true;
return List.of(new LoadedProgram(program, programFolder));
}
finally {
program.endTransaction(transactionID, success);
if (!success) {
program.release(consumer);
}
}
}
@Override
protected boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec,
List<Option> options, MessageLog log, Program program, TaskMonitor monitor)
throws CancelledException, IOException {
LanguageCompilerSpecPair pair = loadSpec.getLanguageCompilerSpec();
LanguageID languageID = program.getLanguageID();
CompilerSpecID compilerSpecID = program.getCompilerSpec().getCompilerSpecID();
if (!(pair.languageID.equals(languageID) && pair.compilerSpecID.equals(compilerSpecID))) {
log.appendMsg(provider.getAbsolutePath() +
" does not have the same language/compiler spec as program " + program.getName());
return false;
}
load(provider, loadSpec, options, program, monitor, log);
return true;
}
@Override
public LoaderTier getTier() {
return LoaderTier.GENERIC_TARGET_LOADER;
}
@Override
public int getTierPriority() {
return 50;
}
}

View File

@ -30,7 +30,7 @@ import ghidra.util.task.TaskMonitor;
/**
* A {@link Loader} for processing Microsoft DEF files.
*/
public class DefLoader extends AbstractLibrarySupportLoader {
public class DefLoader extends AbstractProgramWrapperLoader {
public final static String DEF_NAME = "Module Definition (DEF)";
public static final String NO_MAGIC = "0";

View File

@ -32,7 +32,7 @@ import ghidra.util.task.TaskMonitor;
/**
* A {@link Loader} for DYLD shared cache files.
*/
public class DyldCacheLoader extends AbstractLibrarySupportLoader {
public class DyldCacheLoader extends AbstractProgramWrapperLoader {
public final static String DYLD_CACHE_NAME = "DYLD Cache";

View File

@ -51,7 +51,7 @@ import ghidra.util.task.TaskMonitor;
* ...
* </pre>
*/
public class MapLoader extends AbstractLibrarySupportLoader {
public class MapLoader extends AbstractProgramWrapperLoader {
public final static String MAP_NAME = "Program Mapfile (MAP)";
public static final String NO_MAGIC = "0";

View File

@ -40,7 +40,7 @@ import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor;
import ghidra.util.task.TaskMonitorAdapter;
public class OmfLoader extends AbstractLibrarySupportLoader {
public class OmfLoader extends AbstractProgramWrapperLoader {
public final static String OMF_NAME = "Relocatable Object Module Format (OMF)";
public final static long MIN_BYTE_LENGTH = 11;
public final static long IMAGE_BASE = 0x2000; // Base offset to start loading segments

View File

@ -36,7 +36,7 @@ import ghidra.program.model.symbol.*;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
public class PefLoader extends AbstractLibrarySupportLoader {
public class PefLoader extends AbstractProgramWrapperLoader {
public final static String PEF_NAME = "Preferred Executable Format (PEF)";
private static final long MIN_BYTE_LENGTH = 40;

View File

@ -36,7 +36,7 @@ import ghidra.program.model.symbol.*;
import ghidra.util.exception.InvalidInputException;
import ghidra.util.task.TaskMonitor;
public class DexLoader extends AbstractLibrarySupportLoader {
public class DexLoader extends AbstractProgramWrapperLoader {
public DexLoader() {
}
@ -258,14 +258,4 @@ public class DexLoader extends AbstractLibrarySupportLoader {
Program program) {
return null;
}
@Override
protected boolean isLoadLocalLibraries(List<Option> options) {
return false;
}
@Override
protected boolean isLoadSystemLibraries(List<Option> options) {
return false;
}
}

View File

@ -50,7 +50,7 @@ import ghidra.util.task.TaskMonitor;
/**
* A {@link Loader} for processing dump files and their embedded objects.
*/
public class DumpFileLoader extends AbstractLibrarySupportLoader {
public class DumpFileLoader extends AbstractProgramWrapperLoader {
/** The name of the dump file loader */
public static final String DF_NAME = "Dump File Loader";

View File

@ -39,7 +39,7 @@ import ghidra.util.exception.CancelledException;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.task.TaskMonitor;
public class JavaLoader extends AbstractLibrarySupportLoader {
public class JavaLoader extends AbstractProgramWrapperLoader {
private static final String JAVA_NAME = "Java Class File";
private Register alignmentReg;

View File

@ -21,7 +21,7 @@ import java.util.*;
import ghidra.app.util.Option;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.opinion.AbstractLibrarySupportLoader;
import ghidra.app.util.opinion.AbstractProgramWrapperLoader;
import ghidra.app.util.opinion.LoadSpec;
import ghidra.framework.model.DomainObject;
import ghidra.program.model.listing.Program;
@ -31,7 +31,7 @@ import ghidra.util.task.TaskMonitor;
/**
* TODO: Provide class-level documentation that describes what this loader does.
*/
public class SkeletonLoader extends AbstractLibrarySupportLoader {
public class SkeletonLoader extends AbstractProgramWrapperLoader {
@Override
public String getName() {