Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ compiling problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
gunminiho
Expert Cheater
Reputation: 0

Joined: 15 Dec 2008
Posts: 144
Location: peru

PostPosted: Wed Aug 26, 2009 9:33 am    Post subject: C++ compiling problem Reply with quote

well this is my first try on making something in C++, well i had lots of errors =) but i minimized to 1 Razz wich is this:

Code:
LINK : fatal error LNK1561: You must define an Entry Point



and this is my code:


Code:
#include <windows.h>
#include <stdlib.h>
#include "hax.h"


//declare pointers/variables here
LPCVOID Addy= (void*)0x00CDAEBA;


/*------------------------------*/

/*Otras Funciones*/

//main function
void WINAPI Hack()
{

while(true){


   // HotKey1
   if(GetAsyncKeyState(VK_F1)){
      //MEMORY BASIC INFORMATION mbi;

      LPVOID * tam=0;
      SIZE_T* size=0;
      //if(VirtualProtect(Addy,4,PAGE_EXECUTE_READWRITE,PAGE_READONLY)){
      ReadProcessMemory(GetCurrentProcess(),Addy,tam,4,size);
         *(DWORD*)Addy+=800000;
      //}
   }
}
}

BOOL APIENTRY DllMain(HINSTANCE hDll, DWORD callReason, LPVOID lpReserved)
{
if(callReason == DLL_PROCESS_ATTACH)
{
//edit your message box here (or create more) by changing what is in the quotation marks
MessageBox(0, "My New Hack ", "Injected", MB_ICONEXCLAMATION | MB_OK);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&Main, 0, 0, 0);
}
return true;
}


=) maybe im missing something?


Last edited by gunminiho on Wed Aug 26, 2009 12:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Wed Aug 26, 2009 10:17 am    Post subject: Reply with quote

lol are you making a DLL or an .exe..you have Main, and DllMain.

There is a difference. Google.
Back to top
View user's profile Send private message
gunminiho
Expert Cheater
Reputation: 0

Joined: 15 Dec 2008
Posts: 144
Location: peru

PostPosted: Wed Aug 26, 2009 12:28 pm    Post subject: Reply with quote

nop a DLL, xP! its just that a lil consufed =). i know the differences well teoricly but both of them has a Main function wich is called at starting the program or inject a DLL =).

and about functions notice that im using a void not a int Main(), it that i usualy use that name for the main fuction for my hacks, i think in C++ its wrong =) i think i noticed the problem

i will rename Main() for Hack().
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Wed Aug 26, 2009 2:39 pm    Post subject: Reply with quote

your source is fine, just specify that its a DLL in the compiler options Very Happy
_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Aug 26, 2009 2:57 pm    Post subject: Reply with quote

Code:
#include <windows.h>
#include <tchar.h>

LPCVOID Addy= (void*)0x00CDAEBA;

void Hack()
{
  while( true )
  {
    if( GetAsyncKeyState( VK_F1 ) )
    {
      LPVOID * tam=0;
      SIZE_T* size=0;
      ReadProcessMemory(GetCurrentProcess(),Addy,tam,4,size);
      *(DWORD*)Addy+=800000;
    }

   Sleep(100);
  }
}

BOOL WINAPI DllMain (HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
  if( ul_reason_for_call == DLL_PROCESS_ATTACH)
  {
    MessageBox(0, _T("My New Hack "), _T("Injected"), MB_ICONEXCLAMATION | MB_OK);
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&Hack, 0, 0, 0);
  }

  return true;
}


changed a few things to probably what you wanted, like createthread param, also added some sleep in your main loop, also indented it nicer

didn't really look at rest of code
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Wed Aug 26, 2009 3:22 pm    Post subject: Reply with quote

Why use ReadProcessMemory when you're already in the process's memory space?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Aug 26, 2009 4:10 pm    Post subject: Reply with quote

also if you're going to obtain the pseudo-handle then you might as well only do it once and store the result in a variable
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Wed Aug 26, 2009 5:27 pm    Post subject: Reply with quote

Slugsnack wrote:
also if you're going to obtain the pseudo-handle then you might as well only do it once and store the result in a variable


yea wont calling GetCurrentProcess 100 times a second make it slower?

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Aug 26, 2009 5:27 pm    Post subject: Reply with quote

Just specify the /DLL switch in a linker, otherwise depending on the subsystem option, it's going to be expecting either mainCRTStartup or WinMainCRTStartup as the entry.



Also you can just use a pointer to access the memory.

DWORD* dong = (DWORD*)0x00123456;
*dong = 100;
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Wed Aug 26, 2009 5:29 pm    Post subject: Reply with quote

Slugsnack wrote:
also if you're going to obtain the pseudo-handle then you might as well only do it once and store the result in a variable

Don't forget to close the handle once you're done with it too.

&Also it'll be better if you place variables outside the loop, instead of putting it in the loop.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Aug 26, 2009 5:43 pm    Post subject: Reply with quote

void:] wrote:
&Also it'll be better if you place variables outside the loop, instead of putting it in the loop.


This probably wont matter, variables on the stack are typically created within the function scope, so no, you are not declaring a billion variables a second like you may imagine.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Wed Aug 26, 2009 5:47 pm    Post subject: Reply with quote

void:] wrote:
Slugsnack wrote:
also if you're going to obtain the pseudo-handle then you might as well only do it once and store the result in a variable

Don't forget to close the handle once you're done with it too.

&Also it'll be better if you place variables outside the loop, instead of putting it in the loop.


uhm if you do

HWND hWin = GetCurrentProcess()

at the top of the function, then you wouldn't need to close it? o.o

_________________
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Wed Aug 26, 2009 6:36 pm    Post subject: Reply with quote

blankrider wrote:
void:] wrote:
Slugsnack wrote:
also if you're going to obtain the pseudo-handle then you might as well only do it once and store the result in a variable

Don't forget to close the handle once you're done with it too.

&Also it'll be better if you place variables outside the loop, instead of putting it in the loop.


uhm if you do

HWND hWin = GetCurrentProcess()

at the top of the function, then you wouldn't need to close it? o.o


Yes, proper coders would know that. He's just a bit stupid, quite a few people have recommended staying away from his help.

Anyway,

you could also use -1 for the HANDLE parameter, but you must type-cast it as a HANDLE first to avoid compiler errors.
Back to top
View user's profile Send private message
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Wed Aug 26, 2009 8:23 pm    Post subject: Reply with quote

GetCurrentProcess just returns INVALID_HANDLE_VALUE? Shocked
Back to top
View user's profile Send private message Visit poster's website
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Wed Aug 26, 2009 8:27 pm    Post subject: Reply with quote

Quote:
Remarks

A pseudo handle is a special constant, currently (HANDLE)-1, that is interpreted as the current process handle. For compatibility with future operating systems, it is best to call GetCurrentProcess instead of hard-coding this constant value. The calling process can use a pseudo handle to specify its own process whenever a process handle is required. Pseudo handles are not inherited by child processes.

This handle has the PROCESS_ALL_ACCESS access right to the process object. For more information, see Process Security and Access Rights.

Windows Server 2003 and Windows XP/2000: This handle has the maximum access allowed by the security descriptor of the process to the primary token of the process.

A process can create a "real" handle to itself that is valid in the context of other processes, or that can be inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function. A process can also use the OpenProcess function to open a real handle to itself.

The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with a pseudo handle has no effect. If the pseudo handle is duplicated by DuplicateHandle, the duplicate handle must be closed.



yes

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites