mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge remote-tracking branch 'origin/GT-3078_ghizard_use_SetCommentCmd_over_SetCommentsCmd'
This commit is contained in:
commit
6b49a80dde
8 changed files with 105 additions and 156 deletions
|
@ -75,9 +75,8 @@ public class SetCommentCmd implements Command {
|
||||||
public boolean applyTo(DomainObject obj) {
|
public boolean applyTo(DomainObject obj) {
|
||||||
CodeUnit cu = getCodeUnit((Program) obj);
|
CodeUnit cu = getCodeUnit((Program) obj);
|
||||||
if (cu == null) {
|
if (cu == null) {
|
||||||
message =
|
message = "No Instruction or Data found for address " + address.toString() +
|
||||||
"No Instruction or Data found for address " + address.toString() +
|
" Is this address valid?";
|
||||||
" Is this address valid?";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (commentChanged(cu.getComment(commentType), comment)) {
|
if (commentChanged(cu.getComment(commentType), comment)) {
|
||||||
|
@ -113,4 +112,21 @@ public class SetCommentCmd implements Command {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the specified comment of the specified type at address. The current comment of
|
||||||
|
* this commentType will be cleared.
|
||||||
|
*
|
||||||
|
* @param program the program being analyzed
|
||||||
|
* @param addr the address where data is created
|
||||||
|
* @param comment the comment about the data
|
||||||
|
* @param commentType the type of comment ({@link CodeUnit#PLATE_COMMENT},
|
||||||
|
* {@link CodeUnit#PRE_COMMENT}, {@link CodeUnit#EOL_COMMENT}, {@link CodeUnit#POST_COMMENT},
|
||||||
|
* {@link CodeUnit#REPEATABLE_COMMENT})
|
||||||
|
*/
|
||||||
|
public static void createComment(Program program, Address addr, String comment,
|
||||||
|
int commentType) {
|
||||||
|
SetCommentCmd commentCmd = new SetCommentCmd(addr, commentType, comment);
|
||||||
|
commentCmd.applyTo(program);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,8 @@ public class SetCommentsCmd implements Command {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return true if the newValue and oldValue are different
|
* return true if the newValue and oldValue are different
|
||||||
* @param newValue
|
* @param newValue the value that we desire to set
|
||||||
* @param oldValue
|
* @param oldValue the existing value
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private boolean commentChanged(String newValue, String oldValue) {
|
private boolean commentChanged(String newValue, String oldValue) {
|
||||||
|
@ -141,40 +141,4 @@ public class SetCommentsCmd implements Command {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the specified comment of the specified type at address.
|
|
||||||
*
|
|
||||||
* @param program the program being analyzed
|
|
||||||
* @param addr the address where data is created
|
|
||||||
* @param comment the comment about the data
|
|
||||||
* @param commentType the type of comment ({@link CodeUnit#PLATE_COMMENT},
|
|
||||||
* {@link CodeUnit#PRE_COMMENT}, {@link CodeUnit#EOL_COMMENT}, {@link CodeUnit#POST_COMMENT},
|
|
||||||
* {@link CodeUnit#REPEATABLE_COMMENT})
|
|
||||||
*/
|
|
||||||
public static void createComment(Program program, Address addr, String comment,
|
|
||||||
int commentType) {
|
|
||||||
|
|
||||||
SetCommentsCmd commentCmd = null;
|
|
||||||
switch (commentType) {
|
|
||||||
case CodeUnit.PRE_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, comment, null, null, null, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.POST_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, comment, null, null, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.EOL_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, comment, null, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.PLATE_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, null, comment, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.REPEATABLE_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, null, null, comment);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, comment, null, null);
|
|
||||||
}
|
|
||||||
commentCmd.applyTo(program);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.core.comments;
|
package ghidra.app.plugin.core.comments;
|
||||||
|
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
import docking.ActionContext;
|
||||||
|
import docking.action.*;
|
||||||
import ghidra.app.CorePluginPackage;
|
import ghidra.app.CorePluginPackage;
|
||||||
import ghidra.app.cmd.comments.SetCommentCmd;
|
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||||
import ghidra.app.cmd.comments.SetCommentsCmd;
|
import ghidra.app.cmd.comments.SetCommentsCmd;
|
||||||
|
@ -30,11 +34,6 @@ import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.util.*;
|
import ghidra.program.util.*;
|
||||||
import ghidra.util.HelpLocation;
|
import ghidra.util.HelpLocation;
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
|
|
||||||
import docking.ActionContext;
|
|
||||||
import docking.action.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to handle end comments for a code unit in a program.
|
* Class to handle end comments for a code unit in a program.
|
||||||
*/
|
*/
|
||||||
|
@ -88,8 +87,8 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener {
|
||||||
HelpLocation helpLocation = new HelpLocation(getName(), "Comments_Option");
|
HelpLocation helpLocation = new HelpLocation(getName(), "Comments_Option");
|
||||||
options.setOptionsHelpLocation(helpLocation);
|
options.setOptionsHelpLocation(helpLocation);
|
||||||
options.registerOption(OPTION_NAME, dialog.getEnterMode(), helpLocation,
|
options.registerOption(OPTION_NAME, dialog.getEnterMode(), helpLocation,
|
||||||
"Toggle for whether pressing the <Enter> key causes the comment to be entered,"
|
"Toggle for whether pressing the <Enter> key causes the comment to be entered," +
|
||||||
+ " versus adding a new line character in the comment.");
|
" versus adding a new line character in the comment.");
|
||||||
|
|
||||||
setOptions(options);
|
setOptions(options);
|
||||||
options.addOptionsChangeListener(this);
|
options.addOptionsChangeListener(this);
|
||||||
|
@ -115,15 +114,16 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener {
|
||||||
plateComment = (plateComment.length() == 0) ? null : plateComment;
|
plateComment = (plateComment.length() == 0) ? null : plateComment;
|
||||||
repeatableComment = (repeatableComment.length() == 0) ? null : repeatableComment;
|
repeatableComment = (repeatableComment.length() == 0) ? null : repeatableComment;
|
||||||
|
|
||||||
Command cmd =
|
Command cmd = new SetCommentsCmd(cu.getMinAddress(), preComment, postComment, eolComment,
|
||||||
new SetCommentsCmd(cu.getMinAddress(), preComment, postComment, eolComment,
|
plateComment, repeatableComment);
|
||||||
plateComment, repeatableComment);
|
|
||||||
|
|
||||||
tool.execute(cmd, cu.getProgram());
|
tool.execute(cmd, cu.getProgram());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the deleteAction to delete a comment.
|
* Called by the deleteAction to delete an end-of-line comment.
|
||||||
|
* @param program the {@link Program} for which to act
|
||||||
|
* @param loc the {@link ProgramLocation} for which to delete the comment
|
||||||
*/
|
*/
|
||||||
void deleteComments(Program program, ProgramLocation loc) {
|
void deleteComments(Program program, ProgramLocation loc) {
|
||||||
int commentType = CommentType.getCommentType(null, loc, CodeUnit.EOL_COMMENT);
|
int commentType = CommentType.getCommentType(null, loc, CodeUnit.EOL_COMMENT);
|
||||||
|
@ -147,29 +147,24 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener {
|
||||||
|
|
||||||
editAction = CommentsActionFactory.getEditCommentsAction(dialog, name);
|
editAction = CommentsActionFactory.getEditCommentsAction(dialog, name);
|
||||||
tool.addAction(editAction);
|
tool.addAction(editAction);
|
||||||
preCommentEditAction =
|
preCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name,
|
||||||
CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Pre Comment",
|
"Set Pre Comment", CodeUnit.PRE_COMMENT);
|
||||||
CodeUnit.PRE_COMMENT);
|
|
||||||
tool.addAction(preCommentEditAction);
|
tool.addAction(preCommentEditAction);
|
||||||
|
|
||||||
postCommentEditAction =
|
postCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name,
|
||||||
CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Post Comment",
|
"Set Post Comment", CodeUnit.POST_COMMENT);
|
||||||
CodeUnit.POST_COMMENT);
|
|
||||||
tool.addAction(postCommentEditAction);
|
tool.addAction(postCommentEditAction);
|
||||||
|
|
||||||
plateCommentEditAction =
|
plateCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name,
|
||||||
CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Plate Comment",
|
"Set Plate Comment", CodeUnit.PLATE_COMMENT);
|
||||||
CodeUnit.PLATE_COMMENT);
|
|
||||||
tool.addAction(plateCommentEditAction);
|
tool.addAction(plateCommentEditAction);
|
||||||
|
|
||||||
eolCommentEditAction =
|
eolCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name,
|
||||||
CommentsActionFactory.getSetCommentsAction(dialog, name, "Set EOL Comment",
|
"Set EOL Comment", CodeUnit.EOL_COMMENT);
|
||||||
CodeUnit.EOL_COMMENT);
|
|
||||||
tool.addAction(eolCommentEditAction);
|
tool.addAction(eolCommentEditAction);
|
||||||
|
|
||||||
repeatableCommentEditAction =
|
repeatableCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name,
|
||||||
CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Repeatable Comment",
|
"Set Repeatable Comment", CodeUnit.REPEATABLE_COMMENT);
|
||||||
CodeUnit.REPEATABLE_COMMENT);
|
|
||||||
tool.addAction(repeatableCommentEditAction);
|
tool.addAction(repeatableCommentEditAction);
|
||||||
|
|
||||||
deleteAction = new ListingContextAction("Delete Comments", pluginName) {
|
deleteAction = new ListingContextAction("Delete Comments", pluginName) {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.exceptionhandlers.gcc;
|
package ghidra.app.plugin.exceptionhandlers.gcc;
|
||||||
|
|
||||||
import ghidra.app.cmd.comments.SetCommentsCmd;
|
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||||
import ghidra.app.cmd.data.CreateDataCmd;
|
import ghidra.app.cmd.data.CreateDataCmd;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
|
@ -59,7 +59,7 @@ public abstract class GccAnalysisClass {
|
||||||
* @param program the program being analyzed
|
* @param program the program being analyzed
|
||||||
*/
|
*/
|
||||||
protected void init(Program program) {
|
protected void init(Program program) {
|
||||||
initPointerInfo(program);
|
initPointerInfo();
|
||||||
dwordDT = new DWordDataType();
|
dwordDT = new DWordDataType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +67,8 @@ public abstract class GccAnalysisClass {
|
||||||
* Method that initializes information about the
|
* Method that initializes information about the
|
||||||
* program's pointer size and creates an appropriate
|
* program's pointer size and creates an appropriate
|
||||||
* pointer data type (i.e. ptrDT)
|
* pointer data type (i.e. ptrDT)
|
||||||
*
|
|
||||||
* @param program the program being analyzed
|
|
||||||
*/
|
*/
|
||||||
private void initPointerInfo(Program program) {
|
private void initPointerInfo() {
|
||||||
ptrDT = PointerDataType.getPointer(null, -1);
|
ptrDT = PointerDataType.getPointer(null, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +100,7 @@ public abstract class GccAnalysisClass {
|
||||||
protected static void createAndCommentData(Program program, Address addr, DataType dt,
|
protected static void createAndCommentData(Program program, Address addr, DataType dt,
|
||||||
String comment, int commentType) {
|
String comment, int commentType) {
|
||||||
createData(program, addr, dt);
|
createData(program, addr, dt);
|
||||||
SetCommentsCmd.createComment(program, addr, comment, commentType);
|
SetCommentCmd.createComment(program, addr, comment, commentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* ###
|
/* ###
|
||||||
* IP: GHIDRA
|
* IP: GHIDRA
|
||||||
* REVIEWED: YES
|
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,7 +19,6 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
import ghidra.app.cmd.comments.SetCommentCmd;
|
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||||
import ghidra.app.cmd.comments.SetCommentsCmd;
|
|
||||||
import ghidra.app.cmd.data.CreateArrayCmd;
|
import ghidra.app.cmd.data.CreateArrayCmd;
|
||||||
import ghidra.app.plugin.exceptionhandlers.gcc.*;
|
import ghidra.app.plugin.exceptionhandlers.gcc.*;
|
||||||
import ghidra.app.plugin.exceptionhandlers.gcc.datatype.*;
|
import ghidra.app.plugin.exceptionhandlers.gcc.datatype.*;
|
||||||
|
@ -213,8 +211,8 @@ public class Cie extends GccAnalysisClass {
|
||||||
createAndCommentData(program, addr, new StringDataType(), comment, CodeUnit.EOL_COMMENT);
|
createAndCommentData(program, addr, new StringDataType(), comment, CodeUnit.EOL_COMMENT);
|
||||||
Data dataAt = program.getListing().getDataAt(addr);
|
Data dataAt = program.getListing().getDataAt(addr);
|
||||||
if (dataAt == null) {
|
if (dataAt == null) {
|
||||||
throw new ExceptionHandlerFrameException("Couldn't process augmentation string @ " +
|
throw new ExceptionHandlerFrameException(
|
||||||
addr + ".");
|
"Couldn't process augmentation string @ " + addr + ".");
|
||||||
}
|
}
|
||||||
augmentationString = (String) dataAt.getValue();
|
augmentationString = (String) dataAt.getValue();
|
||||||
curSize += augmentationString.length() + 1; // Add 1 for the NUL byte
|
curSize += augmentationString.length() + 1; // Add 1 for the NUL byte
|
||||||
|
@ -435,14 +433,14 @@ public class Cie extends GccAnalysisClass {
|
||||||
*/
|
*/
|
||||||
private Address processInitialInstructions(Address addr) throws MemoryAccessException {
|
private Address processInitialInstructions(Address addr) throws MemoryAccessException {
|
||||||
CreateArrayCmd arrayCmd = null;
|
CreateArrayCmd arrayCmd = null;
|
||||||
SetCommentsCmd commentCmd = null;
|
|
||||||
|
|
||||||
// Create initial instructions array with remaining bytes
|
// Create initial instructions array with remaining bytes
|
||||||
initialInstructionCount = intLength - curSize;
|
initialInstructionCount = intLength - curSize;
|
||||||
arrayCmd = new CreateArrayCmd(addr, initialInstructionCount, new ByteDataType(), BYTE_LEN);
|
arrayCmd = new CreateArrayCmd(addr, initialInstructionCount, new ByteDataType(), BYTE_LEN);
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, "(CIE) Initial Instructions", null, null);
|
|
||||||
arrayCmd.applyTo(program);
|
arrayCmd.applyTo(program);
|
||||||
commentCmd.applyTo(program);
|
SetCommentCmd.createComment(program, addr, "(CIE) Initial Instructions",
|
||||||
|
CodeUnit.EOL_COMMENT);
|
||||||
|
|
||||||
initialInstructions = new byte[initialInstructionCount];
|
initialInstructions = new byte[initialInstructionCount];
|
||||||
int numBytesRead = program.getMemory().getBytes(addr, initialInstructions);
|
int numBytesRead = program.getMemory().getBytes(addr, initialInstructions);
|
||||||
|
|
||||||
|
@ -469,8 +467,8 @@ public class Cie extends GccAnalysisClass {
|
||||||
* @throws MemoryAccessException if memory for the CIE couldn't be read.
|
* @throws MemoryAccessException if memory for the CIE couldn't be read.
|
||||||
* @throws ExceptionHandlerFrameException if some of the CIE information couldn't be created.
|
* @throws ExceptionHandlerFrameException if some of the CIE information couldn't be created.
|
||||||
*/
|
*/
|
||||||
public void create(Address cieAddress) throws MemoryAccessException,
|
public void create(Address cieAddress)
|
||||||
ExceptionHandlerFrameException {
|
throws MemoryAccessException, ExceptionHandlerFrameException {
|
||||||
|
|
||||||
if (cieAddress == null || monitor.isCancelled()) {
|
if (cieAddress == null || monitor.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
|
@ -605,9 +603,8 @@ public class Cie extends GccAnalysisClass {
|
||||||
|
|
||||||
case 'P':
|
case 'P':
|
||||||
|
|
||||||
DwarfEHDecoder personalityDecoder =
|
DwarfEHDecoder personalityDecoder = processPersonalityEncoding(
|
||||||
processPersonalityEncoding(augmentationDataAddr, augmentationDataIndex,
|
augmentationDataAddr, augmentationDataIndex, augData);
|
||||||
augData);
|
|
||||||
augmentationDataIndex++;
|
augmentationDataIndex++;
|
||||||
|
|
||||||
DwarfDecodeContext personalityDecodeContext =
|
DwarfDecodeContext personalityDecodeContext =
|
||||||
|
@ -669,8 +666,9 @@ public class Cie extends GccAnalysisClass {
|
||||||
DataType prnsFuncPtrDt = personalityDecoder.getDataType(program);
|
DataType prnsFuncPtrDt = personalityDecoder.getDataType(program);
|
||||||
|
|
||||||
createAndCommentData(program, augmentationDataAddr.add(augmentationDataIndex),
|
createAndCommentData(program, augmentationDataAddr.add(augmentationDataIndex),
|
||||||
prnsFuncPtrDt, "(CIE Augmentation Data) Personality Function Pointer (" +
|
prnsFuncPtrDt,
|
||||||
personalityFuncAddr + ")", CodeUnit.EOL_COMMENT);
|
"(CIE Augmentation Data) Personality Function Pointer (" + personalityFuncAddr + ")",
|
||||||
|
CodeUnit.EOL_COMMENT);
|
||||||
|
|
||||||
program.getReferenceManager().addMemoryReference(
|
program.getReferenceManager().addMemoryReference(
|
||||||
augmentationDataAddr.add(augmentationDataIndex), personalityFuncAddr, RefType.DATA,
|
augmentationDataAddr.add(augmentationDataIndex), personalityFuncAddr, RefType.DATA,
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.exceptionhandlers.gcc.structures.ehFrame;
|
package ghidra.app.plugin.exceptionhandlers.gcc.structures.ehFrame;
|
||||||
|
|
||||||
import ghidra.app.cmd.comments.SetCommentsCmd;
|
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||||
import ghidra.app.plugin.exceptionhandlers.gcc.GccAnalysisUtils;
|
import ghidra.app.plugin.exceptionhandlers.gcc.GccAnalysisUtils;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.listing.CodeUnit;
|
import ghidra.program.model.listing.CodeUnit;
|
||||||
|
@ -142,7 +142,7 @@ public class DwarfCallFrameOpcodeParser {
|
||||||
else {
|
else {
|
||||||
switch (exOpcodeOrParam) {
|
switch (exOpcodeOrParam) {
|
||||||
|
|
||||||
// case DW_CFA_extended:
|
// case DW_CFA_extended:
|
||||||
case DW_CFA_nop:
|
case DW_CFA_nop:
|
||||||
primaryOpcode = true;
|
primaryOpcode = true;
|
||||||
sb.append("DW_CFA_nop");
|
sb.append("DW_CFA_nop");
|
||||||
|
@ -187,8 +187,8 @@ public class DwarfCallFrameOpcodeParser {
|
||||||
operand2Len = GccAnalysisUtils.getULEB128Length(program, curr);
|
operand2Len = GccAnalysisUtils.getULEB128Length(program, curr);
|
||||||
curr = curr.add(operand2Len);
|
curr = curr.add(operand2Len);
|
||||||
|
|
||||||
sb.append("DW_CFA_offset_extended reg[" + operand1 + "] reg[" + operand2 +
|
sb.append(
|
||||||
"]");
|
"DW_CFA_offset_extended reg[" + operand1 + "] reg[" + operand2 + "]");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DW_CFA_restore_extended:
|
case DW_CFA_restore_extended:
|
||||||
|
@ -370,35 +370,10 @@ public class DwarfCallFrameOpcodeParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setComment(instrAddr, sb.toString(), CodeUnit.EOL_COMMENT);
|
SetCommentCmd.createComment(program, instrAddr, sb.toString(), CodeUnit.EOL_COMMENT);
|
||||||
|
|
||||||
Msg.info(this, sb.toString());
|
Msg.info(this, sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setComment(Address addr, String comment, int commentType) {
|
|
||||||
SetCommentsCmd commentCmd = null;
|
|
||||||
|
|
||||||
switch (commentType) {
|
|
||||||
case CodeUnit.PRE_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, comment, null, null, null, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.POST_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, comment, null, null, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.EOL_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, comment, null, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.PLATE_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, null, comment, null);
|
|
||||||
break;
|
|
||||||
case CodeUnit.REPEATABLE_COMMENT:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, null, null, comment);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, comment, null, null);
|
|
||||||
}
|
|
||||||
commentCmd.applyTo(program);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
package ghidra.app.plugin.exceptionhandlers.gcc.structures.ehFrame;
|
package ghidra.app.plugin.exceptionhandlers.gcc.structures.ehFrame;
|
||||||
|
|
||||||
import ghidra.app.cmd.comments.SetCommentCmd;
|
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||||
import ghidra.app.cmd.comments.SetCommentsCmd;
|
|
||||||
import ghidra.app.cmd.data.CreateArrayCmd;
|
import ghidra.app.cmd.data.CreateArrayCmd;
|
||||||
import ghidra.app.cmd.function.CreateFunctionCmd;
|
import ghidra.app.cmd.function.CreateFunctionCmd;
|
||||||
import ghidra.app.plugin.exceptionhandlers.gcc.*;
|
import ghidra.app.plugin.exceptionhandlers.gcc.*;
|
||||||
|
@ -113,7 +112,7 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
* @param monitor a status monitor for tracking progress and allowing cancelling when creating
|
* @param monitor a status monitor for tracking progress and allowing cancelling when creating
|
||||||
* an FDE.
|
* an FDE.
|
||||||
* @param program the program where this will create an FDE.
|
* @param program the program where this will create an FDE.
|
||||||
* @param cie the call frame information entry for this FDE.
|
* @param cieSource the call frame information entry for this FDE.
|
||||||
*/
|
*/
|
||||||
public FrameDescriptionEntry(TaskMonitor monitor, Program program, CieSource cieSource) {
|
public FrameDescriptionEntry(TaskMonitor monitor, Program program, CieSource cieSource) {
|
||||||
super(monitor, program);
|
super(monitor, program);
|
||||||
|
@ -157,8 +156,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
case 8:
|
case 8:
|
||||||
return new QWordDataType();
|
return new QWordDataType();
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unhandled pointer size -- " +
|
throw new IllegalArgumentException(
|
||||||
pointerDecodeSize + " bytes");
|
"Unhandled pointer size -- " + pointerDecodeSize + " bytes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,8 +189,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
* @throws MemoryAccessException if the required memory can't be read
|
* @throws MemoryAccessException if the required memory can't be read
|
||||||
* @throws ExceptionHandlerFrameException if there is an error creating the information.
|
* @throws ExceptionHandlerFrameException if there is an error creating the information.
|
||||||
*/
|
*/
|
||||||
private Address createCiePointer(Address addr) throws MemoryAccessException,
|
private Address createCiePointer(Address addr)
|
||||||
ExceptionHandlerFrameException {
|
throws MemoryAccessException, ExceptionHandlerFrameException {
|
||||||
/*
|
/*
|
||||||
* Create a new CIE Pointer field at the specified address and sets an
|
* Create a new CIE Pointer field at the specified address and sets an
|
||||||
* appropriate comment for the new structure.
|
* appropriate comment for the new structure.
|
||||||
|
@ -210,16 +209,16 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
if (isInDebugFrame(addr)) {
|
if (isInDebugFrame(addr)) {
|
||||||
|
|
||||||
if (intPtr == -1) {
|
if (intPtr == -1) {
|
||||||
throw new ExceptionHandlerFrameException("Invalid CIE Reference Pointer (0x" +
|
throw new ExceptionHandlerFrameException(
|
||||||
Integer.toHexString(intPtr) + ")");
|
"Invalid CIE Reference Pointer (0x" + Integer.toHexString(intPtr) + ")");
|
||||||
}
|
}
|
||||||
cieAddr = addr.getNewAddress(intPtr); // absolute ref
|
cieAddr = addr.getNewAddress(intPtr); // absolute ref
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (intPtr == 0) {
|
if (intPtr == 0) {
|
||||||
throw new ExceptionHandlerFrameException("Invalid CIE Reference Pointer (0x" +
|
throw new ExceptionHandlerFrameException(
|
||||||
Integer.toHexString(intPtr) + ")");
|
"Invalid CIE Reference Pointer (0x" + Integer.toHexString(intPtr) + ")");
|
||||||
}
|
}
|
||||||
cieAddr = addr.subtract(intPtr); // relative ref
|
cieAddr = addr.subtract(intPtr); // relative ref
|
||||||
}
|
}
|
||||||
|
@ -282,8 +281,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
* @throws ExceptionHandlerFrameException if there is an error creating the information.
|
* @throws ExceptionHandlerFrameException if there is an error creating the information.
|
||||||
* @throws MemoryAccessException if the required memory can't be read
|
* @throws MemoryAccessException if the required memory can't be read
|
||||||
*/
|
*/
|
||||||
private Address createPcRange(Address addr) throws ExceptionHandlerFrameException,
|
private Address createPcRange(Address addr)
|
||||||
MemoryAccessException {
|
throws ExceptionHandlerFrameException, MemoryAccessException {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new pcRange field at the specified address
|
* Create a new pcRange field at the specified address
|
||||||
|
@ -362,14 +361,11 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
* @throws MemoryAccessException if the required memory can't be read
|
* @throws MemoryAccessException if the required memory can't be read
|
||||||
*/
|
*/
|
||||||
private Address createAugmentationData(Address addr) throws MemoryAccessException {
|
private Address createAugmentationData(Address addr) throws MemoryAccessException {
|
||||||
SetCommentsCmd commentCmd = null;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new Augmentation Data field at the specified address
|
* Create a new Augmentation Data field at the specified address
|
||||||
* and sets an appropriate comment for the new structure.
|
* and sets an appropriate comment for the new structure.
|
||||||
*/
|
*/
|
||||||
commentCmd = new SetCommentsCmd(addr, null, null, "(FDE) Augmentation Data", null, null);
|
SetCommentCmd.createComment(program, addr, "(FDE) Augmentation Data", CodeUnit.EOL_COMMENT);
|
||||||
commentCmd.applyTo(program);
|
|
||||||
|
|
||||||
this.augmentationData = new byte[intAugmentationDataLength];
|
this.augmentationData = new byte[intAugmentationDataLength];
|
||||||
program.getMemory().getBytes(addr, augmentationData);
|
program.getMemory().getBytes(addr, augmentationData);
|
||||||
|
@ -387,16 +383,14 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
*/
|
*/
|
||||||
private Address createCallFrameInstructions(Address addr) throws MemoryAccessException {
|
private Address createCallFrameInstructions(Address addr) throws MemoryAccessException {
|
||||||
CreateArrayCmd arrayCmd = null;
|
CreateArrayCmd arrayCmd = null;
|
||||||
SetCommentsCmd commentCmd = null;
|
|
||||||
|
|
||||||
// Create initial instructions array with remaining bytes.
|
// Create initial instructions array with remaining bytes.
|
||||||
int instructionLength = intLength - curSize;
|
int instructionLength = intLength - curSize;
|
||||||
arrayCmd = new CreateArrayCmd(addr, instructionLength, new ByteDataType(), BYTE_LEN);
|
arrayCmd = new CreateArrayCmd(addr, instructionLength, new ByteDataType(), BYTE_LEN);
|
||||||
arrayCmd.applyTo(program);
|
arrayCmd.applyTo(program);
|
||||||
|
|
||||||
commentCmd =
|
SetCommentCmd.createComment(program, addr, "(FDE) Call Frame Instructions",
|
||||||
new SetCommentsCmd(addr, null, null, "(FDE) Call Frame Instructions", null, null);
|
CodeUnit.EOL_COMMENT);
|
||||||
commentCmd.applyTo(program);
|
|
||||||
|
|
||||||
callFrameInstructions = new byte[instructionLength];
|
callFrameInstructions = new byte[instructionLength];
|
||||||
program.getMemory().getBytes(addr, callFrameInstructions);
|
program.getMemory().getBytes(addr, callFrameInstructions);
|
||||||
|
@ -428,8 +422,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
* @throws MemoryAccessException if memory for the FDE or its associated data can't be accessed
|
* @throws MemoryAccessException if memory for the FDE or its associated data can't be accessed
|
||||||
* @throws ExceptionHandlerFrameException if there is an error creating the FDE information.
|
* @throws ExceptionHandlerFrameException if there is an error creating the FDE information.
|
||||||
*/
|
*/
|
||||||
public RegionDescriptor create(Address fdeBaseAddress) throws MemoryAccessException,
|
public RegionDescriptor create(Address fdeBaseAddress)
|
||||||
ExceptionHandlerFrameException {
|
throws MemoryAccessException, ExceptionHandlerFrameException {
|
||||||
|
|
||||||
if (fdeBaseAddress == null || monitor.isCancelled()) {
|
if (fdeBaseAddress == null || monitor.isCancelled()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -464,8 +458,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
createFuncCmd.applyTo(program);
|
createFuncCmd.applyTo(program);
|
||||||
}
|
}
|
||||||
catch (AddressOutOfBoundsException e) {
|
catch (AddressOutOfBoundsException e) {
|
||||||
throw new ExceptionHandlerFrameException(e.getMessage() + ": " +
|
throw new ExceptionHandlerFrameException(
|
||||||
pcBeginAddr.toString() + " + " + intPcRange);
|
e.getMessage() + ": " + pcBeginAddr.toString() + " + " + intPcRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If some FDE data remains, then it is the augmentation fields or call frame instructions.
|
// If some FDE data remains, then it is the augmentation fields or call frame instructions.
|
||||||
|
@ -572,9 +566,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
|
|
||||||
DwarfEHDecoder decoder = cie.getLSDADecoder();
|
DwarfEHDecoder decoder = cie.getLSDADecoder();
|
||||||
|
|
||||||
DwarfDecodeContext ctx =
|
DwarfDecodeContext ctx = new DwarfDecodeContext(program, augmentationDataAddr,
|
||||||
new DwarfDecodeContext(program, augmentationDataAddr, region.getEHMemoryBlock()
|
region.getEHMemoryBlock().getStart());
|
||||||
.getStart());
|
|
||||||
|
|
||||||
Address potentialAugmentationDataExAddr = decoder.decodeAddress(ctx);
|
Address potentialAugmentationDataExAddr = decoder.decodeAddress(ctx);
|
||||||
|
|
||||||
|
@ -588,9 +581,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String label =
|
String label = "eh_augmentation_" + pcBeginAddr + ".." + pcEndAddr + "_" +
|
||||||
"eh_augmentation_" + pcBeginAddr + ".." + pcEndAddr + "_" +
|
augmentationDataExAddr;
|
||||||
augmentationDataExAddr;
|
|
||||||
|
|
||||||
program.getSymbolTable().createLabel(augmentationDataExAddr, label,
|
program.getSymbolTable().createLabel(augmentationDataExAddr, label,
|
||||||
SourceType.ANALYSIS);
|
SourceType.ANALYSIS);
|
||||||
|
@ -600,9 +592,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CreateArrayCmd arrayCmd =
|
CreateArrayCmd arrayCmd = new CreateArrayCmd(augmentationDataAddr,
|
||||||
new CreateArrayCmd(augmentationDataAddr, intAugmentationDataLength,
|
intAugmentationDataLength, new ByteDataType(), BYTE_LEN);
|
||||||
new ByteDataType(), BYTE_LEN);
|
|
||||||
arrayCmd.applyTo(program);
|
arrayCmd.applyTo(program);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,10 +626,9 @@ public class FrameDescriptionEntry extends GccAnalysisClass {
|
||||||
|
|
||||||
if (!program.getMemory().getAllInitializedAddressSet().contains(lsdaAddr)) {
|
if (!program.getMemory().getAllInitializedAddressSet().contains(lsdaAddr)) {
|
||||||
|
|
||||||
String errorMessage =
|
String errorMessage = "Can't create LSDA data @ " + lsdaAddr +
|
||||||
"Can't create LSDA data @ " + lsdaAddr +
|
". The address is not in the program's initialized memory! CIE @ " +
|
||||||
". The address is not in the program's initialized memory! CIE @ " +
|
cie.getAddress() + " FDE @ " + baseAddress;
|
||||||
cie.getAddress() + " FDE @ " + baseAddress;
|
|
||||||
|
|
||||||
// Log error.
|
// Log error.
|
||||||
Msg.error(this, errorMessage);
|
Msg.error(this, errorMessage);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.util.bin.format.pdb;
|
package ghidra.app.util.bin.format.pdb;
|
||||||
|
|
||||||
import ghidra.app.cmd.comments.SetCommentsCmd;
|
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||||
import ghidra.app.util.PseudoDisassembler;
|
import ghidra.app.util.PseudoDisassembler;
|
||||||
import ghidra.app.util.PseudoInstruction;
|
import ghidra.app.util.PseudoInstruction;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
|
@ -29,6 +29,9 @@ final class PdbUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an address using the relative offset + image base.
|
* Returns an address using the relative offset + image base.
|
||||||
|
* @param program the {@link Program} for which to act
|
||||||
|
* @param relativeOffset the relative offset
|
||||||
|
* @return the calculated {@link Address}
|
||||||
*/
|
*/
|
||||||
final static Address reladdr(Program program, int relativeOffset) {
|
final static Address reladdr(Program program, int relativeOffset) {
|
||||||
return reladdr(program, relativeOffset & Conv.INT_MASK);
|
return reladdr(program, relativeOffset & Conv.INT_MASK);
|
||||||
|
@ -36,6 +39,9 @@ final class PdbUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an address using the relative offset + image base.
|
* Returns an address using the relative offset + image base.
|
||||||
|
* @param program the {@link Program} for which to act
|
||||||
|
* @param relativeOffset the relative offset
|
||||||
|
* @return the calculated {@link Address}
|
||||||
*/
|
*/
|
||||||
final static Address reladdr(Program program, long relativeOffset) {
|
final static Address reladdr(Program program, long relativeOffset) {
|
||||||
return program.getImageBase().add(relativeOffset);
|
return program.getImageBase().add(relativeOffset);
|
||||||
|
@ -59,13 +65,18 @@ final class PdbUtil {
|
||||||
text = comment + "\n" + text;
|
text = comment + "\n" + text;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCommentsCmd.createComment(program, address, text, commentType);
|
SetCommentCmd.createComment(program, address, text, commentType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true is this symbol represents a function.
|
* Returns true is this symbol represents a function.
|
||||||
* For example, "FunctionName@4" or "MyFunction@22".
|
* For example, "FunctionName@4" or "MyFunction@22".
|
||||||
|
* @param program the {@link Program} for which to check
|
||||||
|
* @param symbol the symbol to check
|
||||||
|
* @param addr {@link Address} of the symbol
|
||||||
|
* @param length the length for the check
|
||||||
|
* @return {@code true} upon success
|
||||||
*/
|
*/
|
||||||
final static boolean isFunction(Program program, String symbol, Address addr, int length) {
|
final static boolean isFunction(Program program, String symbol, Address addr, int length) {
|
||||||
int atpos = symbol.lastIndexOf('@');
|
int atpos = symbol.lastIndexOf('@');
|
||||||
|
@ -143,6 +154,8 @@ final class PdbUtil {
|
||||||
* ...
|
* ...
|
||||||
* 23rd pass
|
* 23rd pass
|
||||||
* etc.
|
* etc.
|
||||||
|
* @param pass the number value of the pass to make pretty
|
||||||
|
* @return the string result
|
||||||
*/
|
*/
|
||||||
final static String getPass(int pass) {
|
final static String getPass(int pass) {
|
||||||
if (pass > 20) {
|
if (pass > 20) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue