Java Code Examples for ghidra.app.util.importer.MessageLog#appendException()
The following examples show how to use
ghidra.app.util.importer.MessageLog#appendException() .
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: PefLoader.java From ghidra with Apache License 2.0 | 6 votes |
private MemoryBlock makeFakeImportBlock(Program program, List<ImportedSymbol> symbols, MessageLog log, TaskMonitor monitor) { int size = symbols.size() * 4; if (size == 0) { return null; } Address start = getImportSectionAddress(program); try { return program.getMemory().createInitializedBlock("IMPORTS", start, size, (byte) 0x00, monitor, false); } catch (Exception e) { log.appendException(e); } return null; }
Example 2
Source File: PefLoader.java From ghidra with Apache License 2.0 | 6 votes |
private void processTermSymbol(ContainerHeader header, Program program, ImportStateCache importState, MessageLog log, TaskMonitor monitor) { SymbolTable symbolTable = program.getSymbolTable(); LoaderInfoHeader loader = header.getLoader(); int termSectionIndex = loader.getTermSection(); if (termSectionIndex != -1) { SectionHeader termSection = header.getSections().get(termSectionIndex); MemoryBlock termBlock = importState.getMemoryBlockForSection(termSection); Address address = termBlock.getStart().add(loader.getTermOffset()); try { symbolTable.createLabel(address, PefConstants.TERM, SourceType.IMPORTED); CreateDataCmd cmd = new CreateDataCmd(address, new PointerDataType()); cmd.applyTo(program); } catch (Exception e) { log.appendException(e); } } }
Example 3
Source File: DexHeaderFormatAnalyzer.java From ghidra with Apache License 2.0 | 6 votes |
private void processAnnotationSetItem(Program program, AnnotationSetItem setItem, TaskMonitor monitor, MessageLog log) { try { for (AnnotationOffsetItem offsetItem : setItem.getItems()) { monitor.checkCanceled(); Address aAddress = toAddr(program, offsetItem.getAnnotationsOffset()); AnnotationItem aItem = offsetItem.getItem(); DataType aDataType = aItem.toDataType(); createData(program, aAddress, aDataType); createFragment(program, "annotation_items", aAddress, aAddress.add(aDataType.getLength())); } } catch (Exception e) { log.appendException(e); } }
Example 4
Source File: PefLoader.java From ghidra with Apache License 2.0 | 6 votes |
private void processInitSymbol(ContainerHeader header, Program program, ImportStateCache importState, MessageLog log, TaskMonitor monitor) { SymbolTable symbolTable = program.getSymbolTable(); LoaderInfoHeader loader = header.getLoader(); int initSectionIndex = loader.getInitSection(); if (initSectionIndex != -1) { SectionHeader initSection = header.getSections().get(initSectionIndex); MemoryBlock initBlock = importState.getMemoryBlockForSection(initSection); Address address = initBlock.getStart().add(loader.getInitOffset()); try { symbolTable.createLabel(address, PefConstants.INIT, SourceType.IMPORTED); CreateDataCmd cmd = new CreateDataCmd(address, new PointerDataType()); cmd.applyTo(program); } catch (Exception e) { log.appendException(e); } } }
Example 5
Source File: PefLoader.java From ghidra with Apache License 2.0 | 6 votes |
/** * TODO determine how to correctly identify TOC location */ private void processTocSymbol(ContainerHeader header, Program program, ImportStateCache importState, MessageLog log, TaskMonitor monitor) { SymbolTable symbolTable = program.getSymbolTable(); List<SectionHeader> sections = header.getSections(); if (sections.size() < 2) { return; } SectionHeader dataSection = sections.get(1); if (!dataSection.isWrite()) {//is not a data section... return; } Address tocAddress = importState.getTocAddress(); if (tocAddress == null) { MemoryBlock dataBlock = importState.getMemoryBlockForSection(dataSection); tocAddress = dataBlock.getStart(); } try { symbolTable.createLabel(tocAddress, PefConstants.TOC, SourceType.IMPORTED); CreateDataCmd cmd = new CreateDataCmd(tocAddress, new PointerDataType()); cmd.applyTo(program); } catch (Exception e) { log.appendException(e); } }
Example 6
Source File: DynamicSymbolTableCommand.java From ghidra with Apache License 2.0 | 6 votes |
@Override public void markup(MachHeader header, FlatProgramAPI api, Address baseAddress, boolean isBinary, ProgramModule parentModule, TaskMonitor monitor, MessageLog log) { updateMonitor(monitor); try { if (isBinary) { createFragment(api, baseAddress, parentModule); Address address = baseAddress.getNewAddress(getStartIndex()); api.createData(address, toDataType()); markupTOC(header, api, baseAddress, parentModule, monitor); markupModules(header, api, baseAddress, parentModule, monitor); markupReferencedSymbolTable(header, api, baseAddress, parentModule, monitor); makupIndirectSymbolTable(header, api, baseAddress, parentModule, monitor); markupExternalRelocations(api, baseAddress, parentModule, monitor); markupLocalRelocations(api, baseAddress, parentModule, monitor); } } catch (Exception e) { log.appendMsg("Unable to create " + getCommandName()); log.appendException(e); } }
Example 7
Source File: AbstractBinaryFormatAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
final public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) throws CancelledException { try { return command.applyTo(program, monitor); } catch (Exception e) { log.appendException(e); log.setStatus(e.toString()); } finally { log.copyFrom(command.getMessages()); } return false; }
Example 8
Source File: CoffLoader.java From ghidra with Apache License 2.0 | 5 votes |
private MemoryBlock createInitializedBlock(ByteProvider provider, Program program, FileBytes fileBytes, TaskMonitor monitor, MessageLog log, final Language language, int sectionNumber, CoffSectionHeader section, final int sectionSize, Address sectionAddr, boolean isOverlay) throws AddressOverflowException, IOException { String name = section.getName(); if (isOverlay) { name += "-" + sectionNumber; } MemoryBlock block = null; try { if (section.isProcessedBytes(language)) { try (InputStream dataStream = section.getRawDataStream(provider, language)) { block = MemoryBlockUtils.createInitializedBlock(program, isOverlay, name, sectionAddr, dataStream, sectionSize, "PhysAddr:0x" + Integer.toHexString(section.getPhysicalAddress()) + " " + "Size:0x" + Integer.toHexString(sectionSize) + " " + "Flags:0x" + Integer.toHexString(section.getFlags()), null/*source*/, section.isReadable(), section.isWritable(), section.isExecutable(), log, monitor); } } else { block = MemoryBlockUtils.createInitializedBlock(program, isOverlay, name, sectionAddr, fileBytes, section.getPointerToRawData(), sectionSize, "PhysAddr:0x" + Integer.toHexString(section.getPhysicalAddress()) + " " + "Size:0x" + Integer.toHexString(sectionSize) + " " + "Flags:0x" + Integer.toHexString(section.getFlags()), null/*source*/, section.isReadable(), section.isWritable(), section.isExecutable(), log); } } catch (RuntimeException e) { log.appendMsg( "Unable to create non-loaded block " + section + ". No memory block was created."); log.appendException(e); } return block; }
Example 9
Source File: ImageCor20Header.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void markup(Program program, boolean isBinary, TaskMonitor monitor, MessageLog log, NTHeader ntHeader) throws DuplicateNameException, CodeUnitInsertionException, IOException, MemoryAccessException { if (!metadata.hasParsedCorrectly()) { return; } metadata.markup(program, isBinary, monitor, log, ntHeader); if (entryPointToken > 0) { // DLL's won't have an entry point try { if ((flags & ImageCor20Flags.COMIMAGE_FLAGS_NATIVE_ENTRYPOINT) == ImageCor20Flags.COMIMAGE_FLAGS_NATIVE_ENTRYPOINT) { // Add new symbol for the native entry point program.getSymbolTable().addExternalEntryPoint( program.getImageBase().add(entryPointToken)); } else { // Add a new symbol for the .NET entry point CliStreamMetadata stream = (CliStreamMetadata) metadata.getMetadataRoot().getStreamHeader( CliStreamMetadata.getName()).getStream(); CliMethodDefRow row = (CliMethodDefRow) stream.getTable( (entryPointToken & 0xff000000) >> 24).getRow(entryPointToken & 0x00ffffff); program.getSymbolTable().addExternalEntryPoint( program.getImageBase().add(row.RVA)); } } catch (Exception e) { log.appendException(e); } } }
Example 10
Source File: RelocationState.java From ghidra with Apache License 2.0 | 5 votes |
/** * Adds the fixup address to the contents stored at address, * then creates a pointer at address. * @param address the address to fixup * @param fixupAddress the value to use in fixup * @param log message log for recording errors */ public void fixupMemory(Address address, Address fixupAddress, MessageLog log) { relocateMemoryAt(address, (int) fixupAddress.getOffset(), log); try { program.getListing().createData(address, new PointerDataType(), 4); } catch (Exception e) { log.appendException(e); } }
Example 11
Source File: AbstractJavaAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
@Override final public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) throws CancelledException { try { return analyze(program, set, monitor, log); } catch (Exception e) { log.appendException(e); e.printStackTrace(); } return false; }
Example 12
Source File: GccExceptionAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
private void handleDebugFrameSection(Program program, TaskMonitor monitor, MessageLog log) throws CancelledException { try { DebugFrameSection debugFrameSection = new DebugFrameSection(monitor, program); debugFrameSection.analyze(); } catch (MemoryAccessException | ExceptionHandlerFrameException e) { log.appendMsg("Error analyzing GCC DebugFrame exception tables"); log.appendException(e); } }
Example 13
Source File: GccExceptionAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
private int analyzeEhFrameHeaderSection(Program program, TaskMonitor monitor, MessageLog log) { try { EhFrameHeaderSection ehframehdrSection = new EhFrameHeaderSection(program); return ehframehdrSection.analyze(monitor); } catch (AddressOutOfBoundsException | MemoryAccessException | ExceptionHandlerFrameException e) { log.appendMsg("Error analyzing GCC EH Frame Header exception table"); log.appendException(e); } return 0; }
Example 14
Source File: FileFormatAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
@Override final public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) throws CancelledException { try { return analyze(program, set, monitor, log); } catch (Exception e) { log.appendException(e); } return false; }
Example 15
Source File: DexHeaderFormatAnalyzer.java From ghidra with Apache License 2.0 | 5 votes |
private Symbol createMethodSymbol(Program program, Address methodAddress, String methodName, Namespace classNameSpace, MessageLog log) { program.getSymbolTable().addExternalEntryPoint(methodAddress); try { return program.getSymbolTable().createLabel(methodAddress, methodName, classNameSpace, SourceType.ANALYSIS); } catch (InvalidInputException e) { log.appendException(e); return null; } }
Example 16
Source File: DexLoader.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program, TaskMonitor monitor, MessageLog log) throws IOException { monitor.setMessage( "DEX Loader: creating dex memory" ); try { Address start = program.getAddressFactory().getDefaultAddressSpace().getAddress( 0x0 ); long length = provider.length(); try (InputStream inputStream = provider.getInputStream(0)) { program.getMemory().createInitializedBlock(".dex", start, inputStream, length, monitor, false); } BinaryReader reader = new BinaryReader( provider, true ); DexHeader header = new DexHeader( reader ); monitor.setMessage( "DEX Loader: creating method byte code" ); createMethodLookupMemoryBlock( program, monitor ); createMethodByteCodeBlock( program, length, monitor); for ( ClassDefItem item : header.getClassDefs( ) ) { monitor.checkCanceled( ); ClassDataItem classDataItem = item.getClassDataItem( ); if ( classDataItem == null ) { continue; } createMethods( program, header, item, classDataItem.getDirectMethods( ), monitor, log ); createMethods( program, header, item, classDataItem.getVirtualMethods( ), monitor, log ); } } catch ( Exception e) { log.appendException( e ); } }
Example 17
Source File: GccExceptionAnalyzer.java From ghidra with Apache License 2.0 | 4 votes |
private void handleStandardSections(Program program, TaskMonitor monitor, MessageLog log) throws CancelledException { int fdeTableCount = analyzeEhFrameHeaderSection(program, monitor, log); // If the EHFrameHeader doesn't exist, the fdeTableCount will be 0. monitor.checkCanceled(); try { /* * If the .eh_frame section exists, build the structures * contained within this program section. */ EhFrameSection ehframeSection = new EhFrameSection(monitor, program); List<RegionDescriptor> regions = ehframeSection.analyze(fdeTableCount); AddressSet ehProtected = new AddressSet(); for (RegionDescriptor region : regions) { monitor.checkCanceled(); ehProtected.add(region.getRange()); LSDACallSiteTable callSiteTable = region.getCallSiteTable(); if (callSiteTable != null) { // Process this table's call site records. for (LSDACallSiteRecord cs : callSiteTable.getCallSiteRecords()) { monitor.checkCanceled(); processCallSiteRecord(program, ehProtected, region, cs); } } } } catch (MemoryAccessException | ExceptionHandlerFrameException e) { log.appendMsg("Error analyzing GCC exception tables"); log.appendException(e); } }
Example 18
Source File: ISO9660Analyzer.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) throws CancelledException { ByteProvider provider = new MemoryByteProvider(program.getMemory(), program.getAddressFactory().getDefaultAddressSpace()); BinaryReader reader = new BinaryReader(provider, true); try { Offset signatureOffset = checkSignatures(program); setPointerOffset(signatureOffset, reader); monitor.setMessage("Processing ISO9660 Header"); //Get the full header (contains all volume descriptors) ISO9660Header isoHeader = new ISO9660Header(reader); //Get the list of volumes from the header List<ISO9660BaseVolume> volumes = isoHeader.getVolumeDescriptorSet(); //Set the overall plate comment at the top of this file setPlateComment(program, toAddress(program, 0), isoHeader.toString()); //Create a new module for the volume descriptor fragments ProgramModule descriptorModule = program.getListing().getDefaultRootModule().createModule("Volume Descriptors"); //For each volume, set the volumes plate comment and data at the address it exists setDescriptorData(program, volumes, descriptorModule); processPathTables(isoHeader, reader, program); //Create an alignment over the null characters from start to the first volume int offset = getOffsetValue(signatureOffset); program.getListing().createData(toAddress(program, 0), new AlignmentDataType(), offset - 1); ISO9660VolumeDescriptor pvd = isoHeader.getPrimaryVolumeDescriptor(); ISO9660Directory entryDir = isoHeader.getPrimaryDirectory(); int logicalBlockSize = pvd.getLogicalBlockSizeLE(); List<ISO9660Directory> dirList = createDirectoryList(reader, entryDir, logicalBlockSize); createDirectories(reader, program, dirList, logicalBlockSize); } catch (Exception e) { log.appendException(e); return false; } return true; }