nasm astrset_s函数 x86

xxx.asm

%define p1 ebp+8
%define p2 ebp+12
%define p3 ebp+16

section .text
  global dllmain
  export astrset_s

dllmain:
  mov eax,1
  ret 12

;------------------------------------------------;
;	将字符串的字符设置为字符
;------------------------------------------------;
astrset_s:
  push ebp
  mov ebp,esp
  
  mov ecx,[p1]	; char* str
  mov eax,[p2]	; size_t numberOfElements
  mov edx,[p3]	; int c
  
  .for:
  test eax,eax
  jz .return
  
  cmp byte [ecx],0
  je .return
  
  mov [ecx],dl
  inc ecx
  dec eax
  jmp .for

  .return:
  xor eax,eax
  mov esp,ebp
  pop ebp
  ret 12

c++:

#include <iostream>
#include <Windows.h>

typedef int (CALLBACK* astrset_s_t)(char* str, size_t numberOfElements, int c);
astrset_s_t astrset_s;

int main()
{
  HMODULE myDLL = LoadLibraryA("xxx.dll");
  astrset_s = (astrset_s_t)GetProcAddress(myDLL, "astrset_s");

  char s[12] = "abc";
  _strset_s(s, sizeof(s), "x"[0]);
  printf("%s\n", s);  // xxx

  astrset_s(s, sizeof(s), "y"[0]);
  printf("%s\n", s);  // yyy
  return 0;
}
posted @ 2020-09-28 09:39  Ajanuw  阅读(126)  评论(0编辑  收藏  举报