Ejemplo n.º 1
0
VOID PhpProcessStartupParameters(
    VOID
)
{
    static PH_COMMAND_LINE_OPTION options[] =
    {
        { PH_ARG_SETTINGS, L"settings", MandatoryArgumentType },
        { PH_ARG_NOSETTINGS, L"nosettings", NoArgumentType },
        { PH_ARG_SHOWVISIBLE, L"v", NoArgumentType },
        { PH_ARG_SHOWHIDDEN, L"hide", NoArgumentType },
        { PH_ARG_COMMANDMODE, L"c", NoArgumentType },
        { PH_ARG_COMMANDTYPE, L"ctype", MandatoryArgumentType },
        { PH_ARG_COMMANDOBJECT, L"cobject", MandatoryArgumentType },
        { PH_ARG_COMMANDACTION, L"caction", MandatoryArgumentType },
        { PH_ARG_COMMANDVALUE, L"cvalue", MandatoryArgumentType },
        { PH_ARG_RUNASSERVICEMODE, L"ras", MandatoryArgumentType },
        { PH_ARG_NOKPH, L"nokph", NoArgumentType },
        { PH_ARG_INSTALLKPH, L"installkph", NoArgumentType },
        { PH_ARG_UNINSTALLKPH, L"uninstallkph", NoArgumentType },
        { PH_ARG_DEBUG, L"debug", NoArgumentType },
        { PH_ARG_HWND, L"hwnd", MandatoryArgumentType },
        { PH_ARG_POINT, L"point", MandatoryArgumentType },
        { PH_ARG_SHOWOPTIONS, L"showoptions", NoArgumentType },
        { PH_ARG_PHSVC, L"phsvc", NoArgumentType },
        { PH_ARG_NOPLUGINS, L"noplugins", NoArgumentType },
        { PH_ARG_NEWINSTANCE, L"newinstance", NoArgumentType },
        { PH_ARG_ELEVATE, L"elevate", NoArgumentType },
        { PH_ARG_SILENT, L"s", NoArgumentType },
        { PH_ARG_HELP, L"help", NoArgumentType },
        { PH_ARG_SELECTPID, L"selectpid", MandatoryArgumentType },
        { PH_ARG_PRIORITY, L"priority", MandatoryArgumentType },
        { PH_ARG_PLUGIN, L"plugin", MandatoryArgumentType },
        { PH_ARG_SELECTTAB, L"selecttab", MandatoryArgumentType }
    };
    PH_STRINGREF commandLine;

    PhUnicodeStringToStringRef(&NtCurrentPeb()->ProcessParameters->CommandLine, &commandLine);

    memset(&PhStartupParameters, 0, sizeof(PH_STARTUP_PARAMETERS));

    if (!PhParseCommandLine(
                &commandLine,
                options,
                sizeof(options) / sizeof(PH_COMMAND_LINE_OPTION),
                PH_COMMAND_LINE_IGNORE_UNKNOWN_OPTIONS | PH_COMMAND_LINE_IGNORE_FIRST_PART,
                PhpCommandLineOptionCallback,
                NULL
            ) || PhStartupParameters.Help)
    {
        PhShowInformation(
            NULL,
            L"Command line options:\n\n"
            L"-c\n"
            L"-ctype command-type\n"
            L"-cobject command-object\n"
            L"-caction command-action\n"
            L"-cvalue command-value\n"
            L"-debug\n"
            L"-elevate\n"
            L"-help\n"
            L"-hide\n"
            L"-installkph\n"
            L"-newinstance\n"
            L"-nokph\n"
            L"-noplugins\n"
            L"-nosettings\n"
            L"-plugin pluginname:value\n"
            L"-priority r|h|n|l\n"
            L"-s\n"
            L"-selectpid pid-to-select\n"
            L"-selecttab name-of-tab-to-select\n"
            L"-settings filename\n"
            L"-uninstallkph\n"
            L"-v\n"
        );

        if (PhStartupParameters.Help)
            RtlExitUserProcess(STATUS_SUCCESS);
    }

    if (PhStartupParameters.InstallKph)
    {
        NTSTATUS status;
        PPH_STRING kprocesshackerFileName;
        KPH_PARAMETERS parameters;

        kprocesshackerFileName = PhConcatStrings2(PhApplicationDirectory->Buffer, L"\\kprocesshacker.sys");

        parameters.SecurityLevel = KphSecurityNone;
        parameters.CreateDynamicConfiguration = TRUE;

        status = KphInstallEx(L"KProcessHacker2", kprocesshackerFileName->Buffer, &parameters);

        if (!NT_SUCCESS(status) && !PhStartupParameters.Silent)
            PhShowStatus(NULL, L"Unable to install KProcessHacker", status, 0);

        RtlExitUserProcess(status);
    }

    if (PhStartupParameters.UninstallKph)
    {
        NTSTATUS status;

        status = KphUninstall(L"KProcessHacker2");

        if (!NT_SUCCESS(status) && !PhStartupParameters.Silent)
            PhShowStatus(NULL, L"Unable to uninstall KProcessHacker", status, 0);

        RtlExitUserProcess(status);
    }

    if (PhStartupParameters.Elevate && !PhElevated)
    {
        PhShellProcessHacker(
            NULL,
            NULL,
            SW_SHOW,
            PH_SHELL_EXECUTE_ADMIN,
            PH_SHELL_APP_PROPAGATE_PARAMETERS | PH_SHELL_APP_PROPAGATE_PARAMETERS_FORCE_SETTINGS,
            0,
            NULL
        );
        RtlExitUserProcess(STATUS_SUCCESS);
    }

    if (PhStartupParameters.Debug)
    {
        // The symbol provider won't work if this is chosen.
        PhShowDebugConsole();
    }
}
Ejemplo n.º 2
0
BOOLEAN SetupResetCurrentInstall(
    _In_ PVOID Arguments
    )
{
    STATUS_MSG(L"Setting up for first time use...");

    ProcessHackerShutdown();

    ULONG err = ERROR_SERVICE_DOES_NOT_EXIST;

    do
    {
        Sleep(1000);

        err = KphUninstall();

    } while (err != ERROR_SERVICE_DOES_NOT_EXIST);

    RemoveAppCompatEntries();

    //PPH_STRING clientPath = GetProcessHackerInstallPath();
    //PPH_STRING startmenu = GetKnownLocation(CSIDL_COMMON_PROGRAMS, TEXT("\\ProcessHacker2"));
    //PPH_STRING desktopShortcutString = GetKnownLocation(CSIDL_DESKTOPDIRECTORY, TEXT("\\Process Hacker 2.lnk"));
    //PPH_STRING startmenuShortcutString = GetKnownLocation(CSIDL_COMMON_PROGRAMS, TEXT("\\Process Hacker 2.lnk"));
    //PPH_STRING startmenuStartupShortcutString = GetKnownLocation(CSIDL_COMMON_PROGRAMS, TEXT("\\Startup\\Process Hacker 2.lnk"));


    STATUS_MSG(L"Cleaning up...\n");
    Sleep(1000);

    //PPH_STRING clientPathString = StringFormat(TEXT("%s\\ProcessHacker.exe"), SetupInstallPath->Buffer);
    //PPH_STRING uninstallPath = StringFormat(TEXT("%s\\ProcessHacker-Setup.exe"), SetupInstallPath->Buffer);
    //PPH_STRING clientPathArgsString = StringFormat(TEXT("\"%s\\ProcessHacker.exe\""), SetupInstallPath->Buffer);
    //PPH_STRING clientPathExeString = StringFormat(TEXT("\"%s\" \"%%1\""), clientPathString->Buffer);

    // Create the Uninstall key...

    //HKEY keyHandle = RegistryCreateKey(
    //    HKEY_LOCAL_MACHINE,
    //    TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ProcessHacker2"),
    //    KEY_ALL_ACCESS | KEY_WOW64_32KEY
    //    );
    //
    //if (keyHandle)
    //{
    //    RegistrySetString(keyHandle, TEXT("DisplayName"), TEXT("Process Hacker"));
    //    RegistrySetString(keyHandle, TEXT("InstallLocation"), SetupInstallPath->Buffer);
    //    RegistrySetString(keyHandle, TEXT("UninstallString"), uninstallPath->Buffer);
    //    RegistrySetString(keyHandle, TEXT("DisplayIcon"), uninstallPath->Buffer);
    //    RegistrySetString(keyHandle, TEXT("Publisher"), TEXT("Electronic Arts, Inc."));
    //    RegistrySetString(keyHandle, TEXT("URLInfoAbout"), TEXT("http://wj32.org/ProcessHacker"));
    //    RegistrySetString(keyHandle, TEXT("HelpLink"), TEXT("http://wj32.org/ProcessHacker"));
    //    RegistrySetDword(keyHandle, TEXT("NoModify"), 1);
    //    RegistrySetDword(keyHandle, TEXT("NoRepair"), 1);
    //    RegCloseKey(keyHandle);
    //}

    //if (IsCreateDesktopSelected)
    //{
    //    PPH_STRING desktopFolderString = GetKnownLocation(
    //        CSIDL_DESKTOPDIRECTORY,
    //        TEXT("\\ProcessHacker.lnk")
    //        );

    //    //if (!CreateLink(
    //    //    desktopFolderString->Buffer, clientPathString->Buffer, SetupInstallPath->Buffer,
    //    //    TEXT("")
    //    //    ))
    //    //{
    //    //    DEBUG_MSG(TEXT("ERROR CreateDesktopLink: %u\n"), GetLastError());
    //    //}

    //    PhFree(desktopFolderString);
    //}

    //if (IsCreateStartSelected)
    //{
    //    PPH_STRING startmenuFolderString = GetKnownLocation(
    //        CSIDL_COMMON_PROGRAMS,
    //        TEXT("\\ProcessHacker.lnk")
    //        );

    //    //if (!CreateLink(
    //    //    startmenuFolderString->Buffer, clientPathString->Buffer, SetupInstallPath->Buffer,
    //    //    TEXT("")
    //    //    ))
    //    //{
    //    //    DEBUG_MSG(TEXT("ERROR CreateStartLink: %u\n"), GetLastError());
    //    //}

    //    PhFree(startmenuFolderString);
    //}

    //if (IsCreateRunStartupSelected)
    //{
    //    PPH_STRING startmenuStartupString = GetKnownLocation(
    //        CSIDL_COMMON_STARTUP,
    //        TEXT("\\ProcessHacker.lnk")
    //        );

    //    //if (!CreateLink(
    //    //    startmenuStartupString->Buffer, clientPathString->Buffer, SetupInstallPath->Buffer,
    //    //    TEXT("")
    //    //    ))
    //    //{
    //    //    DEBUG_MSG(TEXT("ERROR CreateLinkStartup: %u\n"), GetLastError());
    //    //}

    //    PhFree(startmenuStartupString);
    //}

    // GetCachedImageIndex Test
    //{
    //    SHFOLDERCUSTOMSETTINGS fcs = { sizeof(SHFOLDERCUSTOMSETTINGS) };
    //    fcs.dwMask = FCSM_ICONFILE;
    //    fcs.pszIconFile = TEXT("ProcessHacker.exe");
    //    fcs.cchIconFile = _tcslen(TEXT("ProcessHacker.exe")) * sizeof(TCHAR);
    //    fcs.iIconIndex = 0;

    //    if (SUCCEEDED(SHGetSetFolderCustomSettings(&fcs, SetupInstallPath->Buffer, FCS_FORCEWRITE)))
    //    {
    //        SHFILEINFO shellFolderInfo = { 0 };

    //        if (SHGetFileInfo(SetupInstallPath->Buffer, 0, &shellFolderInfo, sizeof(SHFILEINFO), SHGFI_ICONLOCATION))
    //        {
    //            PPH_STRING fileName = FileGetBaseName(shellFolderInfo.szDisplayName);


    //            INT shellIconIndex = Shell_GetCachedImageIndex(
    //                fileName->Buffer,
    //                shellFolderInfo.iIcon,
    //                0
    //                );

    //            SHUpdateImage(
    //                fileName->Buffer,
    //                shellFolderInfo.iIcon,
    //                0,
    //                shellIconIndex
    //                );

    //            SHChangeNotify(SHCNE_UPDATEIMAGE, SHCNF_DWORD, NULL, (PVOID)shellIconIndex);

    //            PhFree(fileName);
    //        }
    //    }
    //}

    //_tspawnl(_P_DETACH, clientPathString->Buffer, clientPathArgsString->Buffer, NULL);

    //if (clientPathExeString)
    //    PhFree(clientPathExeString);

    //if (clientPathArgsString)
    //    PhFree(clientPathArgsString);

    //if (uninstallPath)
    //    PhFree(uninstallPath);

    //if (clientPathString)
    //    PhFree(clientPathString);


    return TRUE;
}