mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-3625 Added simplified FileDataTypeManager factory methods and cleanup of CParser utilities.
This commit is contained in:
parent
81c687d06b
commit
c23354b78d
8 changed files with 428 additions and 382 deletions
|
@ -17,13 +17,16 @@ package ghidra.program.model.data;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import generic.jar.ResourceFile;
|
||||
import ghidra.framework.data.OpenMode;
|
||||
import ghidra.framework.store.LockException;
|
||||
import ghidra.framework.store.db.PackedDBHandle;
|
||||
import ghidra.framework.store.db.PackedDatabase;
|
||||
import ghidra.program.model.lang.CompilerSpec;
|
||||
import ghidra.program.model.lang.Language;
|
||||
import ghidra.program.model.lang.*;
|
||||
import ghidra.program.model.listing.IncompatibleLanguageException;
|
||||
import ghidra.program.util.DefaultLanguageService;
|
||||
import ghidra.util.InvalidNameException;
|
||||
import ghidra.util.UniversalID;
|
||||
import ghidra.util.exception.*;
|
||||
|
@ -101,6 +104,77 @@ public class FileDataTypeManager extends StandAloneDataTypeManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new data-type file archive using the default data organization.
|
||||
* @param packedDbFile archive file (filename must end with DataTypeFileManager.SUFFIX)
|
||||
* @param languageId valid language ID (see appropriate *.ldefs file for defined IDs)
|
||||
* @param compilerSpecId valid compiler spec ID which corresponds to the language ID.
|
||||
* @return data-type manager backed by the specified packedDbFile
|
||||
* @returns DuplicateFileException if {@code packedDbFile} already exists
|
||||
* @throws LanguageNotFoundException if specified {@code languageId} not defined.
|
||||
* @throws CompilerSpecNotFoundException if specified {@code compilerSpecId} is not defined
|
||||
* for the specified language.
|
||||
* @throws IOException if an IO error occurs
|
||||
*/
|
||||
public static FileDataTypeManager createFileArchive(File packedDbFile, LanguageID languageId,
|
||||
CompilerSpecID compilerSpecId)
|
||||
throws LanguageNotFoundException, CompilerSpecNotFoundException, IOException {
|
||||
Objects.requireNonNull(languageId, "missing required languageId");
|
||||
Objects.requireNonNull(compilerSpecId, "missing required compilerSpecId");
|
||||
try {
|
||||
if (packedDbFile.exists()) {
|
||||
throw new DuplicateFileException("File already exists: " + packedDbFile);
|
||||
}
|
||||
|
||||
// Verify that the specified language and compiler spec are valid
|
||||
LanguageService languageService = DefaultLanguageService.getLanguageService();
|
||||
Language language = languageService.getLanguage(languageId);
|
||||
language.getCompilerSpecByID(compilerSpecId);
|
||||
|
||||
FileDataTypeManager dtm =
|
||||
new FileDataTypeManager(new ResourceFile(packedDbFile), OpenMode.CREATE,
|
||||
TaskMonitor.DUMMY);
|
||||
|
||||
dtm.setProgramArchitecture(language, compilerSpecId, LanguageUpdateOption.CLEAR,
|
||||
TaskMonitor.DUMMY);
|
||||
|
||||
return dtm;
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
throw new AssertException(e); // unexpected without task monitor use
|
||||
}
|
||||
catch (LockException | IncompatibleLanguageException | UnsupportedOperationException e) {
|
||||
throw new RuntimeException(e); // unexpected for new archive
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new data-type file archive using the default data organization.
|
||||
* @param packedDbfile archive file (filename must end with DataTypeFileManager.SUFFIX)
|
||||
* @param languageId valid language ID (see appropriate *.ldefs file for defined IDs). If null
|
||||
* invocation will be deferred to {@link #createFileArchive(File)}.
|
||||
* @param compilerSpecId valid compiler spec ID which corresponds to the language ID.
|
||||
* @return data-type manager backed by the specified packedDbFile
|
||||
* @throws LanguageNotFoundException if specified {@code languageId} not defined.
|
||||
* @throws CompilerSpecNotFoundException if specified {@code compilerSpecId} is not defined
|
||||
* for the specified language.
|
||||
* @throws IOException if an IO error occurs
|
||||
*/
|
||||
public static FileDataTypeManager createFileArchive(File packedDbfile, String languageId,
|
||||
String compilerSpecId) throws IOException {
|
||||
if (languageId == null) {
|
||||
if (compilerSpecId != null) {
|
||||
throw new IllegalArgumentException("compilerSpecId specified without languageId");
|
||||
}
|
||||
return createFileArchive(packedDbfile);
|
||||
}
|
||||
if (compilerSpecId == null) {
|
||||
throw new IllegalArgumentException("languageId specified without compilerSpecId");
|
||||
}
|
||||
return createFileArchive(packedDbfile, new LanguageID(languageId),
|
||||
new CompilerSpecID(compilerSpecId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an existing data-type file archive using the default data organization.
|
||||
* <p>
|
||||
|
@ -161,7 +235,6 @@ public class FileDataTypeManager extends StandAloneDataTypeManager
|
|||
public void saveAs(File saveFile, UniversalID newUniversalId)
|
||||
throws DuplicateFileException, IOException {
|
||||
ResourceFile resourceSaveFile = new ResourceFile(saveFile);
|
||||
// TODO: this should really be a package method and not public!
|
||||
validateFilename(resourceSaveFile);
|
||||
try {
|
||||
universalID = newUniversalId;
|
||||
|
@ -333,3 +406,4 @@ public class FileDataTypeManager extends StandAloneDataTypeManager
|
|||
return getClass().getSimpleName() + " - " + getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue