Skip to content

Instantly share code, notes, and snippets.

@rbmm
Created April 12, 2024 21:23
Show Gist options
  • Save rbmm/2419121a7ae8857dbad3c5bb50d9d7e5 to your computer and use it in GitHub Desktop.
Save rbmm/2419121a7ae8857dbad3c5bb50d9d7e5 to your computer and use it in GitHub Desktop.
void mm(ULONG s)
{
alloca(s);
}
void DumpStackRegion()
{
MEMORY_BASIC_INFORMATION mbi;
if (VirtualQuery(_AddressOfReturnAddress(), &mbi, sizeof(mbi)))
{
PVOID AllocationBase = mbi.AllocationBase;
mbi.BaseAddress = AllocationBase;
while (VirtualQuery(mbi.BaseAddress, &mbi, sizeof(mbi)) &&
AllocationBase == mbi.AllocationBase)
{
PCSTR pszState = 0;
switch (mbi.State)
{
case MEM_COMMIT:
pszState = "COMMIT";
break;
case MEM_RESERVE:
pszState = "RESERVE";
break;
default: return;
}
DbgPrint("[%p, %p) %p %08x %s\n", mbi.BaseAddress,
(ULONG_PTR)mbi.BaseAddress + mbi.RegionSize,
mbi.RegionSize, mbi.Protect, pszState);
(ULONG_PTR&)mbi.BaseAddress += mbi.RegionSize;
}
}
}
void WINAPI FiberProc(FCTX* ctx)
{
for (;;)
{
DbgPrint("%s\n", ctx->sz);
DumpStackRegion();
mm(0x8000);
DumpStackRegion();
SwitchToContext(ctx->MainFiber);
}
}
/*
[000000DB1C800000, 000000DB1C8FC000) 00000000000FC000 00000000 RESERVE
[000000DB1C8FC000, 000000DB1C8FF000) 0000000000003000 00000104 COMMIT
[000000DB1C8FF000, 000000DB1C900000) 0000000000001000 00000004 COMMIT
************************************************************************
[000000DB1C800000, 000000DB1C8F4000) 00000000000F4000 00000000 RESERVE
[000000DB1C8F4000, 000000DB1C8F7000) 0000000000003000 00000104 COMMIT
[000000DB1C8F7000, 000000DB1C900000) 0000000000009000 00000004 COMMIT
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment