diff --git a/stratosphere/ncm/source/ncm_contentstorage.cpp b/stratosphere/ncm/source/ncm_contentstorage.cpp index c3080129e..567c6720c 100644 --- a/stratosphere/ncm/source/ncm_contentstorage.cpp +++ b/stratosphere/ncm/source/ncm_contentstorage.cpp @@ -82,10 +82,9 @@ namespace ams::ncm { Result ContentStorageInterface::GeneratePlaceHolderId(sf::Out out) { R_TRY(this->EnsureEnabled()); - - ams::os::GenerateRandomBytes(out.GetPointer(), sizeof(PlaceHolderId)); - char placeholder_str[FS_MAX_PATH] = {0}; - GetStringFromPlaceHolderId(placeholder_str, *out.GetPointer()); + PlaceHolderId placeholder_id; + placeholder_id.uuid = util::GenerateUuid(); + out.SetValue(placeholder_id); return ResultSuccess(); } @@ -121,7 +120,7 @@ namespace ams::ncm { Result ContentStorageInterface::WritePlaceHolder(PlaceHolderId placeholder_id, u64 offset, sf::InBuffer data) { /* Offset is too large */ - R_UNLESS(offset<= std::numeric_limits::max(), ncm::ResultInvalidOffset()); + R_UNLESS(offset <= std::numeric_limits::max(), ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); R_TRY(this->placeholder_accessor.Write(placeholder_id, offset, data.GetPointer(), data.GetSize())); return ResultSuccess(); @@ -363,7 +362,7 @@ namespace ams::ncm { Result ContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) { /* Offset is too large */ - R_UNLESS(offset<= std::numeric_limits::max(), ncm::ResultInvalidOffset()); + R_UNLESS(offset <= std::numeric_limits::max(), ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); char content_path[FS_MAX_PATH] = {0}; this->GetContentPath(content_path, content_id); @@ -450,7 +449,7 @@ namespace ams::ncm { Result ContentStorageInterface::WriteContentForDebug(ContentId content_id, u64 offset, sf::InBuffer data) { /* Offset is too large */ - R_UNLESS(offset<= std::numeric_limits::max(), ncm::ResultInvalidOffset()); + R_UNLESS(offset <= std::numeric_limits::max(), ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); bool is_development = false; diff --git a/stratosphere/ncm/source/ncm_make_path.cpp b/stratosphere/ncm/source/ncm_make_path.cpp index 83484a428..9e6f76f1d 100644 --- a/stratosphere/ncm/source/ncm_make_path.cpp +++ b/stratosphere/ncm/source/ncm_make_path.cpp @@ -23,13 +23,13 @@ namespace ams::ncm::path { u16 Get16BitSha256HashPrefix(util::Uuid uuid) { u8 hash[SHA256_HASH_SIZE]; - sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid)); + sha256CalculateHash(hash, uuid.data, sizeof(util::Uuid)); return static_cast(hash[0]) | (static_cast(hash[1]) << 8); } u8 Get8BitSha256HashPrefix(util::Uuid uuid) { u8 hash[SHA256_HASH_SIZE]; - sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid)); + sha256CalculateHash(hash, uuid.data, sizeof(util::Uuid)); return hash[0]; } diff --git a/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp b/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp index 3585eb8fc..337a24eb0 100644 --- a/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp +++ b/stratosphere/ncm/source/ncm_readonlycontentstorage.cpp @@ -150,7 +150,7 @@ namespace ams::ncm { Result ReadOnlyContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) { /* Offset is too large */ - R_UNLESS(offset<= std::numeric_limits::max(), ncm::ResultInvalidOffset()); + R_UNLESS(offset <= std::numeric_limits::max(), ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); char content_path[FS_MAX_PATH] = {0}; diff --git a/stratosphere/ncm/source/ncm_utils.cpp b/stratosphere/ncm/source/ncm_utils.cpp index b15d92804..c78f34b09 100644 --- a/stratosphere/ncm/source/ncm_utils.cpp +++ b/stratosphere/ncm/source/ncm_utils.cpp @@ -34,7 +34,7 @@ namespace ams::ncm { R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderDirectoryEntry()); R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ncm::ResultInvalidPlaceHolderDirectoryEntry()); - PlaceHolderId placeholder_id = {0}; + u8 tmp[sizeof(PlaceHolderId)] = {}; char byte_string[2]; char* end_ptr; u64 converted_val; @@ -46,20 +46,21 @@ namespace ams::ncm { byte_string[1] = name_char_pair[1]; converted_val = strtoull(byte_string, &end_ptr, 0x10); - placeholder_id.uuid[i] = (u8)converted_val; + tmp[i] = (u8)converted_val; } + PlaceHolderId placeholder_id; + std::memcpy(placeholder_id.uuid.data, tmp, sizeof(PlaceHolderId)); *out = placeholder_id; return ResultSuccess(); } std::optional GetContentIdFromString(const char* str, size_t len) { - ContentId content_id = {0}; - if (len < 0x20) { return std::nullopt; } + u8 tmp[sizeof(ContentId)] = {}; char byte_string[2]; char* end_ptr; u64 converted_val; @@ -71,9 +72,11 @@ namespace ams::ncm { byte_string[1] = char_par[1]; converted_val = strtoull(byte_string, &end_ptr, 0x10); - content_id.uuid[i] = (u8)converted_val; + tmp[i] = (u8)converted_val; } + ContentId content_id; + std::memcpy(content_id.uuid.data, tmp, sizeof(ContentId)); return std::optional(content_id); }