zl程序教程

您现在的位置是:首页 >  其它

当前栏目

nasm astrset_s函数 x86

函数 x86
2023-09-14 08:58:44 时间

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;
}