c++ - Build fails when compiling DLL Injector -
i newbie c++ coder. i've been trying compile own dll injector net tutorial.
here's code:
#include <windows.h> #include <tlhelp32.h> #include <shlwapi.h> #include <conio.h> #include <stdio.h> #include <iostream> #define win32_lean_and_mean #define create_thread_access (process_create_thread | process_query_information | process_vm_operation | process_vm_write | process_vm_read) bool inject(dword pid, const char * dll_name); dword gettargetthreadidfromprocname(const char * procname); using namespace std; int main(int argc, char * argv[]) { // name of process want inject dword pid = gettargetthreadidfromprocname("notepad.exe"); // dll's total path name char buf[max_path] = {0}; getfullpathname("project1.dll", max_path, buf, null); // on place project1.dll can set name of dll printf(buf); printf("\n"); // inject our main dll if(!inject(pid, buf)) { printf("not loaded!"); // if injection not sucsessfull } else { printf("loaded!"); // if injection sucsessfull } _getch(); homecoming 0; } bool inject(dword pid, const char * dll_name) { handle proc; hmodule hlib; char buf[50] = {0}; lpvoid remotestring, loadlibaddy; if(!pid) homecoming false; proc = openprocess(process_all_access, false, pid); if(!proc) { sprintf(buf, "openprocess() failed: %d", getlasterror()); //messagebox(null, buf, "loader", mb_ok); printf(buf); homecoming false; } loadlibaddy = (lpvoid)getprocaddress(getmodulehandle("kernel32.dll"), "loadlibrarya"); // allocate space in process our dll remotestring = (lpvoid)virtualallocex(proc, null, strlen(dll_name), mem_reserve | mem_commit, page_readwrite); // write string name of our dll in memory allocated writeprocessmemory(proc, (lpvoid)remotestring, dll_name, strlen(dll_name), null); // load our <strong class="highlight">dll</strong> createremotethread(proc, null, null, (lpthread_start_routine)loadlibaddy, (lpvoid)remotestring, null, null); closehandle(proc); homecoming true; } dword gettargetthreadidfromprocname(const char * procname) { processentry32 pe; handle thsnapshot; bool retval, procfound = false; thsnapshot = createtoolhelp32snapshot(th32cs_snapprocess, 0); if(thsnapshot == invalid_handle_value) { //messagebox(null, "error: unable create toolhelp snapshot!", "2mloader", mb_ok); printf("error: unable create toolhelp snapshot!"); homecoming false; } pe.dwsize = sizeof(processentry32); retval = process32first(thsnapshot, &pe); while(retval) { if(strstri(pe.szexefile, procname)) { homecoming pe.th32processid; } retval = process32next(thsnapshot, &pe); } homecoming 0; } i maintain getting error:
"1>injector.obj : error lnk2019: unresolved external symbol __imp__strstria@8 referenced in function "unsigned long __cdecl gettargetthreadidfromprocname(char const *)" (?gettargetthreadidfromprocname@@yakpbd@z) 1>c:\users\rizker\documents\visual studio 2010\projects\injector\debug\injector.exe : fatal error lnk1120: 1 unresolved externals"
any help appreciated. oh , yeah, code used work before had formatted pc, after that, think somehow broke.
original post: http://www.mpgh.net/forum/showthread.php?t=209479
the linker cannot find strstri function, should add together shlwapi.lib in file.
#pragma comment(lib, "shlwapi.lib") c++ visual-studio-2010 visual-c++ dll-injection
No comments:
Post a Comment