Java Code Examples for ghidra.program.model.listing.CodeUnit#getCommentAsArray()

The following examples show how to use ghidra.program.model.listing.CodeUnit#getCommentAsArray() . 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: DeleteExitCommentsScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
   public void run() throws Exception {
	Listing listing = currentProgram.getListing();
	AddressSetView set = currentProgram.getMemory();
	if (currentSelection != null && !currentSelection.isEmpty()) {
		set = currentSelection;
	}
	int updateCount=0;
	AddressIterator iter = listing.getCommentAddressIterator(CodeUnit.POST_COMMENT, set, true);
	while (iter.hasNext()) {
		Address addr = iter.next();
		CodeUnit cu = listing.getCodeUnitAt(addr);
		String[] comment = cu.getCommentAsArray(CodeUnit.POST_COMMENT);
		if (comment.length == 1 && comment[0].endsWith(EXIT_COMMENT)) {
			cu.setComment(CodeUnit.POST_COMMENT, null);
			++updateCount;
		}
	}
	if (updateCount > 0) {
		String cmt = updateCount > 1? "comments" : "comment";
		println("Removed " + updateCount + " exit post " + cmt + ".");
	}
	else {
		println("Did not find any exit post comments.");
	}
}
 
Example 2
Source File: DeleteDeadDefaultPlatesScript.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
   public void run() throws Exception {
	Listing listing = currentProgram.getListing();
	AddressSetView set = currentProgram.getMemory();
	if (currentSelection != null && !currentSelection.isEmpty()) {
		set = currentSelection;
	}
	int updateCount=0;
	AddressIterator iter = listing.getCommentAddressIterator(CodeUnit.PLATE_COMMENT, set, true);
	while (iter.hasNext()) {
		Address addr = iter.next();
		CodeUnit cu = listing.getCodeUnitAt(addr);
		if (cu != null) {
			String[] comment = cu.getCommentAsArray(CodeUnit.PLATE_COMMENT);
			if (comment.length == 1 && comment[0].equals(DEAD_PLATE)) {
				cu.setComment(CodeUnit.PLATE_COMMENT, null);
				++updateCount;
			}
		}
	}
	if (updateCount > 0) {
		String cmt = updateCount > 1? "comments" : "comment";
		println("Removed " + updateCount + " default plate " + cmt + ".");
	}
	else {
		println("Did not find any dead plate comments.");
	}
}
 
Example 3
Source File: DeleteEmptyPlateCommentsScript.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
   public void run() throws Exception {
	Listing listing = currentProgram.getListing();
	AddressSetView set = currentProgram.getMemory();
	if (currentSelection != null && !currentSelection.isEmpty()) {
		set = currentSelection;
	}
	int updateCount=0;
	AddressIterator iter = listing.getCommentAddressIterator(CodeUnit.PLATE_COMMENT, set, true);
	while (iter.hasNext()) {
		Address addr = iter.next();
		CodeUnit cu = listing.getCodeUnitAt(addr);
		if (cu != null) {
			String[] comment = cu.getCommentAsArray(CodeUnit.PLATE_COMMENT);
			if (comment.length == 1 && comment[0].equals(EMPTY_PLATE)) {
				cu.setComment(CodeUnit.PLATE_COMMENT, null);
				++updateCount;
			}
		}
	}
	if (updateCount > 0) {
		String cmt = updateCount > 1? "comments" : "comment";
		println("Removed " + updateCount + " emtpy plate " + cmt + ".");
	}
	else {
		println("Did not find any empty plate comments.");
	}
}