mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-23 12:49:45 +00:00
GP-2624: Removing library support from a bunch of loaders that shouldn't
have it
This commit is contained in:
parent
f7bb9e9e43
commit
56293636d0
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,7 @@ import ghidra.util.task.TaskMonitor;
|
|||||||
/**
|
/**
|
||||||
* A {@link Loader} for processing Microsoft DEF files.
|
* 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 final static String DEF_NAME = "Module Definition (DEF)";
|
||||||
|
|
||||||
public static final String NO_MAGIC = "0";
|
public static final String NO_MAGIC = "0";
|
||||||
|
@ -32,7 +32,7 @@ import ghidra.util.task.TaskMonitor;
|
|||||||
/**
|
/**
|
||||||
* A {@link Loader} for DYLD shared cache files.
|
* 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";
|
public final static String DYLD_CACHE_NAME = "DYLD Cache";
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ import ghidra.util.task.TaskMonitor;
|
|||||||
* ...
|
* ...
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class MapLoader extends AbstractLibrarySupportLoader {
|
public class MapLoader extends AbstractProgramWrapperLoader {
|
||||||
public final static String MAP_NAME = "Program Mapfile (MAP)";
|
public final static String MAP_NAME = "Program Mapfile (MAP)";
|
||||||
|
|
||||||
public static final String NO_MAGIC = "0";
|
public static final String NO_MAGIC = "0";
|
||||||
|
@ -40,7 +40,7 @@ import ghidra.util.exception.InvalidInputException;
|
|||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
import ghidra.util.task.TaskMonitorAdapter;
|
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 String OMF_NAME = "Relocatable Object Module Format (OMF)";
|
||||||
public final static long MIN_BYTE_LENGTH = 11;
|
public final static long MIN_BYTE_LENGTH = 11;
|
||||||
public final static long IMAGE_BASE = 0x2000; // Base offset to start loading segments
|
public final static long IMAGE_BASE = 0x2000; // Base offset to start loading segments
|
||||||
|
@ -36,7 +36,7 @@ import ghidra.program.model.symbol.*;
|
|||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
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)";
|
public final static String PEF_NAME = "Preferred Executable Format (PEF)";
|
||||||
private static final long MIN_BYTE_LENGTH = 40;
|
private static final long MIN_BYTE_LENGTH = 40;
|
||||||
|
@ -36,7 +36,7 @@ import ghidra.program.model.symbol.*;
|
|||||||
import ghidra.util.exception.InvalidInputException;
|
import ghidra.util.exception.InvalidInputException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
public class DexLoader extends AbstractLibrarySupportLoader {
|
public class DexLoader extends AbstractProgramWrapperLoader {
|
||||||
|
|
||||||
public DexLoader() {
|
public DexLoader() {
|
||||||
}
|
}
|
||||||
@ -258,14 +258,4 @@ public class DexLoader extends AbstractLibrarySupportLoader {
|
|||||||
Program program) {
|
Program program) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isLoadLocalLibraries(List<Option> options) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isLoadSystemLibraries(List<Option> options) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ import ghidra.util.task.TaskMonitor;
|
|||||||
/**
|
/**
|
||||||
* A {@link Loader} for processing dump files and their embedded objects.
|
* 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 */
|
/** The name of the dump file loader */
|
||||||
public static final String DF_NAME = "Dump File Loader";
|
public static final String DF_NAME = "Dump File Loader";
|
||||||
|
@ -39,7 +39,7 @@ import ghidra.util.exception.CancelledException;
|
|||||||
import ghidra.util.exception.DuplicateNameException;
|
import ghidra.util.exception.DuplicateNameException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
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 static final String JAVA_NAME = "Java Class File";
|
||||||
private Register alignmentReg;
|
private Register alignmentReg;
|
||||||
|
@ -21,7 +21,7 @@ import java.util.*;
|
|||||||
import ghidra.app.util.Option;
|
import ghidra.app.util.Option;
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
import ghidra.app.util.bin.ByteProvider;
|
||||||
import ghidra.app.util.importer.MessageLog;
|
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.app.util.opinion.LoadSpec;
|
||||||
import ghidra.framework.model.DomainObject;
|
import ghidra.framework.model.DomainObject;
|
||||||
import ghidra.program.model.listing.Program;
|
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.
|
* TODO: Provide class-level documentation that describes what this loader does.
|
||||||
*/
|
*/
|
||||||
public class SkeletonLoader extends AbstractLibrarySupportLoader {
|
public class SkeletonLoader extends AbstractProgramWrapperLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Loading…
Reference in New Issue
Block a user