Enum Class EmulatorUtilities
- All Implemented Interfaces:
Serializable,Comparable<EmulatorUtilities>,Constable
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe conventional name of the memory block used to specify the location of the stack.static final intThe default block size used to copy program bytes into the emulatorstatic final intThe default max size to assume for the stackstatic final longThese utilities will avoid choosing a stack range lower than this bound, as most platforms will never map this page (even in kernel space) so that 0-valued pointers are never valid. -
Method Summary
Modifier and TypeMethodDescriptionstatic AddressRangechooseStackRange(Program program, Address entry) Choose an assumed stack range of size 16384static AddressRangechooseStackRange(Program program, Address entry, int stackSize) Choose an assumed stack rangestatic AddressRangechooseStackRangeFromBlock(Program program) Choose an assumed stack range by examining the program's memory map for a "STACK" block.static AddressRangechooseStackRangeFromContext(Program program, Address entry, int stackSize) Choose an assumed stack range by examining the entry point for a contextual value of the stack pointer.static <T> voidinitializeForFunction(PcodeThread<T> thread, Function function, int stackSize) Prepare a thread to emulate a given functionstatic voidloadProgram(PcodeMachine<?> machine, Program program) Copy the bytes from the given program into the given emulator's memory.static <T> voidloadProgram(PcodeMachine<T> machine, Program program, int blockSize) Copy the bytes from the given program into the given emulator's memory.static EmulatorUtilitiesReturns the enum constant of this class with the specified name.static EmulatorUtilities[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Field Details
-
BLOCK_NAME_STACK
The conventional name of the memory block used to specify the location of the stack. This should only be the case for single-threaded emulation.- See Also:
-
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZEThe default block size used to copy program bytes into the emulator- See Also:
-
DEFAULT_STACK_SIZE
public static final int DEFAULT_STACK_SIZEThe default max size to assume for the stack- See Also:
-
PAGE_ZERO_END
public static final long PAGE_ZERO_ENDThese utilities will avoid choosing a stack range lower than this bound, as most platforms will never map this page (even in kernel space) so that 0-valued pointers are never valid.- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
loadProgram
public static <T> void loadProgram(PcodeMachine<T> machine, Program program, int blockSize) throws MemoryAccessException Copy the bytes from the given program into the given emulator's memory.This copies each initialized block of memory from the given program into the emulator's shared machine state. Because the machine can have memory of any given type, it will use the machine's arithmetic to create values from the program's concrete data. Data is copied in blocks of the given size, which can be tweaked for performance. The default value, used by
loadProgram(PcodeMachine, Program)is 4096.- Type Parameters:
T- the type of values used by the emulator- Parameters:
machine- the emulator whose memory to initializeprogram- the program whose bytes should be copied into the emulatorblockSize- the size of the temporary buffer used for copying- Throws:
MemoryAccessException- if the program's memory cannot be read
-
loadProgram
public static void loadProgram(PcodeMachine<?> machine, Program program) throws MemoryAccessException Copy the bytes from the given program into the given emulator's memory.- Parameters:
machine- the emulator whose memory to initializeprogram- the program whose bytes should be copied into the emulator- Throws:
MemoryAccessException- if the program's memory cannot be read- See Also:
-
chooseStackRangeFromContext
public static AddressRange chooseStackRangeFromContext(Program program, Address entry, int stackSize) Choose an assumed stack range by examining the entry point for a contextual value of the stack pointer.- Parameters:
program- the program whose context to examineentry- the entry point where context should be examinedstackSize- the assumed max size of the stack- Returns:
- the range assumed to be reserved for the stack, or null if no stack pointer value is in the context
-
chooseStackRangeFromBlock
Choose an assumed stack range by examining the program's memory map for a "STACK" block.- Parameters:
program- the program to examine- Returns:
- the range assumed to be reserved for the stack, or null if no "STACK" block is found.
-
chooseStackRange
Choose an assumed stack rangeThis will first examine the entry point's context for a stack pointer value using
chooseStackRangeFromContext(Program, Address, int). Then, it will examine the progam's memory map usingchooseStackRangeFromBlock(Program). Finally, it will search for a slack address range of the requested size. That is, it seeks a range that does not intersect any existing memory block. If possible, this will avoid choosing a stack range that intersects [0, 4096), so that 0-valued pointers are in fact invalid.Note that a stack is not formally "allocated." Instead, the range is used to initialize a thread's stack pointer. Unless instrumentation is added to detect a stack overflow, nothing really prevents the program from exceeding the returned range. Thus,
stackSizeshould be large enough to accommodate the target. Additionally, the user or client code should be prepared for undefined behavior caused by an unmitigated stack overflow.- Parameters:
program- the programentry- the entry point, in case context there defines an initial stack pointerstackSize- the maximum expected size of the stack- Returns:
- the chosen range assumed to be used for the stack
-
chooseStackRange
Choose an assumed stack range of size 16384- Parameters:
program- the programentry- the entry point, in case context there defines an initial stack pointer- Returns:
- the chosen range assumed to be used for the stack
- See Also:
-
initializeForFunction
public static <T> void initializeForFunction(PcodeThread<T> thread, Function function, int stackSize) Prepare a thread to emulate a given function- Type Parameters:
T- the type of values in the emulator- Parameters:
thread- the thread whose state to initializefunction- the function to prepare to enterstackSize- the maximum expected size of the stack
-