Java Code Examples for ghidra.program.model.listing.CodeUnit#PLATE_COMMENT

The following examples show how to use ghidra.program.model.listing.CodeUnit#PLATE_COMMENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommentMerger.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private int getCodeUnitCommentType(int programMergeCommentType) {
	switch (programMergeCommentType) {
		case ProgramMergeFilter.PLATE_COMMENTS:
			return CodeUnit.PLATE_COMMENT;
		case ProgramMergeFilter.PRE_COMMENTS:
			return CodeUnit.PRE_COMMENT;
		case ProgramMergeFilter.EOL_COMMENTS:
			return CodeUnit.EOL_COMMENT;
		case ProgramMergeFilter.REPEATABLE_COMMENTS:
			return CodeUnit.REPEATABLE_COMMENT;
		case ProgramMergeFilter.POST_COMMENTS:
			return CodeUnit.POST_COMMENT;
		default:
			return -1;
	}
}
 
Example 2
Source File: DecompilerCommentsActionFactory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected ProgramLocation getLocationForContext(
        ActionContext actionContext) {
    // only allow decompiler to have PRE, PLATE, and Generic Comment actions
    if ((actionContext instanceof DecompilerActionContext)
            && commentType != CodeUnit.PRE_COMMENT
            && commentType != CodeUnit.PLATE_COMMENT
            && commentType != CodeUnit.NO_COMMENT) {
        return null;
    }

    if ( !(actionContext instanceof ProgramLocationActionContext) ) {
        return null;
    }
    
    ProgramLocationActionContext context = (ProgramLocationActionContext) actionContext;
    return context.getLocation();
}
 
Example 3
Source File: CommentHistoryDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private JPanel buildMainPanel() {
	JPanel mainPanel = new JPanel(new BorderLayout());
	tabbedPane = new JTabbedPane();
	mainPanel.add(tabbedPane);
	
	eolPanel = new CommentHistoryPanel(CodeUnit.EOL_COMMENT);
	prePanel = new CommentHistoryPanel(CodeUnit.PRE_COMMENT);
	postPanel = new CommentHistoryPanel(CodeUnit.POST_COMMENT);
	platePanel = new CommentHistoryPanel(CodeUnit.PLATE_COMMENT);
	repeatablePanel = new CommentHistoryPanel(CodeUnit.REPEATABLE_COMMENT);

	JScrollPane sp = new JScrollPane(eolPanel);
	JViewport vp = sp.getViewport();
	Dimension d = vp.getPreferredSize();
	sp.getViewport().setPreferredSize(new Dimension(500, d.height*7));
	tabbedPane.addTab("  EOL Comment    ",sp);
	tabbedPane.addTab("  Pre Comment    ",new JScrollPane(prePanel));
	tabbedPane.addTab("  Post Comment   ",new JScrollPane(postPanel));
	tabbedPane.addTab("  Plate Comment  ",new JScrollPane(platePanel));
	tabbedPane.addTab("  Repeatable Comment  ", new JScrollPane(repeatablePanel));
	
	tabbedPane.addChangeListener(this);
	return mainPanel;
}
 
Example 4
Source File: CommentsDialog.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void setCommentType(int type) {
	switch (type) {
		case CodeUnit.EOL_COMMENT:
			tab.setSelectedIndex(0);
			break;
		case CodeUnit.PRE_COMMENT:
			tab.setSelectedIndex(1);
			break;
		case CodeUnit.POST_COMMENT:
			tab.setSelectedIndex(2);
			break;
		case CodeUnit.PLATE_COMMENT:
			tab.setSelectedIndex(3);
			break;
		case CodeUnit.REPEATABLE_COMMENT:
			tab.setSelectedIndex(4);
			break;
	}
}
 
Example 5
Source File: CommentWindowPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private int getCommentType(int type) {
	if (type == ChangeManager.DOCR_PRE_COMMENT_CHANGED) {
		return CodeUnit.PRE_COMMENT;
	}
	if (type == ChangeManager.DOCR_POST_COMMENT_CHANGED) {
		return CodeUnit.POST_COMMENT;
	}
	if (type == ChangeManager.DOCR_EOL_COMMENT_CHANGED) {
		return CodeUnit.EOL_COMMENT;
	}
	if (type == ChangeManager.DOCR_PLATE_COMMENT_CHANGED) {
		return CodeUnit.PLATE_COMMENT;
	}
	if ((type == ChangeManager.DOCR_REPEATABLE_COMMENT_CHANGED) ||
		(type == ChangeManager.DOCR_REPEATABLE_COMMENT_ADDED) ||
		(type == ChangeManager.DOCR_REPEATABLE_COMMENT_REMOVED) ||
		(type == ChangeManager.DOCR_REPEATABLE_COMMENT_CREATED) ||
		(type == ChangeManager.DOCR_REPEATABLE_COMMENT_DELETED)) {
		return CodeUnit.REPEATABLE_COMMENT;
	}
	return -1;
}
 
