Java Code Examples for ghidra.program.model.address.AddressSet#contains()

The following examples show how to use ghidra.program.model.address.AddressSet#contains() . 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: PseudoDisassembler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a new target address from the untried target list if it can find one not already in the
 * disassembled address set that is passed in.
 * @param body address set of disassembled instructions
 * @param untriedTargetList list of untried valid targets
 * @return a new target address or null
 */
private Address getNextTarget(AddressSet body, ArrayList<Address> untriedTargetList) {
	Address newTarget = null;

	// no new target, try to get it from the targetList
	if (!untriedTargetList.isEmpty()) {
		Iterator<Address> iter = untriedTargetList.iterator();
		while (iter.hasNext()) {
			Address possibleTarget = iter.next();
			if (!body.contains(possibleTarget)) {
				newTarget = possibleTarget;
				iter.remove();
				break;
			}
		}
	}
	return newTarget;
}
 
Example 2
Source File: FillOutStructureCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively visit calls that take the structure pointer as a parameter.
 * Add any new references to the offsetToDataTypeMap.
 * @param structDT is the structure to populate
 */
private void pushIntoCalls(Structure structDT) {
	AddressSet doneSet = new AddressSet();
	DataType pointerDT = new PointerDataType(structDT);

	while (addressToCallInputMap.size() > 0) {
		currentCallDepth += 1;
		if (currentCallDepth > maxCallDepth) {
			return;
		}
		HashMap<Address, Integer> savedList = addressToCallInputMap;
		addressToCallInputMap = new HashMap<>();
		Set<Address> keys = savedList.keySet();
		Iterator<Address> keyIter = keys.iterator();
		while (keyIter.hasNext()) {
			Address addr = keyIter.next();

			if (doneSet.contains(addr)) {
				continue;
			}
			doneSet.addRange(addr, addr);
			Function func = currentProgram.getFunctionManager().getFunctionAt(addr);
			int paramIndex = savedList.get(addr);
			Address storageAddr = computeParamAddress(func, paramIndex, pointerDT);
			HighVariable paramHighVar = computeHighVariable(storageAddr, func);
			if (paramHighVar != null) {
				fillOutStructureDef(paramHighVar);
				populateStructure(structDT);
			}
		}
	}
}
 
Example 3
Source File: IsolatedEntrySubModel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
   * Get the subroutine code block which starts at the specified address which
   * is an entry point of a Model-M subroutine.
   * 
   * Classes which extend this class should implement this method.
   *
   * @param   mStartAddr = a Model-M subroutine entry point.
   * @param monitor task monitor which allows user to cancel operation.
   * @return  a subroutine code block
   * @throws CancelledException if the monitor cancels the operation.
   */
  @Override
  protected CodeBlock getSubroutine(Address mStartAddr, TaskMonitor monitor) throws CancelledException {
  	
  	// Create address list which contains all other entry points for this M-model sub
      CodeBlock mSub = modelM.getCodeBlockAt(mStartAddr, monitor);
      if (mSub == null) {
	return null;
}
      Address[] mEntryPts = mSub.getStartAddresses();
      ArrayList<Address> startSet = new ArrayList<Address>();
      for (Address mEntryPt : mEntryPts) {
          if (!mStartAddr.equals(mEntryPt)) {
		startSet.add(mEntryPt);
	}
      }

// create a holder for the blockSet
      AddressSet addrSet = new AddressSet();
      
      // Create the todoStack and initialize it with instr; also initialize the list for entryPts.
      LinkedList<Address> todoList = new LinkedList<Address>();
      todoList.addFirst(mStartAddr);
      
      CodeBlockModel bbModel = modelM.getBasicBlockModel();
      
      // Build model-S subroutine from basic blocks
      while (!todoList.isEmpty()) {
      
      	if (monitor.isCancelled()) {
		throw new CancelledException();
	}
      		
      	// Get basic block at the specified address 
      	Address a = todoList.removeLast();  
      	if (addrSet.contains(a) || startSet.contains(a))
	 {
		continue; // already processed this block or encountered another Model-M entry point  
	}
       CodeBlock bblock = bbModel.getFirstCodeBlockContaining(a, monitor);
       if (bblock == null) {
		continue;
	}
       	
       // Verify that the block contains instructions
       if (listing.getInstructionAt(a) == null) {
		continue;
	}
       	
       // Add basic block to subroutine address set
       addrSet.add(bblock);
      
      	// Process all destination references
      	CodeBlockReferenceIterator destIter = bblock.getDestinations(monitor);
      	while (destIter.hasNext()) {
      		CodeBlockReference destRef = destIter.next();
      		FlowType refFlowType = destRef.getFlowType();
      		if (refFlowType.isJump() || refFlowType.isFallthrough())
           {
           	// Add Jump and Fall-through destinations to the todoList
           	todoList.add(destRef.getDestinationAddress());	
           }
      	}       	
      } 
  	return createSub(addrSet, mStartAddr);
  }