Java Code Examples for ghidra.program.model.listing.Program#getMinAddress()
The following examples show how to use
ghidra.program.model.listing.Program#getMinAddress() .
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: DmgAnalyzer.java From ghidra with Apache License 2.0 | 6 votes |
@Override public boolean analysisWorkerCallback(Program program, Object workerContext, TaskMonitor monitor) throws Exception, CancelledException { Address address = program.getMinAddress(); ByteProvider provider = new MemoryByteProvider(program.getMemory(), address); BinaryReader reader = new BinaryReader(provider, false); DmgHeader header = new DmgHeaderV2(reader); if (!Arrays.equals(header.getSignature(), DmgConstants.DMG_MAGIC_BYTES_v2)) { return false; } DataType headerDataType = header.toDataType(); Data headerData = createData(program, address, headerDataType); createFragment(program, headerDataType.getName(), headerData.getMinAddress(), headerData.getMaxAddress().add(1)); return true; }
Example 2
Source File: DiffController.java From ghidra with Apache License 2.0 | 6 votes |
/** * Constructor * <P>Note: This method is potentially time consuming and should normally * be called from within a background task. * @param p1 The first program to apply differences to. * @param p2 The second program to apply differences from. * @param p1LimitSet Address set the determined differences are limited to. * The addresses in this set should be derived from p1. * @param diffFilter filter indicating difference types to mark. * @param mergeFilter filter indicating difference types to apply. * @param monitor the progress monitor * @throws ProgramConflictException */ public DiffController(Program p1, Program p2, AddressSetView p1LimitSet, ProgramDiffFilter diffFilter, ProgramMergeFilter mergeFilter, TaskMonitor monitor) throws ProgramConflictException { mergeEngine = new ProgramMergeManager(p1, p2, p1LimitSet, monitor); mergeEngine.setDiffFilter(diffFilter); mergeEngine.setMergeFilter(mergeFilter); this.p1LimitSet = p1LimitSet; if (p1LimitSet == null) { p1CurrentAddress = p1.getMinAddress(); } else { p1CurrentAddress = p1LimitSet.getMinAddress(); } p1LastDiffs = new AddressSet(); }
Example 3
Source File: MemSearchPlugin.java From ghidra with Apache License 2.0 | 6 votes |
private Address getSearchStartAddress(SearchInfo localSearchInfo) { ProgramLocation location = navigatable.getLocation(); Address startAddress = location == null ? null : location.getAddress(); if (startAddress == null) { Program program = navigatable.getProgram(); if (program == null) { return null; } startAddress = localSearchInfo.isSearchForward() ? program.getMinAddress() : program.getMaxAddress(); } if (lastMatchingAddress == null) { return startAddress; } // start the search after the last matching search CodeUnit cu = navigatable.getProgram().getListing().getCodeUnitContaining(startAddress); if (cu.contains(lastMatchingAddress)) { startAddress = localSearchInfo.isSearchForward() ? lastMatchingAddress.next() : lastMatchingAddress.previous(); } return startAddress; }
Example 4
Source File: LzssUtil.java From ghidra with Apache License 2.0 | 5 votes |
public final static boolean isLZSS(Program program) { if (program != null) { Address address = program.getMinAddress(); if (address != null) { byte [] compressionBytes = getBytes(program, address); if (Arrays.equals(compressionBytes, LzssConstants.SIGNATURE_COMPRESSION_BYTES)) { byte [] formatBytes = getBytes(program, address.add(compressionBytes.length)); if (Arrays.equals(formatBytes, LzssConstants.SIGNATURE_LZSS_BYTES)) { return true; } } } } return false; }
Example 5
Source File: BootImageUtil.java From ghidra with Apache License 2.0 | 5 votes |
public final static boolean isBootImage( Program program ) { byte [] bytes = new byte[ 8 ]; try { Address address = program.getMinAddress(); program.getMemory().getBytes( address, bytes ); } catch (Exception e) {} return Arrays.equals( bytes, BootImageConstants.BOOT_IMAGE_MAGIC_BYTES ); }
Example 6
Source File: YAFFS2Utils.java From ghidra with Apache License 2.0 | 5 votes |
/** no Magic Bytes, so check for an empty directory in the first header */ public final static boolean isYAFFS2Image(Program program) { byte[] bytes = new byte[YAFFS2Constants.MAGIC_SIZE]; try { Address address = program.getMinAddress(); program.getMemory().getBytes(address, bytes); } catch (Exception e) { } // check for initial byte equal to 0x03, 'directory' // and check that the first byte of the file name is null // ... this is the yaffs2 root level dir header return ((bytes[0] == 0x03) && (bytes[10] == 0x00)); }
Example 7
Source File: Img3Analyzer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public boolean analysisWorkerCallback(Program program, Object workerContext, TaskMonitor monitor) throws Exception, CancelledException { Address address = program.getMinAddress(); ByteProvider provider = new MemoryByteProvider(program.getMemory(), address); BinaryReader reader = new BinaryReader(provider, true); Img3 header = new Img3(reader); if (!header.getMagic().equals(Img3Constants.IMG3_SIGNATURE)) { return false; } DataType headerDataType = header.toDataType(); Data headerData = createData(program, address, headerDataType); createFragment(program, headerDataType.getName(), headerData.getMinAddress(), headerData.getMaxAddress().add(1)); Address tagAddress = headerData.getMaxAddress().add(1); applyTags(program, header, tagAddress, monitor); changeDataSettings(program, monitor); removeEmptyFragments(program); return true; }
Example 8
Source File: Img3Util.java From ghidra with Apache License 2.0 | 5 votes |
public final static boolean isIMG3(Program program) { if (program != null) { Address address = program.getMinAddress(); if (address != null) { byte [] bytes = new byte[4]; try { program.getMemory().getBytes(address, bytes); } catch (MemoryAccessException e) { } return Arrays.equals(bytes, Img3Constants.IMG3_SIGNATURE_BYTES); } } return false; }
Example 9
Source File: LzssAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public boolean analysisWorkerCallback(Program program, Object workerContext, TaskMonitor monitor) throws Exception, CancelledException { Address address = program.getMinAddress(); ByteProvider provider = new MemoryByteProvider(program.getMemory(), address); LzssCompressionHeader header = new LzssCompressionHeader(provider); if (header.getSignature() != LzssConstants.SIGNATURE_COMPRESSION) { return false; } if (header.getCompressionType() != LzssConstants.SIGNATURE_LZSS) { return false; } DataType headerDataType = header.toDataType(); Data headerData = createData(program, address, headerDataType); createFragment(program, headerDataType.getName(), headerData.getMinAddress(), headerData.getMaxAddress().add(1)); changeDataSettings(program, monitor); removeEmptyFragments(program); return true; }
Example 10
Source File: DexAnalysisState.java From ghidra with Apache License 2.0 | 5 votes |
/** * Return persistent <code>DexAnalysisState</code> which corresponds to the specified program instance. * @param program * @return <code>DexAnalysisState</code> for specified program instance */ public static DexAnalysisState getState(Program program) throws IOException { DexAnalysisState analysisState = AnalysisStateInfo.getAnalysisState(program, DexAnalysisState.class); if (analysisState == null) { ByteProvider provider = new MemoryByteProvider(program.getMemory(), program.getMinAddress()); BinaryReader reader = new BinaryReader(provider, true); DexHeader dexHeader = new DexHeader(reader); analysisState = new DexAnalysisState(program, dexHeader); AnalysisStateInfo.putAnalysisState(program, analysisState); } return analysisState; }
Example 11
Source File: Apple8900Util.java From ghidra with Apache License 2.0 | 5 votes |
public final static boolean is8900(Program program) { Address address = program.getMinAddress(); byte [] bytes = new byte[4]; try { program.getMemory().getBytes(address, bytes); } catch (Exception e) {} return Arrays.equals(bytes, Apple8900Constants.MAGIC_BYTES); }
Example 12
Source File: Img2Util.java From ghidra with Apache License 2.0 | 5 votes |
public final static boolean isIMG2(Program program) { Address address = program.getMinAddress(); byte [] bytes = new byte[4]; try { program.getMemory().getBytes(address, bytes); } catch (MemoryAccessException e) {} return Arrays.equals(bytes, Img2Constants.IMG2_SIGNATURE_BYTES); }
Example 13
Source File: ProgramDatabaseSearcher.java From ghidra with Apache License 2.0 | 5 votes |
public ProgramDatabaseSearcher(ServiceProvider serviceProvider, Program program, ProgramLocation startLoc, AddressSetView set, SearchOptions options, TaskMonitor monitor) { this.searchOptions = options; this.monitor = monitor != null ? monitor : TaskMonitor.DUMMY; this.isForward = options.isForward(); if (startLoc == null && set == null) { startLoc = new ProgramLocation(program, isForward ? program.getMinAddress() : program.getMaxAddress()); } initialize(serviceProvider, program, startLoc, set, options); currentAddress = findNextSignificantAddress(); monitor.initialize(totalSearchCount); }
Example 14
Source File: iBootImUtil.java From ghidra with Apache License 2.0 | 5 votes |
public final static boolean isiBootIm(Program program) { if (program != null) { Address address = program.getMinAddress(); if (address != null) { byte [] bytes = getBytes(program, address); if (Arrays.equals(bytes, iBootImConstants.SIGNATURE_BYTES)) { return true; } } } return false; }
Example 15
Source File: AddBlockDialog.java From ghidra with Apache License 2.0 | 4 votes |
private JPanel buildMappedPanel() { JPanel panel = new JPanel(new PairLayout()); baseAddrField = new AddressInput(); baseAddrField.setAddressFactory(addrFactory); baseAddrField.setName("Source Addr"); baseAddrField.addChangeListener(ev -> baseAddressChanged()); JPanel schemePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); schemeDestByteCountField = new IntegerTextField(4, 1); schemeDestByteCountField.setAllowNegativeValues(false); schemeDestByteCountField.setAllowsHexPrefix(false); schemeDestByteCountField.setDecimalMode(); schemeDestByteCountField.addChangeListener(ev -> schemeDestByteCountChanged()); schemeSrcByteCountField = new IntegerTextField(4, 1); schemeSrcByteCountField.setAllowNegativeValues(false); schemeSrcByteCountField.setAllowsHexPrefix(false); schemeSrcByteCountField.setDecimalMode(); schemeSrcByteCountField.addChangeListener(ev -> schemeSrcByteCountChanged()); schemePanel.add(schemeDestByteCountField.getComponent()); schemePanel.add(new GLabel(" : ")); schemePanel.add(schemeSrcByteCountField.getComponent()); Program program = model.getProgram(); Address minAddr = program.getMinAddress(); if (minAddr == null) { minAddr = program.getAddressFactory().getDefaultAddressSpace().getAddress(0); } baseAddrField.setAddress(minAddr); model.setBaseAddress(minAddr); panel.add(new GLabel("Source Address:")); panel.add(baseAddrField); panel.add(new GLabel("Mapping Ratio:")); panel.add(schemePanel); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); return panel; }
Example 16
Source File: YAFFS2Analyzer.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean analysisWorkerCallback(Program program, Object workerContext, TaskMonitor monitor) throws Exception, CancelledException { Address address = program.getMinAddress(); ByteProvider provider = new MemoryByteProvider(program.getMemory(), address); BinaryReader reader = new BinaryReader(provider, true); int index = 0; byte[] block; long lastObjectType = 3; // initialized to object type 3 (a directory) YAFFS2Header header; YAFFS2ExtendedTags tags; YAFFS2Data dataBlock; // loop over reader by record length (2112 bytes) and lay down the appropriate structures while (index < reader.length()) { if (monitor.isCancelled()) { break; } // grab next block of data block = reader.readByteArray(index, YAFFS2Constants.RECORD_SIZE); // header structure if (lastObjectType != 1) { header = new YAFFS2Header(Arrays.copyOfRange(block, 0, YAFFS2Constants.DATA_BUFFER_SIZE)); DataType headerDataType = header.toDataType(); Data headerData = createData(program, address.add(index), headerDataType); if (headerData == null) { log.appendMsg("Unable to create header."); } lastObjectType = header.getObjectType(); } // data block structure else { dataBlock = new YAFFS2Data(Arrays.copyOfRange(block, 0, YAFFS2Constants.DATA_BUFFER_SIZE)); DataType dataBlockDataType = dataBlock.toDataType(); Data dataBlockData = createData(program, address.add(index), dataBlockDataType); if (dataBlockData == null) { log.appendMsg("Unable to create data block."); } } // tags structure tags = new YAFFS2ExtendedTags(Arrays.copyOfRange(block, YAFFS2Constants.DATA_BUFFER_SIZE, YAFFS2Constants.RECORD_SIZE - 1)); DataType tagsDataType = tags.toDataType(); // create data for this block Data tagsData = createData(program, address.add(index + YAFFS2Constants.DATA_BUFFER_SIZE), tagsDataType); if (tagsData == null) { log.appendMsg("Unable to create tags (footer)."); } //increment to next record index += YAFFS2Constants.RECORD_SIZE; } changeDataSettings(program, monitor); removeEmptyFragments(program); return true; }
Example 17
Source File: DexExceptionHandlersAnalyzer.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean canAnalyze(Program program) { ByteProvider provider = new MemoryByteProvider(program.getMemory(), program.getMinAddress()); return DexConstants.isDexFile(provider); }
Example 18
Source File: GenericDataTypeProgramLocation.java From ghidra with Apache License 2.0 | 4 votes |
GenericDataTypeProgramLocation(Program program, DataType dataType) { super(program, program.getMinAddress()); this.dataType = dataType; }
Example 19
Source File: OdexHeaderFormatAnalyzer.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean analyze( Program program, AddressSetView set, TaskMonitor monitor, MessageLog log ) throws Exception { Address address = toAddr( program, 0x0 ); if ( getDataAt( program, address ) != null ) { log.appendMsg( "data already exists." ); return true; } Memory memory = program.getMemory( ); MemoryBlock block = memory.getBlock( "ram" ); block.setRead( true ); block.setWrite( false ); block.setExecute( false ); ByteProvider provider = new MemoryByteProvider( program.getMemory( ), program.getMinAddress( ) ); BinaryReader reader = new BinaryReader( provider, true ); OdexHeader header = new OdexHeader( reader ); DataType headerDataType = header.toDataType(); createData( program, address, headerDataType); createFragment(program, "header", address, address.add(headerDataType.getLength())); Address dexAddress = toAddr(program, header.getDexOffset()); createFragment(program, "dex", dexAddress, dexAddress.add(header.getDexLength())); Address depsAddress = toAddr(program, header.getDepsOffset()); createFragment(program, "deps", depsAddress, depsAddress.add(header.getDepsLength())); processDeps( program, header, monitor, log ); Address auxAddress = toAddr(program, header.getAuxOffset()); createFragment(program, "aux", auxAddress, auxAddress.add(header.getAuxLength())); monitor.setMessage( "ODEX: cleaning up tree" ); removeEmptyFragments( program ); return true; }
Example 20
Source File: DexCondenseFillerBytesAnalyzer.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean canAnalyze( Program program ) { ByteProvider provider = new MemoryByteProvider( program.getMemory( ), program.getMinAddress( ) ); return DexConstants.isDexFile( provider ); }