Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / DLLs in Assembler

Author
Message
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 13th Sep 2004 17:21 Edited at: 5th Oct 2004 15:40
I used the tutorial that TGC's have up for creating DLL's in C++ and worked it in to an assembly coded DLL. This could be useful for guys that know asm and want to start making faster, smaller, etc dll's for DarkBASIC in an assembly language.

[edit]
please scroll down to the newer posts for updates to the commands, and source snippets should I post them.

To compile this source you'll need the FASM compiler, which can be found at http://flatassembler.net/. FASM is much easier to use then TASM, and has lots more function.

The source code, .dll, and .res file that I created are in the .zip file that I'll put a link to below. Tell me your opinion about this?

http://www.blackgate.us/dbp/DarkBASIC_DLL.zip
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 13th Sep 2004 19:12
I'm not sure where my original post went with this topic. As of right now it's not appearing on my screen, but if it eventually shows to use the example command in DarkBASIC Pro copy the .dll to your plugins folder, start up DBP and use this command

message "some message here"

After you do that and run your program it'll pop up a message box with your message.

Also, if they don't fix the original post to make it appear, I'll redo the post with the source code again.
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 13th Sep 2004 23:06
You're still a fairly new member so all posts you make must be approved by a moderator before they appear, this is to stop people creating multiple accounts and spamming the place with inappropriate images.

Nice work on the ASM DLL... despite how crazy someone must be to use ASM lol!


"Computers are useless they can only give you answers."
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 14th Sep 2004 04:19
@Exeact

I'm definetly not new to DarkBASIC, I've been using it off and on for the last 4+ years. My oldest backup of it before hard drive crash in 2000 was from that year. I haven't tried to compile or run any of those old DB things, but it would be interesting to open them up again.

I believe this topic is actually damaged in some way, I've tried editing my posts on this DLL topic and it gives me a server error message and asks me to retry the edited post.

I wanted to update what the two example commands were in the .dll and source code. Here's a quick reference of how to use both commands:

message "some message here"
After you do that and run your program it'll pop up a message box with your message.

number = random number()
This will generate a 9 digit random number

And here's an updated look at the source:


It's crossed my mind a few times to recode some of the commands in DBP in to an ASM coded DLL to speed them up.
JoelJ
20
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 14th Sep 2004 13:59
Joined: Fri Aug 20th 2004

thtas what he was talkking about when he said "new"

Infra-Dark
Bring the 20 liners back!
#coding, like coding, but with a #
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 14th Sep 2004 16:19
Correct. There's nothing wrong with this thread, it's just the way the forum is set up, the forum works from the registration date and not how long you've been using DarkBasic, because you're a new member of the forum, we have to approve all your posts before they become visible.


"Computers are useless they can only give you answers."
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 14th Sep 2004 19:51
Did some small updates to the example plugin DLL in ASM. The new commands I added are:

MAKE MEM integer of size in bytes
This allocates space in memory for a future command that I will add to store things in. This command returns the base address of the space in memory that was created.

DEL MEM base address
This command will free the memory you created with the MAKE MEM command. Be sure to use the base address returned from MAKE MEM or you make cause a non-friendly crash to your program, system, or both. I made this function return a value so that it's possible to error check the routine.

MESSAGE title,message
I changed this command from the previous to allow the title bar to have a custom string.

Here's a quick example of the commands in DBP:


The link to this example DLL is: http://www.blackgate.us/dbp/DarkBASIC_DLL.zip

Even though this is an example to see how to create a plugin DLL in ASM...it could easily turn into something more.
Zero Blitzt
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 14th Sep 2004 20:24
Exeat, when can I expect you Winsock DLL?


Come to #coding. We promise we wont kick you!
DISCLAIMER: Promises may not actually be upheld.
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 15th Sep 2004 17:34
When I get off my lazy bum, I was going to finish it last weekend but ran into a couple problems.


