Skip to content

Commit

Permalink
Win-specific: ScanPopup in 64-bit applications
Browse files Browse the repository at this point in the history
  • Loading branch information
Abs62 committed Jan 24, 2012
1 parent fa60062 commit c9192ac
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 102 deletions.
8 changes: 6 additions & 2 deletions goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,12 @@ SOURCES += folding.cc \
win32 {
SOURCES += mouseover_win32/ThTypes.c \
wordbyauto.cc \
guids.c
guids.c \
x64.cc
HEADERS += mouseover_win32/ThTypes.h \
wordbyauto.hh \
uiauto.hh
uiauto.hh \
x64.hh
}
RESOURCES += resources.qrc \
flags.qrc
Expand Down Expand Up @@ -338,3 +340,5 @@ include( qtsingleapplication/src/qtsingleapplication.pri )





14 changes: 7 additions & 7 deletions mouseover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <aclapi.h>
#include "mouseover_win32/ThTypes.h"
#include "wordbyauto.hh"
#include "x64.hh"
#endif

MouseOver & MouseOver::instance()
Expand Down Expand Up @@ -58,7 +59,6 @@ static void SetLowLabelToGDSynchroObjects()
BOOL fSaclDefaulted = FALSE;
LPCWSTR pwszMapFileName = L"GoldenDictTextOutHookSharedMem";
LPCWSTR pwszSpyMutexName = L"GoldenDictTextOutSpyMutex";
LPCWSTR pwszHookMutexName = L"GoldenDictTextOutHookMutex";

if( ConvertStringSecurityDescriptorToSecurityDescriptorW( LOW_INTEGRITY_SDDL_SACL_W, 1 /* SDDL_REVISION_1 */, &pSD, NULL ) )
{
Expand All @@ -73,9 +73,6 @@ static void SetLowLabelToGDSynchroObjects()
dwErr = SetNamedSecurityInfoW( (LPWSTR)pwszSpyMutexName,
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);

dwErr = SetNamedSecurityInfoW( (LPWSTR)pwszHookMutexName,
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);

}
LocalFree(pSD);
}
Expand All @@ -94,8 +91,9 @@ ChangeWindowMessageFilterExFunc changeWindowMessageFilterExFunc = NULL;

ThTypes_Init();
memset( GlobalData, 0, sizeof( TGlobalDLLData ) );
strcpy( GlobalData->LibName,
QDir::toNativeSeparators( QDir( QCoreApplication::applicationDirPath() ).filePath( "GdTextOutHook.dll" ) ).toLocal8Bit().data() );
// strcpy( GlobalData->LibName,
// QDir::toNativeSeparators( QDir( QCoreApplication::applicationDirPath() ).filePath( "GdTextOutHook.dll" ) ).toLocal8Bit().data() );
QDir::toNativeSeparators( QDir( QCoreApplication::applicationDirPath() ).filePath( "GdTextOutHook.dll" ) ).toWCharArray( GlobalData->LibName );

// Create the window to recive spying results to

Expand Down Expand Up @@ -150,6 +148,7 @@ void MouseOver::enableMouseOver()
if ( !mouseOverEnabled && activateSpyFn )
{
activateSpyFn( true );
installx64Hooks();
mouseOverEnabled = true;
}
#endif
Expand All @@ -161,6 +160,7 @@ void MouseOver::disableMouseOver()
if ( mouseOverEnabled && activateSpyFn )
{
activateSpyFn( false );
removex64Hooks();
mouseOverEnabled = false;
}
#endif
Expand Down Expand Up @@ -338,7 +338,7 @@ MouseOver::~MouseOver()

UnregisterClass( className, GetModuleHandle( 0 ) );

Thtypes_End();
ThTypes_End();

#endif
}
Expand Down
12 changes: 6 additions & 6 deletions mouseover_win32/GetWord.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ static BOOL Is_XP_And_Later()
return (VER_PLATFORM_WIN32_NT == stOSVI.dwPlatformId && (5 < stOSVI.dwMajorVersion || (5 == stOSVI.dwMajorVersion && 1 <= stOSVI.dwMinorVersion)));
}

static char* ExtractWordFromRichEditPos(HWND WND, POINT Pt, int *BeginPos)
static char* ExtractWordFromRichEditPos(HWND WND, POINT Pt, DWORD *BeginPos)
{
return ExtractFromEverything(WND, Pt, BeginPos);
}

static char* ExtractWordFromEditPos(HWND hEdit, POINT Pt, int *BeginPos)
static char* ExtractWordFromEditPos(HWND hEdit, POINT Pt, DWORD *BeginPos)
{
return ExtractFromEverything(hEdit, Pt, BeginPos);
}

static char* ExtractWordFromIE(HWND WND, POINT Pt, int *BeginPos)
static char* ExtractWordFromIE(HWND WND, POINT Pt, DWORD *BeginPos)
{
return ExtractFromEverything(WND, Pt, BeginPos);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ static int GetWordFromConsolePack(TConsoleParams *params)
return WordLen;
}

