📄 injdll.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
//
// Module: injdll.exe - Test CreateProcessWithDll function.
// File: injdll.cpp
// Author: Galen C. Hunt
// Copyright 1998-1999, Microsoft Corporation
//
// http://www.research.microsoft.com/sn/detours
//
#include <stdio.h>
#include <windows.h>
#include <detours.h>
#define arrayof(x) (sizeof(x)/sizeof(x[0]))
//////////////////////////////////////////////////////////////////////////////
//
void PrintUsage(void)
{
printf("Usage:\n"
" injdll [options] [command line]\n"
"Options:\n"
" /p:number : Attach to process number.\n"
" /d:file.dll : Inject file.dll.\n"
" /? : This help screen.\n");
}
//////////////////////////////////////////////////////////////////////// main.
//
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR lpszCmdLine, int nCmdShow)
{
INT argc;
WCHAR **argv;
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
BOOLEAN fNeedHelp = FALSE;
BOOLEAN fVerbose = FALSE;
INT nProcessId = -1;
WCHAR wzDllPath[MAX_PATH] = L"";
for (int arg = 1;
arg < argc && (argv[arg][0] == '-' || argv[arg][0] == '/');
arg++) {
WCHAR *argp = argv[arg] + 2;
if (*argp = ':')
argp++;
switch (argv[arg][1]) {
case 'd': // Set DLL Name
case 'D':
wcscpy(wzDllPath, argp);
break;
case 'p': // Set Process #
case 'P':
nProcessId = _wtoi(argp);
break;
case 'h': // Help
case 'H':
case '?':
fNeedHelp = TRUE;
break;
default:
fNeedHelp = TRUE;
printf("Bad argument: %ls\n", argv[arg]);
break;
}
}
if (wzDllPath[0] == 0) {
fNeedHelp = TRUE;
}
if (nProcessId < 0) {
fNeedHelp = TRUE;
}
if (argc == 1) {
fNeedHelp = TRUE;
}
if (fNeedHelp) {
PrintUsage();
return 1;
}
//////////////////////////////////////////////////////////////////////////
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, nProcessId);
if (hProcess == NULL) {
printf("OpenProcess(%d) failed: %d\n", nProcessId, GetLastError());
return 2;
}
if (!ContinueProcessWithDllW(hProcess, wzDllPath)) {
printf("ContinueProcessWithDll(%ls) failed: %d", wzDllPath, GetLastError());
return 3;
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -