UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
December
Su M Tu W Th F Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Sponsored Links
Latest Postings
Latest Reviews
Topic Options
Rate This Topic
#17858 - 01/12/03 12:23 PM Crash Course in VB memory hacks and strings
SilentRage Offline
DollarDNS Owner

Registered: 03/04/02
Posts: 1273
Loc: OH, USA
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.

Strings

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
http://www.dollardns.net

Top
Sponsored Links
      
#17859 - 01/24/03 02:37 AM Re: Crash Course in VB memory hacks and strings
ninjaneo Offline
UGN Security Staff

Registered: 03/06/02
Posts: 256
Loc: CA, USA
thanks SR, what I was looking for

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

Top
#17860 - 02/19/03 08:58 AM Re: Crash Course in VB memory hacks and strings
psychogen Offline
Member

Registered: 03/02/02
Posts: 257
Loc: UK
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)

Top

Featured Member
Registered: 02/28/02
Posts: 7193
Forum Stats
2152 Members
46 Forums
36187 Topics
71357 Posts

Max Online: 1567 @ 04/25/10 05:20 AM
Top Posters
UGN Security 29348
Gremelin 7193
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
cdefgh368568, HushHush, golqm, Tim050, Gecko666
2151 Registered Users
Who's Online
0 registered (), 387 Guests and 338 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!