CLR C++ FindWindow help[SOLVED]

Posts 1–15 of 38 · Page 1 of 3
CLR C++ FindWindow help[SOLVED]
Hey, i am trying to learn how to make a trainer, and i read the tutorial here on memory hacking, i have created a CLR C++ Project in VC++ and i'm getting a problem with FindWindow.

Here is my code, and bugs i get, can anyone tell me what i might be doing wrong, and why FindWindow isn't working properly.

Test1.h
[php]#pragma once

using namespace System;
using namespace System::Windows::Forms;

ref class CTest1 : public Form
{
public:
CTest1(void);
};[/php]

Test1.cpp
[php]#include "Test1.h"


CTest1::CTest1(void)
{
}[/php]

central.cpp
[php]#include <Windows.h>
#include "Test1.h"

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
Application::Run(gcnew CTest1());

// Find the window of the calculator
HWND hWnd = FindWindow(0, "Calculator");

// The Window Does not Exist
if(hWnd == 0)
{
//MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else
{
//MessageBox(0, "Window exists.", "Error", MB_OK|MB_ICONERROR);
}

return 0;
}[/php]

Currently i am not really trying to do all of the code at once, i want to get FindWindow working first. So the rest will come later.

These are the bugs i get:
1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
1> central.cpp
1>central.obj : error LNK2028: unresolved token (0A00004A) "extern "C" struct HWND__ * __stdcall FindWindowA(char const *,char const *)" (?FindWindowA@@$$J18YGPAUHWND__@@PBD0@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)
1>central.obj : error LNK2019: unresolved external symbol "extern "C" struct HWND__ * __stdcall FindWindowA(char const *,char const *)" (?FindWindowA@@$$J18YGPAUHWND__@@PBD0@Z) referenced in function "extern "C" int __stdcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J216YGHPAUHINSTANCE__@@0PADH@Z)
1>c:\users\dave\documents\visual studio 2010\Projects\Test1\Debug\Test1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have googled for hours and cannot find an answer, i think i might have to define or include something but i do not know what. If you give code please care to include an explanation of what it does so i can learn for it

Thanks, Cheers
If you've just started C++, let go of .NET for now and start with console applications.

[php]
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
HWND hwnd = FindWindow("Calculator",0);

DWORD pid;
GetWindowThreadProcessId(hwnd,&pid);

HANDLE handle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE,0,pid);

//WriteProcessMemory
}
[/php]

That's a pretty basic template, to write to the processes memory, just use WriteProcessMemory.

Also, FindWindow uses the caption name, which isn't always good especially if you have really long captions. My suggestion would be to use a combination of CreateToolhelp32Snapshot, Process32First and Process32Next. This combination removes the need to use GetWindowThreadProcessId, the process ID will be in the structure you got from Process32First/Process32Next.

Good luck.
Quote Originally Posted by Void View Post
If you've just started C++, let go of .NET for now and start with console applications.

[php]
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
HWND hwnd = FindWindow("Calculator",0);

DWORD pid;
GetWindowThreadProcessId(hwnd,&pid);

HANDLE handle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE,0,pid);

//WriteProcessMemory
}
[/php]

That's a pretty basic template, to write to the processes memory, just use WriteProcessMemory.

Also, FindWindow uses the caption name, which isn't always good especially if you have really long captions. My suggestion would be to use a combination of CreateToolhelp32Snapshot, Process32First and Process32Next. This combination removes the need to use GetWindowThreadProcessId, the process ID will be in the structure you got from Process32First/Process32Next.

Good luck.
Well it kind of depends, i did just start about a week ago, and i already had the code you gave me, i also read in another article you or someone else said that a nice GUI isn't a requirement for a hack, which is true. And i think i might just leave it for now then.

So with that being said, i hope you don't mind if i ask another C++ question then.

You see, like i said i already had the code, or similar to it then. I am trying to get Unlimited Power in Split/Second, i have the memory code but i don't know if it is properly structured.

Using Cheat engine i found the code was '004BDE26'
But the tutorial explaining to write/freeze the memory in question etc. has a 0x in it, i don't know if that's a different code or just 0x4BDE26

Oh and eh, here is the code i am using, i just tested it and my game crashed :P Though it does work, i might want to look into your other way of finding windows, but for now i just want to see if i can get this to work

Here is my current code:
[php]#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
HWND hWnd = FindWindow(0, "Split/Second"); // Split/Second - Calculator

