【问题标题】:MFC C++ application: how to clear command line arguments in Task Manager?MFC C++ 应用程序:如何在任务管理器中清除命令行参数?
【发布时间】:2020-08-03 07:44:24
【问题描述】:

我有一个使用命令行参数的 MFC C++ 应用程序。 但是当程序运行时,在命令行输入的敏感信息会显示在任务管理器的命令行栏中。 1.那么如何删除它们? 2.MFC C++中如何修改命令行参数?

非常感谢。

【问题讨论】:

  • 我的应用是 x32

标签: c++ command-line taskmanager


【解决方案1】:

我在 x32 InitInstance 中使用了以下函数,但它不起作用。 Param.CommandLine.Buffer 已更改为空,因为任务管理器仍显示命令行。 有错吗?

#include <Windows.h>
#include <Winternl.h>
#include <stdio.h>
#include <tchar.h>

typedef NTSTATUS (NTAPI *PFN_NT_QUERY_INFORMATION_PROCESS) (
    IN HANDLE ProcessHandle,
    IN PROCESSINFOCLASS ProcessInformationClass,
    OUT PVOID ProcessInformation,
    IN ULONG ProcessInformationLength,
    OUT PULONG ReturnLength OPTIONAL);

void ClearCommandLine()
{
    HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS,
                            FALSE, GetCurrentProcessId());
    PROCESS_BASIC_INFORMATION pbi = {0};
    RTL_USER_PROCESS_PARAMETERS Param = {0};
    PFN_NT_QUERY_INFORMATION_PROCESS pfnNtQueryInformationProcess =
        (PFN_NT_QUERY_INFORMATION_PROCESS) GetProcAddress (
            GetModuleHandle(TEXT("ntdll.dll")), "NtQueryInformationProcess");
    NTSTATUS status = pfnNtQueryInformationProcess (
        hProcess, ProcessBasicInformation,
        (PVOID)&pbi, sizeof(pbi), NULL);
    
    wchar_t* lpwszCmd=L"";
    USHORT usCmdLen = 2 + 2 * (wcslen(lpwszCmd));
    ReadProcessMemory(hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL);
    ReadProcessMemory(hProcess, peb.ProcessParameters, &Param, sizeof(Param), NULL);
    WriteProcessMemory(hProcess, Param.CommandLine.Buffer, lpwszCmd, usCmdLen,NULL);
    WriteProcessMemory(hProcess,&Param.CommandLine.Length, &usCmdLen, sizeof(usCmdLen), NULL);

    CloseHandle(hProcess);
}

【讨论】:

    猜你喜欢
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 2013-06-17
    相关资源
    最近更新 更多