flat assembler
Message board for the users of flat assembler.

Index > Main > Strings, Pointers, and Invoke Parameters

Author
Thread Post new topic Reply to topic
fasmnub



Joined: 26 Jan 2010
Posts: 14
fasmnub
Ok, pulling my hair out here, I only picked up fasm about a week ago so the answer is probably obvious..

I wrote a .dll to handle strings at a high level, because I'm struggling to get my head round the whole string handling thing... in this .dll I have the following functions..

AllocString(string.s) <--- takes a string as a parameter and returns it to eax, which is a bit of a cheat I know

AddString(dest.s,src.s) <--- concats 2 strings and returns the result to eax

The AddString() function returns (or I should say, receives) garbled text when I call it thusly..

invoke AddString,[v_str1],[v_str2] <--- doesn't work
invoke AddString,"Hello ","World!" <--- works fine

defined as..
v_str1 rd 1
v_str2 rd 1

so, my question is.. can you (a) tell my how to get this horrible high-level cheat to work, or (b) explain how I should be doing it properly without cheating.

Thanks! Rolling Eyes
Post 26 Jan 2010, 13:13
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
The symbol v_strX holds the address of (or is a pointer to-) the data you define. [v_strX] holds the dword or 4 bytes at that address. It seems your AddString works on two pointers so you would want to do:
Code:
invoke AddString,v_str1,v_str2 ; I believe FASM does this at compile time instead of "Hello ","World!"

v_str1 db 'Hello ',0
v_str2 db 'World!',0    

If instead you wanted the values of v_strX to be pointers (like rd suggests) to strings:
Code:
invoke AddString,[v_str1],[v_str2] ; ~ s_hello,s_world

v_str1 dd s_hello
v_str2 dd s_world

s_hello db 'Hello ',0
s_world db 'World!',0    

Hope that helps
Post 26 Jan 2010, 13:27
View user's profile Send private message Reply with quote
fasmnub



Joined: 26 Jan 2010
Posts: 14
fasmnub
That makes things a bit clearer.. but the function in the .dll needs to take actual strings, not pointers. (string in-->string out to eax)

v_str1 and v_str2 need to be declared undefined, and changeable (with changeable size)

As a high-level coder with no asm experience this is all really confusing.
Post 26 Jan 2010, 13:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17472
Location: In your JS exploiting you and your system
revolution
You can't "return a string in eax". The eax register is only 32 bits long, enough for only 3 characters plus a terminating null. You have to pass pointers, there is no other way. Your HL language may have been hiding this detail from you.
Post 26 Jan 2010, 13:40
View user's profile Send private message Visit poster's website Reply with quote
fasmnub



Joined: 26 Jan 2010
Posts: 14
fasmnub
I had a feeling I was doing something drastically wrong.

Can someone show a quick example of dynamically working with strings (that aren't pre-defined, but can hold any string/length), concatenation, passing string values with invoke etc..

I'd appreciate any help/info you can give, baring in mind that i have virtually no experience with asm, but the high-level/external stuff is no problem.
Post 26 Jan 2010, 14:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17472
Location: In your JS exploiting you and your system
revolution
For dynamic strings you would allocate/deallocate memory on the fly instead of using fixed string definitions.
Post 26 Jan 2010, 14:14
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Well maybe you should learn pointers first? Most "dynamic" parameters are passed via pointers.
Post 26 Jan 2010, 19:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.