flat assembler
Message board for the users of flat assembler.

Index > Windows > Calling a DLL function created in rust from fasm

Author
Thread Post new topic Reply to topic
bari



Joined: 10 Jan 2024
Posts: 2
bari 10 Jan 2024, 12:07
I am very new to assembly in general, so I wanted to see if I can get a simple project going. I want to (don't ask me why) export a few rust functions into a DLL. I am aware some rust council will try to assassinate me (maybe)

Code:

#[no_mangle]
pub fn myrusthello() {
    println!("Hello from Rust!");
}

    


in the assembly I got an example hello world program for windows which I modified:



Code:
format pe console


include 'include\win32ax.inc'

entry main


section '.txt' code executable readable

main:
    call [myrusthello]
    push 0
    call [ExitProcess]
      
section '.blah' import data readable

library kernel32,'kernel32.dll',\
    msvcrt,'msvcrt.dll', \
    testfunc,'testfunc.dll'

import kernel32, ExitProcess,'ExitProcess'
import testfunc, myrusthello, 'myrusthello'
    


Alright, this entire thing compiles with no issues. The rust function is compiled with

Code:
rustc --crate-type cdylib .\testfunc.rs
    

and the executable like so:

Code:
.\FASM.EXE .\fasmhello.asm
    


I get no output to std... I'm assuming the function isn't being imported correctly or I'm calling it the wrong way? The DLL file is in the same folder as the executable. Any ideas?
Post 10 Jan 2024, 12:07
View user's profile Send private message Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 74
MatQuasar 10 Jan 2024, 13:08
I tested OK with PE64, because my DLL is 64-bit.

Example:
Code:
format pe64 console


include 'win64a.inc'

entry main


section '.txt' code executable readable

main:
    sub  rsp, 40
    call [myrusthello]
    xor  rcx, rcx            
    call [ExitProcess]

....
....
    


Don't know about Rust 32-bit. (I downloaded RUSTUP-INIT.EXE 64-bit)


Description:
Filesize: 38.48 KB
Viewed: 463 Time(s)

Screenshot 2024-01-10 212135.png


Post 10 Jan 2024, 13:08
View user's profile Send private message Reply with quote
bari



Joined: 10 Jan 2024
Posts: 2
bari 11 Jan 2024, 15:15
Thanks, turns out I didn't build a 64 bit executable and needed to use PE64.
Post 11 Jan 2024, 15:15
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.