It is currently Fri Jun 22, 2018 1:01 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: VirtualProtectEx_ + GetLastError_
PostPosted: Tue Mar 13, 2018 10:30 am 
Offline
User
User

Joined: Fri Jul 29, 2005 11:47 am
Posts: 49
Dear all, i've coded a tool to read some memory from a process, but on a VirtualBox that i use for testing i've got that both VirtualProtectEx and GetLastError return 0, but from MSDN i've read that VirtualProtectEx return 0 if fail, but error code 0 is "The operation completed successfully" so what is the problem ? Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: VirtualProtectEx_ + GetLastError_
PostPosted: Tue Mar 13, 2018 2:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 03, 2008 9:56 pm
Posts: 534
After VirtualProtectEx_() fails, you must call GetLastError_() before any other API function. Some PureBasic commands also internally call API functions and they also can overwrite GetLastError_() result.
For example, here we need to call ProgramFilename() after VirtualProtectEx_() so we do it like this:
Code:
v=VirtualProtectEx_(0,0,0,0,0)
;If v=0
e=GetLastError_()
;EndIf
f$=ProgramFilename()
Debug v
Debug e ;ok, we have error code for VirtualProtectEx_()

And not like this:
Code:
v=VirtualProtectEx_(0,0,0,0,0)
f$=ProgramFilename()
;If v=0
e=GetLastError_()
;EndIf
Debug v
Debug e ; error code was overwritten by ProgramFilename() internal API function

If this does not solve your problem then it could be a bug in your specific version of VirtualBox - maybe try updating if you are on older build.


Top
 Profile  
Reply with quote  
 Post subject: Re: VirtualProtectEx_ + GetLastError_
PostPosted: Tue Mar 13, 2018 3:28 pm 
Offline
User
User

Joined: Fri Jul 29, 2005 11:47 am
Posts: 49
my code is like:

if VirtualProtectEx_ (...) = 0
debug GetLastError_ ()
endif

and i got 0 in debug window, VirtualBox is v5.2.6, i cannot test on a real pc because i need to test on x86 machine and i've an x64 machine, so i'm using virtualbox for testing, any other idea or test to do ? Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: VirtualProtectEx_ + GetLastError_
PostPosted: Tue Mar 13, 2018 4:20 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 03, 2008 9:56 pm
Posts: 534
What output inside virtualbox do you get when you run these 2 snippets that i posted above?


Top
 Profile  
Reply with quote  
 Post subject: Re: VirtualProtectEx_ + GetLastError_
PostPosted: Tue Mar 13, 2018 4:22 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13304
Location: France
'Debug' is a complex command and can change the errorcode. You should use DisableDebugger/EnableDebugger if you really to have no interaction between the API call and GetLastError_()

Code:

DisableDebugger
result = VirtualProtectEx_ (...)
lastErrorResult = GetLastError_ ()
EnableDebugger
if result
  debug lastErrorResult
endif


Top
 Profile  
Reply with quote  
 Post subject: Re: VirtualProtectEx_ + GetLastError_
PostPosted: Thu Mar 15, 2018 10:24 am 
Offline
User
User

Joined: Fri Jul 29, 2005 11:47 am
Posts: 49
ok solved, i've 2 problems in my code:

1) wrong parameter passed to VirtualProtectEx
2) String concatenate problem on GetLastError that give me 0 return value

Thanks to all!


Top
 Profile  
Reply with quote  
 Post subject: Re: VirtualProtectEx_ + GetLastError_
PostPosted: Thu Mar 15, 2018 11:25 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13304
Location: France
Please always post a small code snippet when requesting help so we can quickly test and tune it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Charles556 and 9 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye