Skip to content

Commit

Permalink
update bee
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 6, 2024
1 parent 1cb16ab commit e61f1df
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions compile/common/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ lm:source_set 'luadbg' {
windows = {
defines = {
"_CRT_SECURE_NO_WARNINGS",
"_WIN32_WINNT=0x0601",
"_WIN32_WINNT=0x0602",
},
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ lm:source_set 'luadbg-compatible' {
windows = {
defines = {
"_CRT_SECURE_NO_WARNINGS",
"_WIN32_WINNT=0x0601",
"_WIN32_WINNT=0x0602",
},
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ for _, luaver in ipairs {
deps = luaver..'/'..luaver,
defines = {
"_CRT_SECURE_NO_WARNINGS",
"_WIN32_WINNT=0x0601",
"_WIN32_WINNT=0x0602",
("LUA_DLL_VERSION="..luaver)
},
links = {
Expand Down
2 changes: 1 addition & 1 deletion compile/windows/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "compile.common.config"

local platform = lm.runtime_platform

lm.defines = "_WIN32_WINNT=0x0601"
lm.defines = "_WIN32_WINNT=0x0602"
lm.builddir = ("build/%s/%s"):format(platform, lm.mode)

require "compile.common.runtime"
Expand Down
12 changes: 9 additions & 3 deletions src/process_inject/windows/inject.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Windows.h>
#include <bee/lua/binding.h>
#include <bee/platform/win/unicode.h>
#include <bee/utility/zstring_view.h>
#include <bee/subprocess.h>
#include <binding/binding.h>

Expand All @@ -9,22 +10,27 @@

#include "injectdll.h"

inline std::string_view checkstrview(lua_State* L, int idx) {
static bee::zstring_view checkstrview(lua_State* L, int idx) {
size_t len = 0;
const char* buf = luaL_checklstring(L, idx, &len);
return { buf, len };
}

static std::wstring checkstring(lua_State* L, int idx) {
auto str = checkstrview(L, idx);
return bee::win::u2w(str);
}

static int injectdll(lua_State* L) {
if (lua_type(L, 1) == LUA_TNUMBER) {
DWORD pid = (DWORD)luaL_checkinteger(L, 1);
bool ok = injectdll(pid, bee::lua::checkstring(L, 2), bee::lua::checkstring(L, 3), checkstrview(L, 4));
bool ok = injectdll(pid, checkstring(L, 2), checkstring(L, 3), checkstrview(L, 4));
lua_pushboolean(L, ok);
return 1;
}
else {
auto& self = *(bee::subprocess::process*)luaL_checkudata(L, 1, "bee::subprocess");
bool ok = injectdll(self.native_handle(), self.thread_handle(), bee::lua::checkstring(L, 2), bee::lua::checkstring(L, 3), checkstrview(L, 4));
bool ok = injectdll(self.native_handle(), self.thread_handle(), checkstring(L, 2), checkstring(L, 3), checkstrview(L, 4));
lua_pushboolean(L, ok);
return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/process_inject/windows/injectdll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool wow64_write_memory(uint64_t nwvm, HANDLE hProcess, uint64_t lpBaseAd
return true;
}

static bool injectdll_x64(HANDLE process_handle, HANDLE thread_handle, const std::wstring& dll, const std::string_view& entry) {
static bool injectdll_x64(HANDLE process_handle, HANDLE thread_handle, const std::wstring& dll, const bee::zstring_view& entry) {
static unsigned char sc[] = {
0x9C, // pushfq
0x0F, 0xA8, // push gs
Expand Down Expand Up @@ -195,7 +195,7 @@ static bool injectdll_x64(HANDLE process_handle, HANDLE thread_handle, const std
return true;
}

static bool injectdll_x86(HANDLE process_handle, HANDLE thread_handle, const std::wstring& dll, const std::string_view& entry) {
static bool injectdll_x86(HANDLE process_handle, HANDLE thread_handle, const std::wstring& dll, const bee::zstring_view& entry) {
static unsigned char sc[] = {
0x68, 0x00, 0x00, 0x00, 0x00, // push eip
0x9C, // pushfd
Expand Down Expand Up @@ -266,7 +266,7 @@ static bool injectdll_x86(HANDLE process_handle, HANDLE thread_handle, const std
return true;
}

bool injectdll(HANDLE process_handle, HANDLE thread_handle, const std::wstring& x86dll, const std::wstring& x64dll, const std::string_view& entry) {
bool injectdll(HANDLE process_handle, HANDLE thread_handle, const std::wstring& x86dll, const std::wstring& x64dll, const bee::zstring_view& entry) {
if (is_process64(process_handle)) {
return !x64dll.empty() && injectdll_x64(process_handle, thread_handle, x64dll, entry);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ static bool openprocess(DWORD pid, DWORD process_access, DWORD thread_access, PR
return true;
}

bool injectdll(DWORD pid, const std::wstring& x86dll, const std::wstring& x64dll, const std::string_view& entry) {
bool injectdll(DWORD pid, const std::wstring& x86dll, const std::wstring& x64dll, const bee::zstring_view& entry) {
PROCESS_INFORMATION pi = { 0 };
if (!openprocess(pid, PROCESS_ALL_ACCESS, THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, pi)) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/process_inject/windows/injectdll.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <Windows.h>

#include <string>
#include <string_view>
#include <bee/utility/zstring_view.h>

bool injectdll(HANDLE process_handle, HANDLE thread_handle, const std::wstring& x86dll, const std::wstring& x64dll, const std::string_view& entry = 0);
bool injectdll(DWORD pid, const std::wstring& x86dll, const std::wstring& x64dll, const std::string_view& entry = 0);
bool injectdll(HANDLE process_handle, HANDLE thread_handle, const std::wstring& x86dll, const std::wstring& x64dll, const bee::zstring_view& entry = 0);
bool injectdll(DWORD pid, const std::wstring& x86dll, const std::wstring& x64dll, const bee::zstring_view& entry = 0);

0 comments on commit e61f1df

Please sign in to comment.