ghidra.app.plugin.ProgramPlugin Java Examples
The following examples show how to use
ghidra.app.plugin.ProgramPlugin.
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: RegisterEvent.java From gdbghidra with MIT License | 6 votes |
public static void handleEvent(RegisterEvent registerEvent, Program currentProgram, ProgramPlugin plugin, ProgramLocation currentLocation) { var register = currentProgram.getRegister(registerEvent.getName()); if(register == null) { register = currentProgram.getRegister(registerEvent.getName().toUpperCase()); if(register == null) { System.err.println("[GDBGHIDRA] Error unknown register: "+registerEvent.getName()+"\n"); return; } } var address = currentLocation.getAddress(); var cmd = new CompoundCmd("Set Register Values"); var regCmd = new SetRegisterCmd( register, address, address, registerEvent.getValue()); cmd.add(regCmd); plugin.getTool().execute(cmd, currentProgram); }
Example #2
Source File: BreakpointEvent.java From gdbghidra with MIT License | 5 votes |
private static void doBreakpointTransaction(String action, BreakpointEvent breakpoint, Program currentProgram, ProgramPlugin plugin, long relocate) { var caddress = getBreakpointAddress(breakpoint, currentProgram, relocate); var category = "breakpoint"; var tx = currentProgram.startTransaction(action); /*==================== Begin Transaction ====================================*/ var service = plugin.getTool().getService(ColorizingService.class); var bm = currentProgram.getBookmarkManager().getBookmark(caddress, category, category); switch(breakpoint.getAction()) { case ENABLE: service.setBackgroundColor(caddress, caddress, Color.RED); break; case DISABLE: service.setBackgroundColor(caddress, caddress, Color.LIGHT_GRAY); break; case DELETE: service.setBackgroundColor(caddress, caddress, Color.WHITE); break; } if(bm != null) { if(breakpoint.action == BreakpointEventAction.DELETE) { currentProgram.getBookmarkManager().removeBookmark(bm); service = plugin.getTool().getService(ColorizingService.class); }else { bm.set(category, action); } }else { currentProgram.getBookmarkManager().setBookmark(caddress, category, category, action); } /*==================== END Transaction ====================================*/ currentProgram.endTransaction(tx, true); }
Example #3
Source File: BreakpointEvent.java From gdbghidra with MIT License | 5 votes |
public static void handleEvent(BreakpointEvent breakpoint, Program currentProgram, ProgramPlugin plugin, long relocate) { switch(breakpoint.getAction()) { case ENABLE: doBreakpointTransaction("enabled", breakpoint, currentProgram, plugin, relocate); break; case DISABLE: doBreakpointTransaction("disabled", breakpoint, currentProgram, plugin, relocate); break; case DELETE: doBreakpointTransaction("delete", breakpoint, currentProgram, plugin, relocate); break; } }
Example #4
Source File: InstructionSearchData.java From ghidra with Apache License 2.0 | 5 votes |
/** * Searches through instructions in the given program for a specific byte * pattern. If found, returns the instruction. i * * @param program the program to search * @param searchBounds the addresses to search * @param taskMonitor the task monitor * @param forwardSearch if true, search through addresses forward * @throws IllegalArgumentException if there's a problem parsing addresses * @return the instruction, or null if not found */ public InstructionMetadata search(ProgramPlugin plugin, AddressRange searchBounds, TaskMonitor taskMonitor, boolean forwardSearch) { if (plugin == null || plugin.getCurrentProgram() == null) { throw new IllegalArgumentException("Program provided to search is null"); } // Do a quick check to make sure the search bounds are within the bounds of the // program. if (searchBounds.getMinAddress().compareTo( plugin.getCurrentProgram().getMinAddress()) < 0 || searchBounds.getMaxAddress().compareTo( plugin.getCurrentProgram().getMaxAddress()) > 0) { throw new IllegalArgumentException( "Search bounds are not valid; must be within the bounds of the program."); } MaskContainer maskContainer = this.getAllMasks(); if (InstructionSearchUtils.containsOnBit(maskContainer.getMask())) { if (forwardSearch) { return searchForward(plugin, searchBounds, taskMonitor, maskContainer); } return searchBackward(plugin, searchBounds, taskMonitor, maskContainer); } return null; }
Example #5
Source File: InstructionSearchData.java From ghidra with Apache License 2.0 | 4 votes |
/** * Searches for a specific byte pattern in the positive direction. * * @param plugin the instruction pattern search plugin * @param searchBounds the addresses to search * @param taskMonitor the task monitor * @param maskContainer the bytes to search for * @return the instruction, or null if not found */ private InstructionMetadata searchForward(ProgramPlugin plugin, AddressRange searchBounds, TaskMonitor taskMonitor, MaskContainer maskContainer) { Address startAddress = searchBounds.getMinAddress(); Address endAddress = searchBounds.getMaxAddress(); Address currentPosition = plugin.getProgramLocation().getByteAddress().next(); taskMonitor.setShowProgressValue(false);// no need to show the number of bytes taskMonitor.setProgress(0); // The maximum value for the monitor is the number of bytes to be checked - this will // NOT always be the size of the range passed-in. If the cursor is in the middle of // the range already, then only the number of bytes in the range PAST the cursor will // will be checked. long max = searchBounds.getLength(); if (currentPosition.compareTo(searchBounds.getMinAddress()) > 0) { max = searchBounds.getMaxAddress().subtract(currentPosition); } taskMonitor.setMaximum(max); // Move the cursor to the beginning of the range if it is currently short of it. We don't // want to search for any addresses that aren't in the search bounds. if (currentPosition.compareTo(startAddress) < 0) { currentPosition = startAddress; } while (currentPosition.compareTo(endAddress) < 0) { // Search program memory for the given mask and val. currentPosition = plugin.getCurrentProgram().getMemory().findBytes(currentPosition, endAddress, maskContainer.getValue(), maskContainer.getMask(), true, taskMonitor); // If no match was found, currentPosition will be null. if (currentPosition == null) { break; } // Otherwise construct a new entry to put in our results table. MaskContainer masks = new MaskContainer(maskContainer.getMask(), maskContainer.getValue()); InstructionMetadata temp = new InstructionMetadata(masks); temp.setAddr(currentPosition); return temp; } return null; }
Example #6
Source File: InstructionSearchData.java From ghidra with Apache License 2.0 | 4 votes |
/** * Searches for a specific byte pattern in the reverse direction. * * @param plugin the instruction pattern search plugin * @param searchBounds the addresses to search * @param taskMonitor the task monitor * @param maskContainer the bytes to search for * @return the instruction, or null if not found */ private InstructionMetadata searchBackward(ProgramPlugin plugin, AddressRange searchBounds, TaskMonitor taskMonitor, MaskContainer maskContainer) { Address startAddress = searchBounds.getMaxAddress(); Address endAddress = searchBounds.getMinAddress(); Address currentPosition = plugin.getProgramLocation().getByteAddress().previous(); taskMonitor.setShowProgressValue(false); taskMonitor.setProgress(0); // The maximum value for the monitor is the number of bytes to be checked - this will // NOT always be the size of the range passed-in. If the cursor is in the middle of // the range already, then only the number of bytes in the range BEFORE the cursor will // will be checked. long max = searchBounds.getLength(); if (currentPosition.compareTo(searchBounds.getMaxAddress()) < 0) { max = currentPosition.subtract(searchBounds.getMinAddress()); } taskMonitor.setMaximum(max); // Move the cursor to the end of the range if it is currently past it. We don't // want to search for any addresses that aren't in the search bounds. if (currentPosition.compareTo(startAddress) > 0) { currentPosition = startAddress; } while (currentPosition.compareTo(endAddress) > 0) { // Search program memory for the given mask and val. currentPosition = plugin.getCurrentProgram().getMemory().findBytes(currentPosition, endAddress, maskContainer.getValue(), maskContainer.getMask(), false, taskMonitor); // If no match was found, currentPosition will be null. if (currentPosition == null) { break; } // Otherwise construct a new entry to put in our results table. MaskContainer masks = new MaskContainer(maskContainer.getMask(), maskContainer.getValue()); InstructionMetadata temp = new InstructionMetadata(masks); temp.setAddr(currentPosition); return temp; } return null; }