Skip to content

Commit

Permalink
injector
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Jun 6, 2013
1 parent bb3c6a2 commit 28a569a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
28 changes: 17 additions & 11 deletions DynamicPatcherInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool TryInject(const char *process_name, const char *dllname)
::GetModuleBaseNameA(hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR));
if( strstr(szProcessName, process_name)!=NULL) {
if(InjectDLL(hProcess, dll_fullpath)) {
printf("injection completed %s -> %s\n", process_name, dllname);
printf("injection complete: %s -> %s\n", dllname, process_name);
fflush(stdout);
return true;
}
Expand All @@ -80,24 +80,30 @@ bool TryInject(const char *process_name, const char *dllname)
}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prev, LPWSTR cmd, int show)
int main(int argc, char *argv[])
{
if(argc<2) { printf("usage: DynamicPatcherInjector target_process_name.exe config_file_path.dpconf(optional)\n"); }

bool ok = true;
if(__argc>=2) { ok=g_option.load(__wargv[1]) ;}
else { ok=g_option.load(); }
if(!ok) { return 1; }
if(argc>=3) { ok=g_option.load(argv[2]) ;}
else { ok=g_option.load(); }
if(!ok) {
printf("config file could not read.\n");
return 1;
}

const char *target_process = argv[1];
char exe_path[MAX_PATH];
std::string exe_dir;
if(TryInject(g_option.target_process.c_str(), (exe_dir+PatcherDLL).c_str())) {
dpGetMainModulePath(exe_path, _countof(exe_path));
dpSeparateDirFile(exe_path, &exe_dir, nullptr);

if(TryInject(target_process, (exe_dir+PatcherDLL).c_str())) {
std::string conf_path;
dpSeparateFileExt(g_option.target_process.c_str(), &conf_path, nullptr);
dpSeparateFileExt(target_process, &conf_path, nullptr);
conf_path += "dpconf";
g_option.copy(conf_path.c_str());

dpGetMainModulePath(exe_path, _countof(exe_path));
dpSeparateDirFile(exe_path, &exe_dir, nullptr);
TryInject(g_option.target_process.c_str(), (exe_dir+InjectorDLL).c_str());
TryInject(target_process, (exe_dir+InjectorDLL).c_str());
}
return 0;
}
8 changes: 4 additions & 4 deletions DynamicPatcherInjector.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
Expand All @@ -131,7 +131,7 @@
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
Expand All @@ -150,7 +150,7 @@
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
<PostBuildEvent>
Expand All @@ -168,7 +168,7 @@
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
<PostBuildEvent>
Expand Down
1 change: 1 addition & 0 deletions Test/Test_Inject/Test_Inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstdio>

#define dpNoLib
#include "DynamicPatcher.h"

#ifdef _M_X64
Expand Down
1 change: 0 additions & 1 deletion dpConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ bool dpConfigFile::load(const char *path)
int iv;
while(fgets(line, _countof(line), f)) {
if(line[0]=='/') { continue; }
if (sscanf(line, "target_process: \"%[^\"]\"", opt)) { target_process=opt; }
else if(sscanf(line, "log flags: %x", &iv)) { log_flags=iv; }
else if(sscanf(line, "sys flags: %x", &iv)) { sys_flags=iv; }
else if(sscanf(line, "vc ver: %d", &iv)) { vc_ver=iv; }
Expand Down
1 change: 0 additions & 1 deletion dpInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ struct dpConfigFile
std::vector<std::string> module_paths;
std::vector<std::string> msbuild_commands;
std::vector<std::string> build_commands;
std::string target_process;
std::string config_path;

dpConfigFile();
Expand Down

0 comments on commit 28a569a

Please sign in to comment.