Skip to content

Instantly share code, notes, and snippets.

@Const-me
Last active October 24, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Const-me/9c5ea55b1341ffd46cfda16ec891a269 to your computer and use it in GitHub Desktop.
Save Const-me/9c5ea55b1341ffd46cfda16ec891a269 to your computer and use it in GitHub Desktop.
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <stdio.h>
#include <stdint.h>
#include <array>
#include <algorithm>
void printStack( const char* what )
{
ULONG_PTR lo, high;
GetCurrentThreadStackLimits( &lo, &high );
printf( "%s: %p - %p\n", what, lo, high );
}
void* fiberMain, *fiberSecondary;
constexpr size_t cbBuffer = 24;
void __stdcall fiberProc( void* lpFiberParameter )
{
std::array<uint8_t, cbBuffer> localBuffer;
std::copy_n( (const uint8_t*)lpFiberParameter, cbBuffer, localBuffer.begin() );
printStack( "fiber" );
SwitchToFiber( fiberMain );
}
int main()
{
printStack( "start" );
std::array<uint8_t, cbBuffer> localBuffer = { 0x4e, 0x65, 0x76, 0x65, 0x72, 0x20, 0x67, 0x6f, 0x6e, 0x6e, 0x61, 0x20, 0x67, 0x69, 0x76, 0x65, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x70, 0x2c };
fiberMain = ConvertThreadToFiber( nullptr );
fiberSecondary = CreateFiber( 0, &fiberProc, localBuffer.data() );
printStack( "converted" );
SwitchToFiber( fiberSecondary );
printStack( "back to main" );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment