打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用NtSuspendProcess 来暂停程序运行|游戏驱动与保护


  1. *++
  2. Module Name:
  3. NtSuspendProcess.cpp
  4. Abstract:
  5. This utility [Suspend|Resume] processes.
  6. Author:
  7. Michael Wookey 6-Jun-2003 ([email]ntutils@wookey.org[/email])
  8. Notes:
  9. NtSuspendProcess.exe [Suspend|Resume] pid
  10. Compiler:
  11. VC7
  12. Build:
  13. cl NtSuspendProcess.cpp
  14. // Add Unicode Suppert, [2/23/2010 dnybz([email]cnfreebsd@163.com[/email])]
  15. --*/
  16. #define STRICT
  17. #define WIN32_LEAN_AND_MEAN
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <tchar.h>
  22. //
  23. // The native functions exported from ntdll.
  24. //
  25. typedef LONG ( NTAPI *_NtSuspendProcess )( IN HANDLE ProcessHandle );
  26. typedef LONG ( NTAPI *_NtResumeProcess )( IN HANDLE ProcessHandle );
  27. bool EnableDebugPrivilege()  
  28. {  
  29. HANDLE hToken;  
  30. LUID sedebugnameValue;  
  31. TOKEN_PRIVILEGES tkp;  
  32. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  33. {  
  34.    return   FALSE;  
  35. }  
  36. if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue))
  37. {  
  38.    CloseHandle(hToken);  
  39.    return false;  
  40. }  
  41. tkp.PrivilegeCount = 1;  
  42. tkp.Privileges[0].Luid = sedebugnameValue;  
  43. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;  
  44. if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL))
  45. {  
  46.    CloseHandle(hToken);  
  47.    return false;  
  48. }  
  49. return true;  
  50. }
  51. int _tmain( int argc, _TCHAR* argv[] )
  52. {
  53. HANDLE ProcessHandle = 0;
  54. _NtSuspendProcess NtSuspendProcess = 0;
  55. _NtResumeProcess NtResumeProcess = 0;
  56. //
  57. // Make sure we have enough arguments.
  58. //
  59. if( 3 > argc )
  60. {
  61.    printf( "usage [Suspend|Resume] pid\n" );
  62.    return 0;
  63. }
  64. //
  65. // Obtain our function imports.
  66. //
  67. NtSuspendProcess = (_NtSuspendProcess)
  68.    GetProcAddress( GetModuleHandle( _T("ntdll") ), "NtSuspendProcess" );
  69. NtResumeProcess = (_NtResumeProcess)
  70.    GetProcAddress( GetModuleHandle( _T("ntdll") ), "NtResumeProcess" );
  71. //
  72. // Attempt to open the target process.
  73. //
  74. EnableDebugPrivilege();
  75. ProcessHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, _tstoi( argv[2] ));
  76. //
  77. // Suspend or Resume the process. Note that these alter the process'
  78. // suspend count, so freezing the process twice will require thawing
  79. // the process twice to restore.
  80. //
  81. if( ! ProcessHandle )
  82. {
  83.    printf( "Unable to open process id %d\n", _tstoi( argv[2] ));
  84. }
  85. else
  86. {
  87.    if( ! lstrcmpi( argv[1], _T("Suspend") ))
  88.    {
  89.     if( NtSuspendProcess )
  90.     {
  91.      NtSuspendProcess( ProcessHandle );
  92.     }
  93.    }
  94.    else if( ! lstrcmpi( argv[1], _T("Resume") ))
  95.    {
  96.     if( NtResumeProcess )
  97.     {
  98.      NtResumeProcess( ProcessHandle );
  99.     }
  100.    }
  101.    else
  102.    {
  103.     printf( "usage [Suspend|Resume] pid\n" );
  104.    }
  105. }
  106. //
  107. // Close our process handle.
  108. //
  109. if( ProcessHandle )
  110. {
  111.    CloseHandle( ProcessHandle );
  112. }
  113. return 0;
  114. }
  115. /* EOF */


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
delphi 取得任意程序的命令行
delphi 关闭计算机
三个给进程提权的方法 (c/cpp)
DLL注入方法小结
WINDOWS系统下木马程序的设计与实现
Window关机函数ExitWindowsEx详解 - dwdm - 博客园
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服