Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CopyMemory API VB6 1

Status
Not open for further replies.

GibbsTek

Programmer
Jan 13, 2007
4
US
Hey guys. Looks like a good site, a pleasure to be here. Let me explain the problem I am having. (I have been searching daily for almost 2 weeks, no answer) I wrote a program in vb6 that set a integer to the value of 9022. This is displayed in the form and updated to make sure the value does not change. A very simple app. Now the hard part:

I found the location in memory that the value is stored in.It is in hex form. Here is what I know at this point as my app is running:

Location: 0014e618
Value: 9022
Int type 4 bytes

(not sure why it shows up as 4 bytes.. should be 2 bytes correct?)

Anywho... I code a second app that tries to change the value in memory. This is where I am stuck. I have tried to sort through API and come up with two that may work. CopyMemory and writeprocessmemory. However I cannot get either to work. 2 weeks searching daily, 2 prior forums and I havent a clue what to do. If someone could point me in the right direction that would be great!

 
What is it that you are really trying to achieve? i.e why do you want to modify this particular value from a second application?

And now some points:
1) It shows up as 4 bytes because VB integers are actually stored in memory as 4 bytes. There's a bunch of masking etc. that VB does when working with integers to make them appear as 2 bytes - which, it might surprise somne to know, results in Integer operations actually taking longer than Long operations.

2) Under the Windows multitaking OS every application runs in its own, private process space (and, further, think that they have the whole machine and therefore memory address space to themselves) to which other processes do not have access. In other words one process cannot read or write memory in another process*

3) How sure are you that the 9022 that you have found is the variable you are interested in?



* There are some techniques that provide workarounds for this, such as shared memory, but it is far from straightforward
 
I am sure the value I found is the one. I can change the value in a loop adding and subtracting 1 to the value. Thus I get 9022 then 9023 then 9022 and so on. This is how I filtered through memory and found it. I ran across a program that allowed you to edit values in memory. It is called artmoney. I love a challenge and I really want to learn about memory so making this program (if possible) would be great. :) Any information or leads would be much appreciated.

I did find this..


and in it it says this...

When the source or the destination is a memory locationyou should pass a 32-bit address by value, for example:

' Copy the contents of a Long variable to the memory location
' pointed to by the "address" variable

Dim address As Long
...
CopyMemory ByVal address, lngValue, 4


I have tried this in as many ways as possible with no luck.
 
No, and you won't have any luck. As I said, each process gets the machine to itself, with its own memory - so location 0014e618 for one process is not the same as location 0014e618 for a second process. And CopyMemory is going to be no use at all.

When I said "it is far from straightforward" perhaps I should have been more blatant - this isstuff you don't really want to be doing from VB if you can help it. But if you really want to have a go then I suggest you start by looking at VirtualAllocEx(), VirtualFreeEx(), WriteProcessMemory() and ReadProcessMemory(). You'll probably also need something like GetWindowThreadProcessId() and OpenProcess() to get hold of a process handle.

 
I see, thank you very much for your help. If I had recieved a answer like that 2 weeks ago it would have saved so much time. I will look into the other API you listed and try it. Ty again.
 
Yes, in the context of this thread I can provide a short translation: it doesn't provide access to the memory of another process or program.



 
>>There's a bunch of masking etc. that VB does when working with integers to make them appear as 2 bytes - which, it might surprise somne to know, results in Integer operations actually taking longer than Long operations.

Ahhh...
*falls surprised*

;) well, I read these forums exactly to get surprised. Thanks, Strongm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top