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 


Assigning value to a pointer to a typedef'ed variable

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Wed Jul 29, 2009 10:20 am    Post subject: Assigning value to a pointer to a typedef'ed variable Reply with quote

I've created a source, that looks something like this:

Code:
typedef BOOL (WINAPI CrtProc)(__in_opt LPCSTR lpApplicationName, __inout_opt LPSTR lpCommandLine, __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles, __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCSTR lpCurrentDirectory, __in LPSTARTUPINFOA lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation);
CrtProc* crtProc;
...
DWORD codeaddr = 0xDEADBEEF; //of curse not, but its a block of allocated memory
...
crtProc = (CrtProc (__stdcall *))codeaddr;


ass you clearly see, i apply the DWORD to crtProc using this line:
Code:
crtProc = (CrtProc (__stdcall *))codeaddr;

But i was wondering if there is any other way to put the value of codeaddr into crtProc, so that i can be other typedefs, and not just CrtProc?, i've been attempting with (void*), etc, etc, but i didnt manage to get it to work properly...

Any advice would be nice here...
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jul 29, 2009 3:03 pm    Post subject: Reply with quote

Something like this?
Code:
CrtProc* crtProc = (CrtProc*)0x12345;
Back to top
View user's profile Send private message MSN Messenger
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Wed Jul 29, 2009 3:19 pm    Post subject: Reply with quote

Noz3001 wrote:
Something like this?
Code:
CrtProc* crtProc = (CrtProc*)0x12345;


I want to pass crtProc as a void* to a function, like this:

Code:
void function(DWORD value, void* crtProc){
crtProc = value; //How would i do this?
}
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

Joined: 09 May 2003
Posts: 26000
Location: The netherlands

PostPosted: Wed Jul 29, 2009 4:28 pm    Post subject: Reply with quote

Problem with a void type is that it's nothing, so has to be typecast to the type you want to use it as first.
I assume you want to write a DWORD value there, so typecast it to a DWORD pointer first, then dereference the pointer and write to it:
*(DWORD *)crtProc=value;

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Thu Jul 30, 2009 1:57 am    Post subject: Reply with quote

Dark Byte wrote:
Problem with a void type is that it's nothing, so has to be typecast to the type you want to use it as first.
I assume you want to write a DWORD value there, so typecast it to a DWORD pointer first, then dereference the pointer and write to it:
*(DWORD *)crtProc=value;


I did attempt to do that, but since the pointer isn't in any way assigned, it gives me:
Code:
Unhandled exception at 0x00281153 in CreateProcessHook.exe: 0xC0000005: Access violation writing location 0x00000000.
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: Thu Jul 30, 2009 2:49 am    Post subject: Reply with quote

Here nig.


Code:


typedef void (WINAPI CrtProc)(char* cBuffer);
CrtProc* crtProc = (CrtProc*)0xDEADBEEF;

void newFunc(char* cBuffer)
{
    MessageBox(0,cBuffer,"funcptr changed!",0);
}

void oldFunc(char* cBuffer)
{
    MessageBox(0,cBuffer,"funcptr change FAILED!",0);
}

void function(DWORD value, DWORD** crttProc)
{
*(DWORD*)crttProc = value;
}


.....


crtProc = (CrtProc*)oldFunc;
function((DWORD)&newFunc,(DWORD**)&crtProc);
crtProc("bawwwwwwwwwwwwwwwwww");




Works for me.

If it doesn't work, it will have "funcptr change FAILED!" in the title of the messagebox, or else it will say "funcptr changed!".
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
Page 1 of 1

 
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