 |
|
 |
Why do you want to save the general registers? Such as this:
push eax // Preserve the registers
push ecx
...
pop ecx // Restore the registers
pop eax
There is no need.
|
|
|
|
 |
|
 |
mov eax, dword ptr [eax + 0x30]
mov ecx, dword ptr [eax] // Get the whole DWORD
That modifies the original code of the registers
mov command in asm basicly means a "copy" of sorts
*example*
mov eax, 5 (means that the you move the value of eax to 5, so now eax = 5)
*relating to anti-debug example*
mov eax, dword ptr [eax + 0x30] (Moves the value of eax to be the value of the pointer of [eax + 0x30] )
mov ecx, dword ptr [eax] (Moves the value of ecx to be the value pointed by eax)
then you pop the registers again to restor the original values. as if "nothing" happened.
I really like this code as most people use standard winapi "IsDebuggerPresent" and in debuggers it's REALLY easy to see that call to the api (trust me, i kow =) ). using this masks it, very nice =)
|
|
|
|
 |
|
 |
I'm not sure whether the Windows API had call for this at the time this article was written, but it does contain one now: IsDebuggerPresent(). It works in Win98 and up.
|
|
|
|
 |
|
 |
Yes it did. This was just digging under the hood.
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
yes, but if someone decides to debug your app, they can see the call very easily =). This method masks it so you don't really know when you get detected, unless you are a really good "cracker"
|
|
|
|
 |
|
 |
I writing code using DirectShow and Cyberlink MPEG2 DVD decoder, and the filter was showing a warning MessageBox in Debug mode, and after it crash.
So I'm writing this code from your exemple
__asm
{
mov eax, fs:[0x18] // Get the TIB's linear address
mov eax, dword ptr [eax + 0x30]
mov ecx, dword ptr [eax] // Get the whole DWORD
and ecx, 0x11101111
mov dword ptr [eax], ecx
}
Thanks !
|
|
|
|
 |
|
 |
That's definitely a very good use for it Good job!
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
Does someone know whether the meaning of the PEB's offset 0x03 is changed in Windows Xp and 2K3?
|
|
|
|
 |
|
 |
hai,
I have a small doubt in java script.
I want to send parameters to a function which is attached to an element as the parameter values change dynamically.
regards,
kalyan
|
|
|
|
 |
|
 |
Hi ALL
How can I check whether DrWatson is present or not and how can I attach to it. What I mean to say is this I do not want to get a normal windows box ("myexe.exe has enounteread a problem and ....(Send Error Report|Don't Send)) and some how dont send should be pressed by default so that an automatic error dmp is created. Thus we straightway give the control to DrWatson ourselves.
--Vikas
|
|
|
|
 |
|
 |
You only need to check "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger" value. If it is "drwtsn32 -p %ld -e %ld -g", you get it, or else you need type "drwtsn32 -i" to install it manually.
|
|
|
|
 |
|
 |
The SDK function IsDebuggerPresent() is not in Windows 95, only Windows98/ME/NT/2000 and XP.
Does the function IsDebuggerAttached() work in windows95?
|
|
|
|
 |
|
 |
I doubt it will work in Windows 95 as I have described that the TIB is different between the OS's. However, I think Win95 and Win98 should be the same. I could go check in Win98 (I don't have Win95) and see what the difference is so it can be ported for Win9x.
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
What other neat debug tricks/utilities do you have up your sleeve? Perhaps they're not *all* already written in msdn. hehe
|
|
|
|
 |
|
 |
Heheh Well, I have tricks, and I hope they're not documented in MSDN! Anyway, there are some really cool debugging toolkits on this section, so I guess they're in a much more publishable state than what I have on my own.
OK, I will think of some tricks that haven't already been mentioned, if I do in fact have any, and will put them up... But a lot of the time it involves what would often be considered hacking the system, I guess
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
Hack away, man. I'm ready for it. Show me the money!
|
|
|
|
 |
|
 |
Okey-dokey I'll see what I can come up with that makes enough sense. In any case, happen to have anything while debugging you thought might be cool but haven't done or figured out? One thing I did recently was write my own memory allocators by overriding new and delete... Then I could do a gazillion dumps on the allocation info... I also have a memory allocation monitor for processes, but I can't make an article out of that, though...
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
I think I remember in the old days you used to be able to use self modifying code to check for debuggers. This is more a DOS trick than a Windows trick though.
One of the tricks I remeber was to modify the next instruction in memory. If you were in a debugger or being stepped through the cache would be flushed before you accessed that instruction and the "new" instruction would be executed instead of the old. Of course, this was also a good way to detect if your old 386 had any CPU cache to begin with (Systems without cache would always execute the new instruction anyway). There were other tricks though. A jmp would obviously force the clearing of the cache to execute the instruction. I think one of the other tricks was to change certain memory and attempt to read it again.
In windows, this would assume that when this occurs the cache isn't flushed. It also assumes that no context switch occured between the execution time. Also, being that Windows has native support for debugging, it's not like the cache trick would matter most likely.
I'm not sure about this though, I can't remember the details. I know I've done the next byte modification and found cache/non cache systems. I know there was SOME trick that you could use self modifying code to detect debuggers, this may or may not be it. I just don't remember anymore...
|
|
|
|
 |
|
 |
Also considering instruction pairing where two instructions can be paired to execute at the same time... Unless of course the CPU validates it's not referencing the memory of the next instruction before pairing.
|
|
|
|
 |
|
 |
There is a window function available.
BOOL IsDebuggerPresent(VOID);
|
|
|
|
 |
|
 |
I just checked MSDN, and lo' and behold, it does exist!!! Well, guess I never looked in the Win32 API for something like that, but found it while debugging. Thanks for letting me know!
I also checked out the code for IsDebuggerPresent(), and obviously, it checks for the exact same byte! Oh well, it's not a total loss, I guess.
Thanks again!
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
Yes but according to some friends,
the Windows functions can be hooked
and faked by debuggers & hackers.
So can be this one.
Then it's better to use our own version.
Same remark for registry access.
|
|
|
|
 |
|
 |
It is a fact that all Win32 functions can be hooked. But there are two ways to hook them : globally, or per-process. To globally hook the Win32 functions, it can only be done in Win9x. But the per-process hook can be done on both Win9x and WinNT.
Sure this techniques can be used for hacking Pretty common. But I do it to learn system behaviour as researchers to in general. After all, system-wide hooks in Windows has been the holy-grail of Windows systems programming for god knows how long.
Well, as for registry access, Mark Russinovich has already had the final word on that! However, that isn't Win32 API hooking. It was system services.
I admit that I have also in some cases, changed the TIB to fool the system into thinking that there wasn't a debugger attached to make it behave differently.
Thanks for your remarks
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |
|
 |
OK, so there's an equivalent Win32 API call. So what?! IMHO that doesn't deminish the great value of this article which was consise & to the point, and most importantly, shed a bit of light on an area I knew nothing about.
Keep up the good work!
---
Grab WndTabs from http://www.wndtabs.com to make your VC++ experience that much more comfortable...
|
|
|
|
 |
|
 |
Oz,
Thanks a million! Even after I found out about the Win32 API function, I was hoping that I'd have at least mentioned something that wasn't mentioned something before, namely, the TIB. I'm glad you liked the article, and I hope to put some more about the system that would be useful... If I know anything else useful, that is
Thanks again
--------
"Sometimes men stumble upon the truth, but most pick themselves up and hurry of as if nothing happened" ~ Winston Churchill
|
|
|
|
 |