Class AbstractCodeObjectUnit

All Implemented Interfaces:
IUnitCreator, IUserDataSupport, ICodeObjectUnit, IBinaryUnit, IUnit, IEventSource

@Ser public abstract class AbstractCodeObjectUnit extends AbstractBinaryUnit implements ICodeObjectUnit
Convenient base class for code objects.
  • Constructor Details

  • Method Details

    • getLoaderInformation

      public ILoaderInformation getLoaderInformation()
      Description copied from interface: ICodeObjectUnit
      Retrieve basic information about the object file.
      Specified by:
      getLoaderInformation in interface ICodeObjectUnit
      Returns:
      the object file information, never null
    • setLoaderInformation

      protected void setLoaderInformation(ILoaderInformation ldInfo)
    • getSegments

      public List<? extends ISegmentInformation> getSegments()
      Description copied from interface: ICodeObjectUnit
      Retrieve the list of segments defined in the object file. Typically, segments are mapped to memory by a code object loader. Segments and sections may overlap.
      Specified by:
      getSegments in interface ICodeObjectUnit
      Returns:
      the list of segments, or null if unsupported
    • getValidSegments

      public List<? extends ISegmentInformation> getValidSegments()
      Description copied from interface: ICodeObjectUnit
      Retrieve the list of segments that are not marked INVALID.
      Specified by:
      getValidSegments in interface ICodeObjectUnit
      Returns:
    • getSegments

      public List<? extends ISegmentInformation> getSegments(int wflags, int bflags)
      Description copied from interface: ICodeObjectUnit
      Retrieve a list of segments.
      Specified by:
      getSegments in interface ICodeObjectUnit
      Parameters:
      wflags - must-have flags
      bflags - must-not-have flags
      Returns:
    • getSegment

      public ISegmentInformation getSegment(int i)
      Specified by:
      getSegment in interface ICodeObjectUnit
      Returns:
    • getSegmentCount

      public int getSegmentCount()
      Specified by:
      getSegmentCount in interface ICodeObjectUnit
      Returns:
    • addSegment

      protected void addSegment(ISegmentInformation segment)
    • insertSegment

      protected void insertSegment(int index, ISegmentInformation segment)
    • addAllSegments

      protected void addAllSegments(Collection<? extends ISegmentInformation> segments)
    • removeSegment

      protected void removeSegment(int index)
    • getSections

      public List<? extends ISegmentInformation> getSections()
      Description copied from interface: ICodeObjectUnit
      Retrieve the list of sections defined in the object file. Typically, sections are used to point to areas of interest. Sections and segments may overlap.
      Specified by:
      getSections in interface ICodeObjectUnit
      Returns:
      the list of sections, or null if unsupported
    • getValidSections

      public List<? extends ISegmentInformation> getValidSections()
      Description copied from interface: ICodeObjectUnit
      Retrieve the list of sections that are not marked INVALID.
      Specified by:
      getValidSections in interface ICodeObjectUnit
      Returns:
    • getSections

      public List<? extends ISegmentInformation> getSections(int wflags, int bflags)
      Description copied from interface: ICodeObjectUnit
      Retrieve a list of sections.
      Specified by:
      getSections in interface ICodeObjectUnit
      Parameters:
      wflags - must-have flags
      bflags - must-not-have flags
      Returns:
    • getSection

      public ISegmentInformation getSection(int i)
      Specified by:
      getSection in interface ICodeObjectUnit
      Returns:
    • getSectionCount

      public int getSectionCount()
      Specified by:
      getSectionCount in interface ICodeObjectUnit
      Returns:
    • addSection

      protected void addSection(ISegmentInformation section)
    • insertSection

      protected void insertSection(int index, ISegmentInformation section)
    • addAllSections

      protected void addAllSections(Collection<? extends ISegmentInformation> sections)
    • removeSection

      protected void removeSection(int index)
    • getSymbols

      public Collection<? extends ISymbolInformation> getSymbols()
      Specified by:
      getSymbols in interface ICodeObjectUnit
      Returns:
    • getSymbolCount

      public int getSymbolCount()
    • addSymbol

      protected boolean addSymbol(ISymbolInformation symbol)
    • addAllSymbols

      protected void addAllSymbols(Collection<? extends ISymbolInformation> symbols)
    • getImportedSymbols

      public List<? extends ISymbolInformation> getImportedSymbols()
      Description copied from interface: ICodeObjectUnit
      Retrieve the list of imported symbols.
      Specified by:
      getImportedSymbols in interface ICodeObjectUnit
      Returns:
      the list (possibly empty) of imported symbols, or null if unsupported
    • getExportedSymbols

      public List<? extends ISymbolInformation> getExportedSymbols()
      Description copied from interface: ICodeObjectUnit
      Retrieve the list of exported symbols.
      Specified by:
      getExportedSymbols in interface ICodeObjectUnit
      Returns:
      the list (possibly empty) of exported symbols, or null if unsupported
    • getSymbols

      public List<? extends ISymbolInformation> getSymbols(int mustHaveFlags, int mustNotHaveFlags)
      Specified by:
      getSymbols in interface ICodeObjectUnit
      Returns:
    • convertFileOffsetToRelativeAddress

      public long convertFileOffsetToRelativeAddress(long offset)
      Description copied from interface: ICodeObjectUnit
      Convert a file offset to a memory address, relative to the base.
      Specified by:
      convertFileOffsetToRelativeAddress in interface ICodeObjectUnit
      Parameters:
      offset - a file offset
      Returns:
      a base-relative memory address, or -1 if unsupported or if the offset does not map to anywhere in memory
    • convertRelativeAddressToFileOffset

      public long convertRelativeAddressToFileOffset(long rel)
      Description copied from interface: ICodeObjectUnit
      Convert a memory address (relative to the base) to a file offset.
      Specified by:
      convertRelativeAddressToFileOffset in interface ICodeObjectUnit
      Parameters:
      rel - the base-relative memory address
      Returns:
      a file offset, or -1 if unsupported or if the address does not map to anywhere in the file
    • getRawMemoryMappedImage

      public IVirtualMemory getRawMemoryMappedImage()
      Description copied from interface: ICodeObjectUnit
      Retrieve a raw mapping of the code object. No relocations are applied. Do not attempt to modify the returned VM object; it should be considered read-only.
      Specified by:
      getRawMemoryMappedImage in interface ICodeObjectUnit
      Returns:
      the virtual memory containing the mapped, unresolved code object; null on error or if the code object unit decided to not map the object file
    • map

      public boolean map(IVirtualMemory mem, long wantedBase, boolean applyRelocations, ILinkInfoProvider linkInfoPrv)
      Description copied from interface: ICodeObjectUnit
      Map this object file onto virtual memory.
      Specified by:
      map in interface ICodeObjectUnit
      Parameters:
      mem - memory image onto which the mapping should be done
      wantedBase - wanted base; set to -1L to request mapping at the normal base
      linkInfoPrv - optional
      Returns:
      success indicator
    • createSuitableMemory

      protected IVirtualMemory createSuitableMemory()
      Create a virtual memory suitable to map this code object.
      Returns:
    • mapRawNoReloc

      protected boolean mapRawNoReloc(IVirtualMemory mem, long base)
      Map the object's segments at the provided base without applying relocations.
      Parameters:
      mem -
      base -
      Returns:
      the VM, null on error
    • getMappableInput

      protected IInput getMappableInput()
      Retrieve the input that is truly mappable. The default implementation simply returns AbstractBinaryUnit.getInput(), as is expected in most cases (eg, ELF, PE). For formats requiring pre-processing of the input data, such as IHEX or other ascii-encoded code objects, this method should be overridden.
      Returns:
    • shouldAllocateFullImage

      protected abstract boolean shouldAllocateFullImage()
      Indicate whether the loader should allocate the full image range when preparing to load and map a code object file to memory.

      Typically, the answer is yes for PE-like files, no for ELF-like files.

      Returns:
    • applyRelocations

      protected abstract boolean applyRelocations(IVirtualMemory mem, long base, ILinkInfoProvider linkInfoPrv)
      Relocate a mapped code object.
      Parameters:
      mem - virtual memory
      base - mapping base address
      linkInfoPrv - optional
      Returns: