When i compile this code i get a few errors (i guess are simple for you guys)

void WriteMem(DWORD MemOffset, DWORD DataPtr, DWORD dataLen) {
  { DWORD OldProt;
  VirtualProtect((void*) MemOffset, dataLen, PAGE_EXECUTE_READWRITE, &OldProt); 
  RtlMoveMemory((void*) MemOffset, (const void*) DataPtr, dataLen);
  VirtualProtect((void*) MemOffset, dataLen, OldProt, &OldProt); 
  }
  void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len); {
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }

Errors

--------------------Configuration: DLL - Win32 Debug--------------------
Compiling...
Main.cpp
error C2601: 'WriteMem' : local function definitions are illegal
error C2601: 'Initialize' : local function definitions are illegal
error C2601: 'Shutdown' : local function definitions are illegal
error C2601: 'DllMain' : local function definitions are illegal
fatal error C1004: unexpected end of file found
Error executing cl.exe.
DLL.dll - 5 error(s), 0 warning(s)

>> { DWORD OldProt;

remove the '{' character.

LOL im so dumb not to see that! i must be blind but... now i have these

--------------------Configuration: DLL - Win32 Debug--------------------
Compiling...
Main.cpp
error C2601: 'WriteMem' : local function definitions are illegal
error C2065: 'len' : undeclared identifier
warning C4018: '<' : signed/unsigned mismatch
error C2065: 'AddrToChange' : undeclared identifier
error C2065: 'To' : undeclared identifier
Error executing cl.exe.
DLL.dll - 4 error(s), 1 warning(s)

>> void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len); {

remove the semicolon

Now i have like the most errors ever.

--------------------Configuration: DLL - Win32 Debug--------------------
Compiling...
Main.cpp
error C2065: 'MemOffset' : undeclared identifier
error C2065: 'dataLen' : undeclared identifier
error C2065: 'DataPtr' : undeclared identifier
error C2065: 'len' : undeclared identifier
warning C4018: '<' : signed/unsigned mismatch
error C2065: 'AddrToChange' : undeclared identifier
error C2065: 'To' : undeclared identifier
error C2143: syntax error : missing ';' before 'else'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2143: syntax error : missing ';' before 'else'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2143: syntax error : missing ';' before 'else'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2143: syntax error : missing ';' before 'else'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2143: syntax error : missing ';' before 'else'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2143: syntax error : missing ';' before 'else'
error C2143: syntax error : missing ';' before '.'
error C2501: 'ZChat__InputDet' : missing storage-class or type specifiers
error C2371: 'ZChat__InputDet' : redefinition; different basic types
see declaration of 'ZChat__InputDet'
error C2143: syntax error : missing ';' before '.'
error C2143: syntax error : missing ';' before 'return'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
error C2065: 'Initialize' : undeclared identifier
Error executing cl.exe.
DLL.dll - 33 error(s), 1 warning(s)

My Code

void WriteMem(DWORD MemOffset, DWORD DataPtr, DWORD dataLen); {
  DWORD OldProt;
  VirtualProtect((void*) MemOffset, dataLen, PAGE_EXECUTE_READWRITE, &OldProt); 
  RtlMoveMemory((void*) MemOffset, (const void*) DataPtr, dataLen);
  VirtualProtect((void*) MemOffset, dataLen, OldProt, &OldProt); 
  }
  void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len);
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }

that's what happens then you fix something :cheesy: look at the first eror message and try to find out why MemOffset is undefined. Where did you define it? It must be in one of two places: (1) a global variable, or (2) a variable declared inside the function in which its used.

Fix one error and it may solve several error messages.

First you have this:

void WriteMem(DWORD MemOffset, DWORD DataPtr, DWORD dataLen) {
...
  }
  void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len); {
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }

and the recomendation was

>> void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len); {
remove the semicolon

Now you have:

void WriteMem(DWORD MemOffset, DWORD DataPtr, DWORD dataLen); {

What changed in the line (and more importantly, why did it change?)

and first you have this:

void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len); {
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }

and now:

void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len);
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }

which are both wrong. Is this the implementation of the function or are your just trying to call it and is it part of something else?

regards Niek

im trying to make the EnableHack function (its so i can edit a processes memory)

ok, then you should remove the semicolon as Ancient Dragon allready said.

void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len) 
  {
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }

And in your other function too offcourse, as WaltP pointed out.

regards Niek

Yay! i got it to work now for an easy part

void WriteMem(DWORD MemOffset, DWORD DataPtr, DWORD dataLen) {
  DWORD OldProt;
  VirtualProtect((void*) MemOffset, dataLen, PAGE_EXECUTE_READWRITE, &OldProt); 
  RtlMoveMemory((void*) MemOffset, (const void*) DataPtr, dataLen);
  VirtualProtect((void*) MemOffset, dataLen, OldProt, &OldProt); 
  }
  void EnableHack(BYTE* AddrToChange, BYTE* To, DWORD len) 
  {
   for(DWORD i = 0; i < len; i++) 
    WriteMem((DWORD)AddrToChange+i, (DWORD)To+i, 1); 
  }
 
DWORD ZChat__Input = ADDR_ZCHATINPUT;
 
CDetour ZChat__InputDet;
bool __stdcall ZChat__InputHook(const char* lpcLine){
  bool bRet = true;
 
 if(stricmp(lpcLine, "!god") == 0){
  bRet = false;
  if(ADDR_GODMODE[0] != 0x90){
        BYTE godmode[] = {0x90, 0x90};
        EnableHack((BYTE*)ADDR_GODMODE, godmode, 2);
        Echo("GodMode On");
        }
        else
        BYTE godmode[] = {0x7B, 0x05};
        EnableHack((BYTE*)ADDR_GODMODE, godmode, 2);
        Echo("GodMode Off");
        }

Errors

--------------------Configuration: DLL - Win32 Debug--------------------
Compiling...
Main.cpp
error C2109: subscript requires array or pointer type
error C2065: 'godmode' : undeclared identifier
Error executing cl.exe.
Creating browse info file...
DLL.dll - 2 error(s), 0 warning(s)

error C2065: 'godmode' : undeclared identifier

You are declaring "godmode" inside an if-statement, this means it won't be visible outside it. Just declare it at the beginning of the function.

regards Niek

You will see the problem immediately if you format your code better:
Put each { and } on separate lines
Every line between corresponding { }'s should be indented 3-4 SPACEs.

For example:

int function(int val)
{
    int rtn, tmp;
    if (val > 10)
    {
        tmp = val * 4;
        rtn = tmp + val;
    }
    else
    {
        tmp = val * 6;
        rtn = tmp - val;
    }
    return rtn;
}

Errors

--------------------Configuration: DLL - Win32 Debug--------------------
Compiling...
Main.cpp
error C2109: subscript requires array or pointer type
error C2065: 'godmode' : undeclared identifier
Error executing cl.exe.
Creating browse info file...
DLL.dll - 2 error(s), 0 warning(s)

Please let us know what lines these error are on. Just telling us the errors does not give us enough information (although I did find one -- this time)

You are declaring "godmode" inside an if-statement, this means it won't be visible outside it. Just declare it at the beginning of the function.

regards Niek

I dont understand "Just declare it at the beginning of the function." what function the WriteMem of the ZChat::Input Hook?

sry im not that good at C++

just after bool bRet = true; Where did you get this code anyway? Because I'm guessing you didn't write it youself? Be sure to read and understand WaltP's post because you'll encouter a lot more problems related to this...

regard Niek

int function(int val)
{
    int rtn;
    if (val > 10)
    {
        int tmp = val * 4;
        rtn = tmp + val;
    }
    else
    {
        tmp = val * 6;
        rtn = tmp - val;
    }
    return rtn;
}

In this version of WaltPs example rtn is visible/available throughout the function whereas tmp is only visible/available in the body of the if and is not visible/available in the body of the else. This is what's happening in the code you posted.

The function is reduced to this:

int function(int val)
{
    return (val * 5);
}

why? because of the associative (?) properties of mathametics

val * 4 + val
is the same as
val + val + val + val + val; // there are 5 vals on this line

val * 6 - val;
is the same as this
val + val + val + val + val + val - val;
which is
val + val + val + val + val; // there are also 5 vals on this line

Guys, I was showing formatting techniques to aid the poster. Multiple posts explaning the code is not helpful in understanding the formatting:

You will see the problem immediately if you format your code better:
Put each { and } on separate lines
Every line between corresponding { }'s should be indented 3-4 SPACEs.

For example:...

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.