static char* GetWordFromConsole(HWND WND, POINT Pt, int *BeginPos)
static char* GetWordFromConsole(HWND WND, POINT Pt, DWORD *BeginPos)
{
TConsoleParams *TP;
DWORD pid;
Expand Down Expand Up @@ -169,9 +169,9 @@ static char* GetWordFromConsole(HWND WND, POINT Pt, int *BeginPos)
return Result;
}

char* TryGetWordFromAnyWindow(TKnownWndClass WndType, HWND WND, POINT Pt, int *BeginPos)
char* TryGetWordFromAnyWindow(TKnownWndClass WndType, HWND WND, POINT Pt, DWORD *BeginPos)
{
typedef char* (*GetWordFunction_t)(HWND, POINT, int*);
typedef char* (*GetWordFunction_t)(HWND, POINT, DWORD*);
const GetWordFunction_t GetWordFunction[]= {
ExtractFromEverything,
ExtractWordFromRichEditPos,
Expand Down
2 changes: 1 addition & 1 deletion mouseover_win32/GetWord.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ typedef enum TKnownWndClass {
} TKnownWndClass;

TKnownWndClass GetWindowType(HWND WND, const char* WNDClass);
char* TryGetWordFromAnyWindow(TKnownWndClass WndType, HWND WND, POINT Pt, int *BeginPos);
char* TryGetWordFromAnyWindow(TKnownWndClass WndType, HWND WND, POINT Pt, DWORD *BeginPos);

#endif
4 changes: 2 additions & 2 deletions mouseover_win32/HookImportFunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ static BOOL HookImportFunction(HMODULE hModule, LPCSTR szImportModule, LPCSTR sz
if( !VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, PAGE_READWRITE, &mbi_thunk.Protect) )
return FALSE;
if (paOrigFuncs)
*paOrigFuncs = (PROC)InterlockedExchangePointer(&(pRealThunk->u1.Function), paHookFuncs);
*paOrigFuncs = (PROC)InterlockedExchangePointer((PVOID)&(pRealThunk->u1.Function), paHookFuncs);
else
InterlockedExchangePointer(&(pRealThunk->u1.Function), paHookFuncs);
InterlockedExchangePointer((PVOID)&(pRealThunk->u1.Function), paHookFuncs);

VirtualProtect(mbi_thunk.BaseAddress, mbi_thunk.RegionSize, mbi_thunk.Protect, &dwOldProtect);
return TRUE;
Expand Down
4 changes: 4 additions & 0 deletions mouseover_win32/IAccExInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <oleacc.h>
#include <servprov.h>

#ifdef INTERFACE
#undef INTERFACE
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
59 changes: 49 additions & 10 deletions mouseover_win32/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
GCC:=gcc.exe -W -Wall -s -O2
GCC64:=x86_64-w64-mingw32-gcc.exe -W -Wall -s -O2

.PHONY: all clean
.PHONY: all x64 clean

all: GdTextOutHook.dll libGdTextOutHook.a GdTextOutSpy.dll libGdTextOutSpy.a

x64: x64helper.exe GdTextOutHook64.dll libGdTextOutHook64.a GdTextOutSpy64.dll libGdTextOutSpy64.a

clean:
rm -f *.o *.a *.dll
rm -f *.o *.a *.dll *.exe

TextOutHook.o: TextOutHook.c
$(GCC) -DBUILDING_DLL -c $<
Expand All @@ -16,6 +19,15 @@ HookImportFunction.o: HookImportFunction.c
GetWord.o: GetWord.c
$(GCC) -c $<

GdTextOutHook.dll libGdTextOutHook.a: TextOutHook.o HookImportFunction.o GetWord.o
$(GCC) -shared -o GdTextOutHook.dll $^ -lgdi32 -Wl,--out-implib,libGdTextOutHook.a

TextOutSpy.o: TextOutSpy.c
$(GCC) -DBUILDING_DLL -c $<

ThTypes.o: ThTypes.c
$(GCC) -c $<

IAccEx.o: IAccEx.c
$(GCC) -c $<

Expand All @@ -25,14 +37,41 @@ GetWordByIAccEx.o: GetWordByIAccEx.c
guids.o: guids.c
$(GCC) -c $<

GdTextOutHook.dll libGdTextOutHook.a: TextOutHook.o HookImportFunction.o GetWord.o
$(GCC) -shared -o GdTextOutHook.dll $^ -lgdi32 -Wl,--out-implib,libGdTextOutHook.a
GdTextOutSpy.dll libGdTextOutSpy.a: TextOutSpy.o ThTypes.o IAccEx.o guids.o GetWordByIAccEx.o
$(GCC) -shared -o GdTextOutSpy.dll $^ -lgdi32 -luuid -loleacc -loleaut32 -Wl,--out-implib,libGdTextOutSpy.a

TextOutSpy.o: TextOutSpy.c
$(GCC) -DBUILDING_DLL -c $<
x64helper.exe: x64hooks64.o ThTypes64.o
$(GCC64) -Wl,--subsystem,windows -mwindows -o $@ $^

ThTypes.o: ThTypes.c
$(GCC) -c $<
x64hooks64.o: x64hooks.c
$(GCC64) -o $@ -c $<

GdTextOutSpy.dll libGdTextOutSpy.a: TextOutSpy.o ThTypes.o IAccEx.o guids.o GetWordByIAccEx.o
$(GCC) -shared -o GdTextOutSpy.dll $^ -lgdi32 -luuid -loleacc -loleaut32 -Wl,--out-implib,libGdTextOutSpy.a
TextOutHook64.o: TextOutHook.c
$(GCC64) -o $@ -DBUILDING_DLL -c $<

HookImportFunction64.o: HookImportFunction.c
$(GCC64) -o $@ -c $<

GetWord64.o: GetWord.c
$(GCC64) -o $@ -c $<

GdTextOutHook64.dll libGdTextOutHook64.a: TextOutHook64.o HookImportFunction64.o GetWord64.o
$(GCC64) -shared -o GdTextOutHook64.dll $^ -lgdi32 -Wl,--out-implib,libGdTextOutHook64.a

TextOutSpy64.o: TextOutSpy.c
$(GCC64) -o $@ -DBUILDING_DLL -c $<

ThTypes64.o: ThTypes.c
$(GCC64) -o $@ -c $<

IAccEx64.o: IAccEx.c
$(GCC64) -o $@ -c $<

GetWordByIAccEx64.o: GetWordByIAccEx.c
$(GCC64) -o $@ -c $<

guids64.o: guids.c
$(GCC64) -o $@ -c $<

GdTextOutSpy64.dll libGdTextOutSpy64.a: TextOutSpy64.o ThTypes64.o IAccEx64.o guids64.o GetWordByIAccEx64.o
$(GCC64) -shared -o GdTextOutSpy64.dll $^ -lgdi32 -luuid -loleacc -loleaut32 -Wl,--out-implib,libGdTextOutSpy64.a
17 changes: 13 additions & 4 deletions mouseover_win32/TextOutHook.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
#include "HookImportFunction.h"

typedef BOOL (WINAPI *TextOutANextHook_t)(HDC hdc, int nXStart, int nYStart, LPCSTR lpszString,int cbString);
TextOutANextHook_t TextOutANextHook __attribute__ ((aligned (4))) = NULL;
typedef BOOL (WINAPI *TextOutWNextHook_t)(HDC hdc, int nXStart, int nYStart, LPCWSTR lpszString,int cbString);
TextOutWNextHook_t TextOutWNextHook __attribute__ ((aligned (4))) = NULL;
typedef BOOL (WINAPI *ExtTextOutANextHook_t)(HDC hdc, int nXStart, int nYStart, UINT fuOptions, CONST RECT *lprc, LPCSTR lpszString, UINT cbString, CONST INT *lpDx);
ExtTextOutANextHook_t ExtTextOutANextHook __attribute__ ((aligned (4))) = NULL;
typedef BOOL (WINAPI *ExtTextOutWNextHook_t)(HDC hdc, int nXStart, int nYStart, UINT fuOptions, CONST RECT *lprc, LPCWSTR lpszString, UINT cbString, CONST INT *lpDx);
#ifdef __WIN64
TextOutANextHook_t TextOutANextHook __attribute__ ((aligned (8))) = NULL;
TextOutWNextHook_t TextOutWNextHook __attribute__ ((aligned (8))) = NULL;
ExtTextOutANextHook_t ExtTextOutANextHook __attribute__ ((aligned (8))) = NULL;
ExtTextOutWNextHook_t ExtTextOutWNextHook __attribute__ ((aligned (8))) = NULL;
#else
TextOutANextHook_t TextOutANextHook __attribute__ ((aligned (4))) = NULL;
TextOutWNextHook_t TextOutWNextHook __attribute__ ((aligned (4))) = NULL;
ExtTextOutANextHook_t ExtTextOutANextHook __attribute__ ((aligned (4))) = NULL;
ExtTextOutWNextHook_t ExtTextOutWNextHook __attribute__ ((aligned (4))) = NULL;
#endif

#define HOOKS_NUM 4

Expand Down Expand Up @@ -192,7 +199,7 @@ static void GetWordTextOutHook (TEverythingParams *TP)
LeaveCriticalSection(&hookCS);
}

char* ExtractFromEverything(HWND WND, POINT Pt, int *BeginPos)
char* ExtractFromEverything(HWND WND, POINT Pt, DWORD *BeginPos)
{
TEverythingParams CParams;

Expand Down Expand Up @@ -588,6 +595,8 @@ BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
(void) hInst;
(void) reserved;
switch (reason)
{
case DLL_PROCESS_ATTACH:
Expand Down
2 changes: 1 addition & 1 deletion mouseover_win32/TextOutHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct TEverythingParams {
wchar_t MatchedWordW[256];
} TEverythingParams;

char* ExtractFromEverything(HWND WND, POINT Pt, int *BeginPos);
char* ExtractFromEverything(HWND WND, POINT Pt, DWORD *BeginPos);

DLLIMPORT void GetWord (TCurrentMode *P);

Expand Down
Loading

0 comments on commit c9192ac

Please sign in to comment.