Skip to content

Commit

Permalink
Implement info reading from Ro section (strato-emu#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-xd authored Jan 13, 2024
1 parent 1323259 commit 135b7f3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,4 @@ target_include_directories(skyline PRIVATE ${source_DIR}/skyline)
target_compile_options(skyline PRIVATE -Wall -Wno-unknown-attributes -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c99-designator -Wno-reorder -Wno-missing-braces -Wno-unused-variable -Wno-unused-private-field -Wno-dangling-else -Wconversion -fsigned-bitfields)

target_link_libraries(skyline PRIVATE shader_recompiler audio_core)
target_link_libraries_system(skyline android perfetto fmt lz4_static tzcode vkma mbedcrypto opus Boost::intrusive Boost::container Boost::preprocessor range-v3 adrenotools tsl::robin_map)
target_link_libraries_system(skyline android perfetto fmt lz4_static tzcode vkma mbedcrypto opus Boost::intrusive Boost::container Boost::preprocessor Boost::regex range-v3 adrenotools tsl::robin_map)
45 changes: 45 additions & 0 deletions app/src/main/cpp/skyline/loader/nso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <lz4.h>
#include <nce.h>
#include <kernel/types/KProcess.h>
#include <boost/regex/v5/regex.hpp>
#include "nso.h"

namespace skyline::loader {
Expand Down Expand Up @@ -56,6 +57,8 @@ namespace skyline::loader {
executable.dynstr = {header.dynstr.offset, header.dynstr.size};
}

PrintRoContentsInfo(executable.ro.contents);

return loader->LoadExecutable(process, state, executable, offset, name, dynamicallyLinked);
}

Expand All @@ -65,4 +68,46 @@ namespace skyline::loader {
state.process->memory.InitializeRegions(span<u8>{loadInfo.base, loadInfo.size});
return loadInfo.entry;
}

void NsoLoader::PrintRoContentsInfo(const std::vector<u8> &contents) {
const boost::regex moduleRegex(R"([a-z]:[\\/][ -~]{5,}\.nss)", boost::regex::icase);
const boost::regex fsSdkRegex("sdk_version: ([0-9.]*)");
const boost::regex sdkMwRegex("SDK MW[ -~]*");

std::string contentsRaw(contents.begin(), contents.end());
std::string modulePath;
if (memcmp(&contents[0], "\x00\x00\x00\x00", 4) == 0) {
i32 length;
std::memcpy(&length, &contents[4], sizeof(i32));

if (length > 0)
modulePath = reinterpret_cast<const char *>(&contents[4 + sizeof(i32)]);
}

if (modulePath.empty()) {
boost::smatch moduleMatch;
if (boost::regex_search(contentsRaw, moduleMatch, moduleRegex))
modulePath = moduleMatch.str();
}

LOGI("Module Path: {}", modulePath);

boost::smatch fsSdkMatch;
if (boost::regex_search(contentsRaw, fsSdkMatch, fsSdkRegex))
LOGI("SDK Version: {}", fsSdkMatch[1].str());

boost::sregex_iterator sdkMwMatchesBegin(contentsRaw.begin(), contentsRaw.end(), sdkMwRegex);
boost::sregex_iterator sdkMwMatchesEnd;

if (sdkMwMatchesBegin != sdkMwMatchesEnd) {
std::string libContent;

while (sdkMwMatchesBegin != sdkMwMatchesEnd) {
libContent += sdkMwMatchesBegin->str() + "\n";
sdkMwMatchesBegin++;
}

LOGI("SDK Libraries: {}", libContent);
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/cpp/skyline/loader/nso.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace skyline::loader {
*/
static ExecutableLoadInfo LoadNso(Loader *loader, const std::shared_ptr<vfs::Backing> &backing, const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state, size_t offset = 0, const std::string &name = {}, bool dynamicallyLinked = false);

static void PrintRoContentsInfo(const std::vector<u8> &contents);

void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override;
};
}

0 comments on commit 135b7f3

Please sign in to comment.