Class AbstractCodeObjectUnit
java.lang.Object
com.pnfsoftware.jeb.core.events.JebEventSource
com.pnfsoftware.jeb.core.units.AbstractUnit
com.pnfsoftware.jeb.core.units.AbstractBinaryUnit
com.pnfsoftware.jeb.core.units.codeobject.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.
-
Field Summary
Fields inherited from class com.pnfsoftware.jeb.core.events.JebEventSource
onEventCallCount -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCodeObjectUnit(IInput input, String formatType, String name, IUnitProcessor unitProcessor, IUnitCreator parent, IPropertyDefinitionManager pdm) Create a code object unit. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAllSections(Collection<? extends ISegmentInformation> sections) Add section information entries.protected voidaddAllSegments(Collection<? extends ISegmentInformation> segments) Add segment information entries.protected voidaddAllSymbols(Collection<? extends ISymbolInformation> symbols) Add symbol information entries.protected voidaddSection(ISegmentInformation section) Add section information.protected voidaddSegment(ISegmentInformation segment) Add segment information.protected booleanaddSymbol(ISymbolInformation symbol) Add symbol information.protected abstract booleanapplyRelocations(IVirtualMemory mem, long base, ILinkInfoProvider linkInfoPrv) Relocate a mapped code object.longconvertFileOffsetToRelativeAddress(long offset) Convert a file offset to a memory address, relative to the base.longconvertRelativeAddressToFileOffset(long rel) Convert a memory address (relative to the base) to a file offset.protected IVirtualMemoryCreate a virtual memory suitable to map this code object.List<? extends ISymbolInformation> Retrieve the list of exported symbols.List<? extends ISymbolInformation> Retrieve the list of imported symbols.Retrieve basic information about the object file.protected IInputRetrieve the input that is truly mappable.Retrieve a raw mapping of the code object.getSection(int i) Retrieve a section by index.intRetrieve the number of sections.List<? extends ISegmentInformation> Retrieve the list of sections defined in the object file.List<? extends ISegmentInformation> getSections(int wflags, int bflags) Retrieve a list of sections.getSegment(int i) Retrieve a segment by index.intRetrieve the number of segments.List<? extends ISegmentInformation> Retrieve the list of segments defined in the object file.List<? extends ISegmentInformation> getSegments(int wflags, int bflags) Retrieve a list of segments.intGet the number of symbols.Collection<? extends ISymbolInformation> Retrieve the symbols defined in the object file.List<? extends ISymbolInformation> getSymbols(int mustHaveFlags, int mustNotHaveFlags) Retrieve symbols filtered by flags.List<? extends ISegmentInformation> Retrieve the list of sections that are not marked INVALID.List<? extends ISegmentInformation> Retrieve the list of segments that are not marked INVALID.protected voidinsertSection(int index, ISegmentInformation section) Insert section information.protected voidinsertSegment(int index, ISegmentInformation segment) Insert segment information.booleanmap(IVirtualMemory mem, long wantedBase, boolean applyRelocations, ILinkInfoProvider linkInfoPrv) Map this object file onto virtual memory.protected booleanmapRawNoReloc(IVirtualMemory mem, long base) Map the object's segments at the provided base without applying relocations.protected voidremoveSection(int index) Remove section information by index.protected voidremoveSegment(int index) Remove segment information by index.protected voidSet loader information.protected abstract booleanIndicate whether the loader should allocate the full image range when preparing to load and map a code object file to memory.Methods inherited from class com.pnfsoftware.jeb.core.units.AbstractBinaryUnit
getInput, getMimeType, setInput, setMimeTypeMethods inherited from class com.pnfsoftware.jeb.core.units.AbstractUnit
addChild, addChild, addChild, addNotification, canBePersisted, clearAllData, dispose, finalize, generateQuickState, getAllData, getChildren, getContributions, getCreationTimestamp, getData, getDescription, getFormatter, getFormatType, getIconData, getInterpreters, getLock, getName, getNotes, getNotificationManager, getParent, getPropertyDefinitionManager, getPropertyManager, getRealName, getStatus, getUid, getUnitProcessor, hasChildren, initializePropertyObjects, internalSwapChildren, isDeserialized, isDisposed, isProcessed, isStale, isTransientChild, logError, logException, logInfo, logTrace, logWarn, onPropertyChange, postDeserialization, process, processInternal, removeChild, removeChild, setChild, setChild, setData, setName, setNotes, setParent, setProcessed, setProcessed, setRealName, setStatus, setStatus, setUnitProcessor, toStringMethods inherited from class com.pnfsoftware.jeb.core.events.JebEventSource
addListener, countListeners, getListeners, getParentSource, insertListener, notifyListeners, notifyListeners, notifyListeners, removeListener, setParentSourceMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.pnfsoftware.jeb.core.units.IBinaryUnit
getInput, getMimeTypeMethods inherited from interface com.pnfsoftware.jeb.util.events.IEventSource
addListener, countListeners, getListeners, getParentSource, insertListener, notifyListeners, removeListener, setParentSourceMethods inherited from interface com.pnfsoftware.jeb.core.units.IUnit
addChild, addChild, canBePersisted, dispose, execprvfunc, generateQuickState, getChildren, getContributions, getCreationTimestamp, getDescription, getExtraInputs, getFormatter, getFormatType, getIconData, getInterpreters, getLock, getName, getNotes, getNotificationManager, getParent, getParentArtifact, getParentProject, getPropertyDefinitionManager, getPropertyManager, getRealName, getStatus, getUid, getUnitProcessor, initializePropertyObjects, isDisposed, isProcessed, isStale, isTransientChild, notifyGenericChange, postDeserialization, process, removeChild, setName, setNotes, setParent, setRealName, setUnitProcessorMethods inherited from interface com.pnfsoftware.jeb.core.IUserDataSupport
clearAllData, getAllData, getData, setData
-
Constructor Details
-
AbstractCodeObjectUnit
protected AbstractCodeObjectUnit(IInput input, String formatType, String name, IUnitProcessor unitProcessor, IUnitCreator parent, IPropertyDefinitionManager pdm) Create a code object unit.- Parameters:
input- input objectformatType- format typename- unit nameunitProcessor- unit processorparent- parent unit creatorpdm- property definition manager
-
-
Method Details
-
getLoaderInformation
Description copied from interface:ICodeObjectUnitRetrieve basic information about the object file.- Specified by:
getLoaderInformationin interfaceICodeObjectUnit- Returns:
- the object file information, never null
-
setLoaderInformation
Set loader information.- Parameters:
ldInfo- loader information
-
getSegments
Description copied from interface:ICodeObjectUnitRetrieve 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:
getSegmentsin interfaceICodeObjectUnit- Returns:
- the list of segments, or null if unsupported
-
getValidSegments
Description copied from interface:ICodeObjectUnitRetrieve the list of segments that are not marked INVALID.- Specified by:
getValidSegmentsin interfaceICodeObjectUnit- Returns:
- the valid segments, or null if unsupported
-
getSegments
Description copied from interface:ICodeObjectUnitRetrieve a list of segments.- Specified by:
getSegmentsin interfaceICodeObjectUnit- Parameters:
wflags- must-have flagsbflags- must-not-have flags- Returns:
- the matching segments, or null if unsupported
-
getSegment
Description copied from interface:ICodeObjectUnitRetrieve a segment by index.- Specified by:
getSegmentin interfaceICodeObjectUnit- Parameters:
i- segment index- Returns:
- the segment
-
getSegmentCount
public int getSegmentCount()Description copied from interface:ICodeObjectUnitRetrieve the number of segments.- Specified by:
getSegmentCountin interfaceICodeObjectUnit- Returns:
- segment count
-
addSegment
Add segment information.- Parameters:
segment- segment information
-
insertSegment
Insert segment information.- Parameters:
index- insertion indexsegment- segment information
-
addAllSegments
Add segment information entries.- Parameters:
segments- segment information entries
-
removeSegment
protected void removeSegment(int index) Remove segment information by index.- Parameters:
index- segment index
-
getSections
Description copied from interface:ICodeObjectUnitRetrieve 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:
getSectionsin interfaceICodeObjectUnit- Returns:
- the list of sections, or null if unsupported
-
getValidSections
Description copied from interface:ICodeObjectUnitRetrieve the list of sections that are not marked INVALID.- Specified by:
getValidSectionsin interfaceICodeObjectUnit- Returns:
- the valid sections, or null if unsupported
-
getSections
Description copied from interface:ICodeObjectUnitRetrieve a list of sections.- Specified by:
getSectionsin interfaceICodeObjectUnit- Parameters:
wflags- must-have flagsbflags- must-not-have flags- Returns:
- the matching sections, or null if unsupported
-
getSection
Description copied from interface:ICodeObjectUnitRetrieve a section by index.- Specified by:
getSectionin interfaceICodeObjectUnit- Parameters:
i- section index- Returns:
- the section
-
getSectionCount
public int getSectionCount()Description copied from interface:ICodeObjectUnitRetrieve the number of sections.- Specified by:
getSectionCountin interfaceICodeObjectUnit- Returns:
- section count
-
addSection
Add section information.- Parameters:
section- section information
-
insertSection
Insert section information.- Parameters:
index- insertion indexsection- section information
-
addAllSections
Add section information entries.- Parameters:
sections- section information entries
-
removeSection
protected void removeSection(int index) Remove section information by index.- Parameters:
index- section index
-
getSymbols
Description copied from interface:ICodeObjectUnitRetrieve the symbols defined in the object file.- Specified by:
getSymbolsin interfaceICodeObjectUnit- Returns:
- the symbols, or null if unsupported
-
getSymbolCount
public int getSymbolCount()Get the number of symbols.- Returns:
- symbol count
-
addSymbol
Add symbol information.- Parameters:
symbol- symbol information- Returns:
- true if the symbol was added
-
addAllSymbols
Add symbol information entries.- Parameters:
symbols- symbol information entries
-
getImportedSymbols
Description copied from interface:ICodeObjectUnitRetrieve the list of imported symbols.- Specified by:
getImportedSymbolsin interfaceICodeObjectUnit- Returns:
- the list (possibly empty) of imported symbols, or null if unsupported
-
getExportedSymbols
Description copied from interface:ICodeObjectUnitRetrieve the list of exported symbols.- Specified by:
getExportedSymbolsin interfaceICodeObjectUnit- Returns:
- the list (possibly empty) of exported symbols, or null if unsupported
-
getSymbols
Description copied from interface:ICodeObjectUnitRetrieve symbols filtered by flags.- Specified by:
getSymbolsin interfaceICodeObjectUnit- Parameters:
mustHaveFlags- mask of flags that must be presentmustNotHaveFlags- mask of flags that must be absent- Returns:
- the matching symbols, or null if unsupported
-
convertFileOffsetToRelativeAddress
public long convertFileOffsetToRelativeAddress(long offset) Description copied from interface:ICodeObjectUnitConvert a file offset to a memory address, relative to the base.- Specified by:
convertFileOffsetToRelativeAddressin interfaceICodeObjectUnit- 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:ICodeObjectUnitConvert a memory address (relative to the base) to a file offset.- Specified by:
convertRelativeAddressToFileOffsetin interfaceICodeObjectUnit- 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
Description copied from interface:ICodeObjectUnitRetrieve 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:
getRawMemoryMappedImagein interfaceICodeObjectUnit- 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:ICodeObjectUnitMap this object file onto virtual memory.- Specified by:
mapin interfaceICodeObjectUnit- Parameters:
mem- memory image onto which the mapping should be donewantedBase- wanted base; set to -1L to request mapping at the normal baseapplyRelocations- true to apply relocations after mappinglinkInfoPrv- optional link information provider- Returns:
- success indicator
-
createSuitableMemory
Create a virtual memory suitable to map this code object.- Returns:
- virtual memory object
-
mapRawNoReloc
Map the object's segments at the provided base without applying relocations.- Parameters:
mem- virtual memory objectbase- mapping base address, or -1 to use the preferred image base- Returns:
- the VM, null on error
-
getMappableInput
Retrieve the input that is truly mappable. The default implementation simply returnsAbstractBinaryUnit.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:
- mappable input
-
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:
- true if the full image range should be allocated
-
applyRelocations
protected abstract boolean applyRelocations(IVirtualMemory mem, long base, ILinkInfoProvider linkInfoPrv) Relocate a mapped code object.- Parameters:
mem- virtual memorybase- mapping base addresslinkInfoPrv- optional link information provider- Returns:
- true if relocations were applied
-