| View previous topic :: View next topic |
| Author |
Message |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat Jan 10, 2009 10:00 am Post subject: Direct Memory Access [Pointers] |
|
|
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 |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Sat Jan 10, 2009 10:43 am Post subject: |
|
|
| Change &BaseAddress to BaseAddress.
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Sat Jan 10, 2009 10:43 am Post subject: Re: Direct Memory Access [Pointers] |
|
|
| 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 |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Sat Jan 10, 2009 11:00 am Post subject: Re: Direct Memory Access [Pointers] |
|
|
| 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 |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat Jan 10, 2009 11:05 am Post subject: |
|
|
| zand, even though i do that, i get an error
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Jan 10, 2009 11:42 am Post subject: |
|
|
Try converting from hex to dec before storing the edit box value.
_________________
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Sun Jan 11, 2009 5:00 am Post subject: |
|
|
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 |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Jan 11, 2009 9:02 am Post subject: |
|
|
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 |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Sun Jan 11, 2009 11:07 am Post subject: |
|
|
| 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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun Jan 11, 2009 11:28 am Post subject: |
|
|
| 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
|
_________________
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Sun Jan 11, 2009 1:30 pm Post subject: |
|
|
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 |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Jan 11, 2009 1:49 pm Post subject: |
|
|
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 |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sun Jan 11, 2009 2:04 pm Post subject: |
|
|
| 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 |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Sun Jan 11, 2009 3:53 pm Post subject: lets analyze it and find out what is faster o0 |
|
|
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..
regards BanMe
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sun Jan 11, 2009 7:50 pm Post subject: |
|
|
Guy's i already fixed it. It was a stupid error
|
|
| Back to top |
|
 |
|