Skip to content

Commit

Permalink
1.18
Browse files Browse the repository at this point in the history
updated
  • Loading branch information
silight-jp committed Oct 23, 2016
1 parent 3d5df35 commit a3718d8
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 43 deletions.
Binary file modified bin/Release/EasyHK32.dll
Binary file not shown.
Binary file modified bin/Release/EasyHK64.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions readmeEN.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ How to use
Good Luck!

Version History
2016/10/15 1.18 Improve compatibility with MacTray.
Support DynamicCodePolicy.
2016/10/11 1.17 Bug fix for High DPI.
Add ForceNoHinting for Windows Vista or later.
2016/10/08 1.16 Bug fix.
Expand Down
Binary file modified readmeJP.txt
Binary file not shown.
8 changes: 4 additions & 4 deletions resource32.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,17,0,0
PRODUCTVERSION 1,17,0,0
FILEVERSION 1,18,0,0
PRODUCTVERSION 1,18,0,0
FILEFLAGSMASK 0x0L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -31,12 +31,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "MacTypePatch for DirectWrite Hook"
VALUE "FileVersion", "1.17.0.0"
VALUE "FileVersion", "1.18.0.0"
VALUE "InternalName", "EasyHK32.dll"
VALUE "LegalCopyright", "Copyright (C) 2016 silight"
VALUE "OriginalFilename", "EasyHK32.dll"
VALUE "ProductName", "MacTypePatch for DirectWrite Hook"
VALUE "ProductVersion", "1.17.0.0"
VALUE "ProductVersion", "1.18.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
8 changes: 4 additions & 4 deletions resource64.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,17,0,0
PRODUCTVERSION 1,17,0,0
FILEVERSION 1,18,0,0
PRODUCTVERSION 1,18,0,0
FILEFLAGSMASK 0x0L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -31,12 +31,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "MacTypePatch for DirectWrite Hook"
VALUE "FileVersion", "1.17.0.0"
VALUE "FileVersion", "1.18.0.0"
VALUE "InternalName", "EasyHK64.dll"
VALUE "LegalCopyright", "Copyright (C) 2016 silight"
VALUE "OriginalFilename", "EasyHK64.dll"
VALUE "ProductName", "MacTypePatch for DirectWrite Hook"
VALUE "ProductVersion", "1.17.0.0"
VALUE "ProductVersion", "1.18.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
2 changes: 1 addition & 1 deletion src/EasyHK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NTSTATUS __stdcall LhInstallHook(

InEntryPoint = changeHookTargetIfNeed(InEntryPoint);

NTSTATUS isFailed = _LhInstallHook(
NTSTATUS isFailed = LhInstallHook2(
InEntryPoint,
InHookProc,
InCallback,
Expand Down
71 changes: 70 additions & 1 deletion src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,70 @@ static size_t fpIndex = 0;
static HOOK_TRACE_INFO htiArray[MAX_HOOK_COUNT];
static std::unordered_set<void*> fpSet;

extern NTSTATUS LhInstallHook2(
void* InEntryPoint,
void* InHookProc,
void* InCallback,
TRACED_HOOK_HANDLE OutHandle
) {
static auto hModule = GetModuleHandleW(L"Kernel32.dll");
static auto GetProcessMitigationPolicyProc = GetProcAddress(hModule, "GetProcessMitigationPolicy");
static auto pGetProcessMitigationPolicy = (decltype(&GetProcessMitigationPolicy))GetProcessMitigationPolicyProc;
static auto GetThreadInformationProc = GetProcAddress(hModule, "GetThreadInformation");
static auto pGetThreadInformation = (decltype(&GetThreadInformation))GetThreadInformationProc;
static auto SetThreadInformationProc = GetProcAddress(hModule, "SetThreadInformation");
static auto pSetThreadInformation = (decltype(&SetThreadInformation))SetThreadInformationProc;

if (pGetProcessMitigationPolicy && pGetThreadInformation && pSetThreadInformation) {
PROCESS_MITIGATION_DYNAMIC_CODE_POLICY policy;
BOOL isSucceeded = pGetProcessMitigationPolicy(
GetCurrentProcess(),
ProcessDynamicCodePolicy,
&policy,
sizeof(PROCESS_MITIGATION_DYNAMIC_CODE_POLICY)
);

if (!isSucceeded) {
return -1;
}

if (policy.ProhibitDynamicCode) {
if (!policy.AllowThreadOptOut) {
return -1;
}

HANDLE thread = GetCurrentThread();
DWORD prev;
pGetThreadInformation(
thread,
ThreadDynamicCodePolicy,
&prev,
sizeof(DWORD)
);
DWORD policy = THREAD_DYNAMIC_CODE_ALLOW;
pSetThreadInformation(
thread,
ThreadDynamicCodePolicy,
&policy,
sizeof(DWORD)
);
NTSTATUS ret = _LhInstallHook(
InEntryPoint, InHookProc, InCallback, OutHandle
);
pSetThreadInformation(
thread,
ThreadDynamicCodePolicy,
&prev,
sizeof(DWORD)
);
return ret;
}
}
return _LhInstallHook(
InEntryPoint, InHookProc, InCallback, OutHandle
);
}

static void* hookAndGetOrig(void* orig, void* impl) {
auto lock = globalMutex.getLock();

Expand All @@ -28,7 +92,7 @@ static void* hookAndGetOrig(void* orig, void* impl) {
TRACED_HOOK_HANDLE thh = &htiArray[fpIndex];
thh->Link = NULL;

NTSTATUS isFailed = _LhInstallHook(orig, impl, NULL, thh);
NTSTATUS isFailed = LhInstallHook2(orig, impl, NULL, thh);
if (isFailed) return orig;

ULONG ZERO = 0;
Expand Down Expand Up @@ -111,4 +175,9 @@ extern void unhookAll() {
mhookSet.clear();
}
_LhWaitForPendingRemovals();
{
auto lock = globalMutex.getLock();
changeMap.clear();
isInited = false;
}
}
7 changes: 7 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
extern RecursiveMutex globalMutex;


typedef struct _HOOK_TRACE_INFO_ *TRACED_HOOK_HANDLE;
extern NTSTATUS LhInstallHook2(
void* InEntryPoint,
void* InHookProc,
void* InCallback,
TRACED_HOOK_HANDLE OutHandle
);

extern bool insertVtbl(void** vtbl);

Expand Down
73 changes: 40 additions & 33 deletions src/directwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,39 @@ namespace Impl_IDWriteBitmapRenderTarget
RECT* blackBoxRect
) {
HRESULT hr = E_FAIL;
if (FAILED(hr)) {
if (GeneralParams.ForceNoHinting) {
DWRITE_MATRIX prev;
This->GetCurrentTransform(&prev);
if (GeneralParams.ForceNoHinting) {
DWRITE_MATRIX prev;
hr = This->GetCurrentTransform(&prev);
if (SUCCEEDED(hr)) {
DWRITE_MATRIX rotate = prev;
rotate.m12 += 1.0f / 0xFFFF;
rotate.m21 += 1.0f / 0xFFFF;
This->SetCurrentTransform(&rotate);
hr = This->DrawGlyphRun(
baselineOriginX,
baselineOriginY,
measuringMode,
glyphRun,
DirectWriteParams.getDWriteRenderingParams(),
textColor,
blackBoxRect
);
This->SetCurrentTransform(&prev);
} else {
hr = This->DrawGlyphRun(
baselineOriginX,
baselineOriginY,
measuringMode,
glyphRun,
DirectWriteParams.getDWriteRenderingParams(),
textColor,
blackBoxRect
);
hr = This->SetCurrentTransform(&rotate);
if (SUCCEEDED(hr)) {
hr = This->DrawGlyphRun(
baselineOriginX,
baselineOriginY,
measuringMode,
glyphRun,
DirectWriteParams.getDWriteRenderingParams(),
textColor,
blackBoxRect
);
This->SetCurrentTransform(&prev);
}
}
}
if (FAILED(hr)) {
hr = This->DrawGlyphRun(
baselineOriginX,
baselineOriginY,
measuringMode,
glyphRun,
DirectWriteParams.getDWriteRenderingParams(),
textColor,
blackBoxRect
);
}
if (FAILED(hr)) {
hr = This->DrawGlyphRun(
baselineOriginX,
Expand Down Expand Up @@ -381,14 +384,16 @@ namespace Impl_IDWriteFontCollection
UINT32* index,
BOOL* exists
) {
if (FontSubstitutesMap.count(familyName)) {
HRESULT hr = This->FindFamilyName(
FontSubstitutesMap.at(familyName).c_str(),
index,
exists
);
if (SUCCEEDED(hr) && *exists) {
return hr;
if (familyName && index && exists) {
if (FontSubstitutesMap.count(familyName)) {
HRESULT hr = This->FindFamilyName(
FontSubstitutesMap.at(familyName).c_str(),
index,
exists
);
if (SUCCEEDED(hr) && *exists) {
return hr;
}
}
}
return This->FindFamilyName(familyName, index, exists);
Expand Down Expand Up @@ -503,6 +508,8 @@ namespace Impl


extern void hookDirectWrite() {
auto lock = globalMutex.getLock();

HMODULE hModuleDWrite = GetModuleHandleW(L"dwrite.dll");
if (!hModuleDWrite) return;

Expand Down

1 comment on commit a3718d8

@mufunyo
Copy link

@mufunyo mufunyo commented on a3718d8 Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

The latest commit here is for 1.18, but the latest version on your blog is 1.26. Could you please update the source code here on GitHub to 1.26?

Thanks!

Please sign in to comment.