zoukankan      html  css  js  c++  java
  • nasm 函数返回一个数组 x86

    getArguments.asm:

    extern VirtualAlloc
    
    section .text
      global dllmain
      export getArguments
    
    dllmain:
      mov eax,1
      ret 12
    
    getArguments:
      push ebp
      mov ebp,esp
    
      push 0x40   ; PAGE_EXECUTE_READWRITE
      push 0x3000 ; MEM_COMMIT | MEM_RESERVE
      push 8      ; size
      push 0      ; lpAddress
      call VirtualAlloc
      mov dword [eax],1   ; index 0
      mov dword [eax+4],2 ; index 1
    
      mov esp,ebp
      pop ebp
      ret
    

    build.fil:

    /entry:dllmain 
    /dll
    Kernel32.dll
    
    getArguments.obj
    

    build.bat:

    nasm -f win32 getArguments.asm
    golink @build.fil
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef int* (CALLBACK* f_t)();
    f_t f;
    
    int main()
    {
      HMODULE mydll = LoadLibraryA("getArguments.dll");
      if (mydll == NULL) return 0;
    
      f = (f_t)GetProcAddress(mydll, "getArguments");
      int* r = f();
    
      printf("%d
    ", r[0]); // 1
      printf("%d
    ", r[1]); // 2
    
      return 0;
    }
    

    See alse:

  • 相关阅读:
    Lambda
    Thread&线程池
    异常
    Map
    List and Set
    Collection和迭代器Iterator
    Object类,常用API
    (一)自定义 mybatis 之框架介绍
    Nginx三大功能及高并发分流
    http协议改为https
  • 原文地址:https://www.cnblogs.com/ajanuw/p/14203936.html
Copyright © 2011-2022 走看看