Example 6
Source File: LSDAActionRecord.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Creates data for an action record at the indicated address and creates a comment to identify
 * it as an action record.
 * <br>Note: This method must get called before any of the "get..." methods.
 * @param address the start (minimum address) of this action record.
 */
public void create(Address address) {

	if (address == null) {
		throw new IllegalArgumentException("action record's address cannot be null.");
	}
	if (monitor.isCancelled()) {
		return;
	}
	this.recordAddress = address;

	Address addr = address;
	size = 0;

	addr = createTypeFilter(addr);

	addr = createNextActionRef(addr);

	SetCommentCmd commentCmd =
		new SetCommentCmd(address, CodeUnit.PLATE_COMMENT, "(LSDA) Action Record");
	commentCmd.applyTo(program);

	nextAddress = addr;
}
 
Example 7
Source File: ExceptionHandlerFrameHeader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Method that creates an Exception Handler Frame Header Structure
 * at the address specified by 'addr'. If addr is 'null', this method returns without creating
 * the structure.
 * 
 * @param addr - Address at which the Exception Handler Frame Header Structure should be created.
 * @throws AddressOutOfBoundsException if the memory needed for this frame header isn't in the program.
 * @throws MemoryAccessException if the memory needed for this frame header isn't in the program.
 */
public void create(Address addr) throws MemoryAccessException, AddressOutOfBoundsException {
	CreateStructureCmd dataCmd = null;
	
	if (addr == null || monitor.isCancelled()) {
		return;
	}
	
	/* Create a new structure at the start of the .eh_frame_hdr section */
	dataCmd = new CreateStructureCmd( ehFrameHdrStruct, addr );
	dataCmd.applyTo(prog);
	
	/* Set a comment on the newly created structure */
	SetCommentCmd commentCmd = new SetCommentCmd(addr, CodeUnit.PLATE_COMMENT, "Exception Handler Frame Header");
	commentCmd.applyTo(prog);
	
	// Set the class members accordingly
	eh_version = prog.getMemory().getByte(addr) & 0xFF;
	eh_FramePtrEncoding = prog.getMemory().getByte(addr.add(1)) & 0xFF;
	eh_FrameDescEntryCntEncoding = prog.getMemory().getByte(addr.add(2)) & 0xFF;
	eh_FrameTableEncoding = prog.getMemory().getByte(addr.add(3)) & 0xFF;
}
 
Example 8
Source File: CommentType.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comment type from the current location. If the cursor
 * is not over a comment, then just return EOL as the default.
 * @param cu
 * @param loc
 * @param defaultCommentType
 * @return comment type
 */
public static int getCommentType(CodeUnit cu, ProgramLocation loc, int defaultCommentType) {
	if (loc instanceof CommentFieldLocation) {
		CommentFieldLocation cfLoc = (CommentFieldLocation) loc;
		return cfLoc.getCommentType();
	}
	else if (loc instanceof PlateFieldLocation) {
		return CodeUnit.PLATE_COMMENT;
	}
	else if (loc instanceof FunctionRepeatableCommentFieldLocation) {
		return CodeUnit.REPEATABLE_COMMENT;
	}
	else if (cu != null) {
		if (cu.getComment(CodeUnit.PRE_COMMENT) != null) {
			return CodeUnit.PRE_COMMENT;
		}
		if (cu.getComment(CodeUnit.POST_COMMENT) != null) {
			return CodeUnit.POST_COMMENT;
		}
		if (cu.getComment(CodeUnit.EOL_COMMENT) != null) {
			return CodeUnit.EOL_COMMENT;
		}
		if (cu.getComment(CodeUnit.PLATE_COMMENT) != null) {
			return CodeUnit.PLATE_COMMENT;
		}
		if (cu.getComment(CodeUnit.REPEATABLE_COMMENT) != null) {
			return CodeUnit.REPEATABLE_COMMENT;
		}
	}
	return defaultCommentType;
}
 
Example 9
Source File: NewExt4Analyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean setPlateComment( Program program, Address address, String comment ) {
	SetCommentCmd cmd = new SetCommentCmd( address, CodeUnit.PLATE_COMMENT, comment );
	if ( program.getMemory( ).contains( address ) ) {
		return cmd.applyTo( program );
	}
	if ( program2 != null && program2.getMemory( ).contains( address ) ) {
		return cmd.applyTo( program2 );
	}
	throw new RuntimeException( "Cannot set plate comment, neither program contains that address." );
}
 
Example 10
Source File: DecompilerCommentsActionFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected int getEditCommentType(ActionContext context) {
    if (context instanceof DecompilerActionContext) {
        DecompilerActionContext decompContext = (DecompilerActionContext) context;
        Address addr = decompContext.getAddress();
        if (addr.equals(decompContext.getFunctionEntryPoint())) {
            return CodeUnit.PLATE_COMMENT;
        }
        return CodeUnit.PRE_COMMENT;
    }
    CodeUnit cu = getCodeUnit(context);
    return CommentType.getCommentType(cu, getLocationForContext(context), CodeUnit.NO_COMMENT);
}
 
Example 11
Source File: EhFrameHeaderSection.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createFdeTable(Address curAddress, ExceptionHandlerFrameHeader eh_frame_hdr,
		int fdeTableCnt, TaskMonitor monitor) throws MemoryAccessException,
		ExceptionHandlerFrameException {

	/* Build the Frame Descriptor Entry Table */
	int fdeTblEnc = eh_frame_hdr.getEh_FrameTableEncoding();
	DwarfEHDecoder fdeTblDecoder = DwarfDecoderFactory.getDecoder(fdeTblEnc);

	FdeTable fde_table = new FdeTable(monitor, program);
	fde_table.create(curAddress, fdeTblDecoder, fdeTableCnt);

	SetCommentCmd commentCmd =
		new SetCommentCmd(curAddress, CodeUnit.PLATE_COMMENT, "Frame Description Entry Table");
	commentCmd.applyTo(program);
}
 
Example 12
Source File: CommentHistoryDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private CommentHistoryPanel getHistoryPanel(int commentType) {
	switch(commentType) {
		case CodeUnit.EOL_COMMENT:
			return eolPanel;
		case CodeUnit.PRE_COMMENT:
			return prePanel;
		case CodeUnit.POST_COMMENT:
			return postPanel;
		case CodeUnit.PLATE_COMMENT:
			return platePanel;
		case CodeUnit.REPEATABLE_COMMENT:
			return repeatablePanel;
	}
	return null;	
}
 
Example 13
Source File: LSDAActionTable.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Create an LSDA Action Table from the bytes at <code>address</code>.
 * <br>Note: This method must get called before any of the "get..." methods.
 * @param address the start (minimum address) of this action table.
 * @param maxddress the end (maximum address) of this action table.
 */
public void create(Address address, Address maxAddress) {

	if (address == null) {
		throw new IllegalArgumentException("action record's address cannot be null.");
	}
	if (monitor.isCancelled()) {
		return;
	}

	tableAddress = address;

	monitor.setMessage("Creating LSDA Action Table");

	LSDAActionRecord rec = null;
	
	while (address.compareTo(maxAddress) <= 0) {
		rec = new LSDAActionRecord(monitor, program, region, this);
		rec.create(address);

		records.add(rec);

		address = rec.getNextAddress();
	}

	nextAddress = address;

	SetCommentCmd commentCmd =
		new SetCommentCmd(tableAddress, CodeUnit.PLATE_COMMENT, "(LSDA) Action Table");
	commentCmd.applyTo(program);
}
 
Example 14
Source File: PlateCommentMarkupType.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
protected int getCodeUnitCommentType() {
	return CodeUnit.PLATE_COMMENT;
}
 
Example 15
Source File: LSDAHeader.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Create a LSDA Header from the bytes at <code>addr</code>.
 * <br>Note: This method must get called before any of the "get..." methods.
 * @param addr the start (minimum address) of this LSDA header.
 * @throws MemoryAccessException if memory for the header couldn't be read.
 */
