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

    xxx.asm

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrcat_s
    
    dllmain:
      mov eax,1
      ret 12
    
    astrcat_s:
      push ebp
      mov ebp,esp
      push ebx
    
      mov ecx,[p1]	; dst char ptr
      mov eax,[p2]	; src char ptr
      mov edx,[p3]	; dwDstSize
      
      ; if dwDstSize==0 return FALSE
      test edx,edx
      jz .error
      
      ; get dst char end
      .dstFor:
      cmp byte [ecx],0
      je .copyFor
      inc ecx
      dec edx
      test edx,edx
      jz .error
      jmp .dstFor
      
      .copyFor:
      cmp byte [eax],0
      je .success
      dec edx
      test edx,edx
      jz .error
      mov bl,byte [eax]
      mov byte [ecx],bl
      inc eax
      inc ecx
      jmp .copyFor
      
      .error:
      xor eax,eax
      jmp .return
      
      .success:
      mov eax,1
      jmp .return
      
      .return:
      pop ebx
      mov esp,ebp
      pop ebp
      ret 12
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef BOOL(CALLBACK* astrcat_s_t)(char* dst, const char* src, size_t dwDstSize);
    
    astrcat_s_t astrcat_s;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrcat_s = (astrcat_s_t)GetProcAddress(myDLL, "astrcat_s");
    
      const char* a = "hello";
      const char* b = " world";
      char dst[12] = { 0 };
      if (!astrcat_s(dst, a, sizeof(dst)))
      {
        printf("astrcat_s 1 error.
    ");
        return 0;
      }
    
      if (!astrcat_s(dst, b, sizeof(dst)))
      {
        printf("astrcat_s 2 error.
    ");
        return 0;
      }
      
      printf("%p
    ", dst);
      printf("%s
    ", dst); // hello world
      return 0;
    }
    
  • 相关阅读:
    sed处理文本文件
    多节点ssh免密匙登录
    nmon监控工具的使用
    PostgreSQL 磁盘使用大小监控
    PostgreSQL 锁监控
    PostgreSQL installations
    《卸甲笔记》-多表查询之二
    《卸甲笔记》-多表查询之一
    《卸甲笔记》-子查询
    《卸甲笔记》-分组统计查询
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13720484.html
Copyright © 2011-2022 走看看