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

Commit f12f4d8

Browse files
committed
refactor: consistency
1 parent e35b305 commit f12f4d8

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

dump.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@
99

1010
using namespace std;
1111

12-
mutex _mutex;
12+
mutex dumpMutex;
1313

14-
BOOL FileExists(const wstring &name) {
14+
bool fileExists(const wstring &name) {
1515
if (FILE *file = _wfopen(name.c_str(), L"r")) {
1616
fclose(file);
17-
return TRUE;
17+
return true;
1818
} else {
19-
return FALSE;
19+
return false;
2020
}
2121
}
2222

23-
BOOL GetNextFreeFilePath(wstring &path, const char *name) {
23+
bool getNextFreeFilePath(wstring &path, const char *name) {
2424
path.resize(MAX_PATH);
2525
if (!SHGetSpecialFolderPathW(HWND_DESKTOP, path.data(), CSIDL_DESKTOP, FALSE)) {
26-
return FALSE;
26+
return false;
2727
}
2828
path.resize(wcslen(path.data()));
2929

3030
wstring fixedName(MAX_PATH, '\x00');
3131
mbstowcs(fixedName.data(), name, strlen(name));
32-
PathCleanupSpec(NULL, fixedName.data());
32+
PathCleanupSpec(nullptr, fixedName.data());
3333
fixedName.resize(wcslen(fixedName.data()));
3434

3535
int initialLen = path.length();
@@ -43,31 +43,30 @@ BOOL GetNextFreeFilePath(wstring &path, const char *name) {
4343
}
4444
path += L".class";
4545
i++;
46-
} while (FileExists(path));
47-
return TRUE;
46+
} while (fileExists(path));
47+
return true;
4848
}
4949

5050
void DoDump(const char *buf, int len) {
5151
if (!buf || len < 1) {
5252
return;
5353
}
54-
unique_lock<mutex> lock(_mutex);
54+
lock_guard<mutex> lock(dumpMutex);
5555
FILE *fp;
5656
wstring path;
5757
string className = GetJavaClassName(buf);
58-
if (GetNextFreeFilePath(path, className.c_str())) {
58+
if (getNextFreeFilePath(path, className.c_str())) {
5959
fp = _wfopen(path.c_str(), L"wb");
6060
int written = fwrite(buf, sizeof(char), len, fp);
6161
if (written == 0) {
62-
MessageBox(NULL, "Error 2", "Error", MB_OK);
62+
MessageBox(nullptr, "Error 2", "Error", MB_OK);
6363
} else if (written != sizeof(char) * len) {
64-
MessageBox(NULL, "Error 3", "Error", MB_OK);
64+
MessageBox(nullptr, "Error 3", "Error", MB_OK);
6565
}
6666
fclose(fp);
6767
} else {
68-
MessageBox(NULL, "Error 1", "Error", MB_OK);
68+
MessageBox(nullptr, "Error 1", "Error", MB_OK);
6969
}
70-
lock.unlock();
7170
}
7271

7372
#endif //VERSION_DUMP_H

hook.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66

77
using namespace std;
88

9-
typedef jclass JNICALL (*JVM_DefineClass)(JNIEnv *env, const char *name, jobject loader,
10-
const jbyte *buf, jsize len, jobject pd);
9+
typedef jclass JNICALL (*sig_JVM_DefineClass)(JNIEnv *env, const char *name, jobject loader,
10+
const jbyte *buf, jsize len, jobject pd);
11+
typedef jclass JNICALL(*sig_JVM_DefineClassWithSource)(JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
12+
jsize len, jobject pd, const char *source);
13+
typedef jclass JNICALL (*sig_JVM_DefineClassWithSourceCond)(JNIEnv *env, const char *name,
14+
jobject loader, const jbyte *buf, jsize len, jobject pd,
15+
const char *source, jboolean verify);
1116

12-
typedef jclass JNICALL(*JVM_DefineClassWithSource)(JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
13-
jsize len, jobject pd, const char *source);
14-
15-
typedef jclass JNICALL (*JVM_DefineClassWithSourceCond)(JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
16-
jsize len, jobject pd, const char *source, jboolean verify);
17-
18-
JVM_DefineClass orig_JVM_DefineClass = NULL;
19-
JVM_DefineClassWithSource orig_JVM_DefineClassWithSource = NULL;
20-
JVM_DefineClassWithSourceCond orig_JVM_DefineClassWithSourceCond = NULL;
17+
sig_JVM_DefineClass orig_JVM_DefineClass = NULL;
18+
sig_JVM_DefineClassWithSource orig_JVM_DefineClassWithSource = NULL;
19+
sig_JVM_DefineClassWithSourceCond orig_JVM_DefineClassWithSourceCond = NULL;
2120

2221
jclass JNICALL detour_JVM_DefineClass(JNIEnv *env, const char *name, jobject loader,
2322
const jbyte *buf, jsize len, jobject pd) {
@@ -37,21 +36,21 @@ jclass JNICALL detour_JVM_DefineClassWithSourceCond(JNIEnv *env, const char *nam
3736
return orig_JVM_DefineClassWithSourceCond(env, name, loader, buf, len, pd, source, verify);
3837
}
3938

40-
BOOL DoHook() {
39+
bool doHook() {
4140
HMODULE hJvm = LoadLibrary("jvm.dll");
4241
if (!hJvm) {
4342
return FALSE;
4443
}
45-
orig_JVM_DefineClass = (JVM_DefineClass) GetProcAddress(hJvm, "JVM_DefineClass");
44+
orig_JVM_DefineClass = (sig_JVM_DefineClass) GetProcAddress(hJvm, "JVM_DefineClass");
4645
if (!orig_JVM_DefineClass) {
4746
return FALSE;
4847
}
49-
orig_JVM_DefineClassWithSource = (JVM_DefineClassWithSource) GetProcAddress(hJvm, "JVM_DefineClassWithSource");
48+
orig_JVM_DefineClassWithSource = (sig_JVM_DefineClassWithSource) GetProcAddress(hJvm, "JVM_DefineClassWithSource");
5049
if (!orig_JVM_DefineClassWithSource) {
5150
return FALSE;
5251
}
53-
orig_JVM_DefineClassWithSourceCond = (JVM_DefineClassWithSourceCond) GetProcAddress(hJvm,
54-
"JVM_DefineClassWithSourceCond");
52+
orig_JVM_DefineClassWithSourceCond = (sig_JVM_DefineClassWithSourceCond) GetProcAddress(hJvm,
53+
"JVM_DefineClassWithSourceCond");
5554
if (!orig_JVM_DefineClassWithSourceCond) {
5655
return FALSE;
5756
}
@@ -62,10 +61,10 @@ BOOL DoHook() {
6261
return Mhook_SetHookEx(hooks, 3) == 3;
6362
}
6463

65-
BOOL WINAPI DllMain(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
64+
bool WINAPI DllMain(HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
6665
if (fdwReason == DLL_PROCESS_ATTACH) {
6766
SourceInit();
68-
if (DoHook()) {
67+
if (doHook()) {
6968
MessageBox(NULL, "Hooks initialized.", "Success", MB_OK);
7069
} else {
7170
MessageBox(NULL, "Something went wrong.", "Error", MB_OK);

0 commit comments

Comments
 (0)