Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Access Violation if Kernel Function is called

 
Post new topic   Reply to topic Printable version
 View previous topic  Miney Post :: Post Unknown but banned?  View next topic  
Author Message
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Thu Apr 29, 2004 11:25 am   Post maybe stupid    Post subject: Access Violation if Kernel Function is called Reply to topic Reply with quote

If I call kernel functions like "RtlMoveMemory" I get "access violation" error message and my self-written Subspace client gets terminated.
Code: Show/Hide

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
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Thu Apr 29, 2004 11:58 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Cyclovenom told me to move the ByVal keywords to the output. I'll try it without. Seems to work! Thanks!
Back to top
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Thu Apr 29, 2004 3:31 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
nintendo64
Seasoned Helper


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 104
Location: Dominican Republic
Offline

PostPosted: Thu Apr 29, 2004 4:43 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Thu Apr 29, 2004 5:05 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Fri Apr 30, 2004 8:39 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Fri Apr 30, 2004 8:48 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
nintendo64
Seasoned Helper


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 104
Location: Dominican Republic
Offline

PostPosted: Fri Apr 30, 2004 10:38 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Fri Apr 30, 2004 10:41 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Can we keep the cursing to a minimum? Also, General Questions are for Server related questions.

-nintendo64
Back to top
View users profile Send private message Add User to Ignore List Send email
nintendo64
Seasoned Helper


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 104
Location: Dominican Republic
Offline

PostPosted: Fri Apr 30, 2004 10:49 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Mine GO BOOM wrote:
Can we keep the cursing to a minimum? Also, General Questions are for Server related questions.

-nintendo64


not again.... tongue.gif

-nintendo64
Back to top
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Fri Apr 30, 2004 12:16 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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. biggrin.gif
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
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Apr 30, 2004 3:00 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Fri Apr 30, 2004 4:15 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Apr 30, 2004 4:33 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Sat May 01, 2004 1:24 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

That code awfully looks Visual Basic-ish :/
_________________
Performance is often the art of cheating carefully. - James Gosling
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat May 01, 2004 10:26 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
nintendo64
Seasoned Helper


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 104
Location: Dominican Republic
Offline

PostPosted: Sat May 01, 2004 12:32 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Qndre
Server Help Squatter


Gender:Gender:Male
Joined: Jan 25 2004
Posts: 295
Offline

PostPosted: Sat May 01, 2004 12:39 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sun May 02, 2004 10:21 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 11 page(s) served in previous 5 minutes.

phpBB Created this page in 0.673774 seconds : 43 queries executed (82.1%): GZIP compression disabled