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 


Direct Memory Access [Pointers]

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

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sat Jan 10, 2009 10:00 am    Post subject: Direct Memory Access [Pointers] Reply with quote

I was wondering how i ould get the address the pointer is pointing to.

Code:
long newaha = (long)StrToInt( Edit2 -> Text );
short OffSet = (short)StrToInt( Edit3 -> Text );
int BaseAddress = *(ULONG*)newaha;
DWORD NewOne = *(ULONG_PTR*)&BaseAddress+OffSet;


That's my code, but i always get an exception before it continues.
I found out the error is at the last 2 lines. Maybe im not typecasting correctly?
Any help will be appreciated
Back to top
View user's profile Send private message AIM Address MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Sat Jan 10, 2009 10:43 am    Post subject: Reply with quote

Change &BaseAddress to BaseAddress.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Jan 10, 2009 10:43 am    Post subject: Re: Direct Memory Access [Pointers] Reply with quote

slippppppppp wrote:
I was wondering how i ould get the address the pointer is pointing to.

Code:
long newaha = (long)StrToInt( Edit2 -> Text );
short OffSet = (short)StrToInt( Edit3 -> Text );
int BaseAddress = *(ULONG*)newaha;
DWORD NewOne = *(ULONG_PTR*)&BaseAddress+OffSet;


That's my code, but i always get an exception before it continues.
I found out the error is at the last 2 lines. Maybe im not typecasting correctly?
Any help will be appreciated

Why do you do &BaseAddress? Since that gives you the address of BaseAddress in your application's memory.
EDIT: Zand was a few seconds faster ;P

I think you want to do:
Code:

DWORD BaseAddress = newaha;
DWORD NewAddress = ( (*BaseAddress) + Offset );
DWORD NewValue = *NewAddress;
Back to top
View user's profile Send private message
ElectroFusion
Grandmaster Cheater
Reputation: 0

Joined: 17 Dec 2006
Posts: 786

PostPosted: Sat Jan 10, 2009 11:00 am    Post subject: Re: Direct Memory Access [Pointers] Reply with quote

slippppppppp wrote:
I was wondering how i ould get the address the pointer is pointing to.

Code:
long newaha = (long)StrToInt( Edit2 -> Text );
short OffSet = (short)StrToInt( Edit3 -> Text );
int BaseAddress = *(ULONG*)newaha;
DWORD NewOne = *(ULONG_PTR*)&BaseAddress+OffSet;


That's my code, but i always get an exception before it continues.
I found out the error is at the last 2 lines. Maybe im not typecasting correctly?
Any help will be appreciated


Probably because of newaha, all I can guess.

_________________
qwerty147 wrote:

ghostonline wrote:

what world are you in?

bera

but i live in NZ
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sat Jan 10, 2009 11:05 am    Post subject: Reply with quote

zand, even though i do that, i get an error
Back to top
View user's profile Send private message AIM Address MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Sat Jan 10, 2009 11:42 am    Post subject: Reply with quote

Try converting from hex to dec before storing the edit box value.
_________________
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sun Jan 11, 2009 5:00 am    Post subject: Reply with quote

wtf is stingtoint?
use atol.. makes for easy usage;)
Code:

ULONG Base = atol( Edit2 -> Text );
ULONG OffSet = atol( Edit3 -> Text );
ULONG BaseAddress = (ULONG)(Base+OffSet);

if its a pointer dont forget to read the pointer first then add offset o_0
- 0-
0 0
Code:

ULONG CalcTargetAddress(HANDLE hProc,char* InputBase,char*InputOffset,bool IsPointer)
{
       ULONG Pointer;
       SIZE_T bOut;
       ULONG Base = atol(InputBase);
       ULONG Offset = atol(InputOffset);
       if(IsPointer)
       {
            if(ReadProcessMemory(hProc,Base,&Pointer,sizeof(ULONG),&bOut)
            {
                  return (ULONG)(Pointer+Offset);
            }
       }
       else
       {
            return (ULONG)(Base+Offset);
       }
}
Back to top
View user's profile Send private message MSN Messenger
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sun Jan 11, 2009 9:02 am    Post subject: Reply with quote

Thats why u use asm.
_asm{
push eax
mov eax,[value]
mov eax,[eax+offset]
mov eax,[eax+offset]
mov [value],eax
pop eax
}

I think. I might have made a mistake cause I wrote this in like 5 secs I gtg.
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sun Jan 11, 2009 11:07 am    Post subject: Reply with quote

BanMe wrote:
wtf is stingtoint?
use atol.. makes for easy usage;)
Code:

ULONG Base = atol( Edit2 -> Text );
ULONG OffSet = atol( Edit3 -> Text );
ULONG BaseAddress = (ULONG)(Base+OffSet);

if its a pointer dont forget to read the pointer first then add offset o_0
- 0-
0 0
Code:

ULONG CalcTargetAddress(HANDLE hProc,char* InputBase,char*InputOffset,bool IsPointer)
{
       ULONG Pointer;
       SIZE_T bOut;
       ULONG Base = atol(InputBase);
       ULONG Offset = atol(InputOffset);
       if(IsPointer)
       {
            if(ReadProcessMemory(hProc,Base,&Pointer,sizeof(ULONG),&bOut)
            {
                  return (ULONG)(Pointer+Offset);
            }
       }
       else
       {
            return (ULONG)(Base+Offset);
       }
}


He's using Borland C++, they have a StringToInt(); that, well... converts string to int.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Jan 11, 2009 11:28 am    Post subject: Reply with quote

dnsi0 wrote:
Thats why u use asm.
_asm{
push eax
mov eax,[value]
mov eax,[eax+offset]
mov eax,[eax+offset]
mov [value],eax
pop eax
}

I think. I might have made a mistake cause I wrote this in like 5 secs I gtg.


Code:

mov eax,[value]
lea eax,[eax + offset]     ;eax now holds what the pointer was pointing at
mov eax,[eax]               ;eax now holds the value
mov [value],eax

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sun Jan 11, 2009 1:30 pm    Post subject: Reply with quote

lol
this function assumes we are already in target process( a stipulation no one mentioned)...
Code:

ULONG CalcTargetAddress(char* InputBase,char*InputOffset,bool IsPointer)
{
       ULONG Pointer;
       SIZE_T bOut;
       ULONG Base = atol(InputBase);
       ULONG Offset = atol(InputOffset);
       if(IsPointer)
       {
            if(Base)
            { 
                  Pointer = *(ULONG*)Base;
                  return (ULONG)(Pointer+Offset);
            }
            return 0;
       }
       else
       {
            return (ULONG)(Base+Offset);
       }
}
Back to top
View user's profile Send private message MSN Messenger
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sun Jan 11, 2009 1:49 pm    Post subject: Reply with quote

I still think asm would be faster...

and u need the push and pop or else it would really screw up your values and possibly your stack.
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Jan 11, 2009 2:04 pm    Post subject: Reply with quote

dnsi0 wrote:
I still think asm would be faster...

and u need the push and pop or else it would really screw up your values and possibly your stack.


oh yes, screw up your stack. are you kidding me ?
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sun Jan 11, 2009 3:53 pm    Post subject: lets analyze it and find out what is faster o0 Reply with quote

lets see 3 lines of asm to do equivelent in C++ in 1 line...

next up mine compiled...(from above)
Code:

10002F70 > . 55             PUSH EBP
10002F71   . 8BEC           MOV EBP,ESP
10002F73   . 83EC 10        SUB ESP,10
10002F76   . 8B45 08        MOV EAX,DWORD PTR SS:[EBP+8]
10002F79   . 50             PUSH EAX                                 ; /s
10002F7A   . FF15 38400010  CALL DWORD PTR DS:[<&MSVCR80.atol>]      ; \atol
10002F80   . 83C4 04        ADD ESP,4
10002F83   . 8945 F4        MOV DWORD PTR SS:[EBP-C],EAX
10002F86   . 8B4D 0C        MOV ECX,DWORD PTR SS:[EBP+C]
10002F89   . 51             PUSH ECX                                 ; /s
10002F8A   . FF15 38400010  CALL DWORD PTR DS:[<&MSVCR80.atol>]      ; \atol
10002F90 > . 83C4 04        ADD ESP,4
10002F93   . 8945 FC        MOV DWORD PTR SS:[EBP-4],EAX
10002F96   . 0FB655 10      MOVZX EDX,BYTE PTR SS:[EBP+10]
10002F9A   . 85D2           TEST EDX,EDX
10002F9C   . 74 1C          JE SHORT FnLen32.10002FBA
10002F9E   . 837D F4 00     CMP DWORD PTR SS:[EBP-C],0
10002FA2   . 74 10          JE SHORT FnLen32.10002FB4
10002FA4   . 8B45 F4        MOV EAX,DWORD PTR SS:[EBP-C]
10002FA7   . 8B08           MOV ECX,DWORD PTR DS:[EAX]
10002FA9   . 894D F8        MOV DWORD PTR SS:[EBP-8],ECX
10002FAC   . 8B45 F8        MOV EAX,DWORD PTR SS:[EBP-8]
10002FAF   . 0345 FC        ADD EAX,DWORD PTR SS:[EBP-4]
10002FB2   . EB 0C          JMP SHORT FnLen32.10002FC0
10002FB4   > 33C0           XOR EAX,EAX
10002FB6   . EB 08          JMP SHORT FnLen32.10002FC0
10002FB8   . EB 06          JMP SHORT FnLen32.10002FC0
10002FBA   > 8B45 F4        MOV EAX,DWORD PTR SS:[EBP-C]
10002FBD   . 0345 FC        ADD EAX,DWORD PTR SS:[EBP-4]
10002FC0   > 8BE5           MOV ESP,EBP
10002FC2   . 5D             POP EBP
10002FC3   . C2 0C00        RETN 0C


to do something similiar from asm would greatly reduce the over size but what exactly are you cutting off?(cutting off error detection?cutting of parameter checking?what?) now that exact same funtion written in asm (using not a function this time but a real working Program..)

Code:

    .486                    ; set processor model
    .model flat, stdcall    ; default STDCALL calling convention
    option casemap :none    ; always use the case sensitive option

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\macros\macros.asm

    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
   
CalcPointerAddress proc STDCALL Base:DWORD, Offset:DWORD, IsPointer:DWORD
      push edx
      mov eax,Base
      push eax
      call atol
      push eax
      mov eax,Offset
      push eax
      call atol
      push eax
      pop ecx//offset
      pop edx//base
      cmp IsPointer,0
      je IsNotPointer
      mov eax,[edx]
      add eax,ecx
      pop edx
      ret
IsNotPointer:
      add edx,ecx
      mov eax, edx
      pop edx
      ret
CalcPointerAddress endp

start:
    invoke CalcPointerAddress,00400000,0,0
    sub esp,020h
    mov ecx,esp
    invoke itoa,eax,ecx,16
    invoke printf,"%#x",ecx
    invoke sleep,50000
    ret


so hmm i can write a faster smaller asm function, but it isnt as good.. Smile

regards BanMe
Back to top
View user's profile Send private message MSN Messenger
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sun Jan 11, 2009 7:50 pm    Post subject: Reply with quote

Guy's i already fixed it. It was a stupid error Embarassed
Back to top
View user's profile Send private message AIM Address MSN Messenger
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