zoukankan      html  css  js  c++  java
  • nasm and golink create a DLL x86

    制作DLL

    xxx.asm:

    %macro fb 0
    	push ebp
    	mov ebp,esp
    %endmacro
    
    %macro fa 1
    	mov esp,ebp
    	pop ebp
    	ret %1
    %endmacro
    
    section .text
    	global dllmain
    	
    dllmain:
    	mov eax,1
    	ret 12
       
    f1:
    	fb
    	mov eax,[ebp+8]
    	add eax,[ebp+12]
    	fa 8
    

    xxx_link.fil:

    ; > golink @xxx_link.fil
    /entry dllmain
    /dll 
    /exports f1
    
    xxx.obj
    
    >nasm -f win32 xxx.asm
    >golink @xxx_link.fil
    

    制作dll后可以看下pe结构,免得的出问题

    在x86汇编中调用

    将xxx.dll拷贝到asm项目文件中

    hello.asm:

    extern MessageBoxA
    extern ExitProcess
    extern f1
    
    section .data
    	title   db "caption.",0
    	message db "hello world....",0
    	
    section .text
    	global main
    
    main:
    	push 1
    	push 2
    	call f1
    	
    	push 0
    	push title
    	push message
    	push 0
    	call MessageBoxA
    
    _exit:
    	push 0
    	call ExitProcess
    
    > nasm -f win32 hello.asm
    > golink /entry main hello.obj kernel32.dll user32.dll xxx.dll
    

    c++ 显示连接

    将xxx.dll拷贝到c++项目文件中

    #include <iostream>
    #include <Windows.h>
    
    typedef int (CALLBACK* f1_t)(int, int);
    
    f1_t f1;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      f1 = (f1_t)GetProcAddress(myDLL, "f1");
      if (f1)
        printf("%d
    ", f1(1, 2)); // 3
      else
        printf("dll not export f1");
      return 0;
    }
    

    See also:

  • 相关阅读:
    mysql 统计数据库基本资源sql
    java ffmpeg (Linux)截取视频做封面
    shutil模块
    json模块与pickle模块
    hashlib模块
    sys模块
    os模块
    paramiko模块
    Python reduce() 函数
    瀑布流展示图片
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13696329.html
Copyright © 2011-2022 走看看