记住一下几条
调用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;
}