Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some (but not all) AVR8 issues #286

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ghidra/p_code_extractor/internal/HelperFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public static String getRegisterMnemonic(Varnode node) {


/**
* @param constant: Constant value
* @return: Constant value without prefix
* @param constant: Value which may have a prefix
* @return: Value without prefix
*
* Removes the consts prefix from the constant.
* Removes prefixes like "const:" and "mem:" from the constant.
*/
public static String removeConstantPrefix(String constant) {
return constant.replaceFirst("^(const:)", "");
public static String removePrefix(String constant) {
return constant.replaceFirst("^([a-zA-Z]*:)", "");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void warning(SAXParseException exception) throws SAXException {
*/
public static ResourceFile getLdefFile() {
String processorDef = String.format("%s.ldefs", program.getLanguage().getLanguageDescription().getProcessor().toString());
if(processorDef.startsWith("MIPS")) {
if(processorDef.startsWith("MIPS") || processorDef.startsWith("AVR")) {
processorDef = processorDef.toLowerCase();
}
if(processorDef.startsWith("PowerPC")) {
Expand Down
6 changes: 3 additions & 3 deletions src/ghidra/p_code_extractor/internal/TermCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private TermCreator() {
*/
public static Term<Program> createProgramTerm() {
Tid progTid = new Tid(String.format("prog_%s", HelperFunctions.ghidraProgram.getMinAddress().toString()), HelperFunctions.ghidraProgram.getMinAddress().toString());
String imageBase = HelperFunctions.ghidraProgram.getImageBase().toString();
String imageBase = HelperFunctions.removePrefix(HelperFunctions.ghidraProgram.getImageBase().toString());
return new Term<Program>(progTid, new Program(new ArrayList<Term<Sub>>(), HelperFunctions.addEntryPoints(symTab), imageBase));
}

Expand Down Expand Up @@ -195,10 +195,10 @@ public static Variable createVariable(Varnode node) {
var.setName(HelperFunctions.renameVirtualRegister(node.getAddress().toString()));
var.setIsVirtual(true);
} else if (node.isConstant()) {
var.setValue(HelperFunctions.removeConstantPrefix(node.getAddress().toString()));
var.setValue(HelperFunctions.removePrefix(node.getAddress().toString()));
var.setIsVirtual(false);
} else if (node.isAddress()) {
var.setAddress(node.getAddress().toString());
var.setAddress(HelperFunctions.removePrefix(node.getAddress().toString()));
var.setIsVirtual(false);
} else if (node.isFree()) {
var.setAddress(HelperFunctions.removeStackPrefix(node.getAddress().toString()));
Expand Down