This commit is contained in:
love-code-yeyixiao 2024-03-16 20:28:07 +08:00
commit dd85fab321
4 changed files with 197 additions and 125 deletions

View File

@ -44,7 +44,7 @@ static ULONG_PTR Gdi_GdiDllInitialize_Common(
#ifndef _WIN64
static HDC Gdi_CreateDCW(
static HDC Gdi_CreateDCW2(
void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData);
#endif ! _WIN64
@ -99,7 +99,6 @@ static BOOL Gdi_ClosePrinter(HANDLE hPrinter);
typedef HDC(*P_CreateDCA)(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, const void* pdm);
typedef HDC(*P_CreateDCW)(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const void* pdm);
extern P_CreateDCA __sys_CreateDCA;
extern P_CreateDCW __sys_CreateDCW;
typedef ULONG (*P_GdiAddFontResourceW)(
const WCHAR *path, ULONG flags, void *reserved);
@ -150,6 +149,11 @@ P_GetBitmapBits __sys_GetBitmapBits = NULL;
P_DeleteObject __sys_DeleteObject = NULL;
P_DeleteEnhMetaFile __sys_DeleteEnhMetaFile = NULL;
P_GetStockObject __sys_GetStockObject = NULL;
P_CreateDCA __sys_CreateDCA=NULL;
P_DeleteDC __sys_DeleteDC = NULL;
P_BitBlt __sys_BitBlt = NULL;
P_StretchBlt __sys_StretchBlt = NULL;
P_TransparentBlt __sys_TransparentBlt = NULL;
//---------------------------------------------------------------------------
@ -289,13 +293,16 @@ _FX BOOL Gui_BitBlt(
DWORD rop
) {
int ret = __sys_BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop);
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
/*if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
P_GetDeviceCaps GetDeviceCaps = Ldr_GetProcAddrNew(DllName_gdi32, "GetDeviceCaps", "GetDeviceCaps"); if (!GetDeviceCaps) return ret;
int iWidth = GetDeviceCaps(hdc, HORZRES), iHeight = GetDeviceCaps(hdc, VERTRES);
int iWidth2 = GetDeviceCaps(__sys_GetDC(NULL), HORZRES), iHeight2 = GetDeviceCaps(__sys_GetDC(NULL), VERTRES);
if (iWidth == iWidth2 && iHeight == iHeight2) {
__sys_BitBlt(__sys_GetDC(NULL), x, y, cx, cy, hdcSrc, x1, y1, rop);
}
}
}*/
return ret;
}
@ -314,76 +321,22 @@ _FX BOOL Gui_StretchBlt(
)
{
int ret = __sys_StretchBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, rop);
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
/*if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
P_GetDeviceCaps GetDeviceCaps = Ldr_GetProcAddrNew(DllName_gdi32, "GetDeviceCaps", "GetDeviceCaps"); if (!GetDeviceCaps) return ret;
int iWidth = GetDeviceCaps(hdcDest, HORZRES), iHeight = GetDeviceCaps(hdcDest, VERTRES);
int iWidth2 = GetDeviceCaps(__sys_GetDC(NULL), HORZRES), iHeight2 = GetDeviceCaps(__sys_GetDC(NULL), VERTRES);
if (iWidth == iWidth2 && iHeight == iHeight2) {
__sys_StretchBlt(__sys_GetDC(NULL), xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, rop);
}
}
}*/
return ret;
}
HBITMAP bmp = NULL;
_FX HDC Gui_CreateDCA(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, const DEVMODEA* pdm) {
HDC ret = __sys_CreateDCA(pwszDriver, pwszDevice, pszPort, &pdm);
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
if (pwszDevice == NULL && strcmp(pwszDriver, "DISPLAY") == 0) {
typedef HDC(*P_CreateCompatibleDC)(HDC hdc);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);
iWidth = GetDeviceCaps(ret, HORZRES);
iHeight = GetDeviceCaps(ret, VERTRES);
HBITMAP hBmp;
if (bmp == NULL)
bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight);
hBmp = bmp;
SelectObject(ret2, hBmp);
DeleteDC(ret);
ret = ret2;
}
}
return ret;
}
_FX HDC Gui_CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const DEVMODEW* pdm) {
HDC ret = __sys_CreateDCW(pwszDriver, pwszDevice, pszPort, &pdm);
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
if (pwszDevice == NULL && lstrcmp(pwszDriver, L"DISPLAY") == 0) {
typedef HDC(*P_CreateCompatibleDC)(HDC hdc);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);
iWidth = GetDeviceCaps(ret, HORZRES);
iHeight = GetDeviceCaps(ret, VERTRES);
HBITMAP hBmp;
if (bmp == NULL)
bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight);
hBmp = bmp;
SelectObject(ret2, hBmp);
DeleteDC(ret);
ret = ret2;
}
}
return ret;
}
//---------------------------------------------------------------------------
// Gdi_SplWow64
//---------------------------------------------------------------------------
_FX void Gdi_SplWow64(BOOLEAN Register)
{
//
@ -396,7 +349,7 @@ _FX void Gdi_SplWow64(BOOLEAN Register)
// NoSbieDesk END
GUI_SPLWOW64_REQ req;
void *rpl;
void* rpl;
if (Register) {
@ -421,8 +374,8 @@ _FX void Gdi_SplWow64(BOOLEAN Register)
#ifndef _WIN64
_FX HDC Gdi_CreateDCW(
void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData)
_FX HDC Gdi_CreateDCW2(
void* lpszDriver, void* lpszDevice, void* lpszOutput, void* lpInitData)
{
//
// on 64-bit Windows 8, some 32-bit programs (Notepad, Chrome) cannot
@ -436,20 +389,20 @@ _FX HDC Gdi_CreateDCW(
HDC hdc = __sys_CreateDCW(
lpszDriver, lpszDevice, lpszOutput, lpInitData);
if ((! hdc) && lpszDriver && _wcsicmp(lpszDriver, L"WINSPOOL") == 0) {
if ((!hdc) && lpszDriver && _wcsicmp(lpszDriver, L"WINSPOOL") == 0) {
P_DocumentProperties __sys_DocumentProperties =
Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW","DocumentPropertiesW");
Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW", "DocumentPropertiesW");
ULONG retry = 0;
while (__sys_DocumentProperties && (! hdc) && (retry < 20)) {
while (__sys_DocumentProperties && (!hdc) && (retry < 20)) {
HANDLE hPrinter;
Sleep(retry * 25);
if (! __sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL))
if (!__sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL))
break;
__sys_DocumentProperties(
@ -468,6 +421,89 @@ _FX HDC Gdi_CreateDCW(
}
#endif ! _WIN64
HBITMAP bmp2 = NULL;
_FX HDC Gui_CreateDCA(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, const void* pdm) {
HDC ret = __sys_CreateDCA(pwszDriver, pwszDevice, pszPort, pdm);
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
if (pwszDevice == NULL && strcmp(pwszDriver, "DISPLAY") == 0) {
typedef HDC(*P_CreateCompatibleDC)(HDC hdc);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
typedef HBITMAP (*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy);
GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h);
GET_WIN_API(SelectObject, DllName_gdi32);
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
GET_WIN_API(GetDeviceCaps, DllName_gdi32);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);
iWidth = GetDeviceCaps(ret, HORZRES);
iHeight = GetDeviceCaps(ret, VERTRES);
HBITMAP hBmp;
if (bmp2 == NULL)
bmp2 = CreateCompatibleBitmap(ret2, iWidth, iHeight);
hBmp = bmp2;
SelectObject(ret2, hBmp);
DeleteDC(ret);
ret = ret2;
}
}
return ret;
}
_FX HDC Gui_CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const void* pdm) {
void* pdm2=NULL;
memcpy(pdm2, pdm, sizeof(pdm));
#ifdef _WIN64
HDC ret = __sys_CreateDCW(pwszDriver, pwszDevice, pszPort, pdm);
#else
HDC ret = Gdi_CreateDCW2((void*)pwszDriver, (void*)pwszDevice, (void*)pszPort, pdm2);
#endif // _WIN64
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
if (pwszDevice == NULL && lstrcmp(pwszDriver, L"DISPLAY") == 0) {
typedef HDC(*P_CreateCompatibleDC)(HDC hdc);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy);
GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h);
GET_WIN_API(SelectObject, DllName_gdi32);
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
GET_WIN_API(GetDeviceCaps, DllName_gdi32);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);
iWidth = GetDeviceCaps(ret, HORZRES);
iHeight = GetDeviceCaps(ret, VERTRES);
HBITMAP hBmp;
if (bmp2 == NULL)
bmp2 = CreateCompatibleBitmap(ret2, iWidth, iHeight);
hBmp = bmp2;
SelectObject(ret2, hBmp);
DeleteDC(ret);
ret = ret2;
}
}
return ret;
}
//---------------------------------------------------------------------------
@ -901,6 +937,10 @@ _FX BOOLEAN Gdi_Full_Init_impl(HMODULE module, BOOLEAN full)
P_RemoveFontResourceExW RemoveFontResourceExW;
P_GetFontResourceInfoW GetFontResourceInfoW;
P_CreateScalableFontResourceW CreateScalableFontResourceW;
P_BitBlt BitBlt;
P_StretchBlt StretchBlt;
P_CreateDCA CreateDCA;
P_DeleteDC DeleteDC;
P_EnumFontFamiliesEx EnumFontFamiliesExA;
P_EnumFontFamiliesEx EnumFontFamiliesExW;
@ -926,6 +966,18 @@ _FX BOOLEAN Gdi_Full_Init_impl(HMODULE module, BOOLEAN full)
GetFontResourceInfoW = (P_GetFontResourceInfoW)
GetProcAddress(module, "GetFontResourceInfoW");
CreateDCA = (P_CreateDCA)
GetProcAddress(module, "CreateDCA");
BitBlt = (P_BitBlt)
GetProcAddress(module, "BitBlt");
StretchBlt = (P_StretchBlt)
GetProcAddress(module, "StretchBlt");
DeleteDC = (P_DeleteDC)
GetProcAddress(module, "DeleteDC");
if (full) {
CreateScalableFontResourceW = (P_CreateScalableFontResourceW)
GetProcAddress(module, "CreateScalableFontResourceWImpl");
@ -935,21 +987,21 @@ _FX BOOLEAN Gdi_Full_Init_impl(HMODULE module, BOOLEAN full)
GetProcAddress(module, "CreateScalableFontResourceW");
}
#ifndef _WIN64
/*#ifndef _WIN64
if (Dll_OsBuild >= 8400) {
SBIEDLL_HOOK(Gdi_, CreateDCW);
}
#endif ! _WIN64
#endif ! _WIN64*/
SBIEDLL_HOOK(Gdi_, GdiAddFontResourceW);
SBIEDLL_HOOK(Gdi_, RemoveFontResourceExW);
SBIEDLL_HOOK(Gui_,DeleteDC);
SBIEDLL_HOOK(Gui_,BitBlt);
SBIEDLL_HOOK(Gui_,StretchBlt);
//SBIEDLL_HOOK(Gui_,DeleteDC);
//SBIEDLL_HOOK(Gui_,BitBlt);
//SBIEDLL_HOOK(Gui_,StretchBlt);
//SBIEDLL_HOOK_GUI(TransparentBlt);
SBIEDLL_HOOK(Gui_,CreateDCA);
SBIEDLL_HOOK(Gui_,CreateDCW);

View File

@ -432,11 +432,11 @@ _FX BOOLEAN Gui_Init(HMODULE module)
GUI_IMPORT___(GetWindowDC);
GUI_IMPORT___(GetDC);
GUI_IMPORT___(GetDCEx);
GUI_IMPORT___(DeleteDC);
//GUI_IMPORT___(DeleteDC);
GUI_IMPORT___(ReleaseDC);
GUI_IMPORT___(BitBlt);
GUI_IMPORT___(StretchBlt);
GUI_IMPORT___(TransparentBlt);
//GUI_IMPORT___(BitBlt);
//GUI_IMPORT___(StretchBlt);
//GUI_IMPORT___(TransparentBlt);
// GUI_IMPORT___(CreateDCA);
// GUI_IMPORT___(CreateDCW);
GUI_IMPORT___(GetWindowThreadProcessId);

View File

@ -599,10 +599,7 @@ GUI_SYS_VAR(GetDCEx)
GUI_SYS_VAR(GetWindowDC)
GUI_SYS_VAR(ReleaseDC)
GUI_SYS_VAR(PrintWindow)
GUI_SYS_VAR(DeleteDC)
GUI_SYS_VAR(BitBlt)
GUI_SYS_VAR(StretchBlt)
GUI_SYS_VAR(TransparentBlt)
GUI_SYS_VAR(ClipCursor)

