| View previous topic :: View next topic |
| Author |
Message |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Mon Oct 05, 2009 3:54 pm Post subject: Unknown Crash on my VM code |
|
|
| Code: | int VMClass::getRegister( unsigned char szOpcode )
{
switch(szOpcode)
{
case reg_eax:
return EAX;
case reg_ax:
return AX;
case reg_ebx:
return EBX;
case reg_bx:
return BX;
case reg_ecx:
return ECX;
case reg_cx:
return CX;
case reg_edx:
return EDX;
case reg_dx:
return DX;
default:
return -1;
}
}
void VMClass::add( int reg, unsigned long ulValue )
{
switch(reg)
{
case reg_eax:
__asm { mov dword ptr ds:[iValue], EAX }
iValue -= (0-ulValue);
__asm { xor dword ptr ds:[EAX], EAX
add dword ptr ds:[EAX], iValue;
}
break;
default:
return;
}
}
void VMClass::InterpretOperations( unsigned char * vmBuffer, unsigned long vmSize )
{
char * szTok = (char*)malloc(sizeof(char) * 8096);
char * newTok = new char[512];
char * szTemp = new char[512];
szTok = strtok_s((char*)vmBuffer, "e", &newTok);
for(int currentOp = 0; currentOp<(signed)strlen(szTok); currentOp++)
{
switch(szTok[currentOp])
{
case op_add:
if(getRegister(szTok[currentOp+1]) == -1)
goto gtEnd;
ZeroMemory(szTemp, sizeof(szTemp));
for(int i = currentOp+2; i<strlen(szTok); i++)
{
StringCchCat(szTemp, 1, (STRSAFE_LPCSTR)szTok[i]);
}
add(getRegister(szTok[currentOp+1]), atoi(szTemp));
break;
default:
goto gtEnd;
}
}
gtNext:
gtEnd:
free(szTok);
delete[] newTok;
delete[] szTemp;
} |
It never gets to "add(getRegister...". Thanks in advance!
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Mon Oct 05, 2009 4:02 pm Post subject: |
|
|
look at your free()
also, nice code, bro
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Mon Oct 05, 2009 4:11 pm Post subject: |
|
|
| I told you that free was the problem on msn, stop trying to receive credits kthx.
|
|
| Back to top |
|
 |
Guy Expert Cheater
Reputation: 0
Joined: 30 May 2009 Posts: 187
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Oct 05, 2009 6:46 pm Post subject: |
|
|
| I think I died a little inside reading that code. People should learn that C++ isn't C.
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Mon Oct 05, 2009 7:25 pm Post subject: |
|
|
What format? I told you that I prefer it like that. Because I'm cool ;3
@Flyte: I don't like to use the std::string.
|
|
| Back to top |
|
 |
Guy Expert Cheater
Reputation: 0
Joined: 30 May 2009 Posts: 187
|
Posted: Mon Oct 05, 2009 7:36 pm Post subject: |
|
|
| void:] wrote: |
What format? I told you that I prefer it like that. Because I'm cool ;3
@Flyte: I don't like to use the std::string. |
| Code: |
case reg_ebx:
return EBX;
case reg_bx:
|
reg_ebx - you're still copying my format, and making use of 16-bit registers.
Also, you're returning the value of the register itself, not the pointer to the register.
| Code: |
add(getRegister(szTok[currentOp+1]), atoi(szTemp));
break;
default:
goto gtEnd;
}
}
gtNext:
gtEnd:
free(szTok);
delete[] newTok;
delete[] szTemp;
|
Unnecessary use of goto/label.
_________________
Has anyone seen Hitler around..? If so, PM me! |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Oct 05, 2009 10:21 pm Post subject: |
|
|
| void:] wrote: | | @Flyte: I don't like to use the std::string. |
It's more than that. You've just taken C code and shoved it into a class, the only markings that it is in C++ is that you are using classes, and there is a lot more to OOP than that!
|
|
| Back to top |
|
 |
|