if(hWnd == 0)
{
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else
{
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess)
{
MessageBox(0, "Could not open the process!", "Error!", MB_OK|MB_ICONERROR);
}
else
{
int newdata = 999;
DWORD newdatasize = sizeof(newdata);

// Freeze Process
while(1)
{
// Say Nothing, just do for now.
if(WriteProcessMemory(hProcess, (LPVOID)0x4BDE26, &newdata, newdatasize, NULL))
{
//MessageBox(NULL, "WriteProcessMemory worked.", "Success", MB_OK + MB_ICONINFORMATION);
}
else
{
//MessageBox(NULL, "Error cannot WriteProcessMemory!", "Error", MB_OK + MB_ICONERROR);
}
CloseHandle(hProcess);
}
}
}
return 0;
}[/php]
I must say... that was damned quick o_O.
Quote Originally Posted by why06jz View Post
I must say... that was damned quick o_O.
I work fast.
The 0x prefix tells the compiler that it's hexadecimal. 0x100 won't be the same as 100.

That's the address that holds the amount of power you have or what?
Quote Originally Posted by Void View Post
The 0x prefix tells the compiler that it's hexadecimal. 0x100 won't be the same as 100.

That's the address that holds the amount of power you have or what?
Split Second has like a gauge bar, drifting gives you more gauge and you have 3 bars to fill, first 2 bars are blue, which grant you something in front of you to blow up to get rid of your opponents, when the 3d bar is filled you get 1 BIG map changing power up (sort of). But in general the 2 first ones needs to be filled up.

I don't know the values of the bar, but i thought it needed to be NOP in order to work so that you have unlimited power, (granting you ability to constantly crash your opponents)
Okay, so the address holds the amount of power you currently have. The way I would normally do it would be, in CE, find what writes to this address, and NOP that instruction. This way the value could never change.
Quote Originally Posted by Void View Post
Okay, so the address holds the amount of power you currently have. The way I would normally do it would be, in CE, find what writes to this address, and NOP that instruction. This way the value could never change.
Alright so i couldn't exactly find the split second code back so i went into an easier game, Call of Juarez: Bound in Blood, i had the extra ammo you carry in just a second.

So i tried the code and again the game crashed.
The code originally had 59 (you start with 60).

And my changed value was 999.

Cheat engine reported this as the "find out what writes to this thing"

Call of Juarez: 00857d37 - 89 45 04 - mov [ebp+04],eax
[php]
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
HWND hWnd = FindWindow(0, "Call of Juarez: Bound in Blood"); // Split/Second - Calculator

if(hWnd == 0)
{
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else
{
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess)
{
MessageBox(0, "Could not open the process!", "Error!", MB_OK|MB_ICONERROR);
}
else
{
int newdata = 999;
DWORD newdatasize = sizeof(newdata);

while(1)
{
// Call of Juarez: 00857d37 - 89 45 04 - mov [ebp+04],eax
// Say Nothing, just do for now.
if(WriteProcessMemory(hProcess, (LPVOID)0x857d37, &newdata, newdatasize, NULL))
{
//MessageBox(NULL, "WriteProcessMemory worked.", "Success", MB_OK + MB_ICONINFORMATION);
}
else
{
//MessageBox(NULL, "Error cannot WriteProcessMemory!", "Error", MB_OK + MB_ICONERROR);
}
CloseHandle(hProcess);
}
}
}
return 0;
}[/php]
__asm mov EAX, DWORD PTR DS:[ECX+10h]; also works, the h, not sure if thats only when using __asm tho.
I suggest starting off with checking if that instruction is the one you're looking for. You're going to have to set a breakpoint on it to check EBP, then add 4 to whatever address EBP is holding, if the address is the same as the address that holds your ammo you've got it. Try NOP'ing that instruction in CE before trying it with C++, just to see if you've atleast got the right method going.

If you don't mind adding me on MSN, I can help you a little better from there.
davidm_44@hotmail.com
Quote Originally Posted by Void View Post
I suggest starting off with checking if that instruction is the one you're looking for. You're going to have to set a breakpoint on it to check EBP, then add 4 to whatever address EBP is holding, if the address is the same as the address that holds your ammo you've got it. Try NOP'ing that instruction in CE before trying it with C++, just to see if you've atleast got the right method going.

If you don't mind adding me on MSN, I can help you a little better from there.
davidm_44@hotmail.com
Will add you as soon as i got Windows Live installed and pretending i'm not on-line towards other people (lol i don't often msn xD)

I am pretty sure this is the address because i froze it and it flipped the values back to 59 once i reloaded my guns.

Edit: And thanks for helping me anyway Ive been on several C++ forums where it takes 2 hours for some people to comment on c++ specific questions (in a c++ community), here i had an answer almost immediately (even though there are tons of different forums)
Damn, sorry for double post. If someone can delete this, please. Sorry. =/
I have a website that covers everything that you want. Add me on MSN (hawkx5@live.com) and I'll give you the link and help you with whatever you need. Cheers!
Still isn't working specifically for this game but the c++ code is laid out now, i'll be trying out different memory codes to later, big thanks to void, and serpentine for helping me out on MSN
Posts 1–15 of 38 · Page 1 of 3
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us