Author |
Message |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Thu Apr 29, 2004 11:25 am Post maybe stupid Post subject: Access Violation if Kernel Function is called |
 |
|
|
|
If I call kernel functions like "RtlMoveMemory" I get "access violation" error message and my self-written Subspace client gets terminated.
Option Explicit
'[..]
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"_
(Dest As Any, Src As Any, ByVal cb&)
'[..]
Public Function StringToLong(data As String) As Long
Dim output As Long
Call CopyMemory(output, ByVal data, 4)
StringToLong = output
End Function
Public Function LongToString(data As Long) As String
Dim output As String * 4
Call CopyMemory(output, ByVal data, 4)
LongToString = output
End Function
Public Function StringToInteger(data As String) As Integer
Dim output As Integer
Call CopyMemory(output, ByVal data, 2)
StringToInteger = output
End Function
Public Function IntegerToString(data As Integer) As String
Dim output As String * 2
Call CopyMemory(output, ByVal data, 2)
IntegerToString = output
End Function
|
You know where the mistake is? |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Thu Apr 29, 2004 11:58 am Post maybe stupid Post subject: |
 |
|
|
|
Cyclovenom told me to move the ByVal keywords to the output. I'll try it without. Seems to work! Thanks! |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Thu Apr 29, 2004 3:31 pm Post maybe stupid Post subject: |
 |
|
|
|
No! No! No! No! No! Doesn't work! It doesn't give an error but correct conversion is impossible with the function. I see it because encryption is initialized with a wrong key (server disconnects then). Since nothing else changed this can be the only source for the mistake.
_
If you copy something with RtlMoveMemory you get back something completely different than given! This kernel function is the source of the error! It sucks! Development is impossible with such a buggy kernel! It can't even convert Longs to Strings and Strings To Longs. If you convert a 4-byte String to a Long (at example "test") and back, it isn't "test" any more but some binary information. |
|
Back to top |
|
 |
nintendo64 Seasoned Helper

Age:39 Gender: Joined: Dec 01 2002 Posts: 104 Location: Dominican Republic Offline
|
Posted: Thu Apr 29, 2004 4:43 pm Post maybe stupid Post subject: |
 |
|
|
|
I don't know what you are exactly doing but for info.
The MoveMemory function moves a block of memory from one location to another.
VOID MoveMemory (
PVOID Destination, // address of move destination
CONST VOID *Source, // address of block to move
DWORD Length // size, in bytes, of block to move
);
Parameters
Destination
Points to the starting address of the destination of the move.
Source
Points to the starting address of the block of memory to move.
Length
Specifies the size, in bytes, of the block of memory to move.
Return Values
This function has no return value.
Remarks
The source and destination blocks may overlap.
The only use for those functions is to put datatypes that are 4 bytes or 2 bytes in little endian byte order.
Example:
http://www.madsci.org/posts/archives/dec96/843185920.Cs.r.html
In each case, the number being represented by the two 32-bit words is "1".
BIG-ENDIAN BYTE ORDER
---------------------
Most Significant Byte Least Significant Byte
vvvvvvv vvvvvvv
+-------+-------+-------+-------+
|byte 0 |byte 1 |byte 2 |byte 3 | "address"
+-------+-------+-------+-------+
| 0 | 0 | 0 | 1 | "value"
+-------+-------+-------+-------+
LITTLE-ENDIAN BYTE ORDER
---------------------
Least Significant Byte Most Significant Byte
vvvvvvv vvvvvvv
+-------+-------+-------+-------+
|byte 0 |byte 1 |byte 2 |byte 3 | "address"
+-------+-------+-------+-------+
| 1 | 0 | 0 | 0 | "value"
+-------+-------+-------+-------+
-nintendo64 |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Thu Apr 29, 2004 5:05 pm Post maybe stupid Post subject: |
 |
|
|
|
Qndre, stop playing trial and error with programming. It's clear you don't have a clue about BASIC or how software works or Ekted's "Level One Knowledge". You are like a child playing with a control system at a nuclear power plant. _________________ 4,691 irradiated haggis! |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Fri Apr 30, 2004 8:39 am Post maybe stupid Post subject: |
 |
|
|
|
ByVal means that the value is protected in-memory and cannot be modified, so it can't work if you set the output as a ByVal. You set the ByVal keyword in front of a paremeter variable if you want to prevent the called function from modifying it's contents. Since I set the output as a ByVal, it can't be modified by the kernel so it doesn't work! I won't set any of the parameters for the CopyMemory function as a ByVal, so they aren't protected in-memory from being changed.
Mr Ekted wrote: | It's clear you don't have a clue about BASIC or how software works |
I don't know anything about C, I don't know anything about ASM but I'm nearly perfect in BASIC so stop telling such a fuck! |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Fri Apr 30, 2004 8:48 am Post maybe stupid Post subject: |
 |
|
|
|
If I permit the kernel function to modify the output, I get an access violation! If I don't permit the kernel function to modify the output, I can never get the correct value in the output! That's typically M$ - it sucks!
_
PS: Don't say that I don't know programming! It's a mistake in the Windows kernel which makes this error occour! And it is a known problem! Quote from another forum, posted by someone else:
Someone else wrote: |
I use API-function RtlMoveMemory to create the binarysting to be sent over.
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" ( hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
This is ok at the client side. The server on the other hand does not handle the this correctly. When parsing the string using rtlMoveMemory the server crashes... or give fuzzy results (VB just quits with errors!!??)
It seems to me that RtlMoveMemory tries to read a memoryblock that is not readable (because of the General Protection Fault???).
|
And some posts later...
Someone else wrote: |
Well, I have messed up my project, because I could not find any solution to get things working...
|
So you know it's not directly my fault (but it's my fault that I use fucking VB programming language)!
_
The only way around this problem I see is learning Assembler ... another way doesn't seem to exist! |
|
Back to top |
|
 |
nintendo64 Seasoned Helper

Age:39 Gender: Joined: Dec 01 2002 Posts: 104 Location: Dominican Republic Offline
|
Posted: Fri Apr 30, 2004 10:38 am Post maybe stupid Post subject: |
 |
|
|
|
Let me explain how it works and why ByVal is in the correct place, and the Access Violation.
Well Visual Basic when it uses external functions like this uses as a parameter a Pointer for the strings, because that's the parameter asked for the function in this case.
so for a example, as you can see ByVal needs to protect the value of the pointer so it doesn't get changed along the way. If it gets changed NOT USING BYVAL then it will return an access violation, you are altering the memory address of the string. Sometimes it just won't work.
ByVal should only be located where the strings are, this is to allow the transfer of the bytes between both datatypes.
Private Function LongToString(L As Long) As String
Dim S4 As String
S4 = Space(4)
Call CopyMemoryX(ByVal S4, L, 4)
LongToString = S4
End Function
So you see Qndre use a ByVal where it has to be used. In this case it was the strings. Both LongToString, etc... and LongToString... have the use of ByVal with the string.
I wouldn't say the problem is VB, it's a human mistake, althought VB is indeed a problem most of the times, as any language that is so high level.
If you handle things at the low level, or at least use a high level language that enables you to declare your own pointers, you might have more understanding. Certaintly VB could cause some of the errors, but in the functions you need i don't see why, try what i said.
-nintendo64
Last edited by nintendo64 on Fri Apr 30, 2004 10:48 am, edited 1 time in total |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Fri Apr 30, 2004 10:41 am Post maybe stupid Post subject: |
 |
|
|
|
Can we keep the cursing to a minimum? Also, General Questions are for Server related questions.
-nintendo64 |
|
Back to top |
|
 |
nintendo64 Seasoned Helper

Age:39 Gender: Joined: Dec 01 2002 Posts: 104 Location: Dominican Republic Offline
|
Posted: Fri Apr 30, 2004 10:49 am Post maybe stupid Post subject: |
 |
|
|
|
Mine GO BOOM wrote: | Can we keep the cursing to a minimum? Also, General Questions are for Server related questions.
-nintendo64 |
not again....
-nintendo64 |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Fri Apr 30, 2004 12:16 pm Post maybe stupid Post subject: |
 |
|
|
|
nintendo64 wrote: | [..]
I wouldn't say the problem is VB, it's a human mistake, althought VB is indeed a problem most of the times, as any language that is so high level.
If you handle things at the low level, or at least use a high level language that enables you to declare your own pointers, you might have more understanding. Certaintly VB could cause some of the errors, but in the functions you need i don't see why, try what i said.
-nintendo64 |
Yes, it is. You need to know about some strange architectures at the machine and also at the interpreter language so that you know how to do.
So kernel did everything allright but I didn't know how to handle the kernel (didn't know too much details about it). |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Fri Apr 30, 2004 3:00 pm Post maybe stupid Post subject: |
 |
|
|
|
ByVal is not a protection mechanism. It is the newb way to say "by value" instead of "by address". In C it is done explicitly, and you can refer to data in any way you want.
int x = 7;
int *px = &x;
Function(x); // puts the value 7 on the stack
Function(&x); // puts the address of x on the stack
Function(*px); // puts the value 7 on the stack (what px is pointing at)
Function(px); // puts the address of x on the stack (also the VALUE of px)
Function(&px); // puts the address of px on the stack
Understand what's happening in memory with your data, and you will understand how to use your language.
L1K (tm) |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Fri Apr 30, 2004 4:15 pm Post maybe stupid Post subject: |
 |
|
|
|
Mr Ekted wrote: | ByVal is not a protection mechanism. It is the newb way to say "by value" instead of "by address". In C it is done explicitly, and you can refer to data in any way you want.
[..] |
Yes. There is also a ByRef keyword which means "by reference". |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Apr 30, 2004 4:33 pm Post maybe stupid Post subject: |
 |
|
|
|
Nintendo wrote: | I wouldn't say the problem is VB, it's a human mistake, althought VB is indeed a problem most of the times, as any language that is so high level. |
He's using straight BASIC, which is not quite so high level. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Sat May 01, 2004 1:24 am Post maybe stupid Post subject: |
 |
|
|
|
That code awfully looks Visual Basic-ish :/ _________________ Performance is often the art of cheating carefully. - James Gosling |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sat May 01, 2004 10:26 am Post maybe stupid Post subject: |
 |
|
|
|
Acutally, you're right Cyph, maybe Qndre's switched to a higher level language now.
Anyway, if your functions are named correctly, you're trying to convert an ASCII string to an integer? Like "4800" to 0x12C0? If so, then you don't need to copy memory. If you are actually using VisualBasic now, there are the functions CInt() and CLng() that will convert from a string to an integer and long. The = operator will convert from an integer or long to a string for you. |
|
Back to top |
|
 |
nintendo64 Seasoned Helper

Age:39 Gender: Joined: Dec 01 2002 Posts: 104 Location: Dominican Republic Offline
|
Posted: Sat May 01, 2004 12:32 pm Post maybe stupid Post subject: |
 |
|
|
|
Cyan~Fire wrote: | Acutally, you're right Cyph, maybe Qndre's switched to a higher level language now.
Anyway, if your functions are named correctly, you're trying to convert an ASCII string to an integer? Like "4800" to 0x12C0? If so, then you don't need to copy memory. If you are actually using VisualBasic now, there are the functions CInt() and CLng() that will convert from a string to an integer and long. The = operator will convert from an integer or long to a string for you. |
Those functions weren't made for the same purpose as CInt, CLng, CStr, CDate, and the rest of them. As it was stated on a previous reply by me. If Qndre is using them for that, he should stop and start using other functions.
-nintendo64 |
|
Back to top |
|
 |
Qndre Server Help Squatter

Gender: Joined: Jan 25 2004 Posts: 295 Offline
|
Posted: Sat May 01, 2004 12:39 pm Post maybe stupid Post subject: |
 |
|
|
|
CInt and CLng, etc. do something completely else. At example if you convert the number 123 to a string you have "123" and not the character 123. You can't use Chr and Asc either because Chr only works for Bytes and not for Longs. But this conversion works, but Sasme crashes my client ATM. Need to debug and fix several errors, the client ist still very buggy. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sun May 02, 2004 10:21 am Post maybe stupid Post subject: |
 |
|
|
|
Oh, OK, I think I kind of understand what you're doing right now.
I'm not quite sure how a String is implemented by VB. I somehow think that the String reference will not be the start of the actual ASCII string and you'll be getting a bunch of meaningless data instead. Wouldn't reading into a byte array be better for this purpose?
This would all be so easy in C++... |
|
Back to top |
|
 |
|