Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Unknown Crash on my VM code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Oct 05, 2009 3:54 pm    Post subject: Unknown Crash on my VM code Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Oct 05, 2009 4:02 pm    Post subject: Reply with quote

look at your free()

also, nice code, bro
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Oct 05, 2009 4:11 pm    Post subject: Reply with quote

I told you that free was the problem on msn, stop trying to receive credits kthx.
Back to top
View user's profile Send private message
Guy
Expert Cheater
Reputation: 0

Joined: 30 May 2009
Posts: 187

PostPosted: Mon Oct 05, 2009 4:31 pm    Post subject: Reply with quote

Way to copy and paste my format with little understanding of how it works Razz

http://forum.gamedeception.net/showthread.php?p=121355#post121355

Either way, why is your virtual code segment being managed as a string?

_________________
Has anyone seen Hitler around..? If so, PM me!
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Oct 05, 2009 6:46 pm    Post subject: Reply with quote

I think I died a little inside reading that code. People should learn that C++ isn't C.
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Oct 05, 2009 7:25 pm    Post subject: Reply with quote

Guy` wrote:
Way to copy and paste my format with little understanding of how it works Razz

http://forum.gamedeception.net/showthread.php?p=121355#post121355

Either way, why is your virtual code segment being managed as a string?


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
View user's profile Send private message
Guy
Expert Cheater
Reputation: 0

Joined: 30 May 2009
Posts: 187

PostPosted: Mon Oct 05, 2009 7:36 pm    Post subject: Reply with quote

void:] wrote:
Guy` wrote:
Way to copy and paste my format with little understanding of how it works Razz

http://forum.gamedeception.net/showthread.php?p=121355#post121355

Either way, why is your virtual code segment being managed as a string?


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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Oct 05, 2009 10:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites