<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"selfDestroyingThread"</Description>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
createThread(selfFreeingThread)
alloc(selfFreeingThread,2048)
label(mainLoop)
label(exitMyThread)
label(freeTheThread)

label(havetoquit)
registersymbol(havetoquit)
label(counter)
registersymbol(counter)


selfFreeingThread:
  mov rax,selfFreeingThread
  push rax //push base address of the region of pages to be freed
  mov rax,VirtualFree
  push rax //push VirtualFree address

  sub rsp,28

mainLoop:
  mov rcx,#500
  call Sleep

  and byte ptr [havetoquit],01
  jnz exitMyThread

  inc [counter]
  jmp mainLoop


exitMyThread:
  add rsp,28
  jmp freeTheThread

havetoquit:
db 00

counter:
dd 0



selfFreeingThread+800:
freeTheThread:
mov rbp,rsp
sub rsp,40 // room for code and calls (remember pushes at the very beginning)

lea rcx,[rsp+20]
mov rdx,00000020
mov r8d,40
lea r9,[rsp+18]
mov rax,VirtualProtect     // make stack executable
call rax

// place the rest on stack
mov [rsp+20],084D8B48                   // mov rcx,[rbp+08]    // address
mov [rsp+24],41D23148                   // xor rdx,rdx         // size
mov [rsp+28],008000B8                   // mov r8d,00008000    // MEM_RELEASE
mov [rsp+2c],0055FF00                   // call [rbp+00]       // VirtualFree
mov [rsp+30],50C48348                   // add rsp,50          //
mov [rsp+34],000000C3                   // ret
lea rcx,[rsp+20]
jmp rcx

[DISABLE]
havetoquit:
db 01

unregistersymbol(havetoquit)
unregistersymbol(counter)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>1</ID>
          <Description>"counter"</Description>
          <VariableType>4 Bytes</VariableType>
          <Address>counter</Address>
        </CheatEntry>
        <CheatEntry>
          <ID>2</ID>
          <Description>"havetoquit"</Description>
          <VariableType>Byte</VariableType>
          <Address>havetoquit</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>
