diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/cfg/cfg.cpp | 55 | ||||
| -rw-r--r-- | src/core/hle/service/cfg/cfg.h | 21 |
2 files changed, 71 insertions, 5 deletions
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 4ddb1bc90..8c8c1ec77 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <cryptopp/osrng.h> | ||
| 7 | #include <cryptopp/sha.h> | 8 | #include <cryptopp/sha.h> |
| 8 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| @@ -50,6 +51,7 @@ enum ConfigBlockID { | |||
| 50 | SoundOutputModeBlockID = 0x00070001, | 51 | SoundOutputModeBlockID = 0x00070001, |
| 51 | ConsoleUniqueID1BlockID = 0x00090000, | 52 | ConsoleUniqueID1BlockID = 0x00090000, |
| 52 | ConsoleUniqueID2BlockID = 0x00090001, | 53 | ConsoleUniqueID2BlockID = 0x00090001, |
| 54 | ConsoleUniqueID3BlockID = 0x00090002, | ||
| 53 | UsernameBlockID = 0x000A0000, | 55 | UsernameBlockID = 0x000A0000, |
| 54 | BirthdayBlockID = 0x000A0001, | 56 | BirthdayBlockID = 0x000A0001, |
| 55 | LanguageBlockID = 0x000A0002, | 57 | LanguageBlockID = 0x000A0002, |
| @@ -86,7 +88,6 @@ struct ConsoleCountryInfo { | |||
| 86 | static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); | 88 | static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); |
| 87 | } | 89 | } |
| 88 | 90 | ||
| 89 | static const u64 CONSOLE_UNIQUE_ID = 0xDEADC0DE; | ||
| 90 | static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}}; | 91 | static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}}; |
| 91 | static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; | 92 | static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; |
| 92 | static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0}; | 93 | static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0}; |
| @@ -438,13 +439,22 @@ ResultCode FormatConfig() { | |||
| 438 | if (!res.IsSuccess()) | 439 | if (!res.IsSuccess()) |
| 439 | return res; | 440 | return res; |
| 440 | 441 | ||
| 441 | res = CreateConfigInfoBlk(ConsoleUniqueID1BlockID, sizeof(CONSOLE_UNIQUE_ID), 0xE, | 442 | u32 random_number; |
| 442 | &CONSOLE_UNIQUE_ID); | 443 | u64 console_id; |
| 444 | GenerateConsoleUniqueId(random_number, console_id); | ||
| 445 | |||
| 446 | u64_le console_id_le = console_id; | ||
| 447 | res = CreateConfigInfoBlk(ConsoleUniqueID1BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 443 | if (!res.IsSuccess()) | 448 | if (!res.IsSuccess()) |
| 444 | return res; | 449 | return res; |
| 445 | 450 | ||
| 446 | res = CreateConfigInfoBlk(ConsoleUniqueID2BlockID, sizeof(CONSOLE_UNIQUE_ID), 0xE, | 451 | res = CreateConfigInfoBlk(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le); |
| 447 | &CONSOLE_UNIQUE_ID); | 452 | if (!res.IsSuccess()) |
| 453 | return res; | ||
| 454 | |||
| 455 | u32_le random_number_le = random_number; | ||
| 456 | res = CreateConfigInfoBlk(ConsoleUniqueID3BlockID, sizeof(random_number_le), 0xE, | ||
| 457 | &random_number_le); | ||
| 448 | if (!res.IsSuccess()) | 458 | if (!res.IsSuccess()) |
| 449 | return res; | 459 | return res; |
| 450 | 460 | ||
| @@ -663,5 +673,40 @@ SoundOutputMode GetSoundOutputMode() { | |||
| 663 | return static_cast<SoundOutputMode>(block); | 673 | return static_cast<SoundOutputMode>(block); |
| 664 | } | 674 | } |
| 665 | 675 | ||
| 676 | void GenerateConsoleUniqueId(u32& random_number, u64& console_id) { | ||
| 677 | CryptoPP::AutoSeededRandomPool rng; | ||
| 678 | random_number = rng.GenerateWord32(0, 0xFFFF); | ||
| 679 | u64_le local_friend_code_seed; | ||
| 680 | rng.GenerateBlock(reinterpret_cast<byte*>(&local_friend_code_seed), | ||
| 681 | sizeof(local_friend_code_seed)); | ||
| 682 | console_id = (local_friend_code_seed & 0x3FFFFFFFF) | (static_cast<u64>(random_number) << 48); | ||
| 683 | } | ||
| 684 | |||
| 685 | ResultCode SetConsoleUniqueId(u32 random_number, u64 console_id) { | ||
| 686 | u64_le console_id_le = console_id; | ||
| 687 | ResultCode res = | ||
| 688 | SetConfigInfoBlock(ConsoleUniqueID1BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 689 | if (!res.IsSuccess()) | ||
| 690 | return res; | ||
| 691 | |||
| 692 | res = SetConfigInfoBlock(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 693 | if (!res.IsSuccess()) | ||
| 694 | return res; | ||
| 695 | |||
| 696 | u32_le random_number_le = random_number; | ||
| 697 | res = SetConfigInfoBlock(ConsoleUniqueID3BlockID, sizeof(random_number_le), 0xE, | ||
| 698 | &random_number_le); | ||
| 699 | if (!res.IsSuccess()) | ||
| 700 | return res; | ||
| 701 | |||
| 702 | return RESULT_SUCCESS; | ||
| 703 | } | ||
| 704 | |||
| 705 | u64 GetConsoleUniqueId() { | ||
| 706 | u64_le console_id_le; | ||
| 707 | GetConfigInfoBlock(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 708 | return console_id_le; | ||
| 709 | } | ||
| 710 | |||
| 666 | } // namespace CFG | 711 | } // namespace CFG |
| 667 | } // namespace Service | 712 | } // namespace Service |
diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index 618c9647e..1659ebf32 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h | |||
| @@ -342,5 +342,26 @@ void SetSoundOutputMode(SoundOutputMode mode); | |||
| 342 | */ | 342 | */ |
| 343 | SoundOutputMode GetSoundOutputMode(); | 343 | SoundOutputMode GetSoundOutputMode(); |
| 344 | 344 | ||
| 345 | /** | ||
| 346 | * Generates a new random console unique id. | ||
| 347 | * @param random_number a random generated 16bit number stored at 0x90002, used for generating the | ||
| 348 | * console_id | ||
| 349 | * @param console_id the randomly created console id | ||
| 350 | */ | ||
| 351 | void GenerateConsoleUniqueId(u32& random_number, u64& console_id); | ||
| 352 | |||
| 353 | /** | ||
| 354 | * Sets the random_number and the console unique id in the config savegame. | ||
| 355 | * @param random_number the random_number to set | ||
| 356 | * @param console_id the console id to set | ||
| 357 | */ | ||
| 358 | ResultCode SetConsoleUniqueId(u32 random_number, u64 console_id); | ||
| 359 | |||
| 360 | /** | ||
| 361 | * Gets the console unique id from config savegame. | ||
| 362 | * @returns the console unique id | ||
| 363 | */ | ||
| 364 | u64 GetConsoleUniqueId(); | ||
| 365 | |||
| 345 | } // namespace CFG | 366 | } // namespace CFG |
| 346 | } // namespace Service | 367 | } // namespace Service |