VirtualProtectEx_ + GetLastError_
VirtualProtectEx_ + GetLastError_
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!
Re: VirtualProtectEx_ + GetLastError_
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:
And not like this:
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.
For example, here we need to call ProgramFilename() after VirtualProtectEx_() so we do it like this:
Code: Select all
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_()
Code: Select all
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
Re: VirtualProtectEx_ + GetLastError_
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!
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!
Re: VirtualProtectEx_ + GetLastError_
What output inside virtualbox do you get when you run these 2 snippets that i posted above?
Re: VirtualProtectEx_ + GetLastError_
'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: Select all
DisableDebugger
result = VirtualProtectEx_ (...)
lastErrorResult = GetLastError_ ()
EnableDebugger
if result
debug lastErrorResult
endif
Re: VirtualProtectEx_ + GetLastError_
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!
1) wrong parameter passed to VirtualProtectEx
2) String concatenate problem on GetLastError that give me 0 return value
Thanks to all!
Re: VirtualProtectEx_ + GetLastError_
Please always post a small code snippet when requesting help so we can quickly test and tune it.