ghidra.util.exception.CancelledException Java Examples
The following examples show how to use
ghidra.util.exception.CancelledException.
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: SelectByScopedFlowPlugin.java From ghidra with Apache License 2.0 | 6 votes |
private void addEdgesForStartVertex(Graph<CodeBlockVertex, CodeBlockEdge> graph, Map<CodeBlock, CodeBlockVertex> blockToVertexMap, CodeBlockVertex start, TaskMonitor monitor) throws CancelledException { CodeBlock codeBlock = start.getCodeBlock(); CodeBlockReferenceIterator destinations = codeBlock.getDestinations(monitor); for (; destinations.hasNext();) { monitor.checkCanceled(); CodeBlockReference reference = destinations.next(); CodeBlock destinationBlock = reference.getDestinationBlock(); CodeBlockVertex end = blockToVertexMap.get(destinationBlock); if (end == null) { continue; // no vertex means the code block is not in our function } graph.addEdge(new CodeBlockEdge(start, end), start, end); } }
Example #2
Source File: ResultsState.java From ghidra with Apache License 2.0 | 6 votes |
private static Varnode eillimnateCarryOp(PcodeOp pcodeOp, Varnode[] values, AddressFactory addrFactory, TaskMonitor monitor) throws CancelledException { if (values[0].isConstant()) { VarnodeOperation op = flipInputs(pcodeOp, values); pcodeOp = op.getPCodeOp(); } PcodeOp twosCompOp = new PcodeOp(pcodeOp.getSeqnum(), PcodeOp.INT_2COMP, new Varnode[] { pcodeOp.getInput(1) }, getNewUnique(addrFactory, pcodeOp.getInput(1).getSize())); Varnode twosCompValue = simplify(twosCompOp, new Varnode[] { values[1] }, addrFactory, monitor); PcodeOp lessThanOp = new PcodeOp(pcodeOp.getSeqnum(), PcodeOp.INT_LESSEQUAL, new Varnode[] { twosCompOp.getOutput(), pcodeOp.getInput(0) }, pcodeOp.getOutput()); return simplify(lessThanOp, new Varnode[] { twosCompValue, values[1] }, addrFactory, monitor); }
Example #3
Source File: IncomingCallNode.java From ghidra with Apache License 2.0 | 6 votes |
@Override public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException { FunctionSignatureFieldLocation location = new FunctionSignatureFieldLocation(program, functionAddress); Set<Address> addresses = ReferenceUtils.getReferenceAddresses(location, monitor); List<GTreeNode> nodes = new ArrayList<>(); FunctionManager functionManager = program.getFunctionManager(); for (Address fromAddress : addresses) { monitor.checkCanceled(); Function callerFunction = functionManager.getFunctionContaining(fromAddress); if (callerFunction == null) { continue; } IncomingCallNode node = new IncomingCallNode(program, callerFunction, fromAddress, filterDuplicates, filterDepth); addNode(nodes, node); } Collections.sort(nodes, new CallNodeComparator()); return nodes; }
Example #4
Source File: LocalManagedBufferFile.java From ghidra with Apache License 2.0 | 6 votes |
void waitForTask(TaskMonitor taskMonitor) throws CancelledException { if (taskThread.isAlive()) { if (taskMonitor != null) { synchronized (preSaveLock) { taskMonitor.initialize(maxIndex); taskMonitor.setProgress(curIndex); this.monitor = taskMonitor; this.monitorThread = Thread.currentThread(); } } try { taskThread.join(); } catch (InterruptedException e) { // ignore } if (taskMonitor != null) { taskMonitor.checkCanceled(); } } }
Example #5
Source File: DebugFrameSection.java From ghidra with Apache License 2.0 | 6 votes |
/** * Analyzes and annotates the debug frame section. * @return the region descriptors that compose the debug frame section. * @throws MemoryAccessException if memory couldn't be read/written while processing the section. * @throws AddressOutOfBoundsException if one or more expected addresses weren't in the program. * @throws ExceptionHandlerFrameException if the FDE table can't be decoded. */ public List<RegionDescriptor> analyze() throws MemoryAccessException, AddressOutOfBoundsException, ExceptionHandlerFrameException, CancelledException { List<RegionDescriptor> descriptors = new ArrayList<>(); MemoryBlock[] blocks = program.getMemory().getBlocks(); int blockCount = blocks.length; monitor.setMaximum(blockCount); for (MemoryBlock block : blocks) { monitor.checkCanceled(); monitor.incrementProgress(1); if (block.getName().startsWith(DEBUG_FRAME_BLOCK_NAME)) { descriptors.addAll(analyzeSection(block)); } } return Collections.unmodifiableList(descriptors); }
Example #6
Source File: ScalarSearchModel.java From ghidra with Apache License 2.0 | 6 votes |
@Override protected void doLoad(Accumulator<ScalarRowObject> accumulator, TaskMonitor monitor) throws CancelledException { if (listing == null) { return; } sizedAccumulator = new SizeLimitedAccumulatorWrapper<>(accumulator, TEMP_MAX_RESULTS); if (currentSelection != null) { loadTableFromSelection(monitor); return; } monitor.initialize(listing.getNumCodeUnits()); InstructionIterator instructions = listing.getInstructions(true); DataIterator dataIterator = listing.getDefinedData(true); iterateOverInstructions(monitor, instructions); iterateOverData(monitor, dataIterator); sizedAccumulator = null; }
Example #7
Source File: CallAnotherScriptForAllPrograms.java From ghidra with Apache License 2.0 | 6 votes |
private void processProgram(Program program) throws CancelledException, IOException { /* Do you program work here */ println("Processing: " + program.getDomainFile().getPathname()); monitor.setMessage("Processing: " + program.getDomainFile().getName()); int id = program.startTransaction("Batch Script Transaction"); try { GhidraState newState = new GhidraState(state.getTool(), state.getProject(), program, null, null, null); runScript(SUBSCRIPT_NAME, newState); } catch (Exception e) { printerr("ERROR! Exception occurred while processing file: " + program.getDomainFile().getPathname()); printerr(" " + e.getMessage()); e.printStackTrace(); return; } finally { program.endTransaction(id, true); } // ...save any changes program.save("Changes made by script: " + SUBSCRIPT_NAME, monitor); }
Example #8
Source File: SevenZipFileSystem.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void setOperationResult(ExtractOperationResult extractOperationResult) throws SevenZipException { // STEP 4: SevenZip calls this to signal that the extract is done for this file. if (currentTempFileOutputStream != null) { try { currentTempFileOutputStream.close(); extractOperationResultToException(extractOperationResult); fileSystemService.getDerivedFilePush(fsrl.getContainer(), Integer.toString(currentIndex), (os) -> { try (InputStream is = new FileInputStream(currentTempFile)) { FileUtilities.copyStreamToStream(is, os, monitor); } }, monitor); currentTempFile.delete(); } catch (IOException | CancelledException e) { throw new SevenZipException(e); } finally { currentTempFile = null; currentTempFileOutputStream = null; } } }
Example #9
Source File: EmulatorHelper.java From ghidra with Apache License 2.0 | 6 votes |
/** * Execute instruction at current address * @param stopAtBreakpoint if true and breakpoint hits at current execution address * execution will halt without executing instruction. * @throws CancelledException if execution was cancelled */ private void executeInstruction(boolean stopAtBreakpoint, TaskMonitor monitor) throws CancelledException { lastError = null; try { if (emulator.getLastExecuteAddress() == null) { setProcessorContext(); } emulator.executeInstruction(stopAtBreakpoint, monitor); } catch (Throwable t) { // TODO: need to enumerate errors better !! lastError = t.getMessage(); emulator.setHalt(true); // force execution to stop if (t instanceof CancelledException) { throw (CancelledException) t; } } }
Example #10
Source File: ApplyBlockedMatchTask.java From ghidra with Apache License 2.0 | 6 votes |
private void applyMarkupItems(TaskMonitor monitor, Collection<VTMarkupItem> markupItems) throws CancelledException { for (VTMarkupItem item : markupItems) { monitor.checkCanceled(); VTMarkupItemStatus status = item.getStatus(); if (status != VTMarkupItemStatus.UNAPPLIED) { // for now we only handle items that have not been applied continue; } try { applyMarkupItem(item); } catch (VersionTrackingApplyException e) { reportError(e); } } }
Example #11
Source File: DWARFDataTypeImporterTest.java From ghidra with Apache License 2.0 | 6 votes |
@Test public void testAsymetricEquivTypedefedBaseTypes_not_false_positive() throws CancelledException, IOException, DWARFException { // CU1 // this struct has a field with a typedef to a basetype int DebugInfoEntry structDIE = newStruct("mystruct", 10).create(cu); newMember(structDIE, "f1", addTypedef("intX_t", addInt(cu), cu), 0).create(cu); // CU2 // this struct has a field with a basetype float, which is incompatible with int DebugInfoEntry structDIE_CU2 = newStruct("mystruct", 10).create(cu2); newMember(structDIE_CU2, "f1", addFloat(cu2), 0).create(cu2); importAllDataTypes(); DataType dataType = dwarfDTM.getDataType(structDIE.getOffset(), null); DataType dataType2 = dwarfDTM.getDataType(structDIE_CU2.getOffset(), null); // should get 2 datatypes, one with a conflict name assertTrue(dataType != dataType2); assertTrue(dataType2.getName().endsWith(DataType.CONFLICT_SUFFIX)); }
Example #12
Source File: IterativeFindPathsAlgorithm.java From ghidra with Apache License 2.0 | 6 votes |
@SuppressWarnings("hiding") // squash warning on names of variables @Override public void findPaths(GDirectedGraph<V, E> g, V start, V end, Accumulator<List<V>> accumulator, TaskMonitor monitor) throws CancelledException { this.g = g; this.start = start; this.end = end; this.accumulator = accumulator; this.monitor = monitor; if (start.equals(end)) { // can't find the paths between a node and itself throw new IllegalArgumentException("Start and end vertex cannot be the same: " + start); } if (!g.containsVertex(start)) { throw new IllegalArgumentException("Start vertex is not in the graph: " + start); } if (!g.containsVertex(end)) { throw new IllegalArgumentException("End vertex is not in the graph: " + end); } find(); listener.finished(); }
Example #13
Source File: DataTableModel.java From ghidra with Apache License 2.0 | 6 votes |
@Override protected void doLoad(Accumulator<DataRowObject> accumulator, TaskMonitor monitor) throws CancelledException { LongIterator it = LongIterator.EMPTY; if (listing != null) { it = new DataKeyIterator(); } monitor.initialize(getKeyCount()); int progress = 0; while (it.hasNext()) { monitor.setProgress(progress++); monitor.checkCanceled(); long key = it.next(); if (filterAccepts(key)) { accumulator.add(new DataRowObject(key, addressMap)); } } }
Example #14
Source File: DataTypeWriter.java From ghidra with Apache License 2.0 | 6 votes |
private void writeComponent(DataTypeComponent component, Composite composite, StringBuffer sb, TaskMonitor monitor) throws IOException, CancelledException { sb.append(" "); sb.append(annotator.getPrefix(composite, component)); String fieldName = component.getFieldName(); if (fieldName == null || fieldName.length() == 0) { fieldName = component.getDefaultFieldName(); } DataType componentDataType = component.getDataType(); sb.append(getTypeDeclaration(fieldName, componentDataType, component.getLength(), component.isFlexibleArrayComponent(), false, monitor)); sb.append(";"); sb.append(annotator.getSuffix(composite, component)); String comment = component.getComment(); if (comment != null && comment.length() > 0) { sb.append(" " + comment(comment)); } sb.append(EOL); }
Example #15
Source File: AnalyzeAllOpenProgramsTask.java From ghidra with Apache License 2.0 | 6 votes |
/** * Verifies that all programs to be analyzed have similar architectures (if * not, they can't be analyzed in a single batch, as their analyzer options * do not match). * <p> * If any architectures do not match, the user will be notified via * a popup dialog. * * @return the list of programs that can be analyzed, or null if the operation * was cancelled by the user * @throws CancelledException if the user cancelled the operation */ private List<Program> checkForInvalidProgramsByArchitecture() throws CancelledException { List<Program> validList = getValidProgramsByArchitecture(); if (validList.size() != programs.size()) { List<Program> invalidList = new ArrayList<>(programs); invalidList.removeAll(validList); if (!showNonMatchingArchitecturesWarning(validList, invalidList)) { throw new CancelledException(); } } return validList; }
Example #16
Source File: Database.java From ghidra with Apache License 2.0 | 5 votes |
/** * Open the stored database for update use. * @param monitor task monitor (may be null) * @return buffer file * @throws FileInUseException thrown if unable to obtain the required database lock(s). * @throws IOException thrown if IO error occurs. * @throws CancelledException if cancelled by monitor */ public DBHandle openForUpdate(TaskMonitor monitor) throws IOException, CancelledException { if (!updateAllowed) { throw new IOException("Update use not permitted"); } synchronized (syncObject) { return new DBHandle(new LocalManagedBufferFile(bfMgr, true, -1, -1)); } }
Example #17
Source File: FidServiceLibraryIngest.java From ghidra with Apache License 2.0 | 5 votes |
/** * Resolves the remembered unresolved symbols, now that we have all the library's symbols created. * @throws CancelledException if the user cancels */ private void resolveNamedRelations() throws CancelledException { for (Entry<FunctionRecord, Set<ChildSymbol>> entry : unresolvedSymbols.entrySet()) { monitor.checkCanceled(); FunctionRecord functionRecord = entry.getKey(); Set<ChildSymbol> unresolvedForFunction = entry.getValue(); for (ChildSymbol unresolvedSym : unresolvedForFunction) { monitor.checkCanceled(); boolean handled = handleNamedRelationSearch(library, functionRecord, unresolvedSym, RelationType.INTRA_LIBRARY_CALL); if (!handled && linkLibraries != null) { for (LibraryRecord linkLibrary : linkLibraries) { monitor.checkCanceled(); handled = handleNamedRelationSearch(linkLibrary, functionRecord, unresolvedSym, RelationType.INTER_LIBRARY_CALL); if (handled) { break; } } } if (!handled) { // FunctionRecord inferiorFunction = // controller.obtainDegenerateFunction(library, name, namespace); // controller.createRelation(functionRecord, inferiorFunction, // RelationType.NAMED_CHILD, 1); result.addUnresolvedSymbol(unresolvedSym.name); } } } }
Example #18
Source File: FunctionReachabilityTableModel.java From ghidra with Apache License 2.0 | 5 votes |
private CodeBlock getDestinationBlock(CodeBlockReference destination, TaskMonitor monitor) throws CancelledException { Address targetAddress = destination.getDestinationAddress(); BlockModelService blockModelService = serviceProvider.getService(BlockModelService.class); CodeBlockModel codeBlockModel = blockModelService.getActiveSubroutineModel(); CodeBlock targetBlock = codeBlockModel.getFirstCodeBlockContaining(targetAddress, monitor); if (targetBlock == null) { return null; // no code found for call; external? } return targetBlock; }
Example #19
Source File: DataTypesXmlMgr.java From ghidra with Apache License 2.0 | 5 votes |
/** * Writes datatypes into XML using the specified XML writer. * @param writer the XML writer * @param monitor the task monitor * @throws CancelledException if the user cancels the write operation */ public void write(XmlWriter writer, TaskMonitor monitor) throws CancelledException { monitor.setMessage("Writing DATA TYPES ..."); writer.startElement("DATATYPES"); Iterator<?> it = dataManager.getAllDataTypes(); while (it.hasNext()) { writeDataType(writer, (DataType) it.next()); if (monitor.isCancelled()) { throw new CancelledException(); } } writer.endElement("DATATYPES"); }
Example #20
Source File: CodeBlockReferenceImpl.java From ghidra with Apache License 2.0 | 5 votes |
/** * Gets the block (source or destination). If the block is needed, * assume we have the blockHave and compute blockNeeded using that block. * * @param blockNeeded - block we need * @param blockHave - block we know * @param addrInBlock - address in the block we need * @return the block */ private CodeBlock getBlock(CodeBlock blockNeeded, CodeBlock blockHave, Address addrInBlock) { if (blockNeeded == null) { CodeBlockModel model = blockHave.getModel(); try { blockNeeded = model.getFirstCodeBlockContaining(addrInBlock, TaskMonitorAdapter.DUMMY_MONITOR); } catch (CancelledException e) { // can't happen, dummy monitor can't be canceled } // means that there wasn't a good source block there, // make an invalid source block // TODO: This might not be the right thing to do. Return a // codeBlock that really isn't there, but should be if // there were valid instructions. If you got it's start // address then got the block starting at from the model, // you would get null, so maybe the model should be changed // to return a block at this address.... if (blockNeeded == null) { if (model instanceof SimpleBlockModel) { blockNeeded = ((SimpleBlockModel) model).createSimpleDataBlock(addrInBlock, addrInBlock); } } } return blockNeeded; }
Example #21
Source File: BookmarkMerger.java From ghidra with Apache License 2.0 | 5 votes |
private void checkOriginalBookmark(TaskMonitor monitor, Address addr, Bookmark currentBookmark) throws CancelledException { if (currentBookmark.getTypeString() == BookmarkType.NOTE) { checkOriginalNoteBookmark(monitor, addr, currentBookmark); } else { checkOriginalNonNoteBookmark(monitor, addr, currentBookmark); } }
Example #22
Source File: EditFunctionSignatureDialog.java From ghidra with Apache License 2.0 | 5 votes |
/** * This method gets called when the user clicks on the OK Button. The base * class calls this method. */ @Override protected void okCallback() { // only close the dialog if the user made valid changes try { if (applyChanges()) { close(); } } catch (CancelledException e) { // ignore - do not close } }
Example #23
Source File: ClassPackage.java From ghidra with Apache License 2.0 | 5 votes |
@Override void getClasses(Set<Class<?>> set, TaskMonitor monitor) throws CancelledException { checkForDuplicates(set); set.addAll(classes); Iterator<ClassPackage> it = children.iterator(); while (it.hasNext()) { monitor.checkCanceled(); ClassPackage subPkg = it.next(); subPkg.getClasses(set, monitor); } }
Example #24
Source File: GTreeSlowLoadingNode.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void run(TaskMonitor monitor) { if (isLoaded()) { return; } long progressValue = monitor.getProgress(); long maxValue = monitor.getMaximum(); monitor.setMessage("Loading children"); try { setChildren(generateChildren(monitor)); } catch (CancelledException e) { if (!tree.isDisposed()) { runOnSwingThread(new Runnable() { @Override public void run() { tree.collapseAll(tree.getViewRoot()); } }); } doSetChildren(null); } finally { monitor.initialize(maxValue); monitor.setProgress(progressValue); } }
Example #25
Source File: MultEntSubModel.java From ghidra with Apache License 2.0 | 5 votes |
/** * Get the MultEntSubModel Code Block that contains the address. * * @param addr Address to find a containing block. * @param monitor task monitor which allows user to cancel operation. * @return A CodeBlock if any block contains the address. * null otherwise. * @throws CancelledException if the monitor cancels the operation. */ @Override public CodeBlock getFirstCodeBlockContaining(Address addr, TaskMonitor monitor) throws CancelledException { CodeBlock block = getSubFromCache(addr); if (block == null) { block = getAddressSetContaining(addr, monitor); } return block; }
Example #26
Source File: AbstractGraphAlgorithmsTest.java From ghidra with Apache License 2.0 | 5 votes |
protected Collection<TestE> findPostDominance(TestV from) { try { Set<TestV> postDominated = GraphAlgorithms.findPostDominance(g, from, TaskMonitor.DUMMY); Set<TestE> filtered = GraphAlgorithms.retainEdges(g, postDominated); return filtered; } catch (CancelledException e) { // can't happen; dummy monitor fail("Someone changed my monitor!!"); } return null; }
Example #27
Source File: SimpleBlockIterator.java From ghidra with Apache License 2.0 | 5 votes |
/** * Called for iterators restricted by an address range set, * it will find the next block and set up nextBlock and * nextAddr accordingly. * @throws CancelledException if the monitor cancels the operation. */ private void getNextInSet() throws CancelledException { // find next address that has a valid block; Address addr = getNextAddress(nextAddr); // if the instruction's start address is in our set // then we have our block if (addr != null && addrSet.contains(addr)) { nextBlock = model.getCodeBlockAt(addr, monitor); if (nextBlock != null) { nextAddr = nextBlock.getMaxAddress(); return; } } // otherwise we're out of our current address range in // our address range set so we find the next address range // with a min address >= the instructions address and // look for a block there //nextAddr = instr.getMaxAddress(); while (rangeIter.hasNext()) { AddressRange range = rangeIter.next(); if (nextAddr.compareTo(range.getMinAddress()) >= 0) { continue; } nextBlock = getFirstInRange(range); // if we find a block we're done if (nextBlock != null) { nextAddr = nextBlock.getMaxAddress(); return; } // if we find no block then there's no block in the // current range and we can move on to the next one } nextBlock = null; }
Example #28
Source File: ClassPackage.java From ghidra with Apache License 2.0 | 5 votes |
ClassPackage(File rootDir, String packageName, TaskMonitor monitor) throws CancelledException { monitor.checkCanceled(); this.rootDir = rootDir; this.packageName = packageName; this.packageDir = getPackageDir(rootDir, packageName); scanClasses(); scanSubPackages(monitor); }
Example #29
Source File: MySwitchAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
public List<Address> unresolvedIndirectFlow(PcodeOp op, int instrOpIndex, Varnode destination, ContextState currentState, ResultsState results, TaskMonitor monitor) throws CancelledException { // TODO Auto-generated method stub return null; }
Example #30
Source File: SymbolCategoryNode.java From ghidra with Apache License 2.0 | 5 votes |
@Override public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException { SymbolType symbolType = symbolCategory.getSymbolType(); List<GTreeNode> list = getSymbols(symbolType, monitor); monitor.checkCanceled(); if (list.size() > MAX_CHILD_NODES) { list = OrganizationNode.organize(list, MAX_CHILD_NODES, monitor); } return list; }