Your browser does not seem to support CSS. If images appear below, please disregard them.
It appears that you're running an Ad-Blocker. This site is monetized by Advertising and by ">User Donations; we ask that if you find this site helpful that you whitelist us in your Ad-Blocker, or make a ">Donation to help aid in operating costs.
Previous Thread
Next Thread
Print Thread
Rate This Thread
#17858 - 01/12/03 05:23 PM Crash Course in VB memory hacks and strings  
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage  Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
I've written a previous tutorial on memory hacking with CopyMemory, but it wasn't entirely accurate or thorough. This crash course will give you the totally accurate and thorough situation on VB strings and string arrays.

A reminder:
StrPtr function returns the pointer to the string associated with a string variable.

VarPtr function returns the pointer to the actual variable.


Memory Commentary:
A string variable stores a 4 byte pointer to the first byte of the actual string. However, before the string is a 4 byte length descripter OF the string in number of bytes. In VB strings are UNICODE and are terminated by a 2-byte null character. However, make sure to only pass strings as ByVal VarPtr for the source - cause VB has a tendancy to pass the UNICODE strings as ASCII which totally screws things up.

'The returned address is identical to StrPtr(MyString)
CopyMemory Address, ByVal VarPtr(MyString), 4

'Store the length of MyString
CopyMemory Length, ByVal StrPtr(MyString) - 4, 4

'Copy the string from MyString to the Buffer
CopyMemory Buffer, ByVal StrPtr(MyString), Length

String Arrays

Memory Commentary:
A array variable stores a 4 byte pointer to the first element of the actual array. String arrays are actually an array of 4 byte pointers which point to the actual string in each element. Before the actual array is a 4 byte length descripter of the array. So like, if an array has 3 elements, the length will be 12. Each individual element being a pointer to the string associated with that element. That string holds true to strings pointed to by normal string vars. It is preceded by a 4 byte length of the actual string.

'Store the memory location of the array
CopyMemory Address, ByVal VarPtr(MyStringArray(0)), 4

'The 4 bytes before the array is the length of the array in bytes
CopyMemory Length, ByVal Address - 4, 4

'Retrieve the address to the string in the first element
CopyMemory Address, ByVal StrPtr(MyStringArray(0)), 4

'Retrieve the length of the string in the first element
CopyMemory Length, ByVal StrPtr(MyStringArray(0)) - 4, 4

'Copy the string in the first element to a string variable
CopyMemory MyString, ByVal StrPtr(MyStringArray(0)), Length

Domain Registration, Hosting, Management
Sponsored Links
#17859 - 01/24/03 07:37 AM Re: Crash Course in VB memory hacks and strings  
Joined: Mar 2002
Posts: 256
ninjaneo Offline
UGN Security Staff
ninjaneo  Offline
UGN Security Staff

Joined: Mar 2002
Posts: 256
Likes: 1
thanks SR, what I was looking for smile

btw.. this was posted using meh port forwarde :>

#17860 - 02/19/03 01:58 PM Re: Crash Course in VB memory hacks and strings  
Joined: Mar 2002
Posts: 257
psychogen Offline
psychogen  Offline

Joined: Mar 2002
Posts: 257
nice nice :-P

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean, "Someone who loves to program and enjoys being clever about it."
"Its not a bug, its a feature" (Epic Games)

Member Spotlight
Portland, OR; USA
Posts: 7,198
Joined: February 2002
Show All Member Profiles 
Forum Statistics
Average Daily Posts3
Most Online1,567
Apr 25th, 2010
Latest Postings
There is not any party like an arm party
by bagful on 04/27/17 06:26 AM
The innovative concept keep
by bagful on 04/27/17 06:25 AM
The Nike Blazer Studio Mid Decon
by bagful on 04/27/17 06:24 AM
a fresh white enhance midsole device
by bagful on 04/27/17 06:23 AM
shopping for jewelry with something above
by mikejoey on 04/12/17 08:01 AM
PANDORA North The usa
by mikejoey on 04/12/17 07:38 AM
Pandora’s birthstone products will always
by mikejoey on 04/12/17 07:14 AM
the newest Pandora necklaces crafting facility
by mikejoey on 04/12/17 06:53 AM
an Air Jordan 4 by Off White is in
by mikejoey on 04/12/17 06:35 AM
belonging to the adidas NMD XR1
by mikejoey on 04/12/17 05:50 AM
Top Posters(All Time)
UGN Security 41,138
Gremelin 7,198
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Liked Users (All Time)
§intå× Likes: 3
Black Beard Likes: 1
Cold Sunn Likes: 1
Crime Likes: 1
Cyrez Likes: 1
fleshwound Likes: 1
Ghost Likes: 2
Gremelin Likes: 12
Ice Likes: 1
ninjaneo Likes: 1
Top Liked Users (30 Days)
No Data Found
Powered by UBB.threads™ PHP Forum Software 7.6.0
(Snapshot build 20170206)