Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 505ba24

Browse files
committed
style: unify code style, naming, and header ordering
1 parent 64280ef commit 505ba24

13 files changed

Lines changed: 130 additions & 113 deletions

src/appid.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <propkey.h>
66

77
#include "detours.h"
8+
89
#include "utils.h"
910

1011
namespace {

src/chrome++.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "utils.h"
1717
#include "version.h"
1818

19-
typedef int (*Startup)();
19+
using Startup = int (*)();
2020
static bool should_run_exit_cmd = false;
2121
Startup ExeMain = nullptr;
2222

src/green.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include <processthreadsapi.h>
77
#include <shlwapi.h>
88

9-
#include "config.h"
109
#include "detours.h"
10+
11+
#include "config.h"
1112
#include "utils.h"
1213

1314
namespace {

src/hijack.cc

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,44 @@ void InstallDetours(PBYTE pTarget, PBYTE pDetour) {
9696
DetourTransactionCommit();
9797
}
9898

99-
void LoadVersion(HINSTANCE hModule) {
100-
PBYTE pImageBase = (PBYTE)hModule;
101-
PIMAGE_DOS_HEADER pimDH = (PIMAGE_DOS_HEADER)pImageBase;
102-
if (pimDH->e_magic == IMAGE_DOS_SIGNATURE) {
103-
PIMAGE_NT_HEADERS pimNH = (PIMAGE_NT_HEADERS)(pImageBase + pimDH->e_lfanew);
104-
if (pimNH->Signature == IMAGE_NT_SIGNATURE) {
105-
PIMAGE_EXPORT_DIRECTORY pimExD =
106-
(PIMAGE_EXPORT_DIRECTORY)(pImageBase +
107-
pimNH->OptionalHeader
108-
.DataDirectory
109-
[IMAGE_DIRECTORY_ENTRY_EXPORT]
110-
.VirtualAddress);
111-
DWORD* pName = (DWORD*)(pImageBase + pimExD->AddressOfNames);
112-
DWORD* pFunction = (DWORD*)(pImageBase + pimExD->AddressOfFunctions);
113-
WORD* pNameOrdinals = (WORD*)(pImageBase + pimExD->AddressOfNameOrdinals);
99+
void LoadVersion(HINSTANCE module_handle) {
100+
auto image_base = reinterpret_cast<PBYTE>(module_handle);
101+
auto dos_header = reinterpret_cast<PIMAGE_DOS_HEADER>(image_base);
102+
if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) {
103+
auto nt_headers =
104+
reinterpret_cast<PIMAGE_NT_HEADERS>(image_base + dos_header->e_lfanew);
105+
if (nt_headers->Signature == IMAGE_NT_SIGNATURE) {
106+
auto export_directory = reinterpret_cast<PIMAGE_EXPORT_DIRECTORY>(
107+
image_base +
108+
nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]
109+
.VirtualAddress);
110+
auto name_table = reinterpret_cast<DWORD*>(
111+
image_base + export_directory->AddressOfNames);
112+
auto function_table = reinterpret_cast<DWORD*>(
113+
image_base + export_directory->AddressOfFunctions);
114+
auto ordinals_table = reinterpret_cast<WORD*>(
115+
image_base + export_directory->AddressOfNameOrdinals);
114116

115-
wchar_t szSysDirectory[MAX_PATH + 1];
116-
GetSystemDirectory(szSysDirectory, MAX_PATH);
117+
wchar_t system_directory[MAX_PATH + 1];
118+
GetSystemDirectory(system_directory, MAX_PATH);
117119

118-
wchar_t szDLLPath[MAX_PATH + 1];
119-
lstrcpy(szDLLPath, szSysDirectory);
120-
lstrcat(szDLLPath, TEXT("\\version.dll"));
120+
wchar_t dll_path[MAX_PATH + 1];
121+
lstrcpy(dll_path, system_directory);
122+
lstrcat(dll_path, TEXT("\\version.dll"));
121123

122-
HINSTANCE module = LoadLibrary(szDLLPath);
123-
for (size_t i = 0; i < pimExD->NumberOfNames; ++i) {
124-
PBYTE Original =
125-
(PBYTE)GetProcAddress(module, (char*)(pImageBase + pName[i]));
126-
if (Original) {
127-
InstallDetours(pImageBase + pFunction[pNameOrdinals[i]], Original);
124+
HINSTANCE original_dll_handle = LoadLibrary(dll_path);
125+
if (!original_dll_handle) {
126+
return;
127+
}
128+
129+
for (size_t i = 0; i < export_directory->NumberOfNames; ++i) {
130+
auto function_name =
131+
reinterpret_cast<char*>(image_base + name_table[i]);
132+
auto original_function = reinterpret_cast<PBYTE>(
133+
GetProcAddress(original_dll_handle, function_name));
134+
if (original_function) {
135+
InstallDetours(image_base + function_table[ordinals_table[i]],
136+
original_function);
128137
}
129138
}
130139
}

src/hotkey.cc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#include "hotkey.h"
22

3-
#include <algorithm>
4-
#include <iterator>
5-
#include <string>
6-
#include <thread>
7-
#include <unordered_map>
8-
#include <vector>
9-
103
#include <windows.h>
114

125
#include <audiopolicy.h>
136
#include <endpointvolume.h>
147
#include <mmdeviceapi.h>
158
#include <tlhelp32.h>
169

10+
#include <algorithm>
11+
#include <iterator>
12+
#include <string>
13+
#include <thread>
14+
#include <unordered_map>
15+
#include <vector>
16+
1717
#include "config.h"
1818
#include "utils.h"
1919

2020
namespace {
2121

22-
typedef void (*HotkeyAction)();
22+
// typedef void (*HotkeyAction)();
23+
using HotkeyAction = void (*)();
2324

2425
// Static variables for internal use
2526
bool is_hide = false;
@@ -62,16 +63,18 @@ UINT ParseHotkeys(const wchar_t* keys) {
6263
TCHAR wch = key[0];
6364
if (key.length() == 1) // Parse single characters A-Z, 0-9, etc.
6465
{
65-
if (isalnum(wch))
66+
if (isalnum(wch)) {
6667
vk = toupper(wch);
67-
else
68+
} else {
6869
vk = LOWORD(VkKeyScan(wch));
70+
}
6971
} else if (wch == 'F' || wch == 'f') // Parse the F1-F24 function keys.
7072
{
7173
if (isdigit(key[1])) {
7274
int fx = _wtoi(&key[1]);
73-
if (fx >= 1 && fx <= 24)
75+
if (fx >= 1 && fx <= 24) {
7476
vk = VK_F1 + fx - 1;
77+
}
7578
}
7679
}
7780
}
@@ -94,7 +97,7 @@ BOOL CALLBACK SearchChromeWindow(HWND hwnd, LPARAM lparam) {
9497
GetWindowThreadProcessId(hwnd, &pid);
9598
if (pid == GetCurrentProcessId()) {
9699
ShowWindow(hwnd, SW_HIDE);
97-
hwnd_list.push_back(hwnd);
100+
hwnd_list.emplace_back(hwnd);
98101
}
99102
}
100103
}
@@ -113,16 +116,17 @@ std::vector<DWORD> GetAppPids() {
113116
}
114117

115118
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
116-
if (snapshot == INVALID_HANDLE_VALUE)
119+
if (snapshot == INVALID_HANDLE_VALUE) {
117120
return pids;
121+
}
118122

119123
PROCESSENTRY32W pe32;
120124
pe32.dwSize = sizeof(PROCESSENTRY32W);
121125

122126
if (Process32FirstW(snapshot, &pe32)) {
123127
do {
124128
if (_wcsicmp(pe32.szExeFile, exe_name) == 0) {
125-
pids.push_back(pe32.th32ProcessID);
129+
pids.emplace_back(pe32.th32ProcessID);
126130
}
127131
} while (Process32NextW(snapshot, &pe32));
128132
}

src/iaccessible.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "iaccessible.h"
22

3+
#include <windows.h>
4+
35
#include <functional>
46
#include <memory>
57
#include <string>
68
#include <string_view>
79
#include <thread>
810
#include <vector>
911

10-
#include <windows.h>
11-
1212
#include "config.h"
1313
#include "utils.h"
1414

src/pakfile.cc

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,76 +17,78 @@ namespace {
1717
#pragma pack(push)
1818
#pragma pack(1)
1919

20-
#define PACK4_FILE_VERSION (4)
21-
#define PACK5_FILE_VERSION (5)
20+
constexpr int kPack4FileVersion = 4;
21+
constexpr int kPack5FileVersion = 5;
2222

23-
struct PAK4_HEADER {
23+
struct Pak4Header {
2424
uint32_t num_entries;
25-
uint8_t encodeing;
25+
uint8_t encoding;
2626
};
2727

28-
struct PAK5_HEADER {
29-
uint32_t encodeing;
28+
struct Pak5Header {
29+
uint32_t encoding;
3030
uint16_t resource_count;
3131
uint16_t alias_count;
3232
};
3333

34-
struct PAK_ENTRY {
34+
struct PakEntry {
3535
uint16_t resource_id;
3636
uint32_t file_offset;
3737
};
3838

39-
struct PAK_ALIAS {
39+
struct PakAlias {
4040
uint16_t resource_id;
4141
uint16_t entry_index;
4242
};
4343
#pragma pack(pop)
4444

4545
bool CheckHeader(uint8_t* buffer,
46-
PAK_ENTRY*& pak_entry,
47-
PAK_ENTRY*& end_entry) {
46+
PakEntry*& pak_entry,
47+
PakEntry*& end_entry) {
4848
uint32_t version = *(uint32_t*)buffer;
4949

50-
if (version != PACK4_FILE_VERSION && version != PACK5_FILE_VERSION)
50+
if (version != kPack4FileVersion && version != kPack5FileVersion)
5151
return false;
5252

53-
if (version == PACK4_FILE_VERSION) {
54-
PAK4_HEADER* pak_header = (PAK4_HEADER*)(buffer + sizeof(uint32_t));
55-
if (pak_header->encodeing != 1)
53+
if (version == kPack4FileVersion) {
54+
Pak4Header* pak_header = (Pak4Header*)(buffer + sizeof(uint32_t));
55+
if (pak_header->encoding != 1)
5656
return false;
5757

58-
pak_entry = (PAK_ENTRY*)(buffer + sizeof(uint32_t) + sizeof(PAK4_HEADER));
58+
pak_entry = (PakEntry*)(buffer + sizeof(uint32_t) + sizeof(Pak4Header));
5959
end_entry = pak_entry + pak_header->num_entries;
6060
}
6161

62-
if (version == PACK5_FILE_VERSION) {
63-
PAK5_HEADER* pak_header = (PAK5_HEADER*)(buffer + sizeof(uint32_t));
64-
if (pak_header->encodeing != 1)
62+
if (version == kPack5FileVersion) {
63+
Pak5Header* pak_header = (Pak5Header*)(buffer + sizeof(uint32_t));
64+
if (pak_header->encoding != 1)
6565
return false;
6666

67-
pak_entry = (PAK_ENTRY*)(buffer + sizeof(uint32_t) + sizeof(PAK5_HEADER));
67+
pak_entry = (PakEntry*)(buffer + sizeof(uint32_t) + sizeof(Pak5Header));
6868
end_entry = pak_entry + pak_header->resource_count;
6969
}
7070

7171
// In order to save the "next item" of the last item,
7272
// the id of this special item must be 0
73-
if (!end_entry || end_entry->resource_id != 0)
73+
if (!end_entry || end_entry->resource_id != 0) {
7474
return false;
75+
}
7576

7677
return true;
7778
}
7879

7980
void PakFind(uint8_t* buffer,
8081
uint8_t* pos,
8182
std::function<void(uint8_t*, uint32_t)> f) {
82-
PAK_ENTRY* pak_entry = nullptr;
83-
PAK_ENTRY* end_entry = nullptr;
83+
PakEntry* pak_entry = nullptr;
84+
PakEntry* end_entry = nullptr;
8485

85-
if (!CheckHeader(buffer, pak_entry, end_entry))
86+
if (!CheckHeader(buffer, pak_entry, end_entry)) {
8687
return;
88+
}
8789

8890
do {
89-
PAK_ENTRY* next_entry = pak_entry + 1;
91+
PakEntry* next_entry = pak_entry + 1;
9092
if (pos >= buffer + pak_entry->file_offset &&
9193
pos <= buffer + next_entry->file_offset) {
9294
f(buffer + pak_entry->file_offset,
@@ -101,14 +103,15 @@ void PakFind(uint8_t* buffer,
101103

102104
void TraversalGZIPFile(uint8_t* buffer,
103105
std::function<bool(uint8_t*, uint32_t, size_t&)>&& f) {
104-
PAK_ENTRY* pak_entry = nullptr;
105-
PAK_ENTRY* end_entry = nullptr;
106+
PakEntry* pak_entry = nullptr;
107+
PakEntry* end_entry = nullptr;
106108

107-
if (!CheckHeader(buffer, pak_entry, end_entry))
109+
if (!CheckHeader(buffer, pak_entry, end_entry)) {
108110
return;
111+
}
109112

110113
do {
111-
PAK_ENTRY* next_entry = pak_entry + 1;
114+
PakEntry* next_entry = pak_entry + 1;
112115
size_t old_size = next_entry->file_offset - pak_entry->file_offset;
113116

114117
if (old_size < 10 * 1024) {
@@ -126,8 +129,9 @@ void TraversalGZIPFile(uint8_t* buffer,
126129

127130
uint32_t original_size = *(uint32_t*)(buffer + next_entry->file_offset - 4);
128131
uint8_t* unpack_buffer = (uint8_t*)malloc(original_size);
129-
if (!unpack_buffer)
132+
if (!unpack_buffer) {
130133
return;
134+
}
131135

132136
struct mini_gzip gz;
133137
mini_gz_start(&gz, buffer + pak_entry->file_offset, old_size);
@@ -165,8 +169,9 @@ void TraversalGZIPFile(uint8_t* buffer,
165169
// DebugLog(L"gzip compress error %d %d", compress_size, old_size);
166170
}
167171

168-
if (compress_buffer)
172+
if (compress_buffer) {
169173
free(compress_buffer);
174+
}
170175
}
171176
}
172177

src/pakpatch.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
#include <windows.h>
44

5+
#include <string>
6+
57
#include "detours.h"
8+
69
#include "pakfile.h"
710
#include "utils.h"
811
#include "version.h"
@@ -63,7 +66,9 @@ HANDLE WINAPI MyMapViewOfFile(_In_ HANDLE hFileMappingObject,
6366
R"(hidden="true")");
6467
}
6568

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

@@ -135,7 +140,7 @@ HANDLE WINAPI MyCreateFile(_In_ LPCTSTR lpFileName,
135140
lpSecurityAttributes, dwCreationDisposition,
136141
dwFlagsAndAttributes, hTemplateFile);
137142

138-
if (isEndWith(lpFileName, L"resources.pak")) {
143+
if (std::wstring(lpFileName).ends_with(L"resources.pak")) {
139144
resources_pak_file = file;
140145
resources_pak_size = GetFileSize(resources_pak_file, nullptr);
141146

0 commit comments

Comments
 (0)