It is currently Mon Nov 19, 2018 4:01 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Thu Aug 11, 2005 3:50 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
well to call procedures/functions using CALL, you PUSH the parameters to the stack!

basically the api's are called from dll's as user32.dll and kernel32.dll.

so this can be used for all dll's, and the kernel/windows dll's that is holding the api functions too.!

The reason [afaik] killswitch wanted to know how to do it using winapi is, that he is programming an scripting language, and as a good programmer he doesnt just wrap the pb functions for calling dll's.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 3:56 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
Quote:
like:
Code:
variableone=0
variabletwo=292991

variableone=variabletwo

Where is the memory reserving there?

Easy, as soon as you use a var its defaulted to a long (4 bytes). in this case 4 bytes are allocated to store the integers in both vars.

in this code:
Code:
  GetCurrentDirectory=GetProcAddress_(module,"GetCurrentDirectoryA")
  size.l=512
  CurDir.l= 0
  ptrDir.l = @CurDir
 
  !PUSH [v_ptrDir]
  !PUSH [v_size]
  !CALL [v_GetCurrentDirectory]

  Debug PeekS(@CurDir)

My confusion:
1). CurDir.l is a long.
2). ptrDir.l is a long holding the pointer to the long contained in CurDir.
3). No memory allocation for the string is taking place.
4). After the procedure call the string is stuffed into the memory pointed to by ptrDir overwriting the long contained in CurDir?
5). CurDir now holds a string and im thinking an overflow has occured?
6). Confused. :?

I dont suppose anyone wants to treat me like a child and give me a break down of what going on? :oops:

_________________
--Kale

Image


Last edited by Kale on Thu Aug 11, 2005 4:00 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 3:58 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
NO!
curdir now holds an array of chars in decimal value! its STILL not a string.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:03 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
thefool wrote:
NO!
curdir now holds an array of chars in decimal value! its STILL not a string.

surely thats still alot of data in just 32 bits? Have you any links to internet articles or tutorials describing decimal char arrays? just never heard of that before. :)

_________________
--Kale

Image


Last edited by Kale on Thu Aug 11, 2005 4:05 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:04 pm 
Offline
Moderator
Moderator

Joined: Sat Dec 27, 2003 3:55 am
Posts: 3321
Location: Great Southern Land
Kale, I think this is the same as or something like:
Code:
GetCurrentDirectoryA(ptrDir,Size)

(Maybe the pars are wrong way round, I didn't check)
But I think this returns the address of the string into the area pointed to by ptrDir.

PtrDir has the address of curDir. The function uses this address as the place where it will store the address of the string.

But ...
... don't quote me. :)

_________________
@}--`--,-- A rose by any other name ..


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:07 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
well in assembler:

Code:
DB 'b','l','a'

or something like that will store ascii values in hex for those 3 chars.
a string is simply just a ROW of hex chars, wich can be in decimal too.
string arrays are a common thing. just read every beginners assembly tutorial!

Quote:
string, quoted string
Text enclosed in apostrophes is called "string". In general, "string" is array of characters. Term used for string inside source code is called "quoted string".

[url]
http://www.decard.net/article.php?body=tajga&chapter=01[/url]

However for storing a lot of data like that, i dunno how he does that.

@dare2: i doubt that it simply holds a string, as he is peeking directly at curDir [the @] not at what adress it is holding.


Last edited by thefool on Thu Aug 11, 2005 4:09 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:08 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
i always thought in:
Code:
GetCurrentDirectoryA(ptrDir,Size)

ptrDir is a long pointer to a zero terminated string.

_________________
--Kale

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:09 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
not afaik. read my previous post!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:13 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
Yep seen that and understand about storing chars as hex, but this:
Code:
DB 'b','l','a'

would store 3 bytes in ascii

in the example which im having trouble with:
Code:
CurDir.l= 0

is somehow capable of holding up to 511 chars! :shock:

_________________
--Kale

Image


Last edited by Kale on Thu Aug 11, 2005 4:22 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:15 pm 
Offline
Moderator
Moderator

Joined: Sat Dec 27, 2003 3:55 am
Posts: 3321
Location: Great Southern Land
SDK wrote:
GetCurrentDirectory

The GetCurrentDirectory function retrieves the current directory for the current process.


DWORD GetCurrentDirectory(
DWORD nBufferLength,
LPTSTR lpBuffer
);

Parameters
nBufferLength
[in] Length of the buffer for the current directory string, in TCHARs. The buffer length must include room for a terminating null character.
lpBuffer
[out] Pointer to the buffer that receives the current directory string. This null-terminated string specifies the absolute path to the current directory.
To determine the required buffer size, set this parameter to NULL and the nBufferLength parameter to 0.

I read that as being the 2nd par (I did have them wrong way round) receives the address of a buffer. But I guess it could mean it is the address of the buffer.

lol.

Edit:
thefool wrote:
@dare2: i doubt that it simply holds a string, as he is peeking directly at curDir [the @] not at what adress it is holding.


But then don't we end up with the question of where or how the space was safely allocated for >4 bytes of string data?


Paul is probably going to laugh his elbow off when he reads all this stuff.

_________________
@}--`--,-- A rose by any other name ..


Last edited by Dare2 on Thu Aug 11, 2005 4:23 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:22 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
i read it as the parameter gets the adress of a buffer wich gets feeded with the info.


@kale: what is the difference? it doesnt! the Assembler will make them into hex chars in the produced file. the ascii VALUES gets written in the file.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:24 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
thefool wrote:
i read it as the parameter gets the adress of a buffer wich gets feeded with the info.

correct! :)
Quote:
@kale: what is the difference? it doesnt! the Assembler will make them into hex chars in the produced file. the ascii VALUES gets written in the file.

Code:
  GetCurrentDirectory=GetProcAddress_(module,"GetCurrentDirectoryA")
  size.l=512
  CurDir.l= 0
  ptrDir.l = @CurDir
 
  !PUSH [v_ptrDir]
  !PUSH [v_size]
  !CALL [v_GetCurrentDirectory]

  Debug PeekS(@CurDir)

in the procedure call the argument being passed is a pointer to a long and not a pointer to a string buffer, thats my confusion.

_________________
--Kale

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:26 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
the ascii chars just gets feeded to the long. however how the long can hold so much info i dunno.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:46 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
thefool wrote:
the ascii chars just gets feeded to the long. however how the long can hold so much info i dunno.

Which leads me to believe a buffer overflow is taking place. :wink:

_________________
--Kale

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 11, 2005 4:58 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
probably. but is that really a good thing here? i mean, sometimes it is used wisely, sometimes not :shock:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye