mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-28 22:12:40 +02:00
ams_mitm: Implement set:sys firmwareversion mitm
This commit is contained in:
parent
0333c376fd
commit
b628ea560d
@ -172,4 +172,52 @@ namespace ams::settings {
|
||||
return 0 <= rc && rc < RegionCode_Count;
|
||||
}
|
||||
|
||||
/* This needs to be defined separately from libnx's so that it can inherit from sf::LargeData. */
|
||||
|
||||
struct FirmwareVersion : public sf::LargeData {
|
||||
u8 major;
|
||||
u8 minor;
|
||||
u8 micro;
|
||||
u8 padding1;
|
||||
u8 revision_major;
|
||||
u8 revision_minor;
|
||||
u8 padding2;
|
||||
u8 padding3;
|
||||
char platform[0x20];
|
||||
char version_hash[0x40];
|
||||
char display_version[0x18];
|
||||
char display_title[0x80];
|
||||
|
||||
constexpr inline u32 GetVersion() const {
|
||||
return (static_cast<u32>(major) << 16) | (static_cast<u32>(minor) << 8) | (static_cast<u32>(micro) << 0);
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(std::is_pod<FirmwareVersion>::value);
|
||||
static_assert(sizeof(FirmwareVersion) == sizeof(::SetSysFirmwareVersion));
|
||||
|
||||
constexpr inline bool operator==(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
|
||||
return lhs.GetVersion() == rhs.GetVersion();
|
||||
}
|
||||
|
||||
constexpr inline bool operator!=(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
constexpr inline bool operator<(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
|
||||
return lhs.GetVersion() < rhs.GetVersion();
|
||||
}
|
||||
|
||||
constexpr inline bool operator>=(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
constexpr inline bool operator<=(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
|
||||
return lhs.GetVersion() <= rhs.GetVersion();
|
||||
}
|
||||
|
||||
constexpr inline bool operator>(const FirmwareVersion &lhs, const FirmwareVersion &rhs) {
|
||||
return !(lhs <= rhs);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ namespace ams::spl::smc {
|
||||
Result AtmosphereCopyFromIram(void *dram_dst, uintptr_t iram_src, size_t size);
|
||||
Result AtmosphereReadWriteRegister(uint64_t address, uint32_t mask, uint32_t value, uint32_t *out_value);
|
||||
Result AtmosphereWriteAddress(void *dst, const void *src, size_t size);
|
||||
Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id);
|
||||
|
||||
/* Helpers. */
|
||||
inline Result SetConfig(SplConfigItem which, const u64 value) {
|
||||
|
137
source/ams/ams_emummc_api.cpp
Normal file
137
source/ams/ams_emummc_api.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::emummc {
|
||||
|
||||
namespace {
|
||||
|
||||
/* Convenience Definitions. */
|
||||
constexpr u32 StorageMagic = 0x30534645; /* EFS0 */
|
||||
constexpr size_t MaxDirLen = 0x7F;
|
||||
|
||||
/* Types. */
|
||||
struct BaseConfig {
|
||||
u32 magic;
|
||||
u32 type;
|
||||
u32 id;
|
||||
u32 fs_version;
|
||||
};
|
||||
|
||||
struct PartitionConfig {
|
||||
u64 start_sector;
|
||||
};
|
||||
|
||||
struct FileConfig {
|
||||
char path[MaxDirLen + 1];
|
||||
};
|
||||
|
||||
struct ExosphereConfig {
|
||||
BaseConfig base_cfg;
|
||||
union {
|
||||
PartitionConfig partition_cfg;
|
||||
FileConfig file_cfg;
|
||||
};
|
||||
char emu_dir_path[MaxDirLen + 1];
|
||||
};
|
||||
|
||||
enum Storage : u32 {
|
||||
Storage_Emmc,
|
||||
Storage_Sd,
|
||||
Storage_SdFile,
|
||||
|
||||
Storage_Count,
|
||||
};
|
||||
|
||||
/* Globals. */
|
||||
os::Mutex g_lock;
|
||||
ExosphereConfig g_exo_config;
|
||||
bool g_is_emummc;
|
||||
bool g_has_cached;
|
||||
|
||||
/* Helpers. */
|
||||
void CacheValues() {
|
||||
std::scoped_lock lk(g_lock);
|
||||
|
||||
if (g_has_cached) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Retrieve and cache values. */
|
||||
{
|
||||
|
||||
typename std::aligned_storage<2 * (MaxDirLen + 1), 0x1000>::type path_storage;
|
||||
|
||||
struct {
|
||||
char file_path[MaxDirLen + 1];
|
||||
char nintendo_path[MaxDirLen + 1];
|
||||
} *paths = reinterpret_cast<decltype(paths)>(&path_storage);
|
||||
|
||||
/* Retrieve paths from secure monitor. */
|
||||
AMS_ASSERT(spl::smc::AtmosphereGetEmummcConfig(&g_exo_config, paths, 0) == spl::smc::Result::Success);
|
||||
|
||||
const Storage storage = static_cast<Storage>(g_exo_config.base_cfg.type);
|
||||
g_is_emummc = g_exo_config.base_cfg.magic == StorageMagic && storage != Storage_Emmc;
|
||||
|
||||
/* Format paths. Ignore string format warnings. */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||
{
|
||||
if (storage == Storage_SdFile) {
|
||||
std::snprintf(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), "/%s", paths->file_path);
|
||||
}
|
||||
|
||||
std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/%s", paths->nintendo_path);
|
||||
|
||||
/* If we're emummc, implement default nintendo redirection path. */
|
||||
if (g_is_emummc && std::strcmp(g_exo_config.emu_dir_path, "/") == 0) {
|
||||
std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id);
|
||||
}
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
g_has_cached = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Get whether emummc is active. */
|
||||
bool IsActive() {
|
||||
CacheValues();
|
||||
return g_is_emummc;
|
||||
}
|
||||
|
||||
/* Get Nintendo redirection path. */
|
||||
const char *GetNintendoDirPath() {
|
||||
CacheValues();
|
||||
if (!g_is_emummc) {
|
||||
return nullptr;
|
||||
}
|
||||
return g_exo_config.emu_dir_path;
|
||||
}
|
||||
|
||||
/* Get Emummc folderpath, NULL if not file-based. */
|
||||
const char *GetFilePath() {
|
||||
CacheValues();
|
||||
if (!g_is_emummc || g_exo_config.base_cfg.type != Storage_SdFile) {
|
||||
return nullptr;
|
||||
}
|
||||
return g_exo_config.file_cfg.path;
|
||||
}
|
||||
|
||||
}
|
@ -361,4 +361,18 @@ namespace ams::spl::smc {
|
||||
return static_cast<Result>(args.X[0]);
|
||||
}
|
||||
|
||||
Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id) {
|
||||
const u64 paths = reinterpret_cast<u64>(out_paths);
|
||||
AMS_ASSERT(util::IsAligned(paths, 0x1000));
|
||||
|
||||
SecmonArgs args = {};
|
||||
args.X[0] = static_cast<u64>(FunctionId::AtmosphereGetEmummcConfig);
|
||||
args.X[1] = storage_id;
|
||||
args.X[2] = paths;
|
||||
svcCallSecureMonitor(&args);
|
||||
|
||||
std::memcpy(out_config, &args.X[1], sizeof(args) - sizeof(args.X[0]));
|
||||
return static_cast<Result>(args.X[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user