ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

nasm astrstr函数 x86

2020-09-28 11:32:42  阅读:200  来源: 互联网

标签:const x86 -------------------------------------------------- mov ebp astrstr ecx


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\n", strstr( s1, s2)); // llo world
  printf("%s\n", astrstr(s1, s2)); // llo world
  return 0;
}

标签:const,x86,--------------------------------------------------,mov,ebp,astrstr,ecx
来源: https://www.cnblogs.com/ajanuw/p/13743842.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有