深层解析最核心的dll:NTDLL.dll

2010-03-08 23:39:56 作者:bugw.net 来源:网虫之家 浏览次数:0 网友评论 0

  打开NTDLL.dll,惊奇的发现原来CRT的许多基本函数居然都是在这里实现的!甚至包括qsort,ceil这样的函数,还有臭名昭著的 strcpy(严格来讲,这只能怪使用者不当心)。堆的释放,进城管理,似乎都是在这。于是,我决定,仔细察看以下它,这1410个函数是做什么的.

  用户模式的代码在调用系统内核函数的时候,首先把一个叫做system call number的数放在EAX中,把参数放在其它的寄存器中了。然后调用INT 2E中断。但是大部分应用程序并不需要直接这么做。通常都是在调用kernel32.dll等时由他们来调用INT 2E.

  内核模式的代码,做法稍微有点不同。他们通常调用由NTOSKRNL.EXE导出的NTDLL.dll中Zw开头的那一系列函数,比如 ZwWaitForSingleObject, 反之,如果是用户级代码需要调用内核,就会利用INT 2E调用WaitForSingleObject.对于许多函数的批量调用,你会明显发现 Zw族要比Rtl族效率高很多。

  可惜ntdll.dll中的大部分函数都是undocumented.
  对于一部分得知其定义形式的函数,可以这样调用:
  1.先将NTDLL.DLL读入 LoadLibrary(TEXT(\"NTDLL.dll\"))
  2.利用GetProcAddress 获取其函数入口地址
  3.利用得到的函数指针调用
  但是可以大致的分为几类吧
  1 PropertyLengthAsVariant 它被排在了第一号,但是我就是不明白它是做什么的
  2 Csr(configuration status register? Command and Status Register?)系列
  CsrAllocateCaptureBuffer CsrAllocateMessagePointer CsrCaptureMessageBuffer CsrCaptureMessageMultiUnicodeStringsInPlace CsrCaptureMessageString CsrCaptureTimeout CsrClientCallServer CsrClientConnectToServer CsrFreeCaptureBuffer CsrGetProcessId CsrIdentifyAlertableThread CsrNewThread CsrProbeForRead CsrProbeForWrite CsrSetPriorityClass
  3 Dbg系列 调试函数
  DbgBreakPoint DbgPrint DbgPrintEx DbgPrintReturnControlC DbgPrompt DbgQueryDebugFilterState DbgSetDebugFilterState DbgUiConnectToDbg DbgUiContinue DbgUiConvertStateChangeStructure DbgUiDebugActiveProcess DbgUiGetThreadDebugObject DbgUiIssueRemoteBreakin DbgUiRemoteBreakin DbgUiSetThreadDebugObject DbgUiStopDebugging DbgUiWaitStateChange DbgUserBreakPoint
  4 ki系列
  KiRaiseUserExceptionDispatcher
  KiUserApcDispatcher
  KiUserCallbackDispatcher
  KiUserExceptionDispatcher
  5 Ldr系列 Loader APIs,共34个
  API
  NTDLL APIs
  LoadResource
  LdrAccessResource
  Ldr*****nateResourcesEnabled
  DisableThreadLibraryCalls
  LdrDisableThreadCalloutsForDll
  LdrEnumResources
  LdrFindAppCompatVariableInfo
  LdrFindEntryForAddress
  EnumResourceTypesW
  LdrFindResourceDirectory_U
  FindResourceExA
  LdrFindResource_U
  LdrFlush*****nateResourceModules
  LdrGet*****nateResourceModuleHandle
  GetModuleHandleForUnicodeString
  LdrGetDllHandle
  GetProcAddress
  LdrGetProcedureAddress
  LdrInitializeThunk
  LoadLibraryEx (LOAD_LIBRARY_AS_DATAFILE)
  LdrLoad*****nateResourceModule
  LoadLibrary
  LdrLoadDll
  LdrProcessRelocationBlock
  LdrQueryApplicationCompatibilityGoo
  LdrQueryImageFileExecutionOptions
  LdrQueryProcessModuleInformation
  LdrRelocateImage
  ExitProcess
  LdrShutdownProcess
  ExitThread
  LdrShutdownThread
  LdrUnload*****nateResourceModule
  FreeLibrary
  LdrUnloadDll
  LdrVerifyImageMatchesChecksum
  LdrVerifyMappedImageMatchesChecksum
  6 Nls(National Language Support)系列 代码页管理
  NlsAnsiCodePage
  NlsMbCodePageTag
  NlsMbOemCodePageTag
  7 Nt系列 共285个,大部分都是kernel32.dll,user32.dll等的核心实现
  NtCreateFile, NtOpenFile, NtClose, NtWaitForSingleObject 是kernel32.dll中许多用户级代码的核心实现。
  NTSTATUS NtClose( HANDLE Handle);
  竟然是CloseHandle 的原身!唯一的缺点是该函数并没有导出库,如果要调用,就必须使用GetProcAddress 来获得其函数指针然后调用。
  NtCreateFile 可以说是DDK的核心
  RtlUnwind initiates an unwind of procedure call frames
  结构化异常(Structured Exception Handling, SEH )的 核心。
  NTSTATUS NtWaitForSingleObject( HANDLE Handle, BOOLEAN Alertable, PLARGE_INTEGER Timeout);
  Waits until the specified object attains a state of signaled
  我想,信号同步等,应该与之有莫大的联系吧
  8 pfx 不明白
  PfxFindPrefix
  PfxInitialize
  PfxInsertPrefix
  PfxRemovePrefix
  9 RestoreEm87Context SaveEm87Context
  10 rtl系列 共506个。我想,rtl应该是runtime library的缩写吧。一个很庞大的函数族,里面包含像 RtlCreateUserProcess 这样的一些很基本的函数,通常供内核模式的driver等调用
  下面是一部分示例
  APIs Forwarded to NTDLL
  API
  Destination
  DeleteCriticalSection
  Forwarded to NTDLL.RtlDeleteCriticalSection
  EnterCriticalSection
  Forwarded to NTDLL.RtlEnterCriticalSection
  HeapAlloc
  Forwarded to NTDLL.RtlAllocateHeap
  HeapFree
  Forwarded to NTDLL.RtlFreeHeap
  HeapReAlloc
  Forwarded to NTDLL.RtlReAllocateHeap
  HeapSize
  Forwarded to NTDLL.RtlSizeHeap
  LeaveCriticalSection
  Forwarded to NTDLL.RtlLeaveCriticalSection
  RtlFillMemory
  Forwarded to NTDLL.RtlFillMemory
  RtlMoveMemory
  Forwarded to NTDLL.RtlMoveMemory
  RtlUnwind
  Forwarded to NTDLL.RtlUnwind
  RtlZeroMemory
  Forwarded to NTDLL.RtlZeroMemory
  SetCriticalSectionSpinCount
  Forwarded to NTDLL.RtlSetCriticalSection- SpinCount
  TryEnterCriticalSection
  Forwarded to NTDLL.RtlTryEnterCriticalSection
  VerSetConditionMask
  Forwarded to NTDLL.VerSetConditionMask
 

关键词:解析核心NTDLL

[错误报告] [推荐] [收藏] [打印] [关闭] [返回顶部]

  • 验证码:

最新图片文章

最新文章