You're using ) instead of } as closing brackets o__O
I had 14 errors, then I fixed it up a bit to 12...
Can some one please fix up my code and post it here or PM me please??
Here is my code:
The Error Log:Code:#include <iostream> #include <direct.h> #include <windows.h> #include <tlhelp32.h> using namespace std; char* GetCurrentDir() { char* szRet = (char*)malloc(MAX_PATH); _getcwd(szRet, MAX_PATH); return szRet; ) LPCTSTR SzToLPCTSTR(char* szString) { LPTSTR lpszRet; size_t side = strlen(szString)+1; lpszRet = (LPTSTR)malloc(MAX_PATH); mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE); return lpszRet; ) void WaitForProcessToAppear (LPCTSTR, lpsztProc, DWORD dwDelay) { HANDLE hSnap; PROCESSENTRY32 peProc; BOOL bAppeared = FALSE; while(!bAppeared) { if ((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE ( peProc.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hSnap, &peProc)) while(Process32Next(hSnap, &peProc) && !bAppeared) if(!lstrcmp(lpcszProc, peProc.szExeFile)) bAppeared = TRUE; } CloseHandle(hSnap); Sleep(dwDelay); } ) DWORD GetProcessIdByName(LPCTSTR lpcszProc) { HANDLE hSnap; PROCESSENTRY32 peProc; DWORD dwRet = -1; if((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE) { peProc.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hSnap, &peProc)) while(Process32Next(hSnap, &peProc)) if(!lstrcmp(lpcszProc, peProc.szExeFile)) dwRet = peProc.th32ProcessID; } CloseHandle(hSnap); return dwRet; ) BOOL InjectDll(DWORD dwPid, char* szDllPath) { DWORD dwMemSize; HANDLE hProc; LPVOID IpRemoteMem, IpLoadLibrary; BOOL bRet = FALSE; if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL) { dwMemSize = strlen(szDllPath)+1; if((IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE) != NULL) if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL)) { IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"); if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL) bRet = True ) } CloseHandle(hProc); return bRet; ) int main() { char szProc[MAX_PATH], szDll[MAX_PATH]; char* szDllPath = (char*)malloc(MAX_PATH); LPTSTR lpszProc = NULL; for(;;) { cout << "Process: "; cin >> szProc; cout << "DLL: "; cin >> szDll; szDllPath = GetCurrentDir(); strcat_s(szDllPath, MAX_PATH, "\\"); strcat_s(szDllPath, MAX_PATH, szDll); cout << "Waiting for process..." << endl; WaitForProcessToAppear(SzToLPCTSTR(szProc), 100); if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath)) cout << "Injection Success!" << endl; else cout << "Failed to inject!" << endl; cout << "\n"; } return 0; }
Code:------ Build started: Project: Luigi, Configuration: Debug Win32 ------ Compiling... main.cpp c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(23) : error C2065: 'size' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(27) : error C2061: syntax error : identifier 'lpsztProc' c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(35) : error C3861: 'CreateToolHelp32Snapshot': identifier not found c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(42) : error C2065: 'lpcszProc' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(48) : error C2065: 'dwDelay' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(59) : error C3861: 'CreateToolHelp32Snapshot': identifier not found c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(88) : error C2440: '=' : cannot convert from 'bool' to 'LPVOID' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(89) : error C2143: syntax error : missing ')' before '{' c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2065: 'True' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2143: syntax error : missing ';' before '}' c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(119) : error C2660: 'WaitForProcessToAppear' : function does not take 2 arguments Build log was saved at "file://c:\Documents and Settings\-----\My Documents\Visual Studio 2008\Projects\Luigi\Luigi\Debug\BuildLog.htm" Luigi - 11 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited by Pixie; 09-15-2009 at 03:31 PM.
You're using ) instead of } as closing brackets o__O
Fixed brackets and indention, no idea if it will work.Code:#include <iostream> #include <direct.h> #include <windows.h> #include <tlhelp32.h> using namespace std; char* GetCurrentDir() { char* szRet = (char*)malloc(MAX_PATH); _getcwd(szRet, MAX_PATH); return szRet; } LPCTSTR SzToLPCTSTR(char* szString) { LPTSTR lpszRet; size_t side = strlen(szString)+1; lpszRet = (LPTSTR)malloc(MAX_PATH); mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE); return lpszRet; } void WaitForProcessToAppear (LPCTSTR, lpsztProc, DWORD dwDelay) { HANDLE hSnap; PROCESSENTRY32 peProc; BOOL bAppeared = FALSE; while(!bAppeared) { if ((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE) { peProc.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hSnap, &peProc)) { while(Process32Next(hSnap, &peProc) && !bAppeared) { if(!lstrcmp(lpcszProc, peProc.szExeFile)) { bAppeared = TRUE; } CloseHandle(hSnap); } Sleep(dwDelay); } } } } DWORD GetProcessIdByName(LPCTSTR lpcszProc) { HANDLE hSnap; PROCESSENTRY32 peProc; DWORD dwRet = -1; if((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE) { peProc.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hSnap, &peProc)) { while(Process32Next(hSnap, &peProc)) { if(!lstrcmp(lpcszProc, peProc.szExeFile)) { dwRet = peProc.th32ProcessID; } CloseHandle(hSnap); } } return dwRet; } } BOOL InjectDll(DWORD dwPid, char* szDllPath) { DWORD dwMemSize; HANDLE hProc; LPVOID IpRemoteMem, IpLoadLibrary; BOOL bRet = FALSE; if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL) { dwMemSize = strlen(szDllPath)+1; if((IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE) != NULL) { if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL)) { IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"); if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL) { bRet = True } CloseHandle(hProc); } return bRet; } } } int main() { char szProc[MAX_PATH], szDll[MAX_PATH]; char* szDllPath = (char*)malloc(MAX_PATH); LPTSTR lpszProc = NULL; for(;;) { cout << "Process: "; cin >> szProc; cout << "DLL: "; cin >> szDll; szDllPath = GetCurrentDir(); strcat_s(szDllPath, MAX_PATH, "\\"); strcat_s(szDllPath, MAX_PATH, szDll); cout << "Waiting for process..." << endl; WaitForProcessToAppear(SzToLPCTSTR(szProc), 100); if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath)) { cout << "Injection Success!" << endl; } else { cout << "Failed to inject!" << endl; cout << "\n"; } } return 0; }
just use s1nject(closed source) or tatnium injector(open source)
Last edited by Pixie; 09-15-2009 at 03:09 PM.
An error log would make it a lot easier.
Error Log:
Code:------ Build started: Project: Luigi, Configuration: Debug Win32 ------ Compiling... main.cpp c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(23) : error C2065: 'size' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(27) : error C2061: syntax error : identifier 'lpsztProc' c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(35) : error C3861: 'CreateToolHelp32Snapshot': identifier not found c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(42) : error C2065: 'lpcszProc' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(48) : error C2065: 'dwDelay' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(59) : error C3861: 'CreateToolHelp32Snapshot': identifier not found c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(88) : error C2440: '=' : cannot convert from 'bool' to 'LPVOID' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(89) : error C2143: syntax error : missing ')' before '{' c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2065: 'True' : undeclared identifier c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2143: syntax error : missing ';' before '}' c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(119) : error C2660: 'WaitForProcessToAppear' : function does not take 2 arguments Build log was saved at "file://c:\Documents and Settings\-----\My Documents\Visual Studio 2008\Projects\Luigi\Luigi\Debug\BuildLog.htm" Luigi - 11 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hmmmm... well you've got a bunch of uncdeclared identifiers from what I can see. You either need to imports some files that declare those identifiers or use unmanaged ones. Let me look into it.
EDIT: (3 minutes after looking at code)
Wow. There are way to many managed to unmanaged C++ conversions in there. Maybe HD or BA would have a better time understanding it. I suck with managed.
PS: Does anyone know somewhere I could get acquainted with managed C++? A book or a web page or something. Not exactly sure what I should look for.
Last edited by why06; 09-15-2009 at 04:25 PM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
MSDN
one way to approach is it to think that Managed C++ = C# using C++ syntax..
Dont' realyl have time to go over all of this, but for instance this:
...\luigi\main.cpp(23) : error C2065: 'size' : undeclared identifier
Look in that block of code
notice anything what it probably should've been?Code:LPCTSTR SzToLPCTSTR(char* szString) { LPTSTR lpszRet; size_t side = strlen(szString)+1; lpszRet = (LPTSTR)malloc(MAX_PATH); mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE); return lpszRet; }
Why would anyone call the length of a string 'side' instead of size ?
I'm sure there's more like those..
Hmmm I had a feeling someone would say that. Basically MSDN = the manual xD.
Oh well and looking at the small code snipet I see what you mean. whoever wrote this didn't pay much attention to what they were doing or at least didnt debug it. Anyway it also looks like they added 1 to the string length.. o_O wth?
Meh. I'll try to figure it out. it will take a while because I have less experience, I just have to break each function down part by part. Could take about a week, but this should give me some good practice with managed.
Last edited by why06; 09-15-2009 at 05:04 PM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Couple of missing brackets, semi colon, few too many comma's in places they shouldn't be, variable name mis-spellings, Upper vs Lower Case ..
And btw - no managed code in here.. just good old-fashioned Win32 C++
Not trying to sound like an arrogant prick ('cause i'm really not) lol but but this should be beginner level to figure this stuff out, especially when running it through a compiler and it basically telling you what the problem is Perhaps now that you see what the changes are, compare and see if it make sense with what the error message was for each of the errors. Learning opportunity here
disclaimer: it BUILDS, that's it - didn't test if it runs or does what it's supposed toCode:#include <iostream> #include <direct.h> #include <windows.h> #include <tlhelp32.h> using namespace std; char* GetCurrentDir() { char* szRet = (char*)malloc(MAX_PATH); _getcwd(szRet, MAX_PATH); return szRet; } LPCTSTR SzToLPCTSTR(char* szString) { LPTSTR lpszRet; size_t size = strlen(szString)+1; lpszRet = (LPTSTR)malloc(MAX_PATH); mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE); return lpszRet; } void WaitForProcessToAppear(LPCTSTR lpszProc, DWORD dwDelay) { HANDLE hSnap; PROCESSENTRY32 peProc; BOOL bAppeared = FALSE; while(!bAppeared) { if ((hSnap = CreateToolhelp32Snapshot((DWORD)TH32CS_SNAPPROCESS, (DWORD)0)) != INVALID_HANDLE_VALUE) { peProc.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hSnap, &peProc)) { while(Process32Next(hSnap, &peProc) && !bAppeared) { if(!lstrcmp(lpszProc, peProc.szExeFile)) { bAppeared = TRUE; } CloseHandle(hSnap); } Sleep(dwDelay); } } } } DWORD GetProcessIdByName(LPCTSTR lpcszProc) { HANDLE hSnap; PROCESSENTRY32 peProc; DWORD dwRet = -1; if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE) { peProc.dwSize = sizeof(PROCESSENTRY32); if(Process32First(hSnap, &peProc)) { while(Process32Next(hSnap, &peProc)) { if(!lstrcmp(lpcszProc, peProc.szExeFile)) { dwRet = peProc.th32ProcessID; } CloseHandle(hSnap); } } return dwRet; } } BOOL InjectDll(DWORD dwPid, char* szDllPath) { DWORD dwMemSize; HANDLE hProc; LPVOID IpRemoteMem, IpLoadLibrary; BOOL bRet = FALSE; if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL) { dwMemSize = strlen(szDllPath)+1; if( (IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE)) != NULL) { if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL)) { IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"); if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL) { bRet = TRUE; } CloseHandle(hProc); } return bRet; } } } int main() { char szProc[MAX_PATH], szDll[MAX_PATH]; char* szDllPath = (char*)malloc(MAX_PATH); LPTSTR lpszProc = NULL; for(;;) { cout << "Process: "; cin >> szProc; cout << "DLL: "; cin >> szDll; szDllPath = GetCurrentDir(); strcat_s(szDllPath, MAX_PATH, "\\"); strcat_s(szDllPath, MAX_PATH, szDll); cout << "Waiting for process..." << endl; WaitForProcessToAppear(SzToLPCTSTR(szProc), 100); if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath)) { cout << "Injection Success!" << endl; } else { cout << "Failed to inject!" << endl; cout << "\n"; } } return 0; }
Last edited by B1ackAnge1; 09-15-2009 at 05:08 PM.
The code I pasted has 0 build errors, so copy & paste that
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower