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;
    }
    
  • 相关阅读:
    浅析data:image/png;base64的应用
    利用Audacity软件分析ctf音频隐写
    利用Audacity软件分析ctf音频隐写
    php笔记(一)php介绍及数据类型
    php笔记(一)php介绍及数据类型
    ctf学习(web题二)
    ctf学习(web题二)
    win10显示许可证即将过期,但在激活界面显示的仍是已激活问题解决
    实验吧web题:
    js各种练习
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13743842.html
Copyright © 2011-2022 走看看