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++ inline asm
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Sep 16, 2008 12:31 pm    Post subject: Reply with quote

1qaz wrote:
oh i think i forgot to mention that i tried already byte ptr and dword ptr with 0x90 00 00 00 still not working
btw i attached the window to the process as u told me to (still don't know what it's good for) and it doesn't work too


You have to be within it's memory space to directly goof with stuff.

Inject it as a DLL, or start a remote thread.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Tue Sep 16, 2008 1:25 pm    Post subject: Reply with quote

so i assume that this code should work fine if i'll inject the dll
Code:

#include <windows.h>
#include <tchar.h>

DWORD Address = 0x0100346E;

__declspec(naked) void Hack()
{
   __asm
   {
      mov byte ptr ds:[Address],0x90
      RETN
   }
}

void Hacking()
{
   Hack();
}

BOOL WINAPI DllMain (HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
   if (dwReason == DLL_PROCESS_ATTACH)
   {
      CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Hacking,0,0,0);
   }
}


the game crushes every time i inject the dll

_________________
Stylo
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Sep 16, 2008 1:29 pm    Post subject: Reply with quote

You've removed Memory Write Protection if there is any?

VirtualProtect the address to PAGE_EXECUTE_READWRITE before you modify anything.

_________________
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Tue Sep 16, 2008 1:37 pm    Post subject: Reply with quote

Also, the opcode at the address you are writing to might be more than one byte. Make sure you nop all of them.
Back to top
View user's profile Send private message MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Tue Sep 16, 2008 1:48 pm    Post subject: Reply with quote

how do i check if there's any memory write protection? the process is winmine
but even though i used virtualprotect anyway
Code:

VirtualProtect((LPVOID)Address,6,PAGE_EXECUTE_READWRITE,0);

game still keep crushing
i dont know what's the deal with the 4th parameter btw so i guess that's the reason ?! maybe
@noz i tried both byte and dword ways and they didn't work

_________________
Stylo
Back to top
View user's profile Send private message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Tue Sep 16, 2008 1:54 pm    Post subject: Reply with quote

1qaz wrote:
how do i check if there's any memory write protection? the process is winmine
but even though i used virtualprotect anyway
Code:

VirtualProtect((LPVOID)Address,6,PAGE_EXECUTE_READWRITE,0);

game still keep crushing
i dont know what's the deal with the 4th parameter btw so i guess that's the reason ?! maybe
@noz i tried both byte and dword ways and they didn't work

Thats not what he mean.
like if you want to nop:
Code:

push esi

1 byte might be fine, but if you are noping a
Code:

mov [edx],esi

you might need 3 bytes.

_________________
Gone
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Tue Sep 16, 2008 5:07 pm    Post subject: Reply with quote

nog_lorp wrote:
sponge wrote:
Code:
LEAVE
Clean up the Epilogue noggy.


Hi, I'm dumb.

Code:
mov esp, ebp
pop ebp
ret


For some reason I never see leave used.
I see leave plenty.
_________________
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Tue Sep 16, 2008 11:00 pm    Post subject: Reply with quote

Leave is equivalent to
Code:
mov esp,ebp
pop ebp
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Sep 17, 2008 8:27 am    Post subject: Reply with quote

Just wondering. What exactly is the prologue and epilogue when you talk about naked functions? Because it seems rather important and I'm clueless Laughing
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Sep 17, 2008 9:30 am    Post subject: Reply with quote

oib111 wrote:
Just wondering. What exactly is the prologue and epilogue when you talk about naked functions?
There's none. That's why it's called naked.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Sep 17, 2008 11:21 am    Post subject: Reply with quote

okay look at this code and tell me what causes the game crush
Code:

#include <windows.h>
#include <tchar.h>

int* Address = (int*)0x0100346E;

__declspec(naked) void Hack()
{
   __asm
   {
      mov byte ptr ds:[Address],0x90
      mov byte ptr ds:[Address + 1],0x90
      mov byte ptr ds:[Address + 2],0x90
      mov byte ptr ds:[Address + 3],0x90
      mov byte ptr ds:[Address + 4],0x90
      mov byte ptr ds:[Address + 5],0x90
      RETN
   }
}

void Hacking()
{
   VirtualProtect((LPVOID)Address,6,PAGE_EXECUTE_READWRITE,0);
   Hack();
}

BOOL WINAPI DllMain (HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
   if (dwReason == DLL_PROCESS_ATTACH)
   {
      CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Hacking,0,0,0);
   }
}

as u can see i nopped all the 6 bytes at the address.. :\
can any1 make his own code to stuck Minesweeper's flags and upload here so i could figure out what is wrong with what i'm doing?

_________________
Stylo
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Sep 17, 2008 11:34 am    Post subject: Reply with quote

slovach wrote:
You're creating a thread for yourself, not within the other process


He's changed it to a DLL now.
Back to top
View user's profile Send private message MSN Messenger
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Wed Sep 17, 2008 11:51 am    Post subject: Reply with quote

DllMain should return TRUE unless it fails to load.
In your case, I'd suggest the following:
Code:
BOOL WINAPI DllMain (HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
   if (dwReason == DLL_PROCESS_ATTACH)
        return CreateThread(0,0,(LPTHREAD_START_ROUTINE)&Hacking,0,0,0);
   return TRUE;
}

Also note:
  • Your new thread should be declared as stdcall, or should call ExitThread by itself.
  • Hack() doesn't have to be naked, it's usually used for hooks etc'

Another usefull api you could use is FreeLibraryAndExitThread():
Code:
__declspec(naked) void Hack()
{
   ...
}

void Hacking(HMODULE hModule)
{
   if (VirtualProtect((LPVOID)Address,6,PAGE_EXECUTE_READWRITE,0))
     Hack();
   FreeLibraryAndExitThread(hModule,0)
}

BOOL WINAPI DllMain (HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
   ...
}
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Sep 17, 2008 12:52 pm    Post subject: Reply with quote

i think something wrong with my virtualprotect cuz it fail all the time changing the memory protection to execute_readwrite
_________________
Stylo
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Wed Sep 17, 2008 2:03 pm    Post subject: Reply with quote

1qaz wrote:
i think something wrong with my virtualprotect cuz it fail all the time changing the memory protection to execute_readwrite


Im pretty sure you need to hook hop it.

Code:
//VProtect Bypass
static const FARPROC Vprotect = (FARPROC)((DWORD)GetProcAddress(GetModuleHandleA("kernel32.dll"), "VirtualProtectEx")+5);
_declspec(naked) BOOL WINAPI FixMem(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect)
{
   _asm
   {
      mov edi,edi
      push ebp
      mov ebp,esp
      jmp Vprotect
   }
}

_________________
Back to top
View user's profile Send private message Send e-mail
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, 3  Next
Page 2 of 3

 
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