public void create(Address addr) throws MemoryAccessException {

	/* use current program location if 'addr' is null */
	if (addr == null || monitor.isCancelled()) {
		return;
	}

	monitor.setMessage("Creating GCC Exception Table Header");
	Address baseAddr = addr;

	addr = createLPStartEncoding(addr);

	addr = createLPStartPointer(addr);

	addr = createTTypeEncoding(addr);

	addr = createTTypeOffset(addr);

	Address callSiteTableStart = addr;
	addr = createCallSiteTableEncoding(addr);

	addr = createCallSiteTableLength(addr);

	headerSize = addr.subtract(baseAddr);
	callSiteTableHeaderSize = addr.subtract(callSiteTableStart);

	Address extent = addr.add(getCallSiteTableLength() - 1);

	if (ttypeEncoding != OMITTED_ENCODING_TYPE) {
		ttypeAddr = baseAddr.add(ttypeOffset);
		extent = ttypeAddr;
	}

	tableBounds = new AddressRangeImpl(baseAddr, extent);

	String tableLabel = "lsda_exception_table_" + baseAddr;

	try {
		Symbol sym = program.getSymbolTable().getPrimarySymbol(baseAddr);
		if (sym == null) {
			sym =
				program.getSymbolTable().createLabel(baseAddr, tableLabel, SourceType.ANALYSIS);
		}
		else {
			sym.setName(tableLabel, SourceType.ANALYSIS);
		}
	}
	catch (Exception e) {
		// ignored
	}

	SetCommentCmd commentCmd =
		new SetCommentCmd(baseAddr, CodeUnit.PLATE_COMMENT, "(LSDA) Exception Table");
	commentCmd.applyTo(program);

	nextAddress = addr;
}
 
Example 16
Source File: LSDACallSiteRecord.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Creates data for a call site record at the indicated address and creates a comment to 
 * identify it as a call site record.
 * <br>Note: This method must get called before any of the "get..." methods.
 * @param addr the start (minimum address) of this call site record.
 * @param decoder decodes dwarf encoded information within the LSDA
 * @throws MemoryAccessException if memory couldn't be accessed for the call site record
 */
public void create(Address addr, DwarfEHDecoder decoder) throws MemoryAccessException {

	/* use current program location if 'addr' is null */
	if (addr == null || monitor.isCancelled())
		return;

	Address baseAddr = addr;
	monitor.setMessage("Creating LSDA Call Site Record");

	Address callSiteDataAddr = addr;
	addr = createCallSitePosition(addr, decoder);
	addr = createCallSiteLength(addr, decoder);
	Address lpDataAddr = addr;
	addr = createLandingPad(addr, decoder);

	addr = createAction(addr);

	Address lpStart = region.getLSDATable().getHeader().getLPStartAddress();

	Address callSiteBaseAddr = lpStart.add(getCallSitePosition());
	Address callSiteExtentAddr = callSiteBaseAddr.add(getCallSiteLength() - 1);

	callSiteRange = new AddressRangeImpl(callSiteBaseAddr, callSiteExtentAddr);

	landingPadAddr = lpStart.add(getLandingPadOffset());

	SetCommentCmd commentCmd =
		new SetCommentCmd(baseAddr, CodeUnit.PLATE_COMMENT, "(LSDA) Call Site Record");
	commentCmd.applyTo(program);

	if (program.getMemory().contains(callSiteBaseAddr)) {
		program.getReferenceManager().addMemoryReference(callSiteDataAddr, callSiteBaseAddr,
			RefType.DATA, SourceType.ANALYSIS, 0);
	}

	if (program.getMemory().contains(landingPadAddr)) {
		program.getReferenceManager().addMemoryReference(lpDataAddr, landingPadAddr,
			RefType.DATA, SourceType.ANALYSIS, 0);
	}

	nextAddress = addr;
}
 
Example 17
Source File: LSDATable.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Create a LSDA Table from the bytes at <code>addr</code>. Parses the header, call site table,
 * action table, and type table.
 * <br>Note: This method must get called before any of the "get..." methods.
 * @param tableAddr the start (minimum address) of this LSDA table.
 * @param region the region of the program associated with this table
 * @throws MemoryAccessException if memory couldn't be accessed for the LSDA table
 */
public void create(Address tableAddr, RegionDescriptor region)
		throws MemoryAccessException {

	region.setLSDATable(this);

	Address baseAdress = tableAddr;

	header = new LSDAHeader(monitor, program, region);
	header.create(tableAddr);

	tableAddr = header.getNextAddress();

	callSiteTable = new LSDACallSiteTable(monitor, program, region);
	callSiteTable.create(tableAddr);

	tableAddr = callSiteTable.getNextAddress();

	int maxActionOffset = 0;
	boolean generateActionTable = false;
	for (LSDACallSiteRecord cs : callSiteTable.getCallSiteRecords()) {
		maxActionOffset = Math.max(maxActionOffset, cs.getActionOffset());
		if (cs.getActionOffset() != LSDAActionRecord.NO_ACTION) {
			generateActionTable = true;
		}
	}

	if (generateActionTable) {

		Address maxTableAddr = tableAddr.add(maxActionOffset);

		actionTable = new LSDAActionTable(monitor, program, region);
		actionTable.create(tableAddr, maxTableAddr);

		tableAddr = actionTable.getNextAddress();
	}

	if (header.getTTypeEncoding() != LSDAHeader.OMITTED_ENCODING_TYPE) {

		// NOTICE: This builds from the bottom (TTypeBaseAddress) to top
		// (tableAddr)
		Address tTypeBaseAddress = header.getTTypeBaseAddress();
		if (tTypeBaseAddress != Address.NO_ADDRESS) {
			typeTable = new LSDATypeTable(monitor, program, region);
			typeTable.create(tTypeBaseAddress, tableAddr);
		}
	}

	SetCommentCmd commentCmd = new SetCommentCmd(baseAdress, CodeUnit.PLATE_COMMENT, "Language-Specific Data Area");
	commentCmd.applyTo(program);

}
 
Example 18
Source File: AbstractFrameSection.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void createPlateComment(Address curAddress, String fdeComment) {

		SetCommentCmd commentCmd =
			new SetCommentCmd(curAddress, CodeUnit.PLATE_COMMENT, fdeComment);
		commentCmd.applyTo(program);
	}
 
Example 19
Source File: PlateFieldLocation.java    From ghidra with Apache License 2.0 3 votes vote down vote up
/**
 * Construct a new PlateFieldLocation.
 * 
 * @param program the program of the location
 * @param addr the address of the code unit.
 * @param componentPath the componentPath of the codeUnit
 * @param row the line of the location
 * @param charOffset the character position on the row of the location.
 * @param comment plate comment text
 * @param commentRow The row index into the comments of this location.  This is different 
 *        than the <code>row</code> due to the fact that the PlateField has fictitious borders
 *        that don't exist in the actual comment.
 */
public PlateFieldLocation(Program program, Address addr, int[] componentPath, int row,
		int charOffset, String[] comment, int commentRow) {

	super(program, addr, componentPath, comment, CodeUnit.PLATE_COMMENT, row, charOffset);
	this.commentRow = commentRow;
}
 
Example 20
Source File: LSDACallSiteTable.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Create a LSDA Call Site Table from the bytes at <code>addr</code>.
 * <br>Note: This method must get called before any of the "get..." methods.
 * @param addr the start (minimum address) of this call site table.
 * @throws MemoryAccessException if memory couldn't be accessed for the call site table
 */
public void create(Address addr) throws MemoryAccessException {

	records.clear();

	/* use current program location if 'addr' is null */
	if (addr == null || monitor.isCancelled()) {
		return;
	}

	LSDAHeader header = region.getLSDATable().getHeader();

	if (header.getCallSiteTableLength() <= 0) {
		return;
	}

	Address baseAddr = addr;
	monitor.setMessage("Creating GCC LSDA Call Site Table ");

	SetCommentCmd commentCmd =
		new SetCommentCmd(baseAddr, CodeUnit.PLATE_COMMENT, "(LSDA) Call Site Table");
	commentCmd.applyTo(program);

	Address limit = baseAddr.add(header.getCallSiteTableLength() - 1);

	DwarfEHDecoder callSiteDecoder =
		DwarfDecoderFactory.getDecoder(header.getCallSiteTableEncoding());

	long remain = limit.subtract(addr);

	do {
		LSDACallSiteRecord rec = new LSDACallSiteRecord(monitor, program, region);
		rec.create(addr, callSiteDecoder);

		verifyCallSiteRecord(rec);

		records.add(rec);

		addr = rec.getNextAddress();
		remain = limit.subtract(addr);

	}
	while (remain > 0);

	bounds = new AddressRangeImpl(baseAddr, baseAddr.add(header.getCallSiteTableLength()));

	nextAddress = addr;
}