Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine called kernel32.dll function from fault offset

Tags:

c

windows

I have an app running as a Windows Service. Today, I was notified that the service died. I found a event viewer entry whose basic info is: faulting module kernel32.dll, version 6.0.6002.18740, time stamp 0x50b58c3d, exception code 0xc0000005, fault offset 0x0003fc2e

I'm sure that there is a bug in my code. Can I determine the kernel32.dll function (where the exception came from) from the offset? I'm planning to backtrack to the call in my code.

like image 583
user1720902 Avatar asked Jul 23 '13 15:07

user1720902


1 Answers

I agree with what is said in the comments, but anyway I think the answer can be useful. Here is how you can find function name using Windows debugging tools from SDK provided that EventViewer reported offset of failing instruction in kernel32.dll.

First, install Windows debugging tools and configure path to Microsoft public symbol server. Instructions are available online, for example, this video: http://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-Building-your-USB-thumbdrive

Start windows debugger attached to your process or just any process in the system. kernel32.dll is one of the first DLLs any process loads, it is very unlikely that it is rebased. So kernel32.dll’s base address is the same in all processes.

Get base address of kernel32.dll by running “list modules” command in debugger

0:006> lm m kernel32
start    end        module name
7c800000 7c8f6000   kernel32   (pdb symbols)          c:\debuggers\symbols\kernel32.pdb\A22E3A9843CC45B4A2BFA31377127D422\kernel32.pdb

So the base address is 7c800000. Now run “disassemble single instruction” command using DLL base address and offset:

0:006> u 0x7c800000+0x0003fc2e l 1
kernel32!BasepCopyFileExW+0x859:
7c83fc2e 53              push    ebx

So BasepCopyFileExW is the function name. (The result on your system may be different.)

like image 116
glagolig Avatar answered Oct 18 '22 05:10

glagolig