16,467
社区成员
发帖
与我相关
我的任务
分享
// APIEx.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
typedef LRESULT (WINAPI *CWProc)(long,HWND,UINT,WPARAM,LPARAM);
CWProc CallWndProc;
int i;
byte Data[424];
void AddByte(int byt)
{
memcpy(&Data[i],&byt,1);
i++;
}
void AddLong(long lng)
{
memcpy(&Data[i],&lng,4);
i+=4;
}
int main(int argc, char* argv[])
{
long Proc;
long lngStart;
long ps1;
long ps2;
char s1[]="hello";
char s2[]="caption";
Proc=(long)GetProcAddress(LoadLibrary("user32.dll"),"MessageBoxA");
lngStart=((long)&Data|0x0F)+1;
for(int k=0;k<(lngStart-(long)&Data);k++)
{
AddByte(0xCC);
}
ps1=(long)&s1[0];
ps2=(long)&s2[0];
AddByte(0x68);
AddLong(0x00);
AddByte(0x68);
AddLong(ps1);
AddByte(0x68);
AddLong(ps2);
AddByte(0x68);
AddLong(0x00);
AddByte(0xE8);
printf("%d\n",i-(lngStart-(long)&Data));
AddLong(Proc-(long)&Data[i]-4);
AddByte(0xC2);
AddByte(0x10);
AddByte(0x00);
CallWndProc=(CWProc)GetProcAddress(LoadLibrary("user32.dll"),"CallWindowProc");
printf("Data:%d\nlngStart:%d\nFuncProc:%d\n",(long)&Data,lngStart,Proc);
system("pause");
long x=(long)GetProcAddress(LoadLibrary("user32.dll"),"GetForegroundWindow");
printf("%d\n",x);
CallWndProc(x,0,0,0,0);
return 0;
}