Skip to content

Commit 2f5ea67

Browse files
authored
Merge pull request #35 from CppCXY/master
修复一些隐患
2 parents 7230475 + 58c90ae commit 2f5ea67

File tree

4 files changed

+60
-41
lines changed

4 files changed

+60
-41
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@ jobs:
1616
cmake ../
1717
cmake --build . --config RelWithDebInfo --target install
1818
19-
- name: Build x86.51
20-
run: |
21-
cd x86
22-
cmake ../ -DEMMY_LUA_VERSION=51 -DEMMY_USE_LUA_SOURCE=true
23-
cmake --build . --config RelWithDebInfo --target install
24-
25-
- name: Build x86.52
26-
run: |
27-
cd x86
28-
cmake ../ -DEMMY_LUA_VERSION=52 -DEMMY_USE_LUA_SOURCE=true
29-
cmake --build . --config RelWithDebInfo --target install
30-
31-
- name: Build x86.53
32-
run: |
33-
cd x86
34-
cmake ../ -DEMMY_LUA_VERSION=53 -DEMMY_USE_LUA_SOURCE=true
35-
cmake --build . --config RelWithDebInfo --target install
36-
3719
- name: Upload x86
3820
uses: actions/[email protected]
3921
with:
@@ -46,24 +28,6 @@ jobs:
4628
cd x64
4729
cmake ../ -G "Visual Studio 15 2017 Win64"
4830
cmake --build . --config RelWithDebInfo --target install
49-
50-
- name: Build x64.51
51-
run: |
52-
cd x64
53-
cmake ../ -G "Visual Studio 15 2017 Win64" -DEMMY_LUA_VERSION=51 -DEMMY_USE_LUA_SOURCE=true
54-
cmake --build . --config RelWithDebInfo --target install
55-
56-
- name: Build x64.52
57-
run: |
58-
cd x64
59-
cmake ../ -G "Visual Studio 15 2017 Win64" -DEMMY_LUA_VERSION=52 -DEMMY_USE_LUA_SOURCE=true
60-
cmake --build . --config RelWithDebInfo --target install
61-
62-
- name: Build x64.53
63-
run: |
64-
cd x64
65-
cmake ../ -G "Visual Studio 15 2017 Win64" -DEMMY_LUA_VERSION=53 -DEMMY_USE_LUA_SOURCE=true
66-
cmake --build . --config RelWithDebInfo --target install
6731
6832
- name: Upload x64
6933
uses: actions/[email protected]

emmy_debugger/src/emmy_debugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ bool Debugger::DoEval(std::shared_ptr<EvalContext> evalContext)
969969
// setup env
970970
#ifndef EMMY_USE_LUA_SOURCE
971971
lua_setfenv(L, fIdx);
972-
#elif EMMY_LUA_51
972+
#elif defined(EMMY_LUA_51) || defined(EMMY_LUA_JIT)
973973
lua_setfenv(L, fIdx);
974974
#else //52 & 53
975975
lua_setupvalue(L, fIdx, 1);

emmy_hook/src/emmy_hook.windows.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "emmy_debugger/proto/socket_server_transporter.h"
1515
#include "shared/shme.h"
1616

17+
1718
typedef TRACED_HOOK_HANDLE HOOK_HANDLE;
1819
typedef NTSTATUS HOOK_STATUS;
1920

@@ -28,7 +29,11 @@ typedef int (*_lua_pcall)(lua_State* L, int nargs, int nresults, int errfunc);
2829

2930
typedef int (*_lua_pcallk)(lua_State* L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k);
3031

31-
typedef int (*_lua_resume)(lua_State* L, lua_State* from, int nargs, int* nresults);
32+
typedef int (*_lua_resume_54)(lua_State* L, lua_State* from, int nargs, int* nresults);
33+
34+
typedef int (*_lua_resume_53_52)(lua_State* L, lua_State* from, int narg);
35+
36+
typedef int (*_lua_resume_51)(lua_State* L, int narg);
3237

3338
typedef HMODULE (WINAPI *LoadLibraryExW_t)(LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags);
3439

@@ -91,15 +96,33 @@ int lua_error_worker(lua_State* L)
9196
return error(L);
9297
}
9398

94-
int lua_resume_worker(lua_State* L, lua_State* from, int nargs, int* nresults)
99+
int lua_resume_worker_54(lua_State* L, lua_State* from, int nargs, int* nresults)
95100
{
96101
LPVOID lp;
97102
LhBarrierGetCallback(&lp);
98-
const auto luaResume = (_lua_resume)lp;
103+
const auto luaResume = (_lua_resume_54)lp;
99104
EmmyFacade::Get().Attach(L);
100105
return luaResume(L, from, nargs, nresults);
101106
}
102107

108+
int lua_resume_worker_53_52(lua_State* L, lua_State* from, int nargs)
109+
{
110+
LPVOID lp;
111+
LhBarrierGetCallback(&lp);
112+
const auto luaResume = (_lua_resume_53_52)lp;
113+
EmmyFacade::Get().Attach(L);
114+
return luaResume(L, from, nargs);
115+
}
116+
117+
int lua_resume_worker_51(lua_State* L, int nargs)
118+
{
119+
LPVOID lp;
120+
LhBarrierGetCallback(&lp);
121+
const auto luaResume = (_lua_resume_51)lp;
122+
EmmyFacade::Get().Attach(L);
123+
return luaResume(L, nargs);
124+
}
125+
103126
#define HOOK(FN, WORKER, REQUIRED) {\
104127
const auto it = symbols.find(""#FN"");\
105128
if (it != symbols.end()) {\
@@ -112,6 +135,8 @@ int lua_resume_worker(lua_State* L, lua_State* from, int nargs, int* nresults)
112135
}\
113136
}
114137

138+
#define EXIST_SYMBOL(FN) (symbols.find(""#FN"") != symbols.end())
139+
115140
void HookLuaFunctions(std::unordered_map<std::string, DWORD64>& symbols)
116141
{
117142
if (symbols.empty())
@@ -121,7 +146,20 @@ void HookLuaFunctions(std::unordered_map<std::string, DWORD64>& symbols)
121146
// lua 5.2
122147
HOOK(lua_pcallk, lua_pcallk_worker, false);
123148
// HOOK(lua_error, lua_error_worker, true);
124-
HOOK(lua_resume, lua_resume_worker, false);
149+
150+
// lua5.4
151+
if (EXIST_SYMBOL(lua_newuserdatauv))
152+
{
153+
HOOK(lua_resume, lua_resume_worker_54, false);
154+
}
155+
else if(EXIST_SYMBOL(lua_rotate) || EXIST_SYMBOL(lua_callk)) //lua5.3 lua5.2
156+
{
157+
HOOK(lua_resume, lua_resume_worker_53_52, false);
158+
}
159+
else // lua5.1 or luajit
160+
{
161+
HOOK(lua_resume, lua_resume_worker_51, false);
162+
}
125163
}
126164

127165
void LoadSymbolsRecursively(HANDLE hProcess, HMODULE hModule)

emmy_tool/src/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ int doAttach(CommandLine& commandLine)
2121
return 0;
2222
}
2323

24+
void translateText(std::string& text)
25+
{
26+
for(auto& c: text)
27+
{
28+
if(c == '\n')
29+
{
30+
c = ' ';
31+
}
32+
}
33+
}
34+
2435
int doListProcesses()
2536
{
2637
std::vector<Process> list;
@@ -29,7 +40,13 @@ int doListProcesses()
2940
for (auto& value : list)
3041
{
3142
printf("%d\n", value.id);
43+
// title 中可能出现\n 所以title中的\n全部转为' '
44+
translateText(value.title);
45+
3246
printf("%s\n", value.title.c_str());
47+
48+
translateText(value.path);
49+
3350
printf("%s\n", value.path.c_str());
3451
printf("----\n");
3552
}

0 commit comments

Comments
 (0)