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 


Can aonone help me to understand this?

 
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: Sat Aug 01, 2015 5:36 am    Post subject: Can aonone help me to understand this? Reply with quote

Hi

I have found pretty interesting thing that I dont understand why it happens. I am trying to hook GetDiskFreeSpaceW with following code.

Code:
BOOL WINAPI DetourGetDiskFreeSpaceW(
  _In_  LPCTSTR lpRootPathName,
  _Out_ LPDWORD lpSectorsPerCluster,
  _Out_ LPDWORD lpBytesPerSector,
  _Out_ LPDWORD lpNumberOfFreeClusters,
  _Out_ LPDWORD lpTotalNumberOfClusters
){
   printf("DetourGetDiskFreeSpaceW\n&lpNumberOfFreeClusters: %llX\n",&lpNumberOfFreeClusters);
   //BOOL ret = fpGetDiskFreeSpaceW(lpRootPathName,lpSectorsPerCluster,lpBytesPerSector,lpNumberOfFreeClusters,lpTotalNumberOfClusters);
   printf("before cheating %d \n",*lpNumberOfFreeClusters);
   (*lpNumberOfFreeClusters) = (DWORD)99999999;
   (*lpTotalNumberOfClusters) = (DWORD)999999999;
   (*lpBytesPerSector) = (DWORD)65535;
   (*lpSectorsPerCluster) = (DWORD)128;
   printf("faked space %d \n",lpNumberOfFreeClusters);
   return 1;
}


Now, when I try to hook my own program, it works correctly.


But when I hook installer then it crashes.


As it can be seen from screenshots it crashes when printf tries to read the variable.
Code:
 printf("before cheating %d \n",*lpNumberOfFreeClusters);

Could anyone help me to understand why this happens and what could fix it?

It looks so strange to me because I dont do anything with variable itself yet. I just try to read it. I dont even try to modify it at first. And even it I do modify it to invalid value, it still shouldn't crash before the caller uses these value, but it crashes when the code execution is still in hook.

I also figured that when I view address that gets printed in CE then with my app it points to address which value contains lpNumberOfFreeClusters's value but with setup if I add this printed address to CE it is 0.
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: Sat Aug 01, 2015 12:30 pm    Post subject: Reply with quote

You can't write to the following values like you are:
Code:
   (*lpNumberOfFreeClusters) = (DWORD)99999999;
   (*lpTotalNumberOfClusters) = (DWORD)999999999;
   (*lpBytesPerSector) = (DWORD)65535;
   (*lpSectorsPerCluster) = (DWORD)128;


I showed you how to use them properly in the other thread.

_________________
- 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: Sat Aug 01, 2015 1:08 pm    Post subject: Reply with quote

Nope, that's the other thing already. In previous thread I played with GetDiskFreeSpaceExW but now I have GetDiskFreeSpaceW.
And in this thread, it crashes already at printf.
Code:
 printf("before cheating %d \n",*lpNumberOfFreeClusters);

This line doesnt even get printed anymore (as it can be seen from screenshots). And this line is before code you pointed out.
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