nasm astrchr函数 x86

xxx.asm:

%define p1 ebp+8
%define p2 ebp+12
%define p3 ebp+16
section .text
global dllmain
export astrchr
dllmain:
mov eax,1
ret 12
astrchr:
push ebp
mov ebp,esp
mov eax,[p1] ; char ptr
mov ecx,[p2] ; char
.for:
;-------------------------------------------;
; 找到后返回第一次出现的指针
;-------------------------------------------;
cmp [eax],cl
je .return
inc eax
;-------------------------------------------;
; 如果找不到该字符,则该函数返回空指针
;-------------------------------------------;
cmp byte [eax],0
je .error
jmp .for
.error:
xor eax,eax
.return:
mov esp,ebp
pop ebp
ret 8

c++:

#include <iostream>
#include <Windows.h>
typedef char*(CALLBACK* astrchr_t)(const char* str, int character);
astrchr_t astrchr;
int main()
{
HMODULE myDLL = LoadLibraryA("xxx.dll");
astrchr = (astrchr_t)GetProcAddress(myDLL, "astrchr");
char str[] = "hello world";
char* pch = strchr(str, 'l');
printf("%s\n", pch); // llo world
char* pch2 = astrchr(str, 'l');
printf("%s\n", pch2); // llo world
//==============================//
char* pch3 = strchr(str, 'b');
printf("%s\n", pch3); // (null)
char* pch4 = astrchr(str, 'b');
printf("%s\n", pch4); // (null)
return 0;
}
posted @   Ajanuw  阅读(142)  评论(0编辑  收藏  举报
编辑推荐:
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
阅读排行:
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· 赶AI大潮:在VSCode中使用DeepSeek及近百种模型的极简方法
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地
点击右上角即可分享
微信分享提示