电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1072 人浏览分享

ntkrnlpa.exe的基址[源码分享]

[复制链接]
1072 0
XueTr当中用的方法。。没有完全还原。。根据它的思路写了下


  1. #include <ntifs.h>
  2. typedef BOOLEAN BOOL;
  3. typedef unsigned long DWORD;
  4. typedef DWORD * LPDWORD;
  5. typedef DWORD * PDWORD;
  6. typedef unsigned long ULONG;
  7. typedef unsigned short WORD;
  8. typedef unsigned char BYTE;
  9. typedef unsigned int UINT;

  10. typedef struct _LDR_DATA_TABLE_ENTRY {
  11. LIST_ENTRY InLoadOrderLinks;
  12. LIST_ENTRY InMemoryOrderLinks;
  13. LIST_ENTRY InInitializationOrderLinks;
  14. PVOID DllBase;
  15. PVOID EntryPoint;
  16. ULONG SizeOfImage;
  17. UNICODE_STRING FullDllName;
  18. UNICODE_STRING BaseDllName;
  19. ULONG Flags;
  20. USHORT LoadCount;
  21. USHORT TlsIndex;
  22. union {
  23.    LIST_ENTRY HashLinks;
  24.    struct {
  25.     PVOID SectionPointer;
  26.     ULONG CheckSum;
  27.    };
  28. };
  29. union {
  30.    struct {
  31.     ULONG TimeDateStamp;
  32.    };
  33.    struct {
  34.     PVOID LoadedImports;
  35.    };
  36. };
  37. PVOID EntryPointActivationContext;
  38. PVOID PatchInformation;
  39. } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;

  40. BOOL GetSystemKernelModuleInfo(PDRIVER_OBJECT DriverObject,DWORD DriverEntryRetAddress,WCHAR **SystemKernelModulePath,PDWORD SystemKernelModuleBase)
  41. {
  42. PLDR_DATA_TABLE_ENTRY DriverSection,LdrEntry;
  43. int FullDllNameLength;
  44. int Index;
  45. WCHAR *FullDllNameBuffer;
  46. int Len=0;
  47. DriverSection=DriverObject->DriverSection;
  48. LdrEntry=(PLDR_DATA_TABLE_ENTRY)DriverSection->InLoadOrderLinks.Flink;
  49. while (LdrEntry&&DriverSection!=LdrEntry)
  50. {
  51.    
  52.    if ((DWORD)LdrEntry->DllBase>=*(DWORD*)MmSystemRangeStart&&
  53.     DriverEntryRetAddress>=(DWORD)LdrEntry->DllBase&&
  54.     DriverEntryRetAddress<((DWORD)LdrEntry->DllBase+LdrEntry->SizeOfImage)&&
  55.     (DWORD)LdrEntry->DllBase<0x90000000&&
  56.     LdrEntry->FullDllName.Length>4&&
  57.     LdrEntry->FullDllName.Buffer!=NULL)
  58.    {

  59.     if (MmIsAddressValid(&(LdrEntry->FullDllName.Buffer[LdrEntry->FullDllName.Length/2-1])))
  60.      {
  61.           break;

  62.      }

  63.     }
  64.    LdrEntry=(PLDR_DATA_TABLE_ENTRY)LdrEntry->InLoadOrderLinks.Flink;
  65. }
  66. if (LdrEntry==NULL||LdrEntry==DriverSection)
  67. {
  68.    *SystemKernelModulePath=NULL;
  69.    *SystemKernelModuleBase=0;
  70.    return FALSE;
  71. }
  72. FullDllNameBuffer=LdrEntry->FullDllName.Buffer;
  73. FullDllNameLength=LdrEntry->FullDllName.Length/2;
  74. *SystemKernelModulePath=ExAllocatePool(NonPagedPool,260*2);
  75. if (*SystemKernelModulePath==NULL)
  76. {
  77.    *SystemKernelModuleBase=0;
  78.    return FALSE;
  79. }
  80. RtlZeroMemory(*SystemKernelModulePath,260*2);
  81. wcscpy(*SystemKernelModulePath,L"\\SystemRoot\\system32\");
  82. Len=wcslen(*SystemKernelModulePath);
  83. for (Index=FullDllNameLength-1;Index>0;Index--)
  84. {
  85.    if (FullDllNameBuffer[Index]==0x005C)
  86.    {
  87.     RtlCopyMemory(&(*SystemKernelModulePath)[Len],&FullDllNameBuffer[Index+1],(FullDllNameLength-Index-1)*2);
  88.     *SystemKernelModuleBase=(DWORD)LdrEntry->DllBase;
  89.     return TRUE;
  90.    }
  91. }
  92. RtlCopyMemory(&(*SystemKernelModulePath)[Len],FullDllNameBuffer,FullDllNameLength);
  93. *SystemKernelModuleBase=(DWORD)LdrEntry->DllBase;
  94. return TRUE;
  95. }

  96. VOID DriverUnload(
  97.       IN PDRIVER_OBJECT   DriverObject
  98.       )
  99. {
  100. KdPrint(("Driver Unload Called\n"));
  101. }

  102. NTSTATUS DriverEntry(
  103.       IN OUT PDRIVER_OBJECT   DriverObject,
  104.       IN PUNICODE_STRING      RegistryPath
  105.       )
  106. {
  107. DWORD ModuelBase;
  108. WCHAR *ModuleBaseFullName;
  109. DWORD RetAddress;
  110. DriverObject->DriverUnload = DriverUnload;
  111. RetAddress=*(DWORD*)((DWORD)&DriverObject-4);
  112. if(!GetSystemKernelModuleInfo(DriverObject,RetAddress,&ModuleBaseFullName,&ModuelBase))
  113. {
  114.    return STATUS_SUCCESS;
  115. }
  116. KdPrint(("%S,%X\n",ModuleBaseFullName,ModuelBase));
  117. return STATUS_SUCCESS;
  118. }
复制代码

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

23

粉丝

2901

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.