免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

驱动读写进程

驱动层:
  1. #include "ntddk.h"


  2. #define PAGEDCODE code_seg("PAGE")
  3. #define LOCKEDCODE code_seg()
  4. #define INITCODE code_seg("INIT")

  5. #define PAGEDDATA data_seg("PAGE")
  6. #define LOCKEDDATA data_seg()
  7. #define INITDATA data_seg("INIT")

  8. NTSTATUS
  9. ZwAllocateVirtualMemory(
  10.                                                 IN HANDLE  ProcessHandle,
  11.                                                 IN OUT PVOID  *BaseAddress,
  12.                                                 IN ULONG  ZeroBits,
  13.                                                 IN OUT PSIZE_T  RegionSize,
  14.                                                 IN ULONG  AllocationType,
  15.                                                 IN ULONG  Protect
  16.                                                 );


  17. #pragma PAGEDCODE
  18. NTSTATUS ReadWriteProcess()
  19. {
  20.         NTSTATUS Status;
  21.         HANDLE hProcess;
  22.         OBJECT_ATTRIBUTES objAttr;
  23.         CLIENT_ID ClientId;

  24.         PVOID AllocateAddress = NULL;
  25.         size_t RegionSize;

  26.         memset(&objAttr, 0, sizeof(OBJECT_ATTRIBUTES));
  27.         InitializeObjectAttributes(&objAttr, NULL, OBJ_KERNEL_HANDLE,
  28.                 NULL, NULL);

  29.         ClientId.UniqueProcess = (HANDLE)964;
  30.         ClientId.UniqueThread = 0;


  31.         Status = ZwOpenProcess(&hProcess, PROCESS_ALL_ACCESS, &objAttr, &ClientId);

  32.         if (!NT_SUCCESS(Status))
  33.         {
  34.                 KdPrint(("error code: %X", Status));
  35.                 return Status;
  36.         }
  37.        
  38.         KdPrint(("open process success!"));

  39.         RegionSize = 0xff;

  40.         Status = ZwAllocateVirtualMemory(hProcess, &AllocateAddress, 0,
  41.                 &RegionSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  42.         if (!NT_SUCCESS(Status))
  43.         {
  44.                 KdPrint(("error code: %X", Status));
  45.                 return Status;
  46.         }

  47.         KdPrint(("address:%X, size:%d\n", AllocateAddress, RegionSize));

  48.         ZwClose(hProcess);
  49.         return Status;
  50. }




  51. #pragma PAGEDCODE
  52. VOID MyDriverUnload(IN PDRIVER_OBJECT pDriverObject)
  53. {

  54.         KdPrint(("DriverEntry unLoading...\n"));

  55. }



  56. #pragma INITCODE
  57. NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING RegistryPath)
  58. {
  59.         NTSTATUS status = STATUS_SUCCESS;

  60.         ReadWriteProcess();

  61.         pDriverObject->DriverUnload = MyDriverUnload;
  62.         return status;
  63. }
复制代码
应用层:
  1. void CReadwriteprocess_testDlg::OnButton1()
  2. {
  3.         // TODO: Add your control notification handler code here
  4.         ULONG uBaseAddr;
  5.         uBaseAddr =        GetDlgItemInt(IDC_EDIT1);
  6.         SetDlgItemText(IDC_EDIT2, (LPCTSTR)uBaseAddr);
  7. }

  8. void CReadwriteprocess_testDlg::OnButton2()
  9. {
  10.         // TODO: Add your control notification handler code here

  11.         ULONG uBaseAddr;
  12.         char str[10] = "abcedfff";
  13.         uBaseAddr =        GetDlgItemInt(IDC_EDIT1);

  14.         memcpy((PVOID)uBaseAddr, str, 10);
  15. }
复制代码

返回列表