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

    xxx.asm

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrrev
    
    dllmain:
      mov eax,1
      ret 12
    
    ;------------------------------------------------;
    ;	反转字符串的字符。
    ;------------------------------------------------;
    astrrev:
      push ebp
      mov ebp,esp
    
      mov ecx,[p1]	; char *str
      mov edx,[p1]
      
      ;------------------------------------------------;
      ;	get last
      ;------------------------------------------------;
      .getLast:
      mov ah,[ecx]
      test ah,ah
      jz .getLastBreak
      inc ecx
      jmp .getLast
      
      .getLastBreak:
      dec ecx
      
      .rev:
      cmp ecx,edx
      jc .return	; 偶数ecx会小于edx
      je .return	; 奇数会相等
      
      ;------------------------------------------------;
      ;	交换字节
      ;------------------------------------------------;
      mov ah,[ecx]
      mov al,[edx]
      mov [edx],ah
      mov [ecx],al
      
      ; next
      dec ecx
      inc edx
      jmp .rev
      
      .return:
      mov eax,[p1]	; 返回原始指针
      mov esp,ebp
      pop ebp
      ret 4
    

    c++:

    #include <iostream>
    #include <Windows.h>
    #include <tchar.h>
    #include <string>
    
    typedef char* (CALLBACK* astrrev_t)(char* str);
    
    astrrev_t astrrev;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrrev = (astrrev_t)GetProcAddress(myDLL, "astrrev");
    
      char s[12] = "hello world";
      printf("%s, %s
    ", _strrev(s), s); // dlrow olleh, dlrow olleh
      printf("%s, %s
    ", astrrev(s), s); // hello world, hello world
      return 0;
    }
    
  • 相关阅读:
    把文本数据转化为json
    componentsSeparatedByString 的注意事项
    内存管理
    审核问题2.3.1
    H5缩放效果的问题和缓存问题
    iOS库
    DDOS 攻击防范
    连接数过多的问题
    nginx 长连接keeplive
    javascript 判断身份证的正确性
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13743147.html
Copyright © 2011-2022 走看看