//normal.dll
// normaldll.cpp : Defines the exported functions for the DLL application.
//#include "stdafx.h"
#include "normaldll.h"
#include <string>// This is an example of an exported variable
NORMALDLL_API int nnormaldll=0;int ebpretdll[6][2] = { 0 };bool CheckStackFrame()
{int bRet = 0;__asm{push eaxpush ebxpush ecxpush edxpush edipush ebplea edx, [ebpretdll]mov ebx, nnormaldllmov ecx, 5
label:mov [edx], ebpadd edx, 4mov ebx, ebpadd ebx, 4mov edi, [ebx]mov [edx],ediadd edx, 4mov edi, [ebp]mov ebp, edidec ecxjge labelpop ebppop edipop edxpop ecxpop ebxpop eax}printf("EXE Baseaddr:%08x\n follow is check statck info:\n",nnormaldll);for(int i = 0; i < 6; ++i){printf("ebp:%08x retaddr:%08x \n",ebpretdll[i][0],ebpretdll[i][1]);}return bRet;
}
// This is an example of an exported function.
NORMALDLL_API int fnnormaldll(void)
{CheckStackFrame();wchar_t buf[100] = { 0 };wsprintfW(buf,L"EXE address:%08x, current dll address:%08x",nnormaldll,GetModuleHandle(L"normaldll.dll"));MessageBoxW(NULL,buf, L"normal dll caption", MB_OK);return 42;
}// This is the constructor of a class that has been exported.
// see normaldll.h for the class definition
Cnormaldll::Cnormaldll()
{return;
}
?
//invader.dll
// invader.cpp : Defines the exported functions for the DLL application.
//#include "stdafx.h"
#include "invader.h"
#include <windows.h>
#include <stdio.h>
#include <process.h>#include "..\normaldll\normaldll.h"// This is an example of an exported variable
INVADER_API int ninvader=0;HANDLE g_event = NULL;
typedef int (*PFUN)(void);
DWORD fakestack[20] = { 0 };
DWORD addr = 0;_declspec (naked) void fakeframe(DWORD funaddr,DWORD fakestack)
{__asm{mov edi, edipush ebpmov ebp, esppush eaxpush ebx//push ebpmov eax, addradd eax,18*4mov ebx, [ebp]mov [eax], ebxadd eax,4mov [eax], espjmp PUSH_REAL_RET_ADDR
FUN:push 0x771f000a ;//retmov eax, ebpmov ebx, addrmov [eax],ebxmov eax, funaddrjmp eax
PUSH_REAL_RET_ADDR:call FUNmov eax, addradd eax,19*4mov esp, [eax]sub eax, 4mov ebx, [eax]mov [ebp], ebxpop ebxpop eaxmov esp, ebppop ebpret 8}
}void hah1()
{for(int i = 0; i< 20; ){fakestack[i] = (DWORD)&fakestack[i+2];fakestack[i+1] = 0x00000021;i += 2;}HMODULE hnormaldll = GetModuleHandleW(L"C:\\test\\testFakeStackFrames\\Debug\\normaldll.dll");PFUN p = (PFUN)GetProcAddress(hnormaldll,"?fnnormaldll@@YAHXZ");//nnormaldll = (int)GetModuleHandle(L"invader.dll");addr = (DWORD)&fakestack;fakeframe((DWORD)p,addr);
}
void hah2()
{hah1();
}
void hah3()
{hah2();
}
void hah4()
{hah3();
}unsigned __stdcall start_address( void * pa )
{g_event = CreateEventW(NULL,FALSE,FALSE,L"SNOWMAN");printf("11111\n");WaitForSingleObject( g_event, INFINITE );hah4();while(true){printf("dddddddddddddd\n");Sleep(1000);}_endthreadex( 0 );return 0;
}// This is an example of an exported function.
INVADER_API int fninvader(void)
{HANDLE hthread = (HANDLE)_beginthreadex(NULL,0,&start_address,NULL,0,NULL);//Sleep(3000);//hah4();return 42;
}// This is the constructor of a class that has been exported.
// see invader.h for the class definition
Cinvader::Cinvader()
{return;
}
?
//trigeror
#include <windows.h>
#include <stdio.h>
#include <process.h>void main()
{HANDLE g_event = CreateEventW(NULL,FALSE,FALSE,L"SNOWMAN");if(GetLastError() == ERROR_ALREADY_EXISTS){printf(" OK is exist, only triger\n");SetEvent(g_event);}
}