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

    xxx.asm:

    %define p1 ebp+8
    %define p2 ebp+12
    %define p3 ebp+16
    
    section .text
      global dllmain
      export astrstr
    
    dllmain:
      mov eax,1
      ret 12
    
    ;-------------------------------------------------------------;
    ; 返回一个指针,该指针指向字符串中第一次出现的搜索字符串
    ;-------------------------------------------------------------;
    astrstr:
      push ebp
      mov ebp,esp
      sub esp,4
      
      mov ecx,[p1]	; const char *str
      mov edx,[p2]	; const char *strSearch
      
      mov [ebp-4],ecx
      
      .for:
      mov ah,[edx]
      mov al,[ecx]
      
      ;--------------------------------------------------;
      ; strSearch 全部查找完
      ;--------------------------------------------------;
      test ah,ah
      jz .find
      
      ;--------------------------------------------------;
      ; str 全部查找完
      ;--------------------------------------------------;
      test al,al
      jz .notFind
      
      ;--------------------------------------------------;
      ; 如果相等进行下一个strSearch字符的判断
      ;--------------------------------------------------;
      cmp ah,al
      je .foarchNext
      
      ;--------------------------------------------------;
      ; 不相等进行下一个str字符的判断
      ; 如果strSearch指针变动,则恢复strSearch指针
      ;--------------------------------------------------;
      cmp edx,[p2]
      jne .reSearch
      inc ecx
      mov [ebp-4],ecx
      jmp .for
      
      .reSearch:
      mov edx,[p2]
      mov [ebp-4],ecx
      jmp .for
      
      .foarchNext:
      inc ecx
      inc edx
      jmp .for
      
      .notFind:
      xor eax,eax
      jmp .return
      
      .find:
      mov eax,[ebp-4]
      jmp .return
      
      .return:
      add esp,4
      mov esp,ebp
      pop ebp
      ret 8
    

    c++:

    #include <iostream>
    #include <Windows.h>
    
    typedef int (CALLBACK* astrstr_t)(const char* str, const char* strCharSet);
    astrstr_t astrstr;
    
    int main()
    {
      HMODULE myDLL = LoadLibraryA("xxx.dll");
      astrstr = (astrstr_t)GetProcAddress(myDLL, "astrstr");
    
      const char* s1 = "hello world";
      const char* s2 = "ll";
      printf("%s
    ", strstr( s1, s2)); // llo world
      printf("%s
    ", astrstr(s1, s2)); // llo world
      return 0;
    }
    
  • 相关阅读:
    springboot配置tomcat大全
    python 列表推导式
    python中yield的用法详解——最简单,最清晰的解释
    正则表达式
    python 装饰器
    python 接口类、抽象类、多态
    python split和os.path.split()
    pyhton 多继承的执行顺序
    python unittest 加载测试用例的方法
    python unittest中的四个概念
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13743842.html
Copyright © 2011-2022 走看看