Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add launcher config #234

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ffdcb7b
add launcher config
fesily Mar 17, 2023
65e1559
fix config lua version
fesily Mar 17, 2023
fcd627a
reset package_json
fesily Mar 18, 2023
12a31f5
Merge branch 'master' into launcher-config
fesily Mar 18, 2023
cea9c3c
reset packgae_json
fesily Mar 18, 2023
c085d01
reset
fesily Mar 18, 2023
710d3fc
reset
fesily Mar 18, 2023
56628cc
add module
fesily Mar 18, 2023
e2fa78d
update gumpp
fesily Mar 18, 2023
ca1fcc0
remove signature
fesily Mar 18, 2023
1968158
remove ipc_send_latest
fesily Mar 18, 2023
2c569d2
pass version to luadebug
fesily Mar 18, 2023
6dccc08
fix format
fesily Mar 18, 2023
5738af2
force load_luadebug_dll
fesily Mar 18, 2023
fb0659f
fix build error
fesily Mar 18, 2023
9054dee
format
fesily Mar 18, 2023
e728a3b
format
fesily Mar 18, 2023
b762f9f
Merge branch 'actboy168:master' into launcher-config
fesily Mar 19, 2023
8bb60fe
Update package_json.lua
fesily Mar 20, 2023
11fca9c
version add latest
fesily Mar 20, 2023
e2b79c0
Merge branch 'actboy168:master' into launcher-config
fesily Mar 22, 2023
c2de74b
Merge branch 'actboy168:master' into launcher-config
fesily Mar 22, 2023
62266b4
Merge branch 'master' into launcher-config
fesily Mar 22, 2023
4fa4d91
fix build err
fesily Mar 22, 2023
c8bdd8f
fix all error
fesily Mar 23, 2023
d9d53cf
Merge branch 'actboy168:master' into launcher-config
fesily Mar 23, 2023
fb1d2d0
attach luaVersion default unknown
fesily Mar 23, 2023
f5f2e7e
Merge branch 'master' into launcher-config
fesily Mar 25, 2023
ce666d0
add lua_module_backlist
fesily Mar 25, 2023
9d495d6
fix build error
fesily Mar 25, 2023
ff05aa4
update gumpp
fesily Mar 25, 2023
e7d2245
module support symlink
fesily Mar 25, 2023
82d832d
Optimize config
fesily Mar 27, 2023
b5f9176
fix blacklist
fesily Mar 27, 2023
3e53535
update gumpp
fesily Mar 27, 2023
9c02d9c
optimize wait_dll
fesily Mar 27, 2023
6b0fbdb
fix blacklist
fesily Mar 28, 2023
a6b082a
fix miss debugger key
fesily Mar 28, 2023
61a2542
Merge branch 'actboy168:master' into launcher-config
fesily Mar 29, 2023
3b18cc6
Update config.cpp
fesily Mar 29, 2023
d4954b9
Merge branch 'master' into launcher-config
fesily Mar 30, 2023
b272ecb
fix launch mode
fesily Mar 30, 2023
e2b6068
fix launch config
fesily Mar 30, 2023
56bbaf6
fix get_runtime_dir
fesily Mar 30, 2023
bc7ac72
Merge branch 'actboy168:master' into launcher-config
fesily Mar 30, 2023
4286930
Merge branch 'master' into launcher-config
fesily Apr 6, 2023
517b7b5
fix error
fesily Apr 6, 2023
d7219c2
Update proxy.lua
fesily Apr 6, 2023
9f9e319
format
fesily Apr 6, 2023
d190e9b
reset wait_dll
fesily Apr 6, 2023
614be75
reset wait_dll
fesily Apr 6, 2023
47241f0
format code
fesily Apr 6, 2023
cf4251b
Merge branch 'master' into launcher-config
fesily Apr 6, 2023
63667ee
Update src/launcher/config/config.cpp
fesily Apr 6, 2023
2876ad7
format version
fesily Apr 6, 2023
bee2b39
format code
fesily Apr 6, 2023
6eb73db
fix windows
fesily Apr 6, 2023
51cac20
fix err
fesily Apr 6, 2023
31cb123
add debugger_path
fesily Apr 6, 2023
ff4b5fc
fix version
fesily Apr 7, 2023
88b64b1
Merge remote-tracking branch 'upstream/master' into launcher-config
fesily Apr 7, 2023
0de91ca
reset debugger
fesily Apr 7, 2023
a4c2808
整理代码
actboy168 Apr 7, 2023
20f2761
fixes bug
actboy168 Apr 7, 2023
1f4c392
Merge branch 'actboy168:master' into launcher-config
fesily May 4, 2023
640303f
Merge branch 'actboy168:master' into launcher-config
fesily May 5, 2023
e59e4ae
Merge branch 'actboy168:master' into launcher-config
fesily May 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
[submodule "3rd/frida_gum/gumpp"]
path = 3rd/frida_gum/gumpp
url = https://github.com/fesily/gumpp

