From f0aee80fcbaab461a0658a5110a53d5ffadb1f01 Mon Sep 17 00:00:00 2001 From: Giannis Adamopoulos Date: Thu, 6 Feb 2014 13:07:37 +0000 Subject: [PATCH] [atl] - Fix atl thunks to be allocated in executable memory and not from the stack in order to run libraries that use atl (such as browseui) in windows with DEP enabled svn path=/branches/shell-experiments/; revision=62011 --- lib/atl/atlwin.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/atl/atlwin.h b/lib/atl/atlwin.h index cc925758585..47bda8803dc 100644 --- a/lib/atl/atlwin.h +++ b/lib/atl/atlwin.h @@ -153,21 +153,32 @@ struct thunkCode class CWndProcThunk { public: - thunkCode m_thunk; + thunkCode *m_pthunk; _AtlCreateWndData cd; public: + + CWndProcThunk() + { + m_pthunk = (thunkCode*)VirtualAlloc(NULL, sizeof(thunkCode), MEM_COMMIT, PAGE_EXECUTE_READWRITE); + } + + ~CWndProcThunk() + { + VirtualFree(m_pthunk, sizeof(thunkCode), MEM_RELEASE); + } + BOOL Init(WNDPROC proc, void *pThis) { - m_thunk.m_mov = 0x042444C7; - m_thunk.m_this = PtrToUlong(pThis); - m_thunk.m_jmp = 0xe9; - m_thunk.m_relproc = DWORD(reinterpret_cast(proc) - (reinterpret_cast(this) + sizeof(thunkCode))); + m_pthunk->m_mov = 0x042444C7; + m_pthunk->m_this = PtrToUlong(pThis); + m_pthunk->m_jmp = 0xe9; + m_pthunk->m_relproc = DWORD(reinterpret_cast(proc) - (reinterpret_cast(m_pthunk) + sizeof(thunkCode))); return TRUE; } WNDPROC GetWNDPROC() { - return reinterpret_cast(&m_thunk); + return reinterpret_cast(m_pthunk); } };