Skip to content

Commit 6ce57d2

Browse files
committed
重构launch调试
1 parent ce653b9 commit 6ce57d2

File tree

10 files changed

+833
-1067
lines changed

10 files changed

+833
-1067
lines changed

emmy_tool/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ add_dependencies(
99
shared
1010
)
1111

12-
target_sources(emmy_tool PRIVATE
13-
src/utility.h
14-
src/emmy_tool.h
15-
src/command_line.h
12+
target_include_directories(emmy_tool PRIVATE
13+
src
14+
)
1615

17-
src/utility.cpp
18-
src/emmy_tool.windows.cpp
16+
target_sources(emmy_tool PRIVATE
17+
src/windows/utility.cpp
18+
src/windows/emmy_tool.windows.cpp
1919
src/command_line.cpp
2020
src/main.cpp
21+
src/emmy_tool.cpp
2122
)
2223

2324
target_link_libraries(

emmy_tool/src/command_line.cpp

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,58 @@
11
#include "command_line.h"
22

3-
void CommandLine::AddTarget(const std::string& name, bool isParse)
4-
{
3+
void CommandLine::AddTarget(const std::string &name, bool isParse) {
54
_targets.insert({name, isParse});
65
}
76

8-
std::string CommandLine::GetTarget() const noexcept
9-
{
7+
std::string CommandLine::GetTarget() const noexcept {
108
return _currentTarget;
119
}
1210

13-
std::string CommandLine::GetArg(int index) const noexcept
14-
{
15-
if (static_cast<std::size_t>(index) < _argvs.size())
16-
{
11+
std::string CommandLine::GetArg(int index) const noexcept {
12+
if (static_cast<std::size_t>(index) < _argvs.size()) {
1713
return _argvs[index];
18-
}
19-
else
20-
{
14+
} else {
2115
return "";
2216
}
2317
}
2418

25-
bool CommandLine::Parse(int argc, char** argv)
26-
{
27-
if (argc < 2)
28-
{
19+
bool CommandLine::Parse(int argc, char **argv) {
20+
if (argc < 2) {
2921
return false;
3022
}
3123
_currentTarget = argv[1];
3224

33-
if (_targets.count(_currentTarget) == 0)
34-
{
25+
if (_targets.count(_currentTarget) == 0) {
3526
return false;
3627
}
3728

3829
bool isParse = _targets.at(_currentTarget);
3930
_argvs.reserve(argc);
40-
for (int i = 0; i != argc; i++)
41-
{
31+
for (int i = 0; i != argc; i++) {
4232
_argvs.emplace_back(argv[i]);
4333
}
4434

45-
if (!isParse)
46-
{
35+
if (!isParse) {
4736
return true;
4837
}
4938

5039
// index = 0 的参数是程序名
51-
for (int index = 1; index < argc; index++)
52-
{
40+
for (int index = 1; index < argc; index++) {
5341
std::string current = argv[index];
54-
if (current.empty())
55-
{
42+
if (current.empty()) {
5643
continue;
5744
}
5845
// not empty
59-
if (current[0] == '-')
60-
{
46+
if (current[0] == '-') {
6147
// 仅仅支持-dir这种形式
6248
std::string optionName = current.substr(1);
6349
// 如果该参数不存在
64-
if (_args.count(optionName) == 0)
65-
{
50+
if (_args.count(optionName) == 0) {
6651
return false;
6752
}
68-
CommandLineOption& option = _args[optionName];
53+
CommandLineOption &option = _args[optionName];
6954

70-
if (option.Type == CommandLineValueType::Boolean)
71-
{
55+
if (option.Type == CommandLineValueType::Boolean) {
7256
option.Value = "true";
7357
continue;
7458
}
@@ -78,57 +62,43 @@ bool CommandLine::Parse(int argc, char** argv)
7862

7963
// 该选项之后没有接参数
8064
// 目前没有支持bool选项的必要
81-
if (argc <= (index + 1) && !option.RestOfAll)
82-
{
65+
if (argc <= (index + 1) && !option.RestOfAll) {
8366
return false;
8467
}
8568

86-
do
87-
{
88-
if (argc <= (index + 1))
89-
{
69+
do {
70+
if (argc <= (index + 1)) {
9071
break;
9172
}
9273

9374
std::string value = argv[++index];
94-
if (value.empty())
95-
{
75+
if (value.empty()) {
9676
continue;
9777
}
98-
if (option.RestOfAll)
99-
{
78+
if (option.RestOfAll) {
10079
// 剩余参数通常会被传递到子进程再处理
10180
// 如果剩余参数中存在路径,且路径存在空格,那么传递到子进程的创建就会失效
10281
// 所以这里要特别的处理
103-
if (!value.empty())
104-
{
82+
if (!value.empty()) {
10583
// 认为该参数可能是选项
106-
if (value[0] == '-')
107-
{
84+
if (value[0] == '-') {
10885
optionValue.append(" ").append(value);
109-
}
110-
else //认为该参数是值,所以用引号包含起来
86+
} else//认为该参数是值,所以用引号包含起来
11187
{
11288
optionValue.append(" ").append("\"" + value + "\"");
11389
}
11490
}
115-
}
116-
else
117-
{
91+
} else {
11892
// 认为值是被一对引号包起来的
11993
// windows下引号已经被自动处理了
120-
if (value[0] == '\"' || value[0] == '\'')
121-
{
94+
if (value[0] == '\"' || value[0] == '\'') {
12295
optionValue = value.substr(1, value.size() - 2);
123-
}
124-
else
125-
{
96+
} else {
12697
optionValue = value;
12798
}
12899
break;
129100
}
130-
}
131-
while (true);
101+
} while (true);
132102

133103
option.Value = std::move(optionValue);
134104
}

emmy_tool/src/emmy_tool.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-

1+
#include "emmy_tool.h"
2+
3+
EmmyTool::EmmyTool(CommandLine &cmd)
4+
: _cmd(cmd) {
5+
}

emmy_tool/src/emmy_tool.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
#pragma once
2-
#include <Windows.h>
2+
33
#include "command_line.h"
44

5-
bool StartProcessAndInjectDll(LPCSTR exeFileName,
6-
LPSTR command,
7-
LPCSTR workDirectory,
8-
LPCSTR dllDirectory,
9-
LPCSTR dllName,
10-
bool blockOnExit,
11-
int debugPort,
12-
bool listenMode,
13-
bool createNewWindow
14-
);
5+
class EmmyTool {
6+
public:
7+
explicit EmmyTool(CommandLine &cmd);
8+
9+
int Launch();
10+
11+
int Attach();
12+
13+
int ListProcesses();
14+
15+
int ArchFile();
16+
17+
int ArchPid();
18+
19+
int ReceiveLog();
20+
21+
private:
1522

16-
bool InjectDll(DWORD processId, const char* dllDir, const char* dllFileName, bool capture);
23+
CommandLine _cmd;
24+
};
1725

18-
void ReceiveLog(DWORD processId);

0 commit comments

Comments
 (0)