FASM 中的外部程序

发布于 2024-10-31 04:47:33 字数 491 浏览 1 评论 0原文

我一直在尝试将程序从外部文件导出到主汇编程序,但它不起作用。

这是来自外部文件的测试代码:

; Export procedure Summa
format PE GUI 4.0

include 'win32a.inc'

section '.code' code readable executable

proc Summa
Public Summa
ret 2
endp

在主文件中,我尝试附加摘要:

format PE GUI 4.0

include 'win32a.inc'

section '.data' data readable writeable

extrn Summa as Summa : proc  

在编译主文件时,我在带有 extrn 关键字的行中收到非法指令错误。

尝试在网络上搜索,但我没有幸运地找到如何在 FASM 中附加外部程序...

谢谢!

I have been trying to export procedure from external file to the main assembly program, but it didn't work.

Here is test code from external file:

; Export procedure Summa
format PE GUI 4.0

include 'win32a.inc'

section '.code' code readable executable

proc Summa
Public Summa
ret 2
endp

And in the main file I try to attach Summa:

format PE GUI 4.0

include 'win32a.inc'

section '.data' data readable writeable

extrn Summa as Summa : proc  

While compiling main file I get Illegal Instruction error in the line with extrn keyword.

Tried to search the web, but I wasn't lucky to find how I should attach external procedure in FASM...

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我偏爱纯白色 2024-11-07 04:47:33

我看到你有两个 GUI 可执行文件,那么“从外部文件导出过程到主汇编程序”是什么意思?
您想创建两个目标文件 (.obj) 然后将它们链接在一起吗?
然后在两个文件中使用format MS COFF,添加适当的extrnpublic指令,并使用一些链接器(例如link.exe)来构建.exe 文件。

另请阅读 fasm.pdf,第 2.4.3 节“通用对象文件格式”。

I see that you have two GUI executables, so what means "export procedure from external file to the main assembly program"?
Do you want to make two object files (.obj) and then link them together?
Then use format MS COFF in both files, add proper extrn and public directives, and use some linker (for example link.exe) to build .exe file.

Also, read fasm.pdf, section 2.4.3 "Common Object File Format".

盛夏尉蓝 2024-11-07 04:47:33

使用PE,我相信您可以像这样从DLL导入:

library kernel,'KERNEL32.DLL'

import kernel,\
    ExitProcess,'ExitProcess'

如果您使用MS COFF,链接样式将根据您的位数32或64而不同:

32位:

format MS COFF

section '.data' data readable writeable

extrn '__imp__Summa@0' as Summa:dword     

64 位:

format MS64 COFF

section '.data' data readable writeable

extrn '__imp_Summa' as Summa:qword

一个展示 32 位链接的好例子:
https://flatassembler.net/examples/msvc.zip

您还可以将 extrn 与 ELF64 一起使用,Linux 示例:
https://2ton.com.au/rants_and_musings/gcc_integration.html

PE DLL函数导入示例:
https://flatassembler.net/examples/quetannon.zip

With PE, I believe you can import from a DLL like so:

library kernel,'KERNEL32.DLL'

import kernel,\
    ExitProcess,'ExitProcess'

If you use MS COFF, the linking style will be different depending on your bitness 32 or 64:

32-bit:

format MS COFF

section '.data' data readable writeable

extrn '__imp__Summa@0' as Summa:dword     

64-bit:

format MS64 COFF

section '.data' data readable writeable

extrn '__imp_Summa' as Summa:qword

A great example showing linking in 32-bit:
https://flatassembler.net/examples/msvc.zip

You can also use extrn with ELF64, Linux example:
https://2ton.com.au/rants_and_musings/gcc_integration.html

PE DLL function import example:
https://flatassembler.net/examples/quetannon.zip

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文