Chrome++ )" RELEASE_VER_STR u8R"( modified version
)";
60 | ReplaceStringInPlace(html, R"({aboutBrowserVersion})",
61 | prouct_title);
62 |
63 | if (html.length() <= size) {
64 | // Write modifications.
65 | memcpy(begin, html.c_str(), html.length());
66 |
67 | // Modify length.
68 | new_len = html.length();
69 | changed = true;
70 | }
71 | }
72 |
73 | return changed;
74 | });
75 | }
76 |
77 | return buffer;
78 | }
79 |
80 | return RawMapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh,
81 | dwFileOffsetLow, dwNumberOfBytesToMap);
82 | }
83 |
84 | HANDLE WINAPI MyCreateFileMapping(_In_ HANDLE hFile,
85 | _In_opt_ LPSECURITY_ATTRIBUTES lpAttributes,
86 | _In_ DWORD flProtect,
87 | _In_ DWORD dwMaximumSizeHigh,
88 | _In_ DWORD dwMaximumSizeLow,
89 | _In_opt_ LPCTSTR lpName) {
90 | if (hFile == resources_pak_file) {
91 | // Modify it to be modifiable.
92 | resources_pak_map =
93 | RawCreateFileMapping(hFile, lpAttributes, PAGE_WRITECOPY,
94 | dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
95 |
96 | // No more hook needed.
97 | resources_pak_file = nullptr;
98 | DetourTransactionBegin();
99 | DetourUpdateThread(GetCurrentThread());
100 | DetourDetach((LPVOID*)&RawCreateFileMapping, MyCreateFileMapping);
101 | auto status = DetourTransactionCommit();
102 | if (status != NO_ERROR) {
103 | DebugLog(L"Unhook RawCreateFileMapping failed %d", status);
104 | }
105 |
106 | DetourTransactionBegin();
107 | DetourUpdateThread(GetCurrentThread());
108 | DetourAttach((LPVOID*)&RawMapViewOfFile, MyMapViewOfFile);
109 | status = DetourTransactionCommit();
110 | if (status != NO_ERROR) {
111 | DebugLog(L"Hook RawMapViewOfFile failed %d", status);
112 | }
113 |
114 | return resources_pak_map;
115 | }
116 | return RawCreateFileMapping(hFile, lpAttributes, flProtect, dwMaximumSizeHigh,
117 | dwMaximumSizeLow, lpName);
118 | }
119 |
120 | HANDLE WINAPI MyCreateFile(_In_ LPCTSTR lpFileName,
121 | _In_ DWORD dwDesiredAccess,
122 | _In_ DWORD dwShareMode,
123 | _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
124 | _In_ DWORD dwCreationDisposition,
125 | _In_ DWORD dwFlagsAndAttributes,
126 | _In_opt_ HANDLE hTemplateFile) {
127 | HANDLE file = RawCreateFile(lpFileName, dwDesiredAccess, dwShareMode,
128 | lpSecurityAttributes, dwCreationDisposition,
129 | dwFlagsAndAttributes, hTemplateFile);
130 |
131 | if (isEndWith(lpFileName, L"resources.pak")) {
132 | resources_pak_file = file;
133 | resources_pak_size = GetFileSize(resources_pak_file, nullptr);
134 |
135 | DetourTransactionBegin();
136 | DetourUpdateThread(GetCurrentThread());
137 | DetourAttach((LPVOID*)&RawCreateFileMapping, MyCreateFileMapping);
138 | auto status = DetourTransactionCommit();
139 | if (status != NO_ERROR) {
140 | DebugLog(L"Hook RawCreateFileMapping failed %d", status);
141 | }
142 |
143 | // No more hook needed.
144 | DetourTransactionBegin();
145 | DetourUpdateThread(GetCurrentThread());
146 | DetourDetach((LPVOID*)&RawCreateFile, MyCreateFile);
147 | status = DetourTransactionCommit();
148 | if (status != NO_ERROR) {
149 | DebugLog(L"Unhook RawCreateFile failed %d", status);
150 | }
151 | }
152 |
153 | return file;
154 | }
155 |
156 | void PakPatch() {
157 | DetourTransactionBegin();
158 | DetourUpdateThread(GetCurrentThread());
159 | DetourAttach((LPVOID*)&RawCreateFile, MyCreateFile);
160 | auto status = DetourTransactionCommit();
161 | if (status != NO_ERROR) {
162 | DebugLog(L"Hook RawCreateFile failed %d", status);
163 | }
164 | }
165 |
166 | #endif // PAKPATCH_H_
167 |
--------------------------------------------------------------------------------
/src/patch.h:
--------------------------------------------------------------------------------
1 | #ifndef PATCH_H_
2 | #define PATCH_H_
3 |
4 | typedef LONG NTSTATUS, *PNTSTATUS;
5 |
6 | #ifndef NT_SUCCESS
7 | #define NT_SUCCESS(x) ((x) >= 0)
8 | #define STATUS_SUCCESS ((NTSTATUS)0)
9 | #endif
10 |
11 | typedef struct _UNICODE_STRING {
12 | USHORT Length;
13 | USHORT MaximumLength;
14 | PWSTR Buffer;
15 | } UNICODE_STRING, *PUNICODE_STRING;
16 |
17 | typedef NTSTATUS(WINAPI* pLdrLoadDll)(IN PWCHAR PathToFile OPTIONAL,
18 | IN ULONG Flags OPTIONAL,
19 | IN PUNICODE_STRING ModuleFileName,
20 | OUT PHANDLE ModuleHandle);
21 |
22 | pLdrLoadDll RawLdrLoadDll = nullptr;
23 |
24 | // https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/dialogs/outdated_upgrade_bubble.cc?q=outdated_upgrade_bubble&ss=chromium%2Fchromium%2Fsrc
25 | // This function is invalid and needs to be modified.
26 | // void Outdated(HMODULE module) {
27 | // // "OutdatedUpgradeBubble.Show"
28 | // #ifdef _WIN64
29 | // BYTE search[] = {0x48, 0x89, 0x8C, 0x24, 0xF0, 0x00, 0x00, 0x00, 0x80,
30 | // 0x3D}; uint8_t* match = SearchModuleRaw(module, search, sizeof(search));
31 | // #else
32 | // BYTE search[] = {0x31, 0xE8, 0x89, 0x45, 0xF0, 0x88, 0x5D, 0xEF, 0x80,
33 | // 0x3D}; uint8_t* match = SearchModuleRaw(module, search, sizeof(search));
34 | // #endif
35 | // if (match) {
36 | // if (*(match + 0xF) == 0x74) {
37 | // BYTE patch[] = {0x90, 0x90};
38 | // WriteMemory(match + 0xF, patch, sizeof(patch));
39 | // }
40 | // } else {
41 | // DebugLog(L"patch Outdated failed %p", module);
42 | // }
43 | // }
44 |
45 | void DevWarning(HMODULE module) {
46 | // "enable-automation"
47 | }
48 |
49 | NTSTATUS WINAPI MyLdrLoadDll(IN PWCHAR PathToFile OPTIONAL,
50 | IN ULONG Flags OPTIONAL,
51 | IN PUNICODE_STRING ModuleFileName,
52 | OUT PHANDLE ModuleHandle) {
53 | static bool chrome_loaded = false;
54 |
55 | NTSTATUS ntstatus =
56 | RawLdrLoadDll(PathToFile, Flags, ModuleFileName, ModuleHandle);
57 | if (NT_SUCCESS(ntstatus)) {
58 | if (wcsstr(ModuleFileName->Buffer, L"chrome.dll") != 0 && !chrome_loaded) {
59 | chrome_loaded = true;
60 | // Outdated((HMODULE)*ModuleHandle);
61 | DevWarning((HMODULE)*ModuleHandle);
62 | }
63 | }
64 | return ntstatus;
65 | };
66 |
67 | void MakePatch() {
68 | // HMODULE chrome = GetModuleHandle(L"chrome.dll");
69 | // if (chrome)
70 | // {
71 | // Outdated(chrome);
72 | // DevWarning(chrome);
73 | // return;
74 | // }
75 | HMODULE ntdll = GetModuleHandle(L"ntdll.dll");
76 | if (ntdll) {
77 | RawLdrLoadDll = (pLdrLoadDll)GetProcAddress(ntdll, "LdrLoadDll");
78 | if (RawLdrLoadDll) {
79 | DetourTransactionBegin();
80 | DetourUpdateThread(GetCurrentThread());
81 | DetourAttach((LPVOID*)&RawLdrLoadDll, MyLdrLoadDll);
82 | auto status = DetourTransactionCommit();
83 | if (status != NO_ERROR) {
84 | DebugLog(L"Hook LdrLoadDll failed %d", status);
85 | }
86 | }
87 | }
88 | }
89 |
90 | #endif // PATCH_H_
91 |
--------------------------------------------------------------------------------
/src/portable.h:
--------------------------------------------------------------------------------
1 | #ifndef PORTABLE_H_
2 | #define PORTABLE_H_
3 |
4 | // Construct new command line with portable mode.
5 | std::wstring GetCommand(LPWSTR param) {
6 | std::vector