Cannot insert variable into struct.

In header file I have struct like this:
1
2
3
4
5
6
    typedef struct module
    {
        struct module *module;
        struct mod *mod;
        DWORD Base, Size;
    } module;

And in main.cpp file I want to insert a variable into this struct:
 
module mod = SigScanner.GetModule("SignatureTest.exe");

But I got this error:
 
Unknown type name 'module'


And In header file I'm stuck, because:
 
no matching function for call to 'strcmp'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
HANDLE GetProcess(char* processName)
    {
        HANDLE ProcHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        PROCESSENTRY32 Entry;
        Entry.dwSize = sizeof(Entry);

        do {
            if (!strcmp(Entry.szExeFile, processName)){      //error here
                TargetId = Entry.th32ProcessID;
                CloseHandle(ProcHandle);
                TargetProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, TargetId);
                return TargetProcess;
            }
        }
        while (Process32Next(ProcHandle, &Entry));

        return false;       //error here
    }

    module GetModule(char* moduleName){
        HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, TargetId);
        MODULEENTRY32 ModuleEntry;
        ModuleEntry.dwSize = sizeof(ModuleEntry);

        do{
            if(!strcmp(ModuleEntry.szModule, moduleName)){       //error here
                CloseHandle(hModule);
                TargetModule = {(DWORD)ModuleEntry.hModule, (DWORD)ModuleEntry.modBaseSize};
            }
        }while (Module32Next(hModule, &ModuleEntry));

        return {(DWORD)false, (DWORD)false};

    }
Last edited on
C and C++ are case-sensitive. Windows module handle types must be capitalized: MODULE.

Also, whenever you get a message to the effect that the compiler does not know anything about a common function, first make sure that you have #included its header properly, then check that you have the arguments you are supplying to it correct.

Hope this helps
Fixed #include headers, without warnings now.
MODULE still have error.
Er, I’m so sorry. I don’t know what my sleep-deprived brain was saying last night. You have a struct named “module”, which is definitely not an HMODULE, so... yeah, I said a stupid thing.

C++ is case-sensitive, so use the proper name for your objects.

Again, if the compiler is complaining that it does not know what something is, it is because somewhere you have not told it. Are you sure that you have #included the header everywhere you use the struct module?
I dont understand ur suggestion with HMODULE.

Here is all code for clarification:

signaturescanner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef SIGNATURESCANNER_H
#define SIGNATURESCANNER_H

#include <iostream>
#include <string>
#include <windows.h>
#include <tlhelp32.h>

using std::cout;
using std::endl;
using std::string;

class SignatureScanner
{
public:
    typedef struct MODULE
    {
        struct MODULE *MODULE;
        struct MOD *MOD;
        DWORD Base, Size;
    } MODULE;

    MODULE TargetModule;
    HANDLE TargetProcess;
    DWORD TargetId;

    HANDLE GetProcess(char* processName)
    {
        HANDLE ProcHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        PROCESSENTRY32 Entry;
        Entry.dwSize = sizeof(Entry);

        do {
            if (!strcmp(Entry.szExeFile, processName)){
                TargetId = Entry.th32ProcessID;
                CloseHandle(ProcHandle);
                TargetProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, TargetId);
                return TargetProcess;
            }
        }
        while (Process32Next(ProcHandle, &Entry));

        return false;
    }

    MODULE GetModule(char* moduleName){
        HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, TargetId);
        MODULEENTRY32 ModuleEntry;
        ModuleEntry.dwSize = sizeof(ModuleEntry);

        do{
            if(!strcmp(ModuleEntry.szModule, moduleName)){
                CloseHandle(hModule);
                MODULE TargetModule = {(DWORD)ModuleEntry.hModule, (DWORD)ModuleEntry.modBaseSize};
            }
        }while (Module32Next(hModule, &ModuleEntry));

        return {(DWORD)false, (DWORD)false};

    }

    template <typename var>
    bool WriteMemory(DWORD Address, var Value){
        return WriteProcessMemory(TargetProcess,(LPVOID)Address, &Value, sizeof(var), 0);
    }

    template <typename var>
    var ReadMemory(DWORD Address){
        var value;
        ReadProcessMemory(TargetProcess,(LPVOID)Address, &value, sizeof(var), 0);
    }

    bool MemoryCompare(const byte* data, const byte* mask, const char* szMask){
        for (; *szMask; ++szMask, ++data, ++mask){
            if (*szMask == 'X' && *data != *mask){
                return false;
            }

        }
        return (*szMask == 0);
    }

    DWORD FindSignature(DWORD SigStart, DWORD SigSize, const char* Signature, const char* Mask)
    {
        byte* data = new byte[SigSize];
        SIZE_T BytesRead;

        ReadProcessMemory(TargetProcess, (LPVOID)SigStart, data, SigSize, &BytesRead);
        for (DWORD i=0; i<SigSize; i++){
            if(MemoryCompare((const byte*)(data + i), (const byte*)Signature, Mask)){
                delete[] data;
                return SigStart + i;
            }
        }
        return 0;
    }



};

#endif // SIGNATURESCANNER_H 


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "signaturescanner.h"
#include <limits>

int main()
{
    LPCSTR Signature = "\x64\x00\x00\x00\x3C\x56\x4A";
    LPCSTR Mask = "xxxxxxx";
    
    SignatureScanner Sig;

    if (Sig.GetProcess("SignatureTest.exe"))
    {
        MODULE mod = Sig.GetModule("SignatureTest.exe");

        DWORD HealtAddress = FindSignature(mod.Base, mod.Size, Signature, Mask);

        int RemoteHealth = Sig.ReadMemory<int>(HealtAddress);
        cout << "Current player Health is: " << RemoteHealth << endl;

        int NewHealth = 997;
        cout << "Player new health is: " << NewHealth << endl;
        Sig.WriteMemory(HealtAddress, NewHealth);

        getchar();
    }
    return 0;
}

MODULE is defined as a nested class within the SignatureScanner class. Your line 13 needs to be something like:

SignatureScanner::MODULE mod = Sig.GetModule("SignatureTest.exe");

Your strcmp in line 34 is comparing the Entry.szExeFile field. I have no idea what the type of this field is, but the "sz" in the name hints that it might be a size of some type. strcmp does not work on integer types.

Edit: You also still don't include a header file that declares the strcmp function. You need to #include<cstring> .
Last edited on
Ok, thanks for fix with this MODULE.

How can I fix these strcmp() without interrupting (dont change current functionality) these if?

#include <cstring> did not help.

1
2
3
error: cannot convert 'WCHAR* {aka wchar_t*}' to 'const char*' for argument '1' to 
'int strcmp(const char*, const char*)'
             if(!strcmp(ModuleEntry.szModule, moduleName)){
Last edited on
Do you know what strcmp does?

http://www.cplusplus.com/reference/cstring/strcmp/

Do you know what type Module.szModule is? I don't. But unless it is a const char*, you can't use it in strcmp. Are you sure you are calling the right function?

Since I don't know what the if blocks are supposed to be doing, I don't know how to fix them.


Topic archived. No new replies allowed.