"Computers are useless they can only give you answers."
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 15th Sep 2004 17:59
Exeat, you're interfacing the winsock dll to darkbasic from your dll?
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 23rd Sep 2004 18:43 Edited at: 28th Sep 2004 16:28
Below is a link to the dll. I coded this really quick, but tested, and debugged it. So it should work fine for people. Here's a quick reference to the memory and string storage commands:

MAKE MEM (Size in bytes)
Usage:


DEL MEM (Memory Address)
Usage:


WRITE STRING TO MEM String Number,Memory Address,String
Usage:


READ STRING FROM MEM String Number,Memory Address
Usage:


http://www.blackgate.us/dbp/DarkBASIC_testdll.zip

Notes: This code is very raw and undeveloped. When you use it, remember that your first string that you write to memory has to have a 0 for the string number, and then you sequence from there.
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 4th Oct 2004 11:50
Heres a way to build string resources directtly from fasm.. (im studing assembler and how to use masm for darkbasic)



The example is not a big example, just two functions that return one integer and other an string but is to show how to use string resources....

This is the db code



good huh? haha... just a test...

Cheers.

Roberto A. Berrospe Machin, Zona Servicios.
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 4th Oct 2004 13:49
Hey Torrey. I have a question for you..
Have you worked with strings in DBP ?
i cannot find how to pass string variables... i have this code

proc TESTSTR,strVar
mov eax,[strVar]
return
endp

is supposed this will return the string value pased by darkbasic, but this dont.

I have tested ussing:
mov eax,[strVar]
mov [myVar],eax

and tested to return
mov eax,[myVar] or mov eax,myVar
i dont know, everything i can test.. but i cannot see wheres my error . But if you define an string in the program:
myString db 'the string'
and in the function you return:
mov eax,myString
retunr
then you will obtain the string in darkbasic without problem.. For this reason i know my problem is on how darkbasic giveme the string params...

please, if you already know how to do this, can you helpme?

Thanks!

Roberto A. Berrospe Machin, Zona Servicios.
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 4th Oct 2004 14:43 Edited at: 4th Oct 2004 15:10
Quote: "Have you worked with strings in DBP ?"

Yeah, did you try out my previous post, it included a dll for reading and writing strings to memory.

http://www.blackgate.us/dbp/DarkBASIC_testdll.zip

The example asm code you can find when I first started this thread is really old. The actual test source, is pretty advanced looking now. Because I keep adding more to it all the time, I decided to add the keywords file too.

If you want to return a string in to DBP you need to make sure it's reference is in eax upon returning the function. Also that string you return needs to be null terminated.

The dll that I linked to uses a table type method of storing and reading strings. Future plans with that will be the deleting of the string in memory.

I would also like to develop a system for use with AI scripts, item scripts, and last but not least story line scripts. Loading and parsing of the configurable file would take place in memory, with each item and value being loaded in to a table. It's possible to update these variables in memory, so with that it'll be possible for saved game states, and more control over the AI script with ease.
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 5th Oct 2004 00:44
Yes i saw the first code but theres nothing about string.. the latest one dont contain source code
Can you share to me at least by email?

Thanks!

Roberto A. Berrospe Machin, Zona Servicios.
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 5th Oct 2004 15:14
I'll post the read and write source. If you want to use my code, or base something off of it, please give me some credit. A lot of time was spent writing out the flow of code, testing, and debugging. It's like my little baby. hehe

String to memory:


Read string:
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 8th Oct 2004 15:57 Edited at: 8th Oct 2004 16:03
Hello, me again.. well, thanks Torrey for your code.. but, not work for me anyway, i have played with OllyDbg 3 hours and finally find wheres is the thing...
DBP act diferent when the function take parameters and return a value; and when one function does not return any value.
I dont know really why, but dbp do it
I have started testing the first lines of your code wheres you save the string:
cmp [StringNumber],0
jl BadNumber
mov edi,[MemAddress]
mov esi,[String2Write]
mov al,[edi]
cmp al,0
........
I have used a simple function that take a string parametter, and add these parameter to eax, and i try to return the value with no result.. after i have created a variable with a rb of 1024 and try to take the strings ussing edi esi and edi, with no result.. then i have desided to debug them...
So theres is when i find the thing... the dbp somehow push other parameters after the needed one, and then, i have added +4 to the passed parameter and, walá! works!
i have then tested this;

