niaren
December 10th, 2009, 17:01
Hi all, this is my first post.
I will begin by thanking all the people that are devoting time to moderate and otherwise keeping this place up and running. I have used this forum quite a lot recently and thought maybe it is time to chime in although I'm a little unsure if this post qualifies as a first post but I'll give it a try. Now to the business
I'm trying to reverse engineer part of an audio driver. I'm interested in the part which actually modifies the audio. I did some initial analysis using IDA which provided me with some good spots as to where to set some breakpoints for further analysis in a debugger. It took me some time to figure out how to create an appropriate setup for single-stepping in kernel mode. I ended up having XP SP2 (guest OS) running in a Virtual Machine (VMWare) on a Vista laptop (Host OS). Using Windbg on the Host OS it is possible to do kernel mode debugging in the guest OS (this link provide the details on how to do this: http://www.catch22.net/tuts/vmware).
Now I'm able to single-step through the code in the audio driver and everything seems perfectly alright. All the calculations modifying the audio stream are done in floating point and that is where my understanding of things starts to fall short. In Windbg the FP registers st0-st7 are not updated in response to executing FP instructions. Other registers are updated alright for instance eip, esp and ebp are updated when executing move esp, ebp.
In order to find out what is going on I checked the problem with this simple 'driver'
Link to code: http://msdn.microsoft.com/en-us/library/aa489566.aspx
The code depends on libcntpr.lib and ks.lib
The disassembly for the code in the OnUnload routine is
After stepping over the fld1 instruction nothing happens with st0. So the problem persists in this much simpler setup.
The best explanation I have found about this is in the Windbg help
One problem is how to figure out what is the right thread context but another problem is how this can explain why it is only the FP registers that are not updated. My laptop processor is an Intel Pentium Dual CPU.
Maybe I'm overlooking something very simple, that is probably the most likely thing. For the moment this problem has set me stymied so I'm very interested in any kind of input of what could be the problem.
niaren
I will begin by thanking all the people that are devoting time to moderate and otherwise keeping this place up and running. I have used this forum quite a lot recently and thought maybe it is time to chime in although I'm a little unsure if this post qualifies as a first post but I'll give it a try. Now to the business

I'm trying to reverse engineer part of an audio driver. I'm interested in the part which actually modifies the audio. I did some initial analysis using IDA which provided me with some good spots as to where to set some breakpoints for further analysis in a debugger. It took me some time to figure out how to create an appropriate setup for single-stepping in kernel mode. I ended up having XP SP2 (guest OS) running in a Virtual Machine (VMWare) on a Vista laptop (Host OS). Using Windbg on the Host OS it is possible to do kernel mode debugging in the guest OS (this link provide the details on how to do this: http://www.catch22.net/tuts/vmware).
Now I'm able to single-step through the code in the audio driver and everything seems perfectly alright. All the calculations modifying the audio stream are done in floating point and that is where my understanding of things starts to fall short. In Windbg the FP registers st0-st7 are not updated in response to executing FP instructions. Other registers are updated alright for instance eip, esp and ebp are updated when executing move esp, ebp.
In order to find out what is going on I checked the problem with this simple 'driver'
Code:
#include <wdm.h>
#include <windef.h>
KFLOATING_SAVE saveData;
NTSTATUS status;
double floatValue;
VOID OnUnload(PDRIVER_OBJECT DriverObject)
{
status = KeSaveFloatingPointState(&saveData);
if (status == STATUS_SUCCESS)
{
floatValue = (double)1;
KeRestoreFloatingPointState(&saveData);
}
}
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
DriverObject->DriverUnload = OnUnload;
return STATUS_SUCCESS;
}
Link to code: http://msdn.microsoft.com/en-us/library/aa489566.aspx
The code depends on libcntpr.lib and ks.lib
The disassembly for the code in the OnUnload routine is
Code:
8cd7530 8bff mov edi,edi
f8cd7532 55 push ebp
f8cd7533 8bec mov ebp,esp
f8cd7535 684077cdf8 push offset hello!saveData (f8cd7740)
f8cd753a ff151076cdf8 call dword ptr [hello!_imp__KeSaveFloatingPointState (f8cd7610)]
f8cd7540 a33077cdf8 mov dword ptr [hello!status (f8cd7730)],eax
f8cd7545 833d3077cdf800 cmp dword ptr [hello!status (f8cd7730)],0
f8cd754c 7513 jne hello!OnUnload+0x31 (f8cd7561)
f8cd754e d9e8 fld1
f8cd7550 dd1d2877cdf8 fstp qword ptr [hello!floatValue (f8cd7728)]
f8cd7556 684077cdf8 push offset hello!saveData (f8cd7740)
f8cd755b ff151476cdf8 call dword ptr [hello!_imp__KeRestoreFloatingPointState (f8cd7614)]
f8cd7561 5d pop ebp
f8cd7562 c20400 ret 4
After stepping over the fld1 instruction nothing happens with st0. So the problem persists in this much simpler setup.
The best explanation I have found about this is in the Windbg help
Quote:
In kernel-mode debugging, there are many processes, threads, and sometimes user sessions that are executing at the same time. Therefore, phrases such as "virtual address 0x80002000" or "the eax register" are ambiguous. You must specify the context in which such phrases can be understood. ........ The register context determines how the debugger interprets registers and also controls the results of a stack trace. This context is also known as the thread context, although that term is not completely accurate. An explicit context is also a type of register context. If you specify an explicit context, that context is used instead of the current register context. |
One problem is how to figure out what is the right thread context but another problem is how this can explain why it is only the FP registers that are not updated. My laptop processor is an Intel Pentium Dual CPU.
Maybe I'm overlooking something very simple, that is probably the most likely thing. For the moment this problem has set me stymied so I'm very interested in any kind of input of what could be the problem.
niaren