mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-08-27 13:03:12 +00:00
Merge remote-tracking branch 'origin/GP-2925_James_programbuilder_all_langs--SQUASHED'
This commit is contained in:
commit
5b5b2f3eec
|
@ -20,7 +20,6 @@ import java.nio.charset.Charset;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import generic.jar.ResourceFile;
|
||||
import generic.test.AbstractGenericTest;
|
||||
import generic.test.AbstractGuiTest;
|
||||
import ghidra.app.cmd.data.CreateDataCmd;
|
||||
|
@ -33,7 +32,6 @@ import ghidra.app.cmd.label.CreateNamespacesCmd;
|
|||
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
|
||||
import ghidra.app.util.NamespaceUtils;
|
||||
import ghidra.app.util.SymbolPath;
|
||||
import ghidra.framework.Application;
|
||||
import ghidra.framework.options.Options;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.program.database.data.ProgramDataTypeManager;
|
||||
|
@ -82,8 +80,6 @@ public class ProgramBuilder {
|
|||
|
||||
public static final String _TOY = _TOY_BE;
|
||||
|
||||
private static final String LANGUAGE_DELIMITER = ":";
|
||||
|
||||
protected static final String _TOY_LANGUAGE_PREFIX = "Toy:";
|
||||
|
||||
private static final Map<String, Language> LANGUAGE_CACHE = new HashMap<>();
|
||||
|
@ -251,55 +247,14 @@ public class ProgramBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
private Language getLanguage(String languageName) throws Exception {
|
||||
Language language = LANGUAGE_CACHE.get(languageName);
|
||||
if (language != null) {
|
||||
return language;
|
||||
private Language getLanguage(String languageId) throws Exception {
|
||||
Language language = LANGUAGE_CACHE.get(languageId);
|
||||
if (language == null) {
|
||||
language =
|
||||
DefaultLanguageService.getLanguageService().getLanguage(new LanguageID(languageId));
|
||||
LANGUAGE_CACHE.put(languageId, language);
|
||||
}
|
||||
|
||||
ResourceFile ldefFile = null;
|
||||
if (languageName.contains(LANGUAGE_DELIMITER)) {
|
||||
switch (languageName.split(LANGUAGE_DELIMITER)[0]) {
|
||||
case "x86":
|
||||
ldefFile = Application.getModuleDataFile("x86", "languages/x86.ldefs");
|
||||
break;
|
||||
case "8051":
|
||||
ldefFile = Application.getModuleDataFile("8051", "languages/8051.ldefs");
|
||||
break;
|
||||
case "sparc":
|
||||
ldefFile = Application.getModuleDataFile("Sparc", "languages/SparcV9.ldefs");
|
||||
break;
|
||||
case "ARM":
|
||||
ldefFile = Application.getModuleDataFile("ARM", "languages/ARM.ldefs");
|
||||
break;
|
||||
case "AARCH64":
|
||||
ldefFile = Application.getModuleDataFile("AARCH64", "languages/AARCH64.ldefs");
|
||||
break;
|
||||
case "MIPS":
|
||||
ldefFile = Application.getModuleDataFile("MIPS", "languages/mips.ldefs");
|
||||
break;
|
||||
case "Toy":
|
||||
ldefFile = Application.getModuleDataFile("Toy", "languages/toy.ldefs");
|
||||
break;
|
||||
case "PowerPC":
|
||||
ldefFile = Application.getModuleDataFile("PowerPC", "languages/ppc.ldefs");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ldefFile != null) {
|
||||
LanguageService languageService = DefaultLanguageService.getLanguageService(ldefFile);
|
||||
try {
|
||||
language = languageService.getLanguage(new LanguageID(languageName));
|
||||
}
|
||||
catch (LanguageNotFoundException e) {
|
||||
throw new LanguageNotFoundException("Unsupported test language: " + languageName);
|
||||
}
|
||||
LANGUAGE_CACHE.put(languageName, language);
|
||||
return language;
|
||||
}
|
||||
throw new LanguageNotFoundException("Unsupported test language: " + languageName);
|
||||
return language;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
|
@ -352,8 +307,8 @@ public class ProgramBuilder {
|
|||
|
||||
return tx(() -> {
|
||||
return program.getMemory()
|
||||
.createInitializedBlock(name, addr(address), size, (byte) 0,
|
||||
TaskMonitor.DUMMY, true);
|
||||
.createInitializedBlock(name, addr(address), size, (byte) 0, TaskMonitor.DUMMY,
|
||||
true);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -517,8 +472,7 @@ public class ProgramBuilder {
|
|||
});
|
||||
}
|
||||
|
||||
public void addFunctionVariable(Function f, Variable v)
|
||||
throws Exception {
|
||||
public void addFunctionVariable(Function f, Variable v) throws Exception {
|
||||
tx(() -> f.addLocalVariable(v, SourceType.USER_DEFINED));
|
||||
}
|
||||
|
||||
|
@ -561,13 +515,13 @@ public class ProgramBuilder {
|
|||
|
||||
Function function = null;
|
||||
if (namespace == null) {
|
||||
function = functionManager.createFunction(
|
||||
name, entryPoint, body, SourceType.USER_DEFINED);
|
||||
function =
|
||||
functionManager.createFunction(name, entryPoint, body, SourceType.USER_DEFINED);
|
||||
}
|
||||
else {
|
||||
Namespace ns = getNamespace(namespace);
|
||||
function = functionManager.createFunction(
|
||||
name, ns, entryPoint, body, SourceType.USER_DEFINED);
|
||||
function = functionManager.createFunction(name, ns, entryPoint, body,
|
||||
SourceType.USER_DEFINED);
|
||||
}
|
||||
|
||||
Parameter[] myParams = params;
|
||||
|
@ -854,8 +808,8 @@ public class ProgramBuilder {
|
|||
return createString(address, bytes, charset, dataType);
|
||||
}
|
||||
|
||||
public Data createString(String address, byte[] stringBytes, Charset charset,
|
||||
DataType dataType) throws Exception {
|
||||
public Data createString(String address, byte[] stringBytes, Charset charset, DataType dataType)
|
||||
throws Exception {
|
||||
Address addr = addr(address);
|
||||
setBytes(address, stringBytes);
|
||||
if (dataType != null) {
|
||||
|
|
Loading…
Reference in a new issue