View File

@ -1509,9 +1509,16 @@ _FX HDC Gui_GetDC(HWND hWnd)
!Gui_IsSameBox(hWnd, &pid, &tid)) {
typedef HDC(*P_CreateCompatibleDC)(HDC hdc);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
typedef HGDIOBJ (*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h);
GET_WIN_API(SelectObject, DllName_gdi32);
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
GET_WIN_API(GetDeviceCaps, DllName_gdi32);
typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy);
GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);
@ -1549,6 +1556,14 @@ _FX HDC Gui_GetWindowDC(HWND hWnd)
//typedef BOOL(*P_DeleteDC)(HDC hdc);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h);
GET_WIN_API(SelectObject, DllName_gdi32);
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
GET_WIN_API(GetDeviceCaps, DllName_gdi32);
typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy);
GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);
@ -1586,6 +1601,14 @@ _FX HDC Gui_GetDCEx(HWND hWnd, HRGN hrgnClip, DWORD flags)
//typedef BOOL(*P_DeleteDC)(HDC hdc);
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h);
GET_WIN_API(SelectObject, DllName_gdi32);
typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index);
GET_WIN_API(GetDeviceCaps, DllName_gdi32);
typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy);
GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32);
int iWidth, iHeight;
HDC ret2 = CreateCompatibleDC(ret);