)";
56 | ReplaceStringInPlace(html, R"({aboutBrowserVersion})", prouct_title);
57 |
58 | if (html.length() <= size)
59 | {
60 | // 写入修改
61 | memcpy(begin, html.c_str(), html.length());
62 |
63 | // 修改长度
64 | new_len = html.length();
65 | changed = true;
66 | }
67 | }
68 |
69 | return changed;
70 | });
71 | }
72 |
73 | return buffer;
74 | }
75 |
76 | return RawMapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh,
77 | dwFileOffsetLow, dwNumberOfBytesToMap);
78 | }
79 |
80 | HANDLE resources_pak_file = NULL;
81 |
82 | typedef HANDLE(WINAPI *pCreateFileMapping)(
83 | _In_ HANDLE hFile,
84 | _In_opt_ LPSECURITY_ATTRIBUTES lpAttributes,
85 | _In_ DWORD flProtect,
86 | _In_ DWORD dwMaximumSizeHigh,
87 | _In_ DWORD dwMaximumSizeLow,
88 | _In_opt_ LPCTSTR lpName);
89 |
90 | pCreateFileMapping RawCreateFileMapping = NULL;
91 |
92 | HANDLE WINAPI MyCreateFileMapping(
93 | _In_ HANDLE hFile,
94 | _In_opt_ LPSECURITY_ATTRIBUTES lpAttributes,
95 | _In_ DWORD flProtect,
96 | _In_ DWORD dwMaximumSizeHigh,
97 | _In_ DWORD dwMaximumSizeLow,
98 | _In_opt_ LPCTSTR lpName)
99 | {
100 | if (hFile == resources_pak_file)
101 | {
102 | // 修改属性为可修改
103 | resources_pak_map = RawCreateFileMapping(hFile, lpAttributes, PAGE_WRITECOPY,
104 | dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
105 |
106 | // 不再需要hook
107 | resources_pak_file = NULL;
108 | MH_DisableHook(CreateFileMappingW);
109 |
110 | if (MH_CreateHook(MapViewOfFile, MyMapViewOfFile, (LPVOID *)&RawMapViewOfFile) == MH_OK)
111 | {
112 | MH_EnableHook(MapViewOfFile);
113 | }
114 |
115 | return resources_pak_map;
116 | }
117 | return RawCreateFileMapping(hFile, lpAttributes, flProtect, dwMaximumSizeHigh,
118 | dwMaximumSizeLow, lpName);
119 | }
120 |
121 | typedef HANDLE(WINAPI *pCreateFile)(
122 | _In_ LPCTSTR lpFileName,
123 | _In_ DWORD dwDesiredAccess,
124 | _In_ DWORD dwShareMode,
125 | _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
126 | _In_ DWORD dwCreationDisposition,
127 | _In_ DWORD dwFlagsAndAttributes,
128 | _In_opt_ HANDLE hTemplateFile);
129 |
130 | pCreateFile RawCreateFile = NULL;
131 |
132 | HANDLE WINAPI MyCreateFile(
133 | _In_ LPCTSTR lpFileName,
134 | _In_ DWORD dwDesiredAccess,
135 | _In_ DWORD dwShareMode,
136 | _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
137 | _In_ DWORD dwCreationDisposition,
138 | _In_ DWORD dwFlagsAndAttributes,
139 | _In_opt_ HANDLE hTemplateFile)
140 | {
141 | HANDLE file = RawCreateFile(lpFileName, dwDesiredAccess, dwShareMode,
142 | lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
143 | hTemplateFile);
144 |
145 | if (isEndWith(lpFileName, L"resources.pak"))
146 | {
147 | resources_pak_file = file;
148 | resources_pak_size = GetFileSize(resources_pak_file, NULL);
149 |
150 | if (MH_CreateHook(CreateFileMappingW, MyCreateFileMapping, (LPVOID *)&RawCreateFileMapping) == MH_OK)
151 | {
152 | MH_EnableHook(CreateFileMappingW);
153 | }
154 |
155 | // 不再需要hook
156 | MH_DisableHook(CreateFileW);
157 | }
158 |
159 | return file;
160 | }
161 |
162 | void PakPatch()
163 | {
164 | MH_STATUS status = MH_CreateHook(CreateFileW, MyCreateFile, (LPVOID *)&RawCreateFile);
165 | if (status == MH_OK)
166 | {
167 | MH_EnableHook(CreateFileW);
168 | }
169 | else
170 | {
171 | DebugLog(L"MH_CreateHook CreateFileW failed:%d", status);
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/src/TabBookmark.h:
--------------------------------------------------------------------------------
1 | #include