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 


C++ ASM problem.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
stimmedcow
How do I cheat?
Reputation: 0

Joined: 21 May 2007
Posts: 5

PostPosted: Mon May 21, 2007 9:29 pm    Post subject: Reply with quote

This topic is not as simple as it may sound.

There's two main things that you might want to do with ASM code and C++:

1. Write embedded asm code into a C++ program to make life easier or if you do not want to port existing ASM code.

2. Inject ASM code into another program to patch it.

For #1, if you want to simply write ASM code to use in your C++ program, you can use the following:
Code:

__asm
{
// your asm code
}

However, that ASM code is specific to the current executable. If you were to write:
Code:

         __asm
         {
            jmp 0x006B4DF9
            __emit 0x76
         }

That is telling *your program* to jmp to 0x006B4DF9 (which is not possible, since JMP does no take a physical address as the 2nd operand) and then that ASM will 'emit' a 0x76 byte in "your program's" executable.

If you wanted to execute a jmp to that address you would have to move the address into a register 1st, then jmp to that register. The emit tells the compiler to write something into the executable where it occurs at, so it cannot be used by you.

An example of a proper use of emit would be the following, taken from the web:
Code:

__int64 GetCPUCount ( unsigned int loword, unsigned int hiword )
{
      _asm
      {
         _emit 0x0f   // insert rtdsc opcode
         _emit 0x31
         mov hiword , edx
         mov loword , eax
      }      
   return ( (__int64) hiword << 32 ) + loword;
}


If you see the difference, the ASM script is used as "code". That is what __asm and emit are for. Since you do not want to do that, you will have to look at #2

What you want to do, is change the memory address at location "0x006B4DF9" to 0x76 for enable and 0x73 on disable.

To do that via C++ you will have to either:

* Use WriteProcessMemory to write the correct byte to that location in the process of your choice.

* Inject a DLL into the game and change the memory address manually, using a method like Gthuggin's or you can use an asm method of moving the address into eax, the moving the final value into the contents of eax - i.e. something like -

Code:

void Enable()
{
   __asm
   {
      mov eax, 0x006B4DF9
      mov [eax], 0x76
   }
}


Either way, you cannot simply change the memory unless you:
* Get a handle to the process and write the memory though an API function
or
* Get your code into the process and have it executed

If you need some example code of various ways to do this, take a look at this article: www<dot>edgeofnowhere<dot>cc/viewtopic.php?t=308049

Quote:
So is using ASM... At the end, it does the same thing. Why do you think people go through a lot of hooking and coding to be able to be undetected. (There's some exceptions)


One thing to note is that anyone that hooks WriteProcessMemory / ReadProcessMemory can easily get your patches, but if you use an ASM method to patch, they cannot. (However, they can know the address since most of the time you will have to call VirtualProtect on the region of memory first)

Quote:
So how Actually I can put ASM Script in C++ Script?:
Example


I've answered that throughout the post, but __asm is only for the current exe. You will have to write a DLL that contains the __asm and inject that into the process.
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
Goto page Previous  1, 2
Page 2 of 2

 
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