Skip to content

Commit

Permalink
chore: translate and standardize comments into English
Browse files Browse the repository at this point in the history
  • Loading branch information
Bush2021 committed May 6, 2024
1 parent c41f647 commit b29bdec
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 107 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

# Features
* Double-click to close tab.
* Right-click to close tab. (Hold Shift to show the original menu.)
* Preserve the last tab (prevents the browser from closing when the last tab is closed; clicking the close button will not work.)
* Right-click to close tab (Hold Shift to show the original menu).
* Preserve the last tab (prevents the browser from closing when the last tab is closed; clicking the close button will not work).
* Use the mouse wheel to switch tabs when hovering over the tab bar.
* Use the mouse wheel to switch tabs when holding the right mouse button.
* Create new tab to opens the contents entered in address bar. (Can be configured to open in foreground or background.)
* Create new tab to opens bookmarks. (Can be configured to open in foreground or background.)
* Create new tab to opens the contents entered in address bar (Can be configured to open in foreground or background).
* Create new tab to opens bookmarks (Can be configured to open in foreground or background).
* Disable the above two features when the current tab is a new tab.
* Customize hotkeys to quickly hide the browser window (boss key).
* Customize hotkeys to translate web page.
Expand Down
24 changes: 12 additions & 12 deletions src/chrome++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ typedef int (*Startup)();
Startup ExeMain = NULL;

void ChromePlus() {
// 快捷方式
// Shortcut.
SetAppId();

// 便携化补丁
// Portable hajack patch.
MakeGreen();

// 标签页,书签,地址栏增强
// Enhancement of the address bar, tab, and bookmark.
TabBookmark();

// 给pak文件打补丁
// Patch the pak file.
PakPatch();

// 处理热键
// Process the hotkey.
GetHotkey();
}

Expand All @@ -49,28 +49,28 @@ void ChromePlusCommand(LPWSTR param) {
}

int Loader() {
// 硬补丁
// Hard patch.
MakePatch();

// 只关注主界面
// Only main interface.
LPWSTR param = GetCommandLineW();
// DebugLog(L"param %s", param);
if (!wcsstr(param, L"-type=")) {
ChromePlusCommand(param);
}

// 返回到主程序
// Return to the main function.
return ExeMain();
}

void InstallLoader() {
// 获取程序入口点
// Get the address of the original entry point of the main module.
MODULEINFO mi;
GetModuleInformation(GetCurrentProcess(), GetModuleHandle(NULL), &mi,
sizeof(MODULEINFO));
PBYTE entry = (PBYTE)mi.EntryPoint;

// 入口点跳转到Loader
// Jump from the original entry to the loader.
MH_STATUS status = MH_CreateHook(entry, Loader, (LPVOID*)&ExeMain);
if (status == MH_OK) {
MH_EnableHook(entry);
Expand All @@ -88,10 +88,10 @@ EXTERNC BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID pv) {
DisableThreadLibraryCalls(hModule);
hInstance = hModule;

// 保持系统dll原有功能
// Maintain the original function of system DLLs.
LoadSysDll(hModule);

// 初始化HOOK库成功以后安装加载器
// Install the loader after successfully initializing MinHook.
MH_STATUS status = MH_Initialize();
if (status == MH_OK) {
InstallLoader();
Expand Down
13 changes: 7 additions & 6 deletions src/hijack.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ namespace hijack {
__nop(); \
return __COUNTER__; \
}
// 用 __COUNTER__ 来生成一点不一样的代码,避免被 VS 自动合并相同函数
// Use __COUNTER__ to generate slightly different code to avoid
// being automatically merged with the same functions by VS.

#define EXPORT(api) int __cdecl api() NOP_FUNC

#pragma region 声明导出函数
// 声明导出函数
#pragma region Declare the exported functions
// Declare the exported functions.
#pragma comment( \
linker, \
"/export:GetFileVersionInfoA=?GetFileVersionInfoA@hijack@@YAHXZ,@1")
Expand Down Expand Up @@ -91,7 +92,7 @@ EXPORT(VerQueryValueW)
} // namespace hijack
#pragma endregion

#pragma region 还原导出函数
#pragma region Restore the export function
bool WriteMemory(PBYTE BaseAddress, PBYTE Buffer, DWORD nSize) {
DWORD ProtectFlag = 0;
if (VirtualProtectEx(GetCurrentProcess(), BaseAddress, nSize,
Expand All @@ -105,7 +106,7 @@ bool WriteMemory(PBYTE BaseAddress, PBYTE Buffer, DWORD nSize) {
return false;
}

// 还原导出函数
// Restore the export function.
void InstallJMP(PBYTE BaseAddress, uintptr_t Function) {
if (*BaseAddress == 0xE9) {
BaseAddress++;
Expand Down Expand Up @@ -133,7 +134,7 @@ void InstallJMP(PBYTE BaseAddress, uintptr_t Function) {
}
#pragma endregion

#pragma region 加载系统dll
#pragma region Load system dll
void LoadVersion(HINSTANCE hModule) {
PBYTE pImageBase = (PBYTE)hModule;
PIMAGE_DOS_HEADER pimDH = (PIMAGE_DOS_HEADER)pImageBase;
Expand Down
6 changes: 2 additions & 4 deletions src/hotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ UINT ParseHotkeys(const wchar_t* keys) {
}
} else {
TCHAR wch = key[0];
if (key.length() == 1) // 解析单个字符A-Z、0-9等
if (key.length() == 1) // Parse single characters A-Z, 0-9, etc.
{
if (isalnum(wch))
vk = toupper(wch);
else
vk = LOWORD(VkKeyScan(wch));
} else if (wch == 'F' || wch == 'f') // 解析F1-F24功能键
} else if (wch == 'F' || wch == 'f') // Parse the F1-F24 function keys.
{
if (isdigit(key[1])) {
int FX = _wtoi(&key[1]);
Expand All @@ -64,7 +64,6 @@ static bool is_hide = false;
static std::vector<HWND> hwnd_list;

BOOL CALLBACK SearchChromeWindow(HWND hWnd, LPARAM lParam) {
// 隐藏
if (IsWindowVisible(hWnd)) {
wchar_t buff[256];
GetClassNameW(hWnd, buff, 255);
Expand Down Expand Up @@ -110,7 +109,6 @@ void Hotkey(const std::wstring& keys, HotkeyAction action) {
UINT flag = ParseHotkeys(keys.c_str());

std::thread th([flag, action]() {
// 注册热键
RegisterHotKey(NULL, 0, LOWORD(flag), HIWORD(flag));

MSG msg;
Expand Down
22 changes: 11 additions & 11 deletions src/iaccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void TraversalAccessible(NodePtr node, Function f, bool raw_traversal = false) {
}

if (is_task_completed) {
arrChildren[j].pdispVal->Release(); // 立刻释放,避免内存泄漏
arrChildren[j].pdispVal->Release(); // Release immediately to avoid memory leaks.
continue;
}

Expand Down Expand Up @@ -179,7 +179,7 @@ NodePtr FindPageTabList(NodePtr node) {
role == ROLE_SYSTEM_PAGETABLIST) {
page_tab_list = child;
} else if (role == ROLE_SYSTEM_PANE || role == ROLE_SYSTEM_TOOLBAR) {
// 必须保留这两个判断,否则会闪退 (#56)
// These two judgments must be retained, otherwise it will crash (#56)
page_tab_list = FindPageTabList(child);
}
return page_tab_list;
Expand Down Expand Up @@ -241,7 +241,7 @@ NodePtr GetMenuBarPane(HWND hwnd) {
return menu_bar_pane;
}

// 获取当前标签页数量
// Gets the current number of tabs.
__int64 GetTabCount(NodePtr top) {
NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST);
if (!page_tab_list) {
Expand Down Expand Up @@ -295,7 +295,7 @@ NodePtr FindChildElement(NodePtr parent, long role, int skipcount = 0) {
return element;
}

// 鼠标是否在某个标签上
// Whether the mouse is on a tab
bool IsOnOneTab(NodePtr top, POINT pt) {
NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST);
if (!page_tab_list) {
Expand Down Expand Up @@ -338,7 +338,7 @@ bool IsOnlyOneTab(NodePtr top) {
return tab_count <= 1;
}

// 鼠标是否在标签栏上
// Whether the mouse is on the tab bar
bool IsOnTheTabBar(NodePtr top, POINT pt) {
bool flag = false;
NodePtr page_tab_list = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST);
Expand All @@ -352,7 +352,7 @@ bool IsOnTheTabBar(NodePtr top, POINT pt) {
return flag;
}

// 从当前标签页的名称判断是否是新标签页
// Determine whether it is a new tab page from the name of the current tab page.
bool IsNameNewTab(NodePtr top) {

bool flag = false;
Expand All @@ -365,7 +365,7 @@ bool IsNameNewTab(NodePtr top) {
TraversalAccessible(page_tab_list, [&new_tab_name](NodePtr child) {
if (GetAccessibleRole(child) == ROLE_SYSTEM_PUSHBUTTON) {
GetAccessibleName(child, [&new_tab_name](BSTR bstr) {
new_tab_name.reset(_wcsdup(bstr)); // 保存从新建标签页按钮获取的名称
new_tab_name.reset(_wcsdup(bstr)); // Save the name obtained from the new tab button.
});
}
return false;
Expand Down Expand Up @@ -405,7 +405,7 @@ bool IsNameNewTab(NodePtr top) {
return flag;
}

// 从标签页的文档 value 判断是否是新标签页
// Determine whether it is a new tab page from the document value of the tab page.
bool IsDocNewTab() {
bool flag = false;
HWND hwnd = FindWindowEx(GetForegroundWindow(), nullptr,
Expand Down Expand Up @@ -438,7 +438,7 @@ bool IsOnNewTab(NodePtr top) {
return IsNameNewTab(top) || IsDocNewTab();
}

// 鼠标是否在书签上
// Whether the mouse is on a bookmark in the bookmark bar.
bool IsOnBookmark(NodePtr top, POINT pt) {
if (!top) {
return false;
Expand Down Expand Up @@ -471,7 +471,7 @@ bool IsOnBookmark(NodePtr top, POINT pt) {
return flag;
}

// 鼠标是否在菜单栏的书签文件(夹)上
// Whether the mouse is on a bookmark in the menu bar (folder).
bool IsOnMenuBookmark(NodePtr top, POINT pt) {
NodePtr menu_bar = FindElementWithRole(top, ROLE_SYSTEM_MENUBAR);
if (!menu_bar) {
Expand Down Expand Up @@ -512,7 +512,7 @@ bool IsOnMenuBookmark(NodePtr top, POINT pt) {
return flag;
}

// 地址栏是否已经获得焦点
// Whether the omnibox is focused.
bool IsOmniboxFocus(NodePtr top) {
NodePtr tool_bar = FindElementWithRole(top, ROLE_SYSTEM_TOOLBAR);
if (!tool_bar) {
Expand Down
15 changes: 8 additions & 7 deletions src/pakfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ bool CheckHeader(uint8_t* buffer, PAK_ENTRY*& pak_entry,
end_entry = pak_entry + pak_header->resource_count;
}

// 为了保存最后一条的"下一条",这条特殊的条目的id一定为0
// In order to save the "next item" of the last item,
// the id of this special item must be 0
if (!end_entry || end_entry->resource_id != 0)
return false;

Expand All @@ -76,7 +77,7 @@ void PakFind(uint8_t* buffer, uint8_t* pos, Function f) {
PAK_ENTRY* pak_entry = NULL;
PAK_ENTRY* end_entry = NULL;

// 检查文件头
// Check the file header.
if (!CheckHeader(buffer, pak_entry, end_entry))
return;

Expand All @@ -98,7 +99,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) {
PAK_ENTRY* pak_entry = NULL;
PAK_ENTRY* end_entry = NULL;

// 检查文件头
// Check the file header.
if (!CheckHeader(buffer, pak_entry, end_entry))
return;

Expand All @@ -107,15 +108,15 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) {
uint32_t old_size = next_entry->file_offset - pak_entry->file_offset;

if (old_size < 10 * 1024) {
// 小于10k文件跳过
// Files smaller than 10 kb are skipped.
pak_entry = next_entry;
continue;
}

BYTE gzip[] = {0x1F, 0x8B, 0x08};
size_t gzip_len = sizeof(gzip);
if (memcmp(buffer + pak_entry->file_offset, gzip, gzip_len) != 0) {
// 不是gzip文件跳过
// Files that are not gzip format are skipped.
pak_entry = next_entry;
continue;
}
Expand All @@ -133,7 +134,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) {
uint32_t new_len = old_size;
bool changed = f(unpack_buffer, unpack_len, new_len);
if (changed) {
// 如果有改变
// If the file is changed.
size_t compress_size = 0;
uint8_t* compress_buffer =
(uint8_t*)gzip_compress(unpack_buffer, new_len, &compress_size);
Expand All @@ -142,7 +143,7 @@ void TraversalGZIPFile(uint8_t* buffer, Function f) {
fwrite(compress_buffer, compress_size, 1, fp);
fclose(fp);*/

// gzip头
// gzip header
memcpy(buffer + pak_entry->file_offset, compress_buffer, 10);

// extra
Expand Down
2 changes: 1 addition & 1 deletion src/pakpatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject,
R"(hidden="true")");
}

const char prouct_title[] = u8R"({aboutBrowserVersion}</div><div class="secondary"><a target="_blank" href="https://github.com/Bush2021/chrome_plus">Chrome++</a> )" RELEASE_VER_STR u8R"( modified version</div>)";
const char prouct_title[] = u8R"({aboutBrowserVersion}</div><div class="secondary"><a target="_blank" href="https://github.com/Bush2021/chrome_plus">Chrome++</a> )""alpha-dcde2e9" u8R"( modified version</div>)";
ReplaceStringInPlace(html, R"({aboutBrowserVersion}</div>)",
prouct_title);

Expand Down
43 changes: 19 additions & 24 deletions src/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,25 @@ typedef NTSTATUS(WINAPI* pLdrLoadDll)(IN PWCHAR PathToFile OPTIONAL,
pLdrLoadDll RawLdrLoadDll = nullptr;

// https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/dialogs/outdated_upgrade_bubble.cc?q=outdated_upgrade_bubble&ss=chromium%2Fchromium%2Fsrc
// 该功能失效,需要修改
// void Outdated(HMODULE module)
//{
// // "OutdatedUpgradeBubble.Show"
//#ifdef _WIN64
// BYTE search[] = {0x48, 0x89, 0x8C, 0x24, 0xF0, 0x00, 0x00, 0x00, 0x80, 0x3D};
// uint8_t *match = SearchModuleRaw(module, search, sizeof(search));
//#else
// BYTE search[] = {0x31, 0xE8, 0x89, 0x45, 0xF0, 0x88, 0x5D, 0xEF, 0x80, 0x3D};
// uint8_t *match = SearchModuleRaw(module, search, sizeof(search));
//#endif
// if (match)
// {
// if (*(match + 0xF) == 0x74)
// {
// BYTE patch[] = {0x90, 0x90};
// WriteMemory(match + 0xF, patch, sizeof(patch));
// }
// }
// else
// {
// DebugLog(L"patch Outdated failed %p", module);
// }
//}
// This function is invalid and needs to be modified.
// void Outdated(HMODULE module) {
// // "OutdatedUpgradeBubble.Show"
// #ifdef _WIN64
// BYTE search[] = {0x48, 0x89, 0x8C, 0x24, 0xF0, 0x00, 0x00, 0x00, 0x80, 0x3D};
// uint8_t* match = SearchModuleRaw(module, search, sizeof(search));
// #else
// BYTE search[] = {0x31, 0xE8, 0x89, 0x45, 0xF0, 0x88, 0x5D, 0xEF, 0x80, 0x3D};
// uint8_t* match = SearchModuleRaw(module, search, sizeof(search));
// #endif
// if (match) {
// if (*(match + 0xF) == 0x74) {
// BYTE patch[] = {0x90, 0x90};
// WriteMemory(match + 0xF, patch, sizeof(patch));
// }
// } else {
// DebugLog(L"patch Outdated failed %p", module);
// }
// }

void DevWarning(HMODULE module) {
// "enable-automation"
Expand Down

0 comments on commit b29bdec

Please sign in to comment.