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 


How to rewrite memcpy using equal sign?

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

Joined: 18 Mar 2009
Posts: 110

PostPosted: Fri Jul 31, 2015 10:34 am    Post subject: How to rewrite memcpy using equal sign? Reply with quote

Hi.

I was curious to know if there is any better way than memcpy to overwrite lpFreeBytesAvailable with modified?
When I use lpFreeBytesAvailable = modified then it crashes. I also tried to combine these with & and *s but I didn't manage to do that.


Code:
BOOL WINAPI DetourGetDiskFreeSpaceExW(
  _In_opt_  LPCTSTR         lpDirectoryName,
  _Out_opt_ PULARGE_INTEGER lpFreeBytesAvailable,
  _Out_opt_ PULARGE_INTEGER lpTotalNumberOfBytes,
  _Out_opt_ PULARGE_INTEGER lpTotalNumberOfFreeBytes
){
   BOOL ret = fpGetDiskFreeSpaceExW(lpDirectoryName,lpFreeBytesAvailable,lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes);
   PULARGE_INTEGER modified = (PULARGE_INTEGER)123; //fake free space
   memcpy(lpFreeBytesAvailable, &modified, 8);
   //lpFreeBytesAvailable = modified;
   wprintf(L"Space2: %s %llX => %I64u\n", lpDirectoryName,lpFreeBytesAvailable, *lpFreeBytesAvailable);
   return ret;
}


The problem is that call to memcpy crashes with some processes so I want to rewrite it using equal sign to see if it fixes the problem.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jul 31, 2015 11:44 am    Post subject: Reply with quote

Given that ULARGE_INTEGER is a struct containing a union based on the number parts, you would have to assign each part of the structure. (You can't just use equals to set the value on it.)

Instead you would have to do something like this:
Code:
lpFreeBytesAvailable->QuadPart = 123;

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Fri Jul 31, 2015 1:22 pm    Post subject: Reply with quote

tnx
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