首页 > 其他 > 详细

nasm astrlen函数 x86

时间:2020-09-23 20:57:46      阅读:46      评论:0      收藏:0      [点我收藏+]

xxx.asm

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

section .text
  global dllmain
  export astrlen

dllmain:
  mov eax,1
  ret 12

astrlen:
  push ebp
  mov ebp,esp

  mov ecx,[p1]  	 ; char ptr
  xor eax,eax

  .for:
  cmp byte [ecx],0
  je .return

  inc ecx
  inc eax
  jmp .for

  .return:
  mov esp,ebp
  pop ebp
  ret 4

link.fil:

/entry dllmain
/dll

xxx.obj

c++

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

typedef int (CALLBACK* astrlen_t)(const char*);

astrlen_t astrlen;

int main()
{
  HMODULE myDLL = LoadLibraryA("xxx.dll");
  astrlen = (astrlen_t)GetProcAddress(myDLL, "astrlen");
  
  printf("%d\n", astrlen("hello world")); // 11
  printf("%d\n", astrlen("nasm")); // 4

  return 0;
}

nasm astrlen函数 x86

原文:https://www.cnblogs.com/ajanuw/p/13719952.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!