Maybe you guys know how these two subjects are related, but I’m not sure the rest of us do - perhaps
this should be a separate thread. It’s still early, so I may just be missing something, and if so,
please accept my apologies.
As far the original question, the whole thing is really quite sketchy, there’s incomplete code, no
debugging information (!analyze -v ideally), and I’m not sure what to make of ‘(probably a BSOD),’ -
this is pretty much a binary phenomenon - but this is part of the problem, because it will trash
your stack:
__asm
> {
> pushad
> pushfd
> }
> DbgPrint(“YEP:Inline patching occurs…\n”); // <- HERE, problem
> occurs!!!
> __asm
> {
> popad
> popfd
> }
Minimally, I think you need to reverse the ‘pop’ statements. Presently, ignoring all other effects,
you are popping the previously pushed value of EFLAGS from the stack in to whatever register that
‘popad’ populates first (which I think is EDI, but I’m not sure); I’m not really sure what will
happen when you pop the first register pushed by pushad from the stack in to EFLAGS (I think that
means EAX). Some flags are restored and some are not (I don’t remember the specifics), but I think
it safe to say that nothing good will come of this either.
As far as what windbg reports later (not clear where you’re getting that from), it looks like
garbage, which is probably all there is going to be given the stack trashing that I think already
took place; in particular, I believe that this what windbg interprets an opcode of ‘0’ to be, but
I’m not sure:
815201d0 add byte ptr [eax],al ds:023:00000023=??
Fundamentally, as David just mentioned, you’re not encoding the instruction correctly.
If you’re learning or just experimenting, then no worries, but downloading a copy of the Intel
manuals would be a good start.
http://www.intel.com/products/processor/manuals/
There is mounting evidence that my brain is not yet quite working today, so if I’ve overlooked
something, my bad.
mm
Selvan Murasoli wrote:
Hi
Right now I am using the build environment which Microsoft has given for
building my kernel mode drivers.
Is there any other IDE for building and debugging? What you are using
actually?
And one more thing for debugging the driver we are using the dbgview
tool to debug the driver messages.
What u are using?
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Wednesday, December 03, 2008 6:24 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] [Inline patching] DbgPrint causes blocking of my VM
Hello,
I’m going to explain you my problem that i don’t success to solve for a
while…
I am realizing inline patching on the specific function. For that, i put
a DbgPrint() call so as to check if my detour function is really called.
When i debug step to step, i notice that DebugPrint() function causes a
blocking of my VM (probably a BSOD) because (i think) it’s not the rigth
address.
Problem occurs inside of my detour function which is placed into a non
paged memory.
Below, some piece of code.
- First, an extract of my function which allows me to put the inline
patching:
VOID PrepareDetourFunction()
{
char *actual_function = (char *)MyFunctionToPatch;
char *non_paged_memory;
unsigned long detour_address;
unsigned long reentry_address;
int i = 0;
char newcode = { 0xEA, 0x44, 0x33, 0x22, 0x11, 0x08, 0x00, 0x90, 0x90,
0x90 };
reentry_address = ((unsigned long)MyFunctionToPatch) + 10;
non_paged_memory = ExAllocatePool(NonPagedPool, 256);
…
}
Note: non_paged_memory pointer corresponds at my_detour_function()
address and so points on the memory pool allocated for
my_detour_function().
and now, the code which causes my problem, once called:
__declspec(naked) my_detour_function()
{
__asm
{
pushad
pushfd
}
DbgPrint(“YEP:Inline patching occurs…\n”); // <- HERE, problem
occurs!!!
__asm
{
popad
popfd
}
…
}
Thanks to WinDbg, i have the following line during the DbgPrint call:
815201d0 add byte ptr [eax],al ds:023:00000023=??
where 0x815201d0 is address of DbgPrint() function inside
my_detour_function().
But, i noticed that the rigth address is 0x80500799 (nt!DbgPrint).
Why in my non paged function, i don’t have the right address of
DbgPrint() Function? Can you explain me this behaviour and how to sove
it?
Thanks for your help.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
This e-mail has been scanned by Arbitron’s Email Content Service.