From 2174080d396ed005562242a28c405cf61d361017 Mon Sep 17 00:00:00 2001 From: ghizard <50744617+ghizard@users.noreply.github.com> Date: Mon, 12 Aug 2019 17:25:39 -0400 Subject: [PATCH 1/2] GT-3078 initial check-in of SetCommentCmd over SetCommentsCmd --- .../app/cmd/comments/SetCommentCmd.java | 21 +++++- .../app/cmd/comments/SetCommentsCmd.java | 40 +----------- .../plugin/core/comments/CommentsPlugin.java | 47 ++++++-------- .../gcc/GccAnalysisClass.java | 10 ++- .../gcc/structures/ehFrame/Cie.java | 26 ++++---- .../ehFrame/DwarfCallFrameOpcodeParser.java | 35 ++-------- .../ehFrame/FrameDescriptionEntry.java | 64 ++++++++----------- .../app/util/bin/format/pdb/PdbUtil.java | 17 ++++- 8 files changed, 104 insertions(+), 156 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java index 531204e6a8..a3a2514675 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java @@ -75,9 +75,8 @@ public class SetCommentCmd implements Command { public boolean applyTo(DomainObject obj) { CodeUnit cu = getCodeUnit((Program) obj); if (cu == null) { - message = - "No Instruction or Data found for address " + address.toString() + - " Is this address valid?"; + message = "No Instruction or Data found for address " + address.toString() + + " Is this address valid?"; return false; } if (commentChanged(cu.getComment(commentType), comment)) { @@ -113,4 +112,20 @@ public class SetCommentCmd implements Command { return message; } + /** + * 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) { + SetCommentCmd commentCmd = new SetCommentCmd(addr, commentType, comment); + commentCmd.applyTo(program); + } + } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentsCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentsCmd.java index 0da6bf5103..d666f55985 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentsCmd.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentsCmd.java @@ -65,8 +65,8 @@ public class SetCommentsCmd implements Command { /** * return true if the newValue and oldValue are different - * @param newValue - * @param oldValue + * @param newValue the value that we desire to set + * @param oldValue the existing value * @return boolean */ private boolean commentChanged(String newValue, String oldValue) { @@ -141,40 +141,4 @@ public class SetCommentsCmd implements Command { 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); - } - } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java index a638dab628..447a7ac2d6 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java @@ -15,6 +15,10 @@ */ package ghidra.app.plugin.core.comments; +import java.awt.event.KeyEvent; + +import docking.ActionContext; +import docking.action.*; import ghidra.app.CorePluginPackage; import ghidra.app.cmd.comments.SetCommentCmd; import ghidra.app.cmd.comments.SetCommentsCmd; @@ -30,11 +34,6 @@ import ghidra.program.model.listing.Program; import ghidra.program.util.*; 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. */ @@ -88,8 +87,8 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener { HelpLocation helpLocation = new HelpLocation(getName(), "Comments_Option"); options.setOptionsHelpLocation(helpLocation); options.registerOption(OPTION_NAME, dialog.getEnterMode(), helpLocation, - "Toggle for whether pressing the key causes the comment to be entered," - + " versus adding a new line character in the comment."); + "Toggle for whether pressing the key causes the comment to be entered," + + " versus adding a new line character in the comment."); setOptions(options); options.addOptionsChangeListener(this); @@ -115,15 +114,16 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener { plateComment = (plateComment.length() == 0) ? null : plateComment; repeatableComment = (repeatableComment.length() == 0) ? null : repeatableComment; - Command cmd = - new SetCommentsCmd(cu.getMinAddress(), preComment, postComment, eolComment, - plateComment, repeatableComment); + Command cmd = new SetCommentsCmd(cu.getMinAddress(), preComment, postComment, eolComment, + plateComment, repeatableComment); 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) { 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); tool.addAction(editAction); - preCommentEditAction = - CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Pre Comment", - CodeUnit.PRE_COMMENT); + preCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name, + "Set Pre Comment", CodeUnit.PRE_COMMENT); tool.addAction(preCommentEditAction); - postCommentEditAction = - CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Post Comment", - CodeUnit.POST_COMMENT); + postCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name, + "Set Post Comment", CodeUnit.POST_COMMENT); tool.addAction(postCommentEditAction); - plateCommentEditAction = - CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Plate Comment", - CodeUnit.PLATE_COMMENT); + plateCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name, + "Set Plate Comment", CodeUnit.PLATE_COMMENT); tool.addAction(plateCommentEditAction); - eolCommentEditAction = - CommentsActionFactory.getSetCommentsAction(dialog, name, "Set EOL Comment", - CodeUnit.EOL_COMMENT); + eolCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name, + "Set EOL Comment", CodeUnit.EOL_COMMENT); tool.addAction(eolCommentEditAction); - repeatableCommentEditAction = - CommentsActionFactory.getSetCommentsAction(dialog, name, "Set Repeatable Comment", - CodeUnit.REPEATABLE_COMMENT); + repeatableCommentEditAction = CommentsActionFactory.getSetCommentsAction(dialog, name, + "Set Repeatable Comment", CodeUnit.REPEATABLE_COMMENT); tool.addAction(repeatableCommentEditAction); deleteAction = new ListingContextAction("Delete Comments", pluginName) { diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccAnalysisClass.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccAnalysisClass.java index 27ce25c210..119ac4a1a6 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccAnalysisClass.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/GccAnalysisClass.java @@ -15,7 +15,7 @@ */ 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.program.model.address.Address; import ghidra.program.model.data.*; @@ -59,7 +59,7 @@ public abstract class GccAnalysisClass { * @param program the program being analyzed */ protected void init(Program program) { - initPointerInfo(program); + initPointerInfo(); dwordDT = new DWordDataType(); } @@ -67,10 +67,8 @@ public abstract class GccAnalysisClass { * Method that initializes information about the * program's pointer size and creates an appropriate * 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); } @@ -102,7 +100,7 @@ public abstract class GccAnalysisClass { protected static void createAndCommentData(Program program, Address addr, DataType dt, String comment, int commentType) { createData(program, addr, dt); - SetCommentsCmd.createComment(program, addr, comment, commentType); + SetCommentCmd.createComment(program, addr, comment, commentType); } } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/Cie.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/Cie.java index 38973d0bcc..bcaa07e3de 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/Cie.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/Cie.java @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (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 ghidra.app.cmd.comments.SetCommentCmd; -import ghidra.app.cmd.comments.SetCommentsCmd; import ghidra.app.cmd.data.CreateArrayCmd; import ghidra.app.plugin.exceptionhandlers.gcc.*; 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); Data dataAt = program.getListing().getDataAt(addr); if (dataAt == null) { - throw new ExceptionHandlerFrameException("Couldn't process augmentation string @ " + - addr + "."); + throw new ExceptionHandlerFrameException( + "Couldn't process augmentation string @ " + addr + "."); } augmentationString = (String) dataAt.getValue(); 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 { CreateArrayCmd arrayCmd = null; - SetCommentsCmd commentCmd = null; // Create initial instructions array with remaining bytes initialInstructionCount = intLength - curSize; arrayCmd = new CreateArrayCmd(addr, initialInstructionCount, new ByteDataType(), BYTE_LEN); - commentCmd = new SetCommentsCmd(addr, null, null, "(CIE) Initial Instructions", null, null); arrayCmd.applyTo(program); - commentCmd.applyTo(program); + SetCommentCmd.createComment(program, addr, "(CIE) Initial Instructions", + CodeUnit.EOL_COMMENT); + initialInstructions = new byte[initialInstructionCount]; 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 ExceptionHandlerFrameException if some of the CIE information couldn't be created. */ - public void create(Address cieAddress) throws MemoryAccessException, - ExceptionHandlerFrameException { + public void create(Address cieAddress) + throws MemoryAccessException, ExceptionHandlerFrameException { if (cieAddress == null || monitor.isCancelled()) { return; @@ -605,9 +603,8 @@ public class Cie extends GccAnalysisClass { case 'P': - DwarfEHDecoder personalityDecoder = - processPersonalityEncoding(augmentationDataAddr, augmentationDataIndex, - augData); + DwarfEHDecoder personalityDecoder = processPersonalityEncoding( + augmentationDataAddr, augmentationDataIndex, augData); augmentationDataIndex++; DwarfDecodeContext personalityDecodeContext = @@ -669,8 +666,9 @@ public class Cie extends GccAnalysisClass { DataType prnsFuncPtrDt = personalityDecoder.getDataType(program); createAndCommentData(program, augmentationDataAddr.add(augmentationDataIndex), - prnsFuncPtrDt, "(CIE Augmentation Data) Personality Function Pointer (" + - personalityFuncAddr + ")", CodeUnit.EOL_COMMENT); + prnsFuncPtrDt, + "(CIE Augmentation Data) Personality Function Pointer (" + personalityFuncAddr + ")", + CodeUnit.EOL_COMMENT); program.getReferenceManager().addMemoryReference( augmentationDataAddr.add(augmentationDataIndex), personalityFuncAddr, RefType.DATA, diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/DwarfCallFrameOpcodeParser.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/DwarfCallFrameOpcodeParser.java index 0befbcf953..23868eaeb3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/DwarfCallFrameOpcodeParser.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/DwarfCallFrameOpcodeParser.java @@ -18,7 +18,7 @@ */ 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.program.model.address.Address; import ghidra.program.model.listing.CodeUnit; @@ -142,7 +142,7 @@ public class DwarfCallFrameOpcodeParser { else { switch (exOpcodeOrParam) { - // case DW_CFA_extended: + // case DW_CFA_extended: case DW_CFA_nop: primaryOpcode = true; sb.append("DW_CFA_nop"); @@ -187,8 +187,8 @@ public class DwarfCallFrameOpcodeParser { operand2Len = GccAnalysisUtils.getULEB128Length(program, curr); 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; 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()); } } - 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); - } - } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java index c05585d56b..18b9d868f9 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/structures/ehFrame/FrameDescriptionEntry.java @@ -16,7 +16,6 @@ package ghidra.app.plugin.exceptionhandlers.gcc.structures.ehFrame; import ghidra.app.cmd.comments.SetCommentCmd; -import ghidra.app.cmd.comments.SetCommentsCmd; import ghidra.app.cmd.data.CreateArrayCmd; import ghidra.app.cmd.function.CreateFunctionCmd; 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 * 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) { super(monitor, program); @@ -157,8 +156,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass { case 8: return new QWordDataType(); default: - throw new IllegalArgumentException("Unhandled pointer size -- " + - pointerDecodeSize + " bytes"); + throw new IllegalArgumentException( + "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 ExceptionHandlerFrameException if there is an error creating the information. */ - private Address createCiePointer(Address addr) throws MemoryAccessException, - ExceptionHandlerFrameException { + private Address createCiePointer(Address addr) + throws MemoryAccessException, ExceptionHandlerFrameException { /* * Create a new CIE Pointer field at the specified address and sets an * appropriate comment for the new structure. @@ -210,16 +209,16 @@ public class FrameDescriptionEntry extends GccAnalysisClass { if (isInDebugFrame(addr)) { if (intPtr == -1) { - throw new ExceptionHandlerFrameException("Invalid CIE Reference Pointer (0x" + - Integer.toHexString(intPtr) + ")"); + throw new ExceptionHandlerFrameException( + "Invalid CIE Reference Pointer (0x" + Integer.toHexString(intPtr) + ")"); } cieAddr = addr.getNewAddress(intPtr); // absolute ref } else { if (intPtr == 0) { - throw new ExceptionHandlerFrameException("Invalid CIE Reference Pointer (0x" + - Integer.toHexString(intPtr) + ")"); + throw new ExceptionHandlerFrameException( + "Invalid CIE Reference Pointer (0x" + Integer.toHexString(intPtr) + ")"); } 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 MemoryAccessException if the required memory can't be read */ - private Address createPcRange(Address addr) throws ExceptionHandlerFrameException, - MemoryAccessException { + private Address createPcRange(Address addr) + throws ExceptionHandlerFrameException, MemoryAccessException { /* * 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 */ private Address createAugmentationData(Address addr) throws MemoryAccessException { - SetCommentsCmd commentCmd = null; - /* * Create a new Augmentation Data field at the specified address * and sets an appropriate comment for the new structure. */ - commentCmd = new SetCommentsCmd(addr, null, null, "(FDE) Augmentation Data", null, null); - commentCmd.applyTo(program); + SetCommentCmd.createComment(program, addr, "(FDE) Augmentation Data", CodeUnit.EOL_COMMENT); this.augmentationData = new byte[intAugmentationDataLength]; program.getMemory().getBytes(addr, augmentationData); @@ -387,16 +383,14 @@ public class FrameDescriptionEntry extends GccAnalysisClass { */ private Address createCallFrameInstructions(Address addr) throws MemoryAccessException { CreateArrayCmd arrayCmd = null; - SetCommentsCmd commentCmd = null; // Create initial instructions array with remaining bytes. int instructionLength = intLength - curSize; arrayCmd = new CreateArrayCmd(addr, instructionLength, new ByteDataType(), BYTE_LEN); arrayCmd.applyTo(program); - commentCmd = - new SetCommentsCmd(addr, null, null, "(FDE) Call Frame Instructions", null, null); - commentCmd.applyTo(program); + SetCommentCmd.createComment(program, addr, "(FDE) Call Frame Instructions", + CodeUnit.EOL_COMMENT); callFrameInstructions = new byte[instructionLength]; 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 ExceptionHandlerFrameException if there is an error creating the FDE information. */ - public RegionDescriptor create(Address fdeBaseAddress) throws MemoryAccessException, - ExceptionHandlerFrameException { + public RegionDescriptor create(Address fdeBaseAddress) + throws MemoryAccessException, ExceptionHandlerFrameException { if (fdeBaseAddress == null || monitor.isCancelled()) { return null; @@ -464,8 +458,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass { createFuncCmd.applyTo(program); } catch (AddressOutOfBoundsException e) { - throw new ExceptionHandlerFrameException(e.getMessage() + ": " + - pcBeginAddr.toString() + " + " + intPcRange); + throw new ExceptionHandlerFrameException( + e.getMessage() + ": " + pcBeginAddr.toString() + " + " + intPcRange); } // 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(); - DwarfDecodeContext ctx = - new DwarfDecodeContext(program, augmentationDataAddr, region.getEHMemoryBlock() - .getStart()); + DwarfDecodeContext ctx = new DwarfDecodeContext(program, augmentationDataAddr, + region.getEHMemoryBlock().getStart()); Address potentialAugmentationDataExAddr = decoder.decodeAddress(ctx); @@ -588,9 +581,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass { try { - String label = - "eh_augmentation_" + pcBeginAddr + ".." + pcEndAddr + "_" + - augmentationDataExAddr; + String label = "eh_augmentation_" + pcBeginAddr + ".." + pcEndAddr + "_" + + augmentationDataExAddr; program.getSymbolTable().createLabel(augmentationDataExAddr, label, SourceType.ANALYSIS); @@ -600,9 +592,8 @@ public class FrameDescriptionEntry extends GccAnalysisClass { } } else { - CreateArrayCmd arrayCmd = - new CreateArrayCmd(augmentationDataAddr, intAugmentationDataLength, - new ByteDataType(), BYTE_LEN); + CreateArrayCmd arrayCmd = new CreateArrayCmd(augmentationDataAddr, + intAugmentationDataLength, new ByteDataType(), BYTE_LEN); arrayCmd.applyTo(program); } } @@ -635,10 +626,9 @@ public class FrameDescriptionEntry extends GccAnalysisClass { if (!program.getMemory().getAllInitializedAddressSet().contains(lsdaAddr)) { - String errorMessage = - "Can't create LSDA data @ " + lsdaAddr + - ". The address is not in the program's initialized memory! CIE @ " + - cie.getAddress() + " FDE @ " + baseAddress; + String errorMessage = "Can't create LSDA data @ " + lsdaAddr + + ". The address is not in the program's initialized memory! CIE @ " + + cie.getAddress() + " FDE @ " + baseAddress; // Log error. Msg.error(this, errorMessage); diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbUtil.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbUtil.java index 595aab9d2a..12e3c86125 100644 --- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbUtil.java +++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbUtil.java @@ -15,7 +15,7 @@ */ 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.PseudoInstruction; import ghidra.program.model.address.Address; @@ -29,6 +29,9 @@ final class PdbUtil { /** * 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) { return reladdr(program, relativeOffset & Conv.INT_MASK); @@ -36,6 +39,9 @@ final class PdbUtil { /** * 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) { return program.getImageBase().add(relativeOffset); @@ -59,13 +65,18 @@ final class PdbUtil { text = comment + "\n" + text; } - SetCommentsCmd.createComment(program, address, text, commentType); + SetCommentCmd.createComment(program, address, text, commentType); } /** * Returns true is this symbol represents a function. * 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) { int atpos = symbol.lastIndexOf('@'); @@ -143,6 +154,8 @@ final class PdbUtil { * ... * 23rd pass * etc. + * @param pass the number value of the pass to make pretty + * @return the string result */ final static String getPass(int pass) { if (pass > 20) { From 4748ddc2ef43695a45fc0eaae02e322fa28f4d1d Mon Sep 17 00:00:00 2001 From: ghizard <50744617+ghizard@users.noreply.github.com> Date: Tue, 13 Aug 2019 12:54:16 -0400 Subject: [PATCH 2/2] GT-3078 review fix. --- .../src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java index a3a2514675..61b297d566 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/comments/SetCommentCmd.java @@ -113,7 +113,8 @@ public class SetCommentCmd implements Command { } /** - * Creates the specified comment of the specified type at address. + * 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