#pragma once
#include "IAsmHelper.h"
#include "../Include/Macro.h"
namespace blackbone
{
class AsmHelper64 : public IAsmHelper
{
public:
BLACKBONE_API AsmHelper64();
BLACKBONE_API ~AsmHelper64( void );
///
/// Generate function prologue code
///
/// true if execution must be swithed to x64 mode
virtual void GenPrologue( bool switchMode = false );
///
/// Generate function epilogue code
///
/// true if execution must be swithed to x86 mode
/// Stack change value
virtual void GenEpilogue( bool switchMode = false, int retSize = -1 );
///
/// Generate function call
///
/// Function pointer
/// Function arguments
/// Ignored
virtual void GenCall( const AsmFunctionPtr& pFN, const std::vector& args, eCalligConvention cc = cc_stdcall );
///
/// Save rax value and terminate current thread
///
/// NtTerminateThread address
/// Memory where rax value will be saved
virtual void ExitThreadWithStatus( uint64_t pExitThread, uint64_t resultPtr );
///
/// Save return value and signal thread return event
///
/// NtSetEvent address
/// Result value memory location
/// Event memory location
/// Error code memory location
/// Return type
virtual void SaveRetValAndSignalEvent(
uint64_t pSetEvent,
uint64_t ResultPtr,
uint64_t EventPtr,
uint64_t lastStatusPtr,
eReturnType rtype = rt_int32
);
///
/// Set stack reservation policy on call generation
///
///
/// If true - stack space will be reserved during each call generation
/// If false - no automatic stack reservation, user must allocate stack by hand
///
virtual void EnableX64CallStack( bool state );
private:
AsmHelper64( const AsmHelper64& ) = delete;
AsmHelper64& operator = (const AsmHelper64&) = delete;
///
/// Push function argument
///
/// Argument.
/// Push type(register or stack)
void PushArg( const AsmVariant& arg, int32_t index );
///
/// Push function argument
///
/// Argument
/// Argument index
/// true if argument is a floating point value
template
void PushArgp( const _Type& arg, int32_t index, bool fpu = false );
private:
bool _stackEnabled; // if true - GenCall will allocate shadow stack space
};
}