• Welcome to Valhalla Legends Archive.
 

Modified copymemory for pointers

Started by brew, April 12, 2007, 06:19 PM

Previous topic - Next topic

brew

Quote from: Joex86] link=topic=16610.msg168333#msg168333 date=1177434740]
Quote from: l2k-Shadow on April 23, 2007, 05:46 PM
how the fuck can the compiler know that you're not passing the correct amount of variables to a function located outside the program defined by the user?

The same would happen in C++ if the function wasn't defined in windows.h

I hope you know that you just reiterated exactly what I said. :)

Acually, he asked "how the hell could one would possibly expect a compiler to catch something like that?" the same would happen in ANY language. Compilers nowadays are plenty intelligent-- A program is only as intelligent as it's creator made it, not limited to the ide/compiler for a language. For example, say if you were trying to pass the value of 10.0 in an integer variable by pointers. C++, for example, is intelligent enough to demote the value of 10.0 to an integer before it even attempts to pull that off. Sheesh, you don't give modern compilers enough credit. You don't even have to define ANY variables in visual basic, for fucks sake. By the way, what you said about arguments was a retarded example, but I get what you ment.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Joe[x86]

Visual Basic simply declares it in the back of it's mind as a Variant.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

brew

It's still pretty damn smart. Think of C++, where it flips out if you don't delcare something
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

MyndFyre

Quote from: brew on April 24, 2007, 08:41 PM
It's still pretty damn smart. Think of C++, where it flips out if you don't delcare something
You mean, to help enforce code maintainability and efficiency?  Oh noes!
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

So, like, why hasn't anyone bitched him out yet for trying to copy x amount of data into a y sized buffer with no bounds checks? Last time I checked, we've been trying to get rid of these sort of bugs for oh...I don't know...thirty years? One of the reasons people use VB is to stay AWAY from pointers: they're dangerous.

Hint: Put "ByRef" in front of one of your string arguments and assign to it and see what happens.

brew

#36
Quote from: Banana fanna fo fanna on April 25, 2007, 09:08 AM
So, like, why hasn't anyone bitched him out yet for trying to copy x amount of data into a y sized buffer with no bounds checks? Last time I checked, we've been trying to get rid of these sort of bugs for oh...I don't know...thirty years? One of the reasons people use VB is to stay AWAY from pointers: they're dangerous.

Hint: Put "ByRef" in front of one of your string arguments and assign to it and see what happens.
Did you see the original copymemory api with modified arguments? It's source is ByVal for a reason.

Edit***
On another note, I tried out the function that I came up with to extract the value of a string variable from a pointer. It works fine when in vb6, but when compiled, it crashes. Any ideas? And it totally doesn't work when you put in any value lower then the pointer's value for the source, I was going to try to make a quick program to read the first MB of memory. Crashed faster then a 95 yr old woman on the highway :/ Any ideas on how to do this properly?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Banana fanna fo fanna

Quote from: brew on April 18, 2007, 08:36 PM
I can already pretty much do this with non-array variables, using pointers. Which by the way was the reason I started getting interested with VB pointers. Say if I was making a program which used many databases, and they were all loaded into memory. I would have to make an entirely different subroutine for each database I wish to load, and this redundant code can consiterably lower performance. For instance....

Public Crap As String

Private Sub Form_Load()
LoadGeneric "crap.txt", VarPtr(Crap)
... so on, maybe, in different areas of the program

Public Sub LoadGeneric(strFilename As String, lngPtr As Long)
   Dim lngVarLen&
   Open App.Path & "\" & strFilename For Binary Access Read As #1
   blah blah blah.....
   CopyMemoryRead lngVarLen, (lngPtr - 4), 4
   CopyMemoryRead lngPtr, LoadedString, lngVarLen
End Sub

Heh.


Could be accomplished by using ByRef. I know what ByVal and ByRef means, brew.

brew

ohhhhhhhhhh shit, hahahahaha omg bannana that made me feel like a total idiot. this entire thing was useless. I thought you ment adding a byref in one of the arguments in Copymemory, sorry I wasn't reading your post correctly. i can't believe i didn't think of that.....
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

|