zoukankan      html  css  js  c++  java
  • nasm astrncat_s函数 x86

    xxx.asm:

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    %define p4 ebp+20
    
    section .text
      global dllmain
      export astrncat_s
    
    dllmain:
      mov eax,1
      ret 12
    
    ;------------------------------------------------;
    ;	将字符追加到字符串
    ;------------------------------------------------;
    astrncat_s:
      push ebp
      mov ebp,esp
      sub esp,8
      mov [ebp-4],ebx
    
      mov ecx,[p1]	; char *strDest
      mov eax,[p2]	; size_t numberOfElements
      mov edx,[p3]	; const char *strSource
      mov ebx,[p4]	; size_t count
     
      ; get strDest end
      .for1:
      test eax,eax
      jz .return
      cmp byte [ecx],0
      je .eachCopy
      inc ecx
      dec eax
      jmp .for1
      
      .eachCopy:
      test ebx,ebx
      jz .return
      test eax,eax
      jz .return
      mov [ebp-8],ebx
      
      ; copy
      mov bl,byte [edx]
      test bl,bl
      je .return
      mov byte [ecx],bl
      
      ; next
      mov ebx,[ebp-8]
      inc ecx
      inc edx
      dec eax
      dec ebx
      jmp .eachCopy
       
      .return:
      xor eax,eax
      mov ebx,[ebp+4]
      add esp,8
      mov esp,ebp
      pop ebp
      ret 16
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef int (CALLBACK* astrncat_s_t)(char* strDest, size_t numberOfElements, const char* strSource, size_t count); 
    
    astrncat_s_t astrncat_s;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrncat_s = (astrncat_s_t)GetProcAddress(myDLL, "astrncat_s");
      
      char s1[10] = "ab";
      const char* s2 = "cde";
      strncat_s(s1, sizeof(s1), s2, 2);
      printf("%s
    ", s1); // abcd
    
      //----------------------------------------------------------------------
    
      char s3[10] = "ab";
      const char* s4 = "cde";
      astrncat_s(s3, sizeof(s3), s4, 2);
      printf("%s
    ", s3); // abcd
      return 0;
    }
    
  • 相关阅读:
    【QTP】自动化测试:
    sql基本语句
    【转】ASP.NET网站怎么发布web项目程序和怎么部署
    NHibernate的简单例子
    解决ehcache的UpdateChecker问题
    正则表达式的贪婪与懒惰
    Linux查找文件夹名
    centos安装lxml和pyspider
    如何通过写一个chrome扩展启动本地程序
    网页图片滚动效果
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13742387.html
Copyright © 2011-2022 走看看