proc TestStr,strParam
mov eax,[strParamA+4]
return
endp

And in dbp i have tested with PRINT TestStr("HELLO") and whalá, theres the result "HELLO"..

After all, i have retested a function without return values, and theres i saw the thing about how db passes the parameters when the function return a value and how act when not..
I have tested ussing:

proc ShowMsg,strMessage
mov eax,[strMessage]
invoke MessageBox,HWND_DESKTOP,eax,msgTitle,MB_OK
return
endp

This work perfect!, dbp passes the params normally and the message box are shown...

So, that is my conclussion... so, thanks for your help anyway, as you do, i hope this i give can help you and every one too. also, ill post my first dll with my first function with the code in the next post

Cheers and thanks.

Roberto A. Berrospe Machin, Zona Servicios.
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 8th Oct 2004 16:21
All of those I've figured out on my own a long time ago. You still haven't discovered the other problem yet when it comes to the stack. For example if you take one of your simple test functions and have it in a loop, that continuously grabs the value from your function eventually the stack becomes corrupted and the program exits without warning.

The thing you have to do for that is debug your dll when using it with a DBP program, and single step through your function to find out how many values you need to remove before returning back to the main loop in the program. This is why you see this at the end of my proc for that function:

add esp,0x4
retn


Depending on the number of parameters and size of the parameters your proc needs, will determine how much you need to clear off the stack before returning to the DBP loop.
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 8th Oct 2004 21:42
Oh i see that in your code, i dont understand why you use that... in my case, i dont have problems already, but if i have, ill test this you give to me before debug.. thanks for the tip.. is good to have a little explanation of the code

Cheers.

Roberto A. Berrospe Machin, Zona Servicios.
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 8th Oct 2004 22:13 Edited at: 8th Oct 2004 22:14
Hey, i have tested with some code and i cannot see what you say... maybe is the version of the dbp you're ussing? i mean an old version bug? some mnemonic / instruction you have ussed? I have the latest dbp with the latest update 5.6, maybe is it

I have atahced a zip with my code, three test functions.
That takes an string parameter, and return the same string with an extra internal dll defined string atached.
Other functon that take two passed strings parameters and return these string joined, and last function, a simple example with a message box that does not return any value; this is good to see how db passes the parameters when the function does not return any param and how act when the function have params....
Here is the code to review...



In the dbp side, this is the test code...



Even, i have added to the zip, the compiled dll and the example dbp code is added too.

http://www.zonauy.com/darkbasic/darkbasic_stringtests.zip

Cheers and thanks.

Roberto A. Berrospe Machin, Zona Servicios.
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 8th Oct 2004 22:50 Edited at: 8th Oct 2004 22:51
When TPC returns a string, DBpro will pass the pointer of an old string to your function. You need to call DBpro's CreateDeleteString function (which involves receiving the pointer to the so called "GlobStruct"). That makes sure the memory management of strings remains in the hands of DBpro.


As for the stack, DBpro calls TPC functions with the CDECL convention. That means that DBpro will clean up the stack on return and not the function.

Play Nice! Play Basic! Out now.

nFinity Emulator. Coming soon.
Zona Servicios
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: Florida - Uruguay
Posted: 9th Oct 2004 01:04
Ohh i see why then dbp uses this stranger way to pass parameters and why i dont have problems with the stack....

Thanks all.

Roberto A. Berrospe Machin, Zona Servicios.

Login to post a reply

Server time is: 2024-03-28 09:34:26
Your offset time is: 2024-03-28 09:34:26