[submodule "3rd/json"]
path = 3rd/json
url = https://github.com/nlohmann/json
1 change: 1 addition & 0 deletions 3rd/json
Submodule json added at 546370
1 change: 1 addition & 0 deletions compile/common/launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lm:lua_source 'launcher_source' {
"3rd/bee.lua",
"3rd/frida_gum/gumpp",
"3rd/lua/lua54",
"3rd/json/single_include",
"src/launcher",
},
sources = {
Expand Down
9 changes: 9 additions & 0 deletions compile/common/package_json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ Debugger address.
},
type = "string",
},
module = {
default = "null",
markdownDescription = "specify lua module path/name",
type = "string",
}
}

if OS == "win32" then
Expand Down Expand Up @@ -471,6 +476,10 @@ for k, v in pairs(attributes.common) do
attributes.attach[k] = v
attributes.launch[k] = v
end

table.insert(attributes.attach.luaVersion.enum, "unknown")
attributes.attach.luaVersion.default = "unknown"

json.contributes.debuggers[1].configurationAttributes = {
launch = { properties = attributes.launch },
attach = { properties = attributes.attach },
Expand Down
21 changes: 8 additions & 13 deletions extension/script/attach.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local path, pid = ...
local path, pid, version = ...
if _VERSION == nil
or type == nil
or assert == nil
Expand All @@ -19,27 +19,22 @@ if is_luajit and jit == nil then
return "wait initialized"
end

if version == "" then
version = nil
end

local function dofile(filename, ...)
local load = _VERSION == "Lua 5.1" and loadstring or load
local f = assert(io.open(filename))
local str = f:read "*a"
f:close()
return assert(load(str, "=(debugger.lua)"))(...)
end
local function isLatest()
local ipc = dofile(path.."/script/common/ipc.lua")
local fd = ipc(path, pid, "luaVersion")
local result = false
if fd then
result = "latest" == fd:read "a"
fd:close()
end
return result
end

local dbg = dofile(path.."/script/debugger.lua", path)
dbg:start {
address = ("@%s/tmp/pid_%s"):format(path, pid),
latest = isLatest(),
fesily marked this conversation as resolved.
Show resolved Hide resolved
version = version,
}
dbg:event "wait"
return "ok"
return "ok"
50 changes: 33 additions & 17 deletions extension/script/debugger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,42 @@ local function detectLuaDebugPath(cfg)
end
end

local rt = "/runtime/"..PLATFORM
if cfg.latest then
rt = rt.."/lua-latest"
elseif _VERSION == "Lua 5.4" then
rt = rt.."/lua54"
elseif _VERSION == "Lua 5.3" then
rt = rt.."/lua53"
elseif _VERSION == "Lua 5.2" then
rt = rt.."/lua52"
elseif _VERSION == "Lua 5.1" then
if (tostring(assert):match('builtin') ~= nil) then
rt = rt.."/luajit"
jit.off()
else
rt = rt.."/lua51"
local function get_luadebug_dir()
local version = cfg.version
if not version then
if tostring(assert):match('builtin') ~= nil then
version = "jit"
jit.off()
else
version = _VERSION
end
end
else
error(_VERSION.." is not supported.")

local t = {
["Lua 5.4"] = "lua54",
["Lua 5.3"] = "lua53",
["Lua 5.2"] = "lua52",
["Lua 5.1"] = "lua51",
latest = "lua-latest",
lua54 = "lua54",
lua53 = "lua53",
lua52 = "lua52",
lua51 = "lua51",
luajit = "luajit",
["5.4"] = "lua54",
["5.3"] = "lua53",
["5.2"] = "lua52",
["5.1"] = "lua51",
jit = 'luajit'
}
fesily marked this conversation as resolved.
Show resolved Hide resolved
if not t[version] then
error(version.." is not supported.")
end
return t[version]
end

local rt = "/runtime/"..PLATFORM.."/"..get_luadebug_dir()

local ext = isWindows() and "dll" or "so"
return root..rt..'/luadebug.'..ext
end
Expand Down
6 changes: 3 additions & 3 deletions extension/script/frontend/debuger_factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ local function create_process_in_console(args, callback)
if not process then
return nil, err
end
if callback then
callback(process)
end
if args.inject ~= "none" then
local ok, errmsg = process_inject.inject(process, "launch", args)
if not ok then
Expand All @@ -231,9 +234,6 @@ local function create_process_in_console(args, callback)
end
end
end
if callback then
callback(process)
end
if need_resume then
process:resume()
end
Expand Down
35 changes: 20 additions & 15 deletions extension/script/frontend/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local fs = require 'bee.filesystem'
local sp = require 'bee.subprocess'
local platform_os = require 'frontend.platform_os'
local process_inject = require 'frontend.process_inject'
local json = require 'common.json'
local server
local client
local initReq
Expand All @@ -15,11 +16,16 @@ local function getUnixAddress(pid)
return "@"..(path / ("pid_%d"):format(pid)):string()
end

local function ipc_send_latest(pid)
local function ipc_send_config(pid, args)
--TODO: clear config file
fs.create_directories(WORKDIR / "tmp")
local ipc = require "common.ipc"
local fd = assert(ipc(WORKDIR, pid, "luaVersion", "w"))
fd:write("latest")
local fd = assert(ipc(WORKDIR, pid, "config", "w"))
local config = {
version = args.luaVersion,
module = args.module
}
fd:write(json.encode(config))
fd:close()
end

Expand Down Expand Up @@ -56,13 +62,11 @@ end

local function attach_process(pkg, pid)
local args = pkg.arguments
if args.luaVersion == "latest" then
ipc_send_latest(pid)
end
ipc_send_config(pid, args)
local ok, errmsg = process_inject.inject(pid, "attach", args)
if not ok then
return false, errmsg
end
return false, errmsg
end

server = network(getUnixAddress(pid), true)
server.sendmsg(initReq)
Expand All @@ -80,8 +84,8 @@ local function proxy_attach(pkg)
local args = pkg.arguments
platform_os.init(args)
if platform_os() ~= "Windows" and platform_os() ~= "macOS" then
attach_tcp(pkg, args)
return
attach_tcp(pkg, args)
return
end
if args.processId then
local processId = tonumber(args.processId)
Expand All @@ -92,7 +96,7 @@ local function proxy_attach(pkg)
return
end
if args.processName then
local pids = require "frontend.query_process"(args.processName)
local pids = require "frontend.query_process" (args.processName)
if #pids == 0 then
response_error(pkg, ('Cannot found process `%s`.'):format(args.processName))
return
Expand All @@ -113,7 +117,7 @@ local function create_server(args, pid)
local s, address
if args.address ~= nil then
s = network(args.address, args.client)
address = (args.client and "s:" or "c:") .. args.address
address = (args.client and "s:" or "c:")..args.address
else
pid = pid or sp.get_id()
s = network(getUnixAddress(pid), true)
Expand Down Expand Up @@ -158,11 +162,12 @@ local function proxy_launch_console(pkg)
response_error(pkg, "`runtimeExecutable` need specify `inject` or `address`.")
return
end
local process, err = debuger_factory.create_process_in_console(args, function (process)
local process, err = debuger_factory.create_process_in_console(args, function(process)
local address
server, address = create_server(args, process:get_id())
if args.luaVersion == "latest" and type(address) == "number" then
ipc_send_latest(address)

if type(address) == "number" then
ipc_send_config(address, args)
end
end)
if not process then
Expand Down
36 changes: 32 additions & 4 deletions src/launcher/autoattach/autoattach.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#include <autoattach/autoattach.h>
#include <autoattach/ctx.h>
#include <autoattach/lua_module.h>
#include <autoattach/wait_dll.h>
#include <bee/nonstd/format.h>
#include <resolver/lua_resolver.h>
#include <config/config.h>
#include <util/log.h>

#include <array>
#include <atomic>
#include <gumpp.hpp>
#include <memory>
#include <string>
#include <thread>

namespace luadebug::autoattach {
#ifdef _WIN32
# define EXT ".dll"
#else
# define EXT ".so"
#endif
constexpr auto lua_module_backlist = {
"launcher" EXT,
"luadebug" EXT,
};

constexpr auto find_lua_module_key = "lua_newstate";
constexpr auto lua_module_strings = std::array<const char*, 3> {
"luaJIT_BC_%s", // luajit
Expand All @@ -27,6 +34,22 @@ namespace luadebug::autoattach {
" $", // others
};
static bool is_lua_module(const char* module_path, bool check_export = true, bool check_strings = false) {
auto str = std::string_view(module_path);
// blacklist module
auto root = config::get_plugin_root();
if (root) {
if (str.find((*root).string()) != std::string_view::npos) {
// in luadebug root dir
for (auto& s : lua_module_backlist) {
if (str.find(s) != std::string_view::npos)
return false;
}
}
}

const auto& target_lua_module = ctx::get()->config->lua_module;
if (!target_lua_module.empty() && str.find(target_lua_module) != std::string_view::npos) return true;

if (check_export && Gum::Process::module_find_export_by_name(module_path, find_lua_module_key)) return true;
if (Gum::Process::module_find_symbol_by_name(module_path, find_lua_module_key)) return true;
// TODO: when signature mode, check strings
Expand Down Expand Up @@ -62,6 +85,11 @@ namespace luadebug::autoattach {
return;
}

ctx->config = config::init_from_file();
if (!ctx->config) {
log::info("can't load config");
}

bool found = false;
lua_module rm(ctx->mode);
Gum::Process::enumerate_modules([&rm, &found](const Gum::ModuleDetails& details) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions src/launcher/autoattach/ctx.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <autoattach/autoattach.h>
#include <autoattach/lua_module.h>
#include <config/config.h>

#include <atomic>
#include <gumpp.hpp>
Expand All @@ -15,6 +16,7 @@ namespace luadebug::autoattach {
work_mode mode;
std::optional<struct lua_module> lua_module;
bool wait_dll = false;
std::optional<config::Config> config;

static ctx* get() {
static ctx obj;
Expand Down
Loading