diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/amiibo_crypto.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_device.cpp | 65 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_result.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_types.h | 47 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_user.cpp | 30 |
6 files changed, 112 insertions, 42 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index e27d84734..025f1c78e 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -1017,9 +1017,11 @@ bool EmulatedController::SetPollingMode(Common::Input::PollingMode polling_mode) | |||
| 1017 | auto& output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)]; | 1017 | auto& output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)]; |
| 1018 | auto& nfc_output_device = output_devices[3]; | 1018 | auto& nfc_output_device = output_devices[3]; |
| 1019 | 1019 | ||
| 1020 | nfc_output_device->SetPollingMode(polling_mode); | 1020 | const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode); |
| 1021 | const auto mapped_nfc_result = output_device->SetPollingMode(polling_mode); | ||
| 1021 | 1022 | ||
| 1022 | return output_device->SetPollingMode(polling_mode) == Common::Input::PollingError::None; | 1023 | return virtual_nfc_result == Common::Input::PollingError::None || |
| 1024 | mapped_nfc_result == Common::Input::PollingError::None; | ||
| 1023 | } | 1025 | } |
| 1024 | 1026 | ||
| 1025 | bool EmulatedController::SetCameraFormat( | 1027 | bool EmulatedController::SetCameraFormat( |
diff --git a/src/core/hle/service/nfp/amiibo_crypto.cpp b/src/core/hle/service/nfp/amiibo_crypto.cpp index ce0bc3f75..c32a6816b 100644 --- a/src/core/hle/service/nfp/amiibo_crypto.cpp +++ b/src/core/hle/service/nfp/amiibo_crypto.cpp | |||
| @@ -28,7 +28,7 @@ bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) { | |||
| 28 | LOG_DEBUG(Service_NFP, "model_number=0x{0:x}", | 28 | LOG_DEBUG(Service_NFP, "model_number=0x{0:x}", |
| 29 | static_cast<u16>(amiibo_data.model_info.model_number)); | 29 | static_cast<u16>(amiibo_data.model_info.model_number)); |
| 30 | LOG_DEBUG(Service_NFP, "series={}", amiibo_data.model_info.series); | 30 | LOG_DEBUG(Service_NFP, "series={}", amiibo_data.model_info.series); |
| 31 | LOG_DEBUG(Service_NFP, "fixed_value=0x{0:x}", amiibo_data.model_info.constant_value); | 31 | LOG_DEBUG(Service_NFP, "tag_type=0x{0:x}", amiibo_data.model_info.tag_type); |
| 32 | 32 | ||
| 33 | LOG_DEBUG(Service_NFP, "tag_dynamic_lock=0x{0:x}", ntag_file.dynamic_lock); | 33 | LOG_DEBUG(Service_NFP, "tag_dynamic_lock=0x{0:x}", ntag_file.dynamic_lock); |
| 34 | LOG_DEBUG(Service_NFP, "tag_CFG0=0x{0:x}", ntag_file.CFG0); | 34 | LOG_DEBUG(Service_NFP, "tag_CFG0=0x{0:x}", ntag_file.CFG0); |
| @@ -55,7 +55,7 @@ bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) { | |||
| 55 | if (amiibo_data.constant_value != 0xA5) { | 55 | if (amiibo_data.constant_value != 0xA5) { |
| 56 | return false; | 56 | return false; |
| 57 | } | 57 | } |
| 58 | if (amiibo_data.model_info.constant_value != 0x02) { | 58 | if (amiibo_data.model_info.tag_type != PackedTagType::Type2) { |
| 59 | return false; | 59 | return false; |
| 60 | } | 60 | } |
| 61 | if ((ntag_file.dynamic_lock & 0xFFFFFF) != 0x0F0001U) { | 61 | if ((ntag_file.dynamic_lock & 0xFFFFFF) != 0x0F0001U) { |
diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index 0d4ffd3a5..ec895ac01 100644 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp | |||
| @@ -98,11 +98,6 @@ bool NfpDevice::LoadAmiibo(std::span<const u8> data) { | |||
| 98 | 98 | ||
| 99 | memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); | 99 | memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); |
| 100 | 100 | ||
| 101 | if (!AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { | ||
| 102 | LOG_INFO(Service_NFP, "Invalid amiibo"); | ||
| 103 | return false; | ||
| 104 | } | ||
| 105 | |||
| 106 | device_state = DeviceState::TagFound; | 101 | device_state = DeviceState::TagFound; |
| 107 | deactivate_event->GetReadableEvent().Clear(); | 102 | deactivate_event->GetReadableEvent().Clear(); |
| 108 | activate_event->GetWritableEvent().Signal(); | 103 | activate_event->GetWritableEvent().Signal(); |
| @@ -148,20 +143,28 @@ void NfpDevice::Finalize() { | |||
| 148 | } | 143 | } |
| 149 | 144 | ||
| 150 | Result NfpDevice::StartDetection(s32 protocol_) { | 145 | Result NfpDevice::StartDetection(s32 protocol_) { |
| 151 | if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) { | 146 | if (device_state != DeviceState::Initialized && device_state != DeviceState::TagRemoved) { |
| 152 | npad_device->SetPollingMode(Common::Input::PollingMode::NFC); | 147 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 153 | device_state = DeviceState::SearchingForTag; | 148 | return WrongDeviceState; |
| 154 | protocol = protocol_; | ||
| 155 | return ResultSuccess; | ||
| 156 | } | 149 | } |
| 157 | 150 | ||
| 158 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 151 | if (!npad_device->SetPollingMode(Common::Input::PollingMode::NFC)) { |
| 159 | return WrongDeviceState; | 152 | LOG_ERROR(Service_NFP, "Nfc not supported"); |
| 153 | return NfcDisabled; | ||
| 154 | } | ||
| 155 | |||
| 156 | device_state = DeviceState::SearchingForTag; | ||
| 157 | protocol = protocol_; | ||
| 158 | return ResultSuccess; | ||
| 160 | } | 159 | } |
| 161 | 160 | ||
| 162 | Result NfpDevice::StopDetection() { | 161 | Result NfpDevice::StopDetection() { |
| 163 | npad_device->SetPollingMode(Common::Input::PollingMode::Active); | 162 | npad_device->SetPollingMode(Common::Input::PollingMode::Active); |
| 164 | 163 | ||
| 164 | if (device_state == DeviceState::Initialized) { | ||
| 165 | return ResultSuccess; | ||
| 166 | } | ||
| 167 | |||
| 165 | if (device_state == DeviceState::TagFound || device_state == DeviceState::TagMounted) { | 168 | if (device_state == DeviceState::TagFound || device_state == DeviceState::TagMounted) { |
| 166 | CloseAmiibo(); | 169 | CloseAmiibo(); |
| 167 | return ResultSuccess; | 170 | return ResultSuccess; |
| @@ -225,6 +228,11 @@ Result NfpDevice::Mount(MountTarget mount_target_) { | |||
| 225 | return WrongDeviceState; | 228 | return WrongDeviceState; |
| 226 | } | 229 | } |
| 227 | 230 | ||
| 231 | if (!AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { | ||
| 232 | LOG_ERROR(Service_NFP, "Not an amiibo"); | ||
| 233 | return NotAnAmiibo; | ||
| 234 | } | ||
| 235 | |||
| 228 | if (!AmiiboCrypto::DecodeAmiibo(encrypted_tag_data, tag_data)) { | 236 | if (!AmiiboCrypto::DecodeAmiibo(encrypted_tag_data, tag_data)) { |
| 229 | LOG_ERROR(Service_NFP, "Can't decode amiibo {}", device_state); | 237 | LOG_ERROR(Service_NFP, "Can't decode amiibo {}", device_state); |
| 230 | return CorruptedData; | 238 | return CorruptedData; |
| @@ -238,6 +246,9 @@ Result NfpDevice::Mount(MountTarget mount_target_) { | |||
| 238 | Result NfpDevice::Unmount() { | 246 | Result NfpDevice::Unmount() { |
| 239 | if (device_state != DeviceState::TagMounted) { | 247 | if (device_state != DeviceState::TagMounted) { |
| 240 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 248 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 249 | if (device_state == DeviceState::TagRemoved) { | ||
| 250 | return TagRemoved; | ||
| 251 | } | ||
| 241 | return WrongDeviceState; | 252 | return WrongDeviceState; |
| 242 | } | 253 | } |
| 243 | 254 | ||
| @@ -256,6 +267,9 @@ Result NfpDevice::Unmount() { | |||
| 256 | Result NfpDevice::GetTagInfo(TagInfo& tag_info) const { | 267 | Result NfpDevice::GetTagInfo(TagInfo& tag_info) const { |
| 257 | if (device_state != DeviceState::TagFound && device_state != DeviceState::TagMounted) { | 268 | if (device_state != DeviceState::TagFound && device_state != DeviceState::TagMounted) { |
| 258 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 269 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 270 | if (device_state == DeviceState::TagRemoved) { | ||
| 271 | return TagRemoved; | ||
| 272 | } | ||
| 259 | return WrongDeviceState; | 273 | return WrongDeviceState; |
| 260 | } | 274 | } |
| 261 | 275 | ||
| @@ -287,12 +301,7 @@ Result NfpDevice::GetCommonInfo(CommonInfo& common_info) const { | |||
| 287 | 301 | ||
| 288 | // TODO: Validate this data | 302 | // TODO: Validate this data |
| 289 | common_info = { | 303 | common_info = { |
| 290 | .last_write_date = | 304 | .last_write_date = settings.write_date.GetWriteDate(), |
| 291 | { | ||
| 292 | settings.write_date.GetYear(), | ||
| 293 | settings.write_date.GetMonth(), | ||
| 294 | settings.write_date.GetDay(), | ||
| 295 | }, | ||
| 296 | .write_counter = tag_data.write_counter, | 305 | .write_counter = tag_data.write_counter, |
| 297 | .version = 0, | 306 | .version = 0, |
| 298 | .application_area_size = sizeof(ApplicationArea), | 307 | .application_area_size = sizeof(ApplicationArea), |
| @@ -303,6 +312,9 @@ Result NfpDevice::GetCommonInfo(CommonInfo& common_info) const { | |||
| 303 | Result NfpDevice::GetModelInfo(ModelInfo& model_info) const { | 312 | Result NfpDevice::GetModelInfo(ModelInfo& model_info) const { |
| 304 | if (device_state != DeviceState::TagMounted) { | 313 | if (device_state != DeviceState::TagMounted) { |
| 305 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 314 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 315 | if (device_state == DeviceState::TagRemoved) { | ||
| 316 | return TagRemoved; | ||
| 317 | } | ||
| 306 | return WrongDeviceState; | 318 | return WrongDeviceState; |
| 307 | } | 319 | } |
| 308 | 320 | ||
| @@ -341,12 +353,7 @@ Result NfpDevice::GetRegisterInfo(RegisterInfo& register_info) const { | |||
| 341 | // TODO: Validate this data | 353 | // TODO: Validate this data |
| 342 | register_info = { | 354 | register_info = { |
| 343 | .mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii), | 355 | .mii_char_info = manager.ConvertV3ToCharInfo(tag_data.owner_mii), |
| 344 | .creation_date = | 356 | .creation_date = settings.init_date.GetWriteDate(), |
| 345 | { | ||
| 346 | settings.init_date.GetYear(), | ||
| 347 | settings.init_date.GetMonth(), | ||
| 348 | settings.init_date.GetDay(), | ||
| 349 | }, | ||
| 350 | .amiibo_name = GetAmiiboName(settings), | 357 | .amiibo_name = GetAmiiboName(settings), |
| 351 | .font_region = {}, | 358 | .font_region = {}, |
| 352 | }; | 359 | }; |
| @@ -478,8 +485,7 @@ Result NfpDevice::GetApplicationArea(std::vector<u8>& data) const { | |||
| 478 | } | 485 | } |
| 479 | 486 | ||
| 480 | if (data.size() > sizeof(ApplicationArea)) { | 487 | if (data.size() > sizeof(ApplicationArea)) { |
| 481 | LOG_ERROR(Service_NFP, "Wrong data size {}", data.size()); | 488 | data.resize(sizeof(ApplicationArea)); |
| 482 | return ResultUnknown; | ||
| 483 | } | 489 | } |
| 484 | 490 | ||
| 485 | memcpy(data.data(), tag_data.application_area.data(), data.size()); | 491 | memcpy(data.data(), tag_data.application_area.data(), data.size()); |
| @@ -518,7 +524,7 @@ Result NfpDevice::SetApplicationArea(std::span<const u8> data) { | |||
| 518 | 524 | ||
| 519 | Common::TinyMT rng{}; | 525 | Common::TinyMT rng{}; |
| 520 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); | 526 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); |
| 521 | // HW seems to fill excess data with garbage | 527 | // Fill remaining data with random numbers |
| 522 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), | 528 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), |
| 523 | sizeof(ApplicationArea) - data.size()); | 529 | sizeof(ApplicationArea) - data.size()); |
| 524 | 530 | ||
| @@ -561,12 +567,12 @@ Result NfpDevice::RecreateApplicationArea(u32 access_id, std::span<const u8> dat | |||
| 561 | 567 | ||
| 562 | if (data.size() > sizeof(ApplicationArea)) { | 568 | if (data.size() > sizeof(ApplicationArea)) { |
| 563 | LOG_ERROR(Service_NFP, "Wrong data size {}", data.size()); | 569 | LOG_ERROR(Service_NFP, "Wrong data size {}", data.size()); |
| 564 | return ResultUnknown; | 570 | return WrongApplicationAreaSize; |
| 565 | } | 571 | } |
| 566 | 572 | ||
| 567 | Common::TinyMT rng{}; | 573 | Common::TinyMT rng{}; |
| 568 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); | 574 | std::memcpy(tag_data.application_area.data(), data.data(), data.size()); |
| 569 | // HW seems to fill excess data with garbage | 575 | // Fill remaining data with random numbers |
| 570 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), | 576 | rng.GenerateRandomBytes(tag_data.application_area.data() + data.size(), |
| 571 | sizeof(ApplicationArea) - data.size()); | 577 | sizeof(ApplicationArea) - data.size()); |
| 572 | 578 | ||
| @@ -612,7 +618,6 @@ u64 NfpDevice::GetHandle() const { | |||
| 612 | } | 618 | } |
| 613 | 619 | ||
| 614 | u32 NfpDevice::GetApplicationAreaSize() const { | 620 | u32 NfpDevice::GetApplicationAreaSize() const { |
| 615 | // Investigate if this value is really constant | ||
| 616 | return sizeof(ApplicationArea); | 621 | return sizeof(ApplicationArea); |
| 617 | } | 622 | } |
| 618 | 623 | ||
diff --git a/src/core/hle/service/nfp/nfp_result.h b/src/core/hle/service/nfp/nfp_result.h index ac259e2ff..d8e4cf094 100644 --- a/src/core/hle/service/nfp/nfp_result.h +++ b/src/core/hle/service/nfp/nfp_result.h | |||
| @@ -8,6 +8,8 @@ | |||
| 8 | namespace Service::NFP { | 8 | namespace Service::NFP { |
| 9 | 9 | ||
| 10 | constexpr Result DeviceNotFound(ErrorModule::NFP, 64); | 10 | constexpr Result DeviceNotFound(ErrorModule::NFP, 64); |
| 11 | constexpr Result InvalidArgument(ErrorModule::NFP, 65); | ||
| 12 | constexpr Result WrongApplicationAreaSize(ErrorModule::NFP, 68); | ||
| 11 | constexpr Result WrongDeviceState(ErrorModule::NFP, 73); | 13 | constexpr Result WrongDeviceState(ErrorModule::NFP, 73); |
| 12 | constexpr Result NfcDisabled(ErrorModule::NFP, 80); | 14 | constexpr Result NfcDisabled(ErrorModule::NFP, 80); |
| 13 | constexpr Result WriteAmiiboFailed(ErrorModule::NFP, 88); | 15 | constexpr Result WriteAmiiboFailed(ErrorModule::NFP, 88); |
diff --git a/src/core/hle/service/nfp/nfp_types.h b/src/core/hle/service/nfp/nfp_types.h index dd4525b61..867ea2f36 100644 --- a/src/core/hle/service/nfp/nfp_types.h +++ b/src/core/hle/service/nfp/nfp_types.h | |||
| @@ -84,6 +84,15 @@ enum class TagType : u32 { | |||
| 84 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s | 84 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s |
| 85 | }; | 85 | }; |
| 86 | 86 | ||
| 87 | enum class PackedTagType : u8 { | ||
| 88 | None, | ||
| 89 | Type1, // ISO14443A RW 96-2k bytes 106kbit/s | ||
| 90 | Type2, // ISO14443A RW/RO 540 bytes 106kbit/s | ||
| 91 | Type3, // Sony Felica RW/RO 2k bytes 212kbit/s | ||
| 92 | Type4, // ISO14443A RW/RO 4k-32k bytes 424kbit/s | ||
| 93 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s | ||
| 94 | }; | ||
| 95 | |||
| 87 | enum class TagProtocol : u32 { | 96 | enum class TagProtocol : u32 { |
| 88 | None, | 97 | None, |
| 89 | TypeA, // ISO14443A | 98 | TypeA, // ISO14443A |
| @@ -104,6 +113,13 @@ struct TagUuid { | |||
| 104 | }; | 113 | }; |
| 105 | static_assert(sizeof(TagUuid) == 10, "TagUuid is an invalid size"); | 114 | static_assert(sizeof(TagUuid) == 10, "TagUuid is an invalid size"); |
| 106 | 115 | ||
| 116 | struct WriteDate { | ||
| 117 | u16 year; | ||
| 118 | u8 month; | ||
| 119 | u8 day; | ||
| 120 | }; | ||
| 121 | static_assert(sizeof(WriteDate) == 0x4, "WriteDate is an invalid size"); | ||
| 122 | |||
| 107 | struct AmiiboDate { | 123 | struct AmiiboDate { |
| 108 | u16 raw_date{}; | 124 | u16 raw_date{}; |
| 109 | 125 | ||
| @@ -121,6 +137,21 @@ struct AmiiboDate { | |||
| 121 | return static_cast<u8>(GetValue() & 0x001F); | 137 | return static_cast<u8>(GetValue() & 0x001F); |
| 122 | } | 138 | } |
| 123 | 139 | ||
| 140 | WriteDate GetWriteDate() const { | ||
| 141 | if (!IsValidDate()) { | ||
| 142 | return { | ||
| 143 | .year = 2000, | ||
| 144 | .month = 1, | ||
| 145 | .day = 1, | ||
| 146 | }; | ||
| 147 | } | ||
| 148 | return { | ||
| 149 | .year = GetYear(), | ||
| 150 | .month = GetMonth(), | ||
| 151 | .day = GetDay(), | ||
| 152 | }; | ||
| 153 | } | ||
| 154 | |||
| 124 | void SetYear(u16 year) { | 155 | void SetYear(u16 year) { |
| 125 | const u16 year_converted = static_cast<u16>((year - 2000) << 9); | 156 | const u16 year_converted = static_cast<u16>((year - 2000) << 9); |
| 126 | raw_date = Common::swap16((GetValue() & ~0xFE00) | year_converted); | 157 | raw_date = Common::swap16((GetValue() & ~0xFE00) | year_converted); |
| @@ -133,6 +164,13 @@ struct AmiiboDate { | |||
| 133 | const u16 day_converted = static_cast<u16>(day); | 164 | const u16 day_converted = static_cast<u16>(day); |
| 134 | raw_date = Common::swap16((GetValue() & ~0x001F) | day_converted); | 165 | raw_date = Common::swap16((GetValue() & ~0x001F) | day_converted); |
| 135 | } | 166 | } |
| 167 | |||
| 168 | bool IsValidDate() const { | ||
| 169 | const bool is_day_valid = GetDay() > 0 && GetDay() < 32; | ||
| 170 | const bool is_month_valid = GetMonth() >= 0 && GetMonth() < 13; | ||
| 171 | const bool is_year_valid = GetYear() >= 2000; | ||
| 172 | return is_year_valid && is_month_valid && is_day_valid; | ||
| 173 | } | ||
| 136 | }; | 174 | }; |
| 137 | static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size"); | 175 | static_assert(sizeof(AmiiboDate) == 2, "AmiiboDate is an invalid size"); |
| 138 | 176 | ||
| @@ -163,7 +201,7 @@ struct AmiiboModelInfo { | |||
| 163 | AmiiboType amiibo_type; | 201 | AmiiboType amiibo_type; |
| 164 | u16_be model_number; | 202 | u16_be model_number; |
| 165 | AmiiboSeries series; | 203 | AmiiboSeries series; |
| 166 | u8 constant_value; // Must be 02 | 204 | PackedTagType tag_type; |
| 167 | INSERT_PADDING_BYTES(0x4); // Unknown | 205 | INSERT_PADDING_BYTES(0x4); // Unknown |
| 168 | }; | 206 | }; |
| 169 | static_assert(sizeof(AmiiboModelInfo) == 0xC, "AmiiboModelInfo is an invalid size"); | 207 | static_assert(sizeof(AmiiboModelInfo) == 0xC, "AmiiboModelInfo is an invalid size"); |
| @@ -250,13 +288,6 @@ struct TagInfo { | |||
| 250 | }; | 288 | }; |
| 251 | static_assert(sizeof(TagInfo) == 0x58, "TagInfo is an invalid size"); | 289 | static_assert(sizeof(TagInfo) == 0x58, "TagInfo is an invalid size"); |
| 252 | 290 | ||
| 253 | struct WriteDate { | ||
| 254 | u16 year; | ||
| 255 | u8 month; | ||
| 256 | u8 day; | ||
| 257 | }; | ||
| 258 | static_assert(sizeof(WriteDate) == 0x4, "WriteDate is an invalid size"); | ||
| 259 | |||
| 260 | struct CommonInfo { | 291 | struct CommonInfo { |
| 261 | WriteDate last_write_date; | 292 | WriteDate last_write_date; |
| 262 | u16 write_counter; | 293 | u16 write_counter; |
diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index c61df9401..4ed53b534 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp | |||
| @@ -93,6 +93,18 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { | |||
| 93 | return; | 93 | return; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | if (!ctx.CanWriteBuffer()) { | ||
| 97 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 98 | rb.Push(InvalidArgument); | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (ctx.GetWriteBufferSize() == 0) { | ||
| 103 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 104 | rb.Push(InvalidArgument); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 96 | std::vector<u64> nfp_devices; | 108 | std::vector<u64> nfp_devices; |
| 97 | const std::size_t max_allowed_devices = ctx.GetWriteBufferSize() / sizeof(u64); | 109 | const std::size_t max_allowed_devices = ctx.GetWriteBufferSize() / sizeof(u64); |
| 98 | 110 | ||
| @@ -255,6 +267,12 @@ void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) { | |||
| 255 | return; | 267 | return; |
| 256 | } | 268 | } |
| 257 | 269 | ||
| 270 | if (!ctx.CanWriteBuffer()) { | ||
| 271 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 272 | rb.Push(InvalidArgument); | ||
| 273 | return; | ||
| 274 | } | ||
| 275 | |||
| 258 | auto device = GetNfpDevice(device_handle); | 276 | auto device = GetNfpDevice(device_handle); |
| 259 | 277 | ||
| 260 | if (!device.has_value()) { | 278 | if (!device.has_value()) { |
| @@ -283,6 +301,12 @@ void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) { | |||
| 283 | return; | 301 | return; |
| 284 | } | 302 | } |
| 285 | 303 | ||
| 304 | if (!ctx.CanReadBuffer()) { | ||
| 305 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 306 | rb.Push(InvalidArgument); | ||
| 307 | return; | ||
| 308 | } | ||
| 309 | |||
| 286 | auto device = GetNfpDevice(device_handle); | 310 | auto device = GetNfpDevice(device_handle); |
| 287 | 311 | ||
| 288 | if (!device.has_value()) { | 312 | if (!device.has_value()) { |
| @@ -358,6 +382,12 @@ void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) { | |||
| 358 | return; | 382 | return; |
| 359 | } | 383 | } |
| 360 | 384 | ||
| 385 | if (!ctx.CanReadBuffer()) { | ||
| 386 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 387 | rb.Push(InvalidArgument); | ||
| 388 | return; | ||
| 389 | } | ||
| 390 | |||
| 361 | auto device = GetNfpDevice(device_handle); | 391 | auto device = GetNfpDevice(device_handle); |
| 362 | 392 | ||
| 363 | if (!device.has_value()) { | 393 | if (!device.has_value()) { |