#include <iostream>
#include <string>
#include <sstream>
#include <windows.h>
using namespace std;
int main()
{
string source = "I love fat boys";
string search = "love";
string replace = "wanna throw rocks at";
string buffer = "";
stringstream replaced("");
stringstream original(source);
while (original >> buffer)
{
if (buffer == search) replaced << replace << " ";
else replaced << buffer << " ";
}
cout << replaced.str();
system("Pause");
return 0;
}
You need to set ThreadActive to false after your program has finished working. Otherwise i think the thread wont be closed by itself.
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
DWORD dwThreadId;
DWORD dwExitCode;
bool Acceleration = false;
bool ThreadActive = true;
UINT TimerThread();
void EhitaL6ng()
{
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TimerThread, NULL/*&lParms*/, 0, &dwThreadId);
LastErr("Thread declaration");
}
UINT TimerThread()
{
//See tuleks enne progre töö lõppu falseks lükata kuskil
//DLL_DETACH'is ntx
while(ThreadActive)
{
if (KEYDOWN(VK_NUMPAD1))
{
switch (Acceleration)
{
case true:
printf("True \n");
break;
case false:
printf("False \n");
break;
}
Acceleration = !Acceleration;
}
Sleep(250);
}
ExitThread(NULL);
};
Teeb konsooli, suvalisse appi. Eriti hea on seda kasutada kui ei viitsi mingit opengl’i või directx’i printimist enda progrele leiutada lithsate variablete nägemiseks.
//Credits to unknown internet guy
printf("Lulz it works!\n");
VOID CreateConsole()
{
int hConHandle = 0;
HANDLE lStdHandle = 0;
FILE *fp = 0;
// Allocate a console
AllocConsole();
// redirect unbuffered STDOUT to the console
lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
// redirect unbuffered STDIN to the console
lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "r");
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
// redirect unbuffered STDERR to the console
lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
}
Template funktsioonile, mis codecave funktsioonile tuleks anda.
DWORD ReturnAddress = 0;
__declspec(naked) void Funktsioon(void)
{
__asm
{
pop ReturnAddress
PUSHAD
PUSHFD
}
//Cpp kood siia
__asm
{
POPFD
POPAD
push ReturnAddress
ret
}
}
Teeb CALL’i antud aadressile, mis kutsub määratud funktsiooni. Viimane argument ütleb funktsioonile, mitu baiti nopida tuleb.
Kasutab WriteBytesASM funktsiooni.
//Credits to Drew_Benton
VOID Codecave(DWORD destAddress, VOID (*func)(VOID), BYTE nopCount)
{
// Calculate the code cave for chat interception
DWORD offset = (PtrToUlong(func) - destAddress) - 5;
// Buffer of NOPs, static since we limit to 'UCHAR_MAX' NOPs
BYTE nopPatch[0xFF] = {0};
// Construct the patch to the function call
BYTE patch[5] = {0xE8, 0x00, 0x00, 0x00, 0x00};
memcpy(patch + 1, &offset, sizeof(DWORD));
WriteBytesASM(destAddress, patch, 5);
// We are done if we do not have NOPs
if(nopCount == 0)
return;
// Fill it with nops
memset(nopPatch, 0x90, nopCount);
// Make the patch now
WriteBytesASM(destAddress + 5, nopPatch, nopCount);
}