Skip to content

Commit 0511226

Browse files
committed
- Add more verbose logging.
- Fix bug where MetaData is not initialized for old SysBot builds predating game version/game title verification.
1 parent 20459b3 commit 0511226

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

source/commandHandler.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,29 @@ namespace CommandHandler {
2424
return buffer;
2525
}
2626

27-
Logger::instance().log("HandleCommand cmd: " + cmd + ". Params#: " + std::to_string(params.size()));
27+
std::string log = "HandleCommand cmd: " + cmd;
28+
if (!params.empty()) {
29+
log += ". Parameters: ";
30+
for (size_t i = 0; i < params.size(); ++i) {
31+
log += "[" + std::to_string(i) + "]: " + params[i];
32+
if (i < params.size() - 1) {
33+
log += ", ";
34+
}
35+
}
36+
}
37+
38+
Logger::instance().log(log);
39+
u64 pid = 0;
40+
Result rc = pmdmntGetApplicationProcessId(&pid);
41+
if (R_FAILED(rc)) {
42+
Logger::instance().log("initMetaData() pmdmntGetApplicationProcessId() failed: pid=" + std::to_string(pid), std::to_string(R_DESCRIPTION(rc)));
43+
}
44+
45+
if (m_metaData.pid == 0 || m_metaData.pid != pid) {
46+
m_metaData.pid = pid;
47+
initMetaData();
48+
}
49+
2850
auto it = Handler::m_cmd.find(cmd);
2951
if (it != Handler::m_cmd.end()) {
3052
it->second(params, buffer);

source/memoryCommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace MemoryCommands {
107107
attach();
108108
Result rc = svcReadDebugProcessMemory((void*)(buffer.data() + multi), m_debugHandle, offset, size);
109109
if (R_FAILED(rc)) {
110-
Logger::instance().log("readMem() svcReadDebugProcessMemory() failed.", std::to_string(R_DESCRIPTION(rc)));
110+
Logger::instance().log("readMem() svcReadDebugProcessMemory() failed. Offset=" + std::to_string(offset) + ", Size=" + std::to_string(size), std::to_string(R_DESCRIPTION(rc)));
111111
}
112112
detach();
113113
}
@@ -122,7 +122,7 @@ namespace MemoryCommands {
122122
attach();
123123
Result rc = svcWriteDebugProcessMemory(m_debugHandle, (void*)buffer.data(), offset, size);
124124
if (R_FAILED(rc)) {
125-
Logger::instance().log("writedMem() svcWriteDebugProcessMemory() failed.", std::to_string(R_DESCRIPTION(rc)));
125+
Logger::instance().log("writeMem() svcWriteDebugProcessMemory() failed. Offset=" + std::to_string(offset) + ", Size=" + std::to_string(size), std::to_string(R_DESCRIPTION(rc)));
126126
}
127127
detach();
128128
}

source/moduleBase.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,11 @@ namespace ModuleBase {
1414
* @return true if attach succeeded, false otherwise.
1515
*/
1616
bool BaseCommands::attach() {
17-
u64 pid = 0;
18-
Result rc = pmdmntGetApplicationProcessId(&pid);
17+
Logger::instance().log("attach() Attaching to pid=" + std::to_string(m_metaData.pid) + ".");
18+
Result rc = svcDebugActiveProcess(&m_debugHandle, m_metaData.pid);
1919
if (R_FAILED(rc)) {
20-
Logger::instance().log("attach() pmdmntGetApplicationProcessId() failed.", std::to_string(R_DESCRIPTION(rc)));
21-
return false;
22-
}
23-
24-
if (m_metaData.pid != pid) {
25-
Logger::instance().log("attach() m_metaData.pid != pid, calling initMetaData().");
26-
m_metaData.pid = pid;
27-
initMetaData();
28-
} else {
20+
Logger::instance().log("attach() svcDebugActiveProcess() failed: pid=" + std::to_string(m_metaData.pid), std::to_string(R_DESCRIPTION(rc)));
2921
detach();
30-
}
31-
32-
rc = svcDebugActiveProcess(&m_debugHandle, pid);
33-
if (R_FAILED(rc)) {
34-
Logger::instance().log("attach() svcDebugActiveProcess() failed.", std::to_string(R_DESCRIPTION(rc)));
3522
return false;
3623
}
3724

@@ -53,7 +40,6 @@ namespace ModuleBase {
5340
void BaseCommands::initMetaData() {
5441
if (!attach()) {
5542
Logger::instance().log("initMetaData() attach() failed.");
56-
detach();
5743
return;
5844
}
5945

@@ -63,9 +49,8 @@ namespace ModuleBase {
6349
m_metaData.titleVersion = GetTitleVersion();
6450
m_metaData.buildID = getBuildID();
6551

66-
detach();
6752
if (metaHasZeroValue(m_metaData)) {
68-
Logger::instance().log("initMetaData() MetaData had one or more zero value.");
53+
Logger::instance().log("initMetaData() One or more metadata values are zero.");
6954
}
7055
}
7156

@@ -116,6 +101,7 @@ namespace ModuleBase {
116101
u64 BaseCommands::getHeapBase() {
117102
u64 heap_base = 0;
118103
Result rc = svcGetInfo(&heap_base, InfoType_HeapRegionAddress, m_debugHandle, 0);
104+
detach();
119105
if (R_FAILED(rc)) {
120106
Logger::instance().log("getHeapBase() svcGetInfo() failed.", std::to_string(R_DESCRIPTION(rc)));
121107
return 0;
@@ -182,7 +168,6 @@ namespace ModuleBase {
182168
}
183169

184170
std::vector<NsApplicationControlData> buf(1);
185-
initMetaData();
186171
rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, m_metaData.titleID, buf.data(), sizeof(NsApplicationControlData), &out);
187172
nsExit();
188173
if (R_FAILED(rc)) {
@@ -441,7 +426,7 @@ namespace ModuleBase {
441426

442427
/**
443428
* @brief Get the current Switch time.
444-
* @param[out] buffer Output buffer for time value.
429+
* @param[out] Output buffer for time value.
445430
*/
446431
void BaseCommands::getSwitchTime(std::vector<char>& buffer) {
447432
time_t posix = 0;
@@ -506,7 +491,7 @@ namespace ModuleBase {
506491

507492
/**
508493
* @brief Reset the Switch time using NTP if available.
509-
* @param[out] buffer Output buffer indicating success.
494+
* @param[out] Output buffer indicating success.
510495
*/
511496
void BaseCommands::resetSwitchTime(std::vector<char>& buffer) {
512497
bool success = false;

source/socketConnection.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ namespace SocketConnection {
172172
return false;
173173
}
174174

175-
m_handler->HandleCommand("click", std::vector<std::string> { "UNUSED" });
176-
m_handler->HandleCommand("detachController", {});
177175
Logger::instance().log("Client connected.");
178176
return true;
179177
}

0 commit comments

Comments
 (0)