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++][AA][SOLVED] AA code to C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
TheTime
How do I cheat?
Reputation: 0

Joined: 22 May 2012
Posts: 2

PostPosted: Tue May 22, 2012 5:20 pm    Post subject: [C++][AA][SOLVED] AA code to C++ Reply with quote

Here is my AA code that works in game injected using CE :

Code:
[ENABLE]
alloc(newmem,512)
label(returnhere)

007XXXX9:
jmp newmem
nop
returnhere:

newmem:
and dword ptr [esp+20],7XXXXXXX
fmul dword ptr [esp+20]
mov eax,[eax]
jmp returnhere

[DISABLE]
dealloc(newmem)

007XXXX9:
fmul dword ptr [esp+20]
mov eax,[eax]


I have converted this code in C++ to inject it via a dll, but my code when it's injected makes the game crash :

Code:

#define jmp(frm, to) (int)(((int)to - (int)frm) - 5);
DWORD Address = 0x007XXXX9, AddressRet = 0x007XXXXF; // Those are correct, checked via CE
char  szAddressMem[5];

void __declspec(naked) __stdcall On() 
{
    _asm
    {
      and dword ptr [esp+0x20],0x7XXXXXXX
      fmul dword ptr [esp+0x20]
      mov eax,[eax]
      jmp dword ptr [AddressRet]
    }
}

void Jump(unsigned long ulAddress, void* Function, unsigned long ulNops)
{
        *(unsigned char*)ulAddress = 0xE9;
        *(unsigned long*)(ulAddress + 1) = jmp(ulAddress, Function);
        memset((void*)(ulAddress + 5), 0x90, ulNops);


void _stdcall OnOff()
{
    Jump(Address, On, 1);
}


What I'm doing wrong ?


Last edited by TheTime on Wed May 23, 2012 2:48 am; edited 2 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25833
Location: The netherlands

PostPosted: Tue May 22, 2012 5:32 pm    Post subject: Reply with quote

perhaps ulAddress is readonly
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
TheTime
How do I cheat?
Reputation: 0

Joined: 22 May 2012
Posts: 2

PostPosted: Wed May 23, 2012 2:34 am    Post subject: Reply with quote

Dark Byte wrote:
perhaps ulAddress is readonly


You were right !

So I added method :

Code:
void MakePageWritable(unsigned long ulAddress, unsigned long ulSize)
{
    MEMORY_BASIC_INFORMATION* mbi = new MEMORY_BASIC_INFORMATION;
    VirtualQuery((void*)ulAddress, mbi, ulSize);
    if (mbi->Protect != PAGE_EXECUTE_READWRITE)
    {
        unsigned long* ulProtect = new unsigned long;
        VirtualProtect((void*)ulAddress, ulSize, PAGE_EXECUTE_READWRITE, ulProtect);
        delete ulProtect;
    }
    delete mbi;
}


Then i called the h*ck like this :
Code:

void _stdcall OnOff()
{
    MakePageWritable(Address,6);
    Jump(Address, PatchBoostOn, 1);
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon May 28, 2012 7:50 am    Post subject: Reply with quote

TheTime wrote:
Dark Byte wrote:
perhaps ulAddress is readonly


You were right !

So I added method :

Code:
void MakePageWritable(unsigned long ulAddress, unsigned long ulSize)
{
    MEMORY_BASIC_INFORMATION* mbi = new MEMORY_BASIC_INFORMATION;
    VirtualQuery((void*)ulAddress, mbi, ulSize);
    if (mbi->Protect != PAGE_EXECUTE_READWRITE)
    {
        unsigned long* ulProtect = new unsigned long;
        VirtualProtect((void*)ulAddress, ulSize, PAGE_EXECUTE_READWRITE, ulProtect);
        delete ulProtect;
    }
    delete mbi;
}


Then i called the h*ck like this :
Code:

void _stdcall OnOff()
{
    MakePageWritable(Address,6);
    Jump(Address, PatchBoostOn, 1);
}


Given that you are hacking, why care what the protection is unless you absolutely have to change it to something specific? Just force the change no matter what.

Also, there is no reason to allocate memory to call VirtualProtect.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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