Ok well first I'll tell you the 3 errors that I am getting... All 3 errors are near the bottom of the code

  • main.cpp(103) : error C2664: 'errno_t strcat_s(char *,rsize_t,const char *)' : cannot convert parameter 3 from 'char' to 'const char *'
  • main.cpp(105) : error C2664: 'SzToLPCTSTR' : cannot convert parameter 1 from 'char' to 'char *'
  • main.cpp(106) : error C2664: 'SzToLPCTSTR' : cannot convert parameter 1 from 'char' to 'char *'

Also I am just starting to learn c++ so I don't really know much c++. I know more about visual basic but am trying to broaden my skills.

This is a Win32 Console Application. Here is the 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 size = strlen(szString)+1;

    lpszRet = (LPTSTR)malloc(MAX_PATH);
    mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);

    return lpszRet;
}

void WaitForProcessToAppear(LPCTSTR lpcszProc, 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            lpRemoteMem, lpLoadLibrary;
    BOOL            bRet = FALSE;

    if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)
    {
    dwMemSize = strlen(szDllPath)+1;
    if((lpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE)) != NULL)
    {
    lpLoadLibrary = GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
    if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)lpLoadLibrary, lpRemoteMem, 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 Successful" << endl;
        else
            cout << "Injection Failed" << endl;
        cout << "\n";
    }
   
    return 0;
}

Thanks for any help in advance.

line 91: use [ and ] instead of ( and )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.