0

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)
5
Contributors
17
Replies
19
Views
10 Years
Discussion Span
Last Post by WaltP
0

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)
0

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); 
  }
0

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.

0

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?)

0

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

0

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

0

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

0

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)
0

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

0

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)

0

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++

0

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

0
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.

0

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

0

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:...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.