VC++ 内联汇编

 记住一下几条

     调用api  call dword ptr[API]

     调用CRT函数 直接 call xxx

     windows 中的所有函数调用都不会改写 esi edi 寄存器

    mov eax,dowrd ptr[esp]  别忘了加上 dowrd ptr 编译器在无法确认的时候 会选择 BYTE ptr

   

#include <windows.h>
#include <stdio.h>

void __declspec(naked) ShowEnvValue(char *pName)
{
	__asm
	{
		push ebp
		mov  ebp,esp
		push esi
		push edi
		push esp
		lea  eax,[esp]
		push 1
		push eax
		push DWORD ptr[esp + 28]
		call DWORD ptr[GetEnvironmentVariableA]
		add  esp,4
		test eax,eax
		jz   _out
		mov  edi,eax
		push edi
		call malloc
		add  esp,4
		mov	 esi,eax
		push edi
		push esi
		push DWORD ptr[esp + 24]
		call DWORD ptr[GetEnvironmentVariableA]
		test eax,eax
		jnz  _ok
_free:	push esi
		call free
		add  esp,4
		jmp  _out
_ok:	push esi
		call printf
		pop  eax
		jmp  _free
_out:	pop  edi
		pop  esi
		pop  ebp
		retn
	}
}

int main(int argc, char* argv[])
{
	ShowEnvValue("path");
	return 0;
}

转载于:https://my.oschina.net/sincoder/blog/112652

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值