• nasm astrcpy_s函数 x86


    xxx.asm

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrcpy_s
    
    dllmain:
      mov eax,1
      ret 12
    
    astrcpy_s:
      push ebp
      mov ebp,esp
      push ebx
      
      mov eax,[p1]	; dst char ptr
      mov ecx,[p2]	; dwDstSize
      mov edx,[p3]	; src char ptr
      
      .for:
      ;-------------------------------------;
      ; get src first char
      ;-------------------------------------;
      mov bl,[edx]
      
      ;-------------------------------------;
      ; 检查src是否结束
      ;-------------------------------------;
      test bl,bl
      jz .return
      
      ;-------------------------------------;
      ; copy
      ;-------------------------------------;
      mov [eax],bl
      
      ;-------------------------------------;
      ; 避免dst溢出
      ;-------------------------------------;
      dec ecx
      test ecx,ecx
      jz .return
      
      ;-------------------------------------;
      ; next
      ;-------------------------------------;
      inc eax
      inc edx
      jmp .for
      
      .return:
      pop ebx
      mov esp,ebp
      pop ebp
      ret 12
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef void (CALLBACK* astrcpy_s_t)(char* dest, size_t dest_size, const char* src);
    
    astrcpy_s_t astrcpy_s;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrcpy_s = (astrcpy_s_t)GetProcAddress(myDLL, "astrcpy_s");
    
      char r[100];
    
      strcpy_s(r, sizeof(r), "123");
      printf("%s
    ", r); // 123
    
      astrcpy_s(r, sizeof(r), "456");
      printf("%s
    ", r); // 456
    
      //===============================//
    
      strcpy_s(r, 2, "1");
      printf("%s
    ", r); // 1
    
      astrcpy_s(r, 2, "2");
      printf("%s
    ", r); // 2
      return 0;
    }
    
  • 相关阅读:
    Qt应用如何发布
    关于在windows下部署发布QT程序的总结
    干净地发布QT程序
    解析 Qt 程序在Windows 下发布
    Qt 5.2.0 和 VS 2012集成
    Unable to find a qt build, to solve this problem specify a qt build
    运行python程序不显示cmd的方法
    py2exe使用方法
    python 类
    在Pygtk和Glade使用Gtkbuilder
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13723735.html
Copyright © 2020-2023  润新知