diff options
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | externals/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | externals/cryptopp/CMakeLists.txt | 168 | ||||
| m--------- | externals/cryptopp/cryptopp | 0 | ||||
| -rw-r--r-- | src/core/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 43 | ||||
| -rw-r--r-- | src/core/file_sys/archive_selfncch.cpp | 257 | ||||
| -rw-r--r-- | src/core/file_sys/archive_selfncch.h (renamed from src/core/file_sys/archive_romfs.h) | 23 | ||||
| -rw-r--r-- | src/core/file_sys/errors.h | 10 | ||||
| -rw-r--r-- | src/core/hle/result.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/fs/archive.h | 2 | ||||
| -rw-r--r-- | src/core/loader/3dsx.cpp | 6 | ||||
| -rw-r--r-- | src/core/loader/ncch.cpp | 6 |
13 files changed, 471 insertions, 61 deletions
diff --git a/.gitmodules b/.gitmodules index dbb1b0dd3..f98725622 100644 --- a/.gitmodules +++ b/.gitmodules | |||
| @@ -19,3 +19,6 @@ | |||
| 19 | [submodule "xbyak"] | 19 | [submodule "xbyak"] |
| 20 | path = externals/xbyak | 20 | path = externals/xbyak |
| 21 | url = https://github.com/herumi/xbyak.git | 21 | url = https://github.com/herumi/xbyak.git |
| 22 | [submodule "cryptopp"] | ||
| 23 | path = externals/cryptopp/cryptopp | ||
| 24 | url = https://github.com/weidai11/cryptopp.git | ||
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 7e4b05ffc..309e98464 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt | |||
| @@ -6,3 +6,6 @@ if (ARCHITECTURE_x86_64) | |||
| 6 | target_compile_options(xbyak INTERFACE -fno-operator-names) | 6 | target_compile_options(xbyak INTERFACE -fno-operator-names) |
| 7 | endif() | 7 | endif() |
| 8 | endif() | 8 | endif() |
| 9 | |||
| 10 | add_subdirectory(cryptopp) | ||
| 11 | |||
diff --git a/externals/cryptopp/CMakeLists.txt b/externals/cryptopp/CMakeLists.txt new file mode 100644 index 000000000..bbac71bb9 --- /dev/null +++ b/externals/cryptopp/CMakeLists.txt | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | # The CMakeLists.txt shipped with cryptopp pollutes our option list and installation list, | ||
| 2 | # so we made our own one. This is basically a trimmed down version of the shipped CMakeLists.txt | ||
| 3 | # The differences are: | ||
| 4 | # - removed support for legacy CMake versions | ||
| 5 | # - removed support for 32-bit | ||
| 6 | # - removed rdrand module.asm as a workaround for an issue (see below) | ||
| 7 | # - added prefix "CRYPTOPP_" to all option names | ||
| 8 | # - disabled testing | ||
| 9 | # - disabled installation | ||
| 10 | # - disabled documentation | ||
| 11 | # - configured to build a static library only | ||
| 12 | |||
| 13 | include(TestBigEndian) | ||
| 14 | include(CheckCXXCompilerFlag) | ||
| 15 | |||
| 16 | #============================================================================ | ||
| 17 | # Settable options | ||
| 18 | #============================================================================ | ||
| 19 | |||
| 20 | option(CRYPTOPP_DISABLE_ASM "Disable ASM" OFF) | ||
| 21 | option(CRYPTOPP_DISABLE_SSSE3 "Disable SSSE3" OFF) | ||
| 22 | option(CRYPTOPP_DISABLE_AESNI "Disable AES-NI" OFF) | ||
| 23 | option(CRYPTOPP_DISABLE_CXXFLAGS_OPTIMIZATIONS "Disable CXXFLAGS optimizations" OFF) | ||
| 24 | |||
| 25 | #============================================================================ | ||
| 26 | # Internal compiler options | ||
| 27 | #============================================================================ | ||
| 28 | |||
| 29 | # Only set when cross-compiling, http://www.vtk.org/Wiki/CMake_Cross_Compiling | ||
| 30 | if (NOT (CMAKE_SYSTEM_VERSION AND CMAKE_SYSTEM_PROCESSOR)) | ||
| 31 | set(CRYPTOPP_CROSS_COMPILE 1) | ||
| 32 | else() | ||
| 33 | set(CRYPTOPP_CROSS_COMPILE 0) | ||
| 34 | endif() | ||
| 35 | |||
| 36 | # Don't use RPATH's. The resulting binary could fail a security audit. | ||
| 37 | if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) | ||
| 38 | set(CMAKE_MACOSX_RPATH 0) | ||
| 39 | endif() | ||
| 40 | |||
| 41 | if(CMAKE_CXX_COMPILER_ID MATCHES "Intel") | ||
| 42 | add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180) | ||
| 43 | endif() | ||
| 44 | |||
| 45 | # Endianness | ||
| 46 | TEST_BIG_ENDIAN(IS_BIG_ENDIAN) | ||
| 47 | if(IS_BIG_ENDIAN) | ||
| 48 | add_definitions(-DIS_BIG_ENDIAN) | ||
| 49 | endif() | ||
| 50 | |||
| 51 | if(CRYPTOPP_DISABLE_ASM) | ||
| 52 | add_definitions(-DCRYPTOPP_DISABLE_ASM) | ||
| 53 | endif() | ||
| 54 | if(CRYPTOPP_DISABLE_SSSE3) | ||
| 55 | add_definitions(-DCRYPTOPP_DISABLE_SSSE3) | ||
| 56 | endif() | ||
| 57 | if(CRYPTOPP_DISABLE_AESNI) | ||
| 58 | add_definitions(-DCRYPTOPP_DISABLE_AESNI) | ||
| 59 | endif() | ||
| 60 | |||
| 61 | # We need the output 'uname -s' for Unix and Linux system detection | ||
| 62 | if (NOT CRYPTOPP_CROSS_COMPILE) | ||
| 63 | set (UNAME_CMD "uname") | ||
| 64 | set (UNAME_ARG "-s") | ||
| 65 | execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG} | ||
| 66 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
| 67 | RESULT_VARIABLE UNAME_RESULT | ||
| 68 | OUTPUT_VARIABLE UNAME_SYSTEM) | ||
| 69 | string(REGEX REPLACE "\n$" "" UNAME_SYSTEM "${UNAME_SYSTEM}") | ||
| 70 | endif() | ||
| 71 | |||
| 72 | # We need the output 'uname -m' for Unix and Linux platform detection | ||
| 73 | if (NOT CRYPTOPP_CROSS_COMPILE) | ||
| 74 | set (UNAME_CMD "uname") | ||
| 75 | set (UNAME_ARG "-m") | ||
| 76 | execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG} | ||
| 77 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
| 78 | RESULT_VARIABLE UNAME_RESULT | ||
| 79 | OUTPUT_VARIABLE UNAME_MACHINE) | ||
| 80 | string(REGEX REPLACE "\n$" "" UNAME_MACHINE "${UNAME_MACHINE}") | ||
| 81 | endif() | ||
| 82 | |||
| 83 | if(WINDOWS_STORE OR WINDOWS_PHONE) | ||
| 84 | if("${CMAKE_SYSTEM_VERSION}" MATCHES "10\\.0.*") | ||
| 85 | SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" ) | ||
| 86 | endif() | ||
| 87 | SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" ) | ||
| 88 | endif() | ||
| 89 | |||
| 90 | # Enable PIC for all targets except Windows and 32-bit x86. | ||
| 91 | # Avoid on 32-bit x86 due to register pressures. | ||
| 92 | if ((NOT CRYPTOPP_CROSS_COMPILE) AND (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE))) | ||
| 93 | # Use Regex; match i386, i486, i586 and i686 | ||
| 94 | if (NOT (${UNAME_MACHINE} MATCHES "i.86")) | ||
| 95 | SET(CMAKE_POSITION_INDEPENDENT_CODE 1) | ||
| 96 | endif() | ||
| 97 | endif() | ||
| 98 | |||
| 99 | # -march=native for GCC, Clang and ICC in any version that does support it. | ||
| 100 | if ((NOT CRYPTOPP_DISABLE_CXXFLAGS_OPTIMIZATIONS) AND (NOT CRYPTOPP_CROSS_COMPILE) AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|Intel")) | ||
| 101 | CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED) | ||
| 102 | if (COMPILER_OPT_ARCH_NATIVE_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "-march=") | ||
| 103 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") | ||
| 104 | endif() | ||
| 105 | endif() | ||
| 106 | |||
| 107 | # Link is driven through the compiler, but CXXFLAGS are not used. Also see | ||
| 108 | # http://public.kitware.com/pipermail/cmake/2003-June/003967.html | ||
| 109 | if (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE)) | ||
| 110 | SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_FLAGS}") | ||
| 111 | endif() | ||
| 112 | |||
| 113 | #============================================================================ | ||
| 114 | # Sources & headers | ||
| 115 | #============================================================================ | ||
| 116 | |||
| 117 | # Library headers | ||
| 118 | file(GLOB cryptopp_HEADERS cryptopp/*.h) | ||
| 119 | |||
| 120 | # Library sources. You can use the GNUmakefile to generate the list: `make sources`. | ||
| 121 | file(GLOB cryptopp_SOURCES cryptopp/*.cpp) | ||
| 122 | list(REMOVE_ITEM cryptopp_SOURCES | ||
| 123 | # These are removed in the original CMakeLists.txt | ||
| 124 | ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/pch.cpp | ||
| 125 | ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/simple.cpp | ||
| 126 | ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/winpipes.cpp | ||
| 127 | ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/cryptlib_bds.cpp | ||
| 128 | ${cryptopp_SOURCES_TEST} | ||
| 129 | ) | ||
| 130 | |||
| 131 | if(MINGW OR WIN32) | ||
| 132 | list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/winpipes.cpp) | ||
| 133 | endif() | ||
| 134 | |||
| 135 | if(MSVC AND NOT CRYPTOPP_DISABLE_ASM) | ||
| 136 | if(${CMAKE_GENERATOR} MATCHES ".*ARM") | ||
| 137 | message(STATUS "Disabling ASM because ARM is specified as target platform.") | ||
| 138 | else() | ||
| 139 | # Note that we removed rdrand.asm. This is a workaround for the issue that rdrand.asm cannnot compiled properly | ||
| 140 | # on MSVC. Because there is also a rdrand.S file in the submodule, CMake will specify the target path for | ||
| 141 | # rdrand.asm as "/crytopp.dir/{Debug|Release}/cryptopp/rdrand.asm.obj". The additional target folder "cryptopp" | ||
| 142 | # is specified because the file rdrand.asm is in the source folder "cryptopp". But MSVC assembler can't build | ||
| 143 | # target file to an non-existing folder("cryptopp"). | ||
| 144 | list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64dll.asm) | ||
| 145 | list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64masm.asm) | ||
| 146 | # list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/rdrand.asm) | ||
| 147 | set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64") | ||
| 148 | set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64") | ||
| 149 | # set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64") | ||
| 150 | enable_language(ASM_MASM) | ||
| 151 | endif() | ||
| 152 | endif() | ||
| 153 | |||
| 154 | #============================================================================ | ||
| 155 | # Compile targets | ||
| 156 | #============================================================================ | ||
| 157 | add_library(cryptopp STATIC ${cryptopp_SOURCES}) | ||
| 158 | |||
| 159 | #============================================================================ | ||
| 160 | # Third-party libraries | ||
| 161 | #============================================================================ | ||
| 162 | |||
| 163 | if(WIN32) | ||
| 164 | target_link_libraries(cryptopp ws2_32) | ||
| 165 | endif() | ||
| 166 | |||
| 167 | find_package(Threads) | ||
| 168 | target_link_libraries(cryptopp ${CMAKE_THREAD_LIBS_INIT}) | ||
diff --git a/externals/cryptopp/cryptopp b/externals/cryptopp/cryptopp new file mode 160000 | |||
| Subproject 841c37e34765487a2968357369ab74db8b10a62 | |||
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b178914dd..1da10afab 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -20,10 +20,10 @@ set(SRCS | |||
| 20 | file_sys/archive_extsavedata.cpp | 20 | file_sys/archive_extsavedata.cpp |
| 21 | file_sys/archive_ncch.cpp | 21 | file_sys/archive_ncch.cpp |
| 22 | file_sys/archive_other_savedata.cpp | 22 | file_sys/archive_other_savedata.cpp |
| 23 | file_sys/archive_romfs.cpp | ||
| 24 | file_sys/archive_savedata.cpp | 23 | file_sys/archive_savedata.cpp |
| 25 | file_sys/archive_sdmc.cpp | 24 | file_sys/archive_sdmc.cpp |
| 26 | file_sys/archive_sdmcwriteonly.cpp | 25 | file_sys/archive_sdmcwriteonly.cpp |
| 26 | file_sys/archive_selfncch.cpp | ||
| 27 | file_sys/archive_source_sd_savedata.cpp | 27 | file_sys/archive_source_sd_savedata.cpp |
| 28 | file_sys/archive_systemsavedata.cpp | 28 | file_sys/archive_systemsavedata.cpp |
| 29 | file_sys/disk_archive.cpp | 29 | file_sys/disk_archive.cpp |
| @@ -197,10 +197,10 @@ set(HEADERS | |||
| 197 | file_sys/archive_extsavedata.h | 197 | file_sys/archive_extsavedata.h |
| 198 | file_sys/archive_ncch.h | 198 | file_sys/archive_ncch.h |
| 199 | file_sys/archive_other_savedata.h | 199 | file_sys/archive_other_savedata.h |
| 200 | file_sys/archive_romfs.h | ||
| 201 | file_sys/archive_savedata.h | 200 | file_sys/archive_savedata.h |
| 202 | file_sys/archive_sdmc.h | 201 | file_sys/archive_sdmc.h |
| 203 | file_sys/archive_sdmcwriteonly.h | 202 | file_sys/archive_sdmcwriteonly.h |
| 203 | file_sys/archive_selfncch.h | ||
| 204 | file_sys/archive_source_sd_savedata.h | 204 | file_sys/archive_source_sd_savedata.h |
| 205 | file_sys/archive_systemsavedata.h | 205 | file_sys/archive_systemsavedata.h |
| 206 | file_sys/directory_backend.h | 206 | file_sys/directory_backend.h |
| @@ -360,9 +360,10 @@ set(HEADERS | |||
| 360 | ) | 360 | ) |
| 361 | 361 | ||
| 362 | include_directories(../../externals/dynarmic/include) | 362 | include_directories(../../externals/dynarmic/include) |
| 363 | include_directories(../../externals/cryptopp) | ||
| 363 | 364 | ||
| 364 | create_directory_groups(${SRCS} ${HEADERS}) | 365 | create_directory_groups(${SRCS} ${HEADERS}) |
| 365 | 366 | ||
| 366 | add_library(core STATIC ${SRCS} ${HEADERS}) | 367 | add_library(core STATIC ${SRCS} ${HEADERS}) |
| 367 | 368 | ||
| 368 | target_link_libraries(core dynarmic) | 369 | target_link_libraries(core dynarmic cryptopp) |
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp deleted file mode 100644 index 6c99ca5b4..000000000 --- a/src/core/file_sys/archive_romfs.cpp +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <memory> | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "core/file_sys/archive_romfs.h" | ||
| 10 | #include "core/file_sys/ivfc_archive.h" | ||
| 11 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 13 | // FileSys namespace | ||
| 14 | |||
| 15 | namespace FileSys { | ||
| 16 | |||
| 17 | ArchiveFactory_RomFS::ArchiveFactory_RomFS(Loader::AppLoader& app_loader) { | ||
| 18 | // Load the RomFS from the app | ||
| 19 | if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) { | ||
| 20 | LOG_ERROR(Service_FS, "Unable to read RomFS!"); | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) { | ||
| 25 | auto archive = std::make_unique<IVFCArchive>(romfs_file, data_offset, data_size); | ||
| 26 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | ||
| 27 | } | ||
| 28 | |||
| 29 | ResultCode ArchiveFactory_RomFS::Format(const Path& path, | ||
| 30 | const FileSys::ArchiveFormatInfo& format_info) { | ||
| 31 | LOG_ERROR(Service_FS, "Attempted to format a RomFS archive."); | ||
| 32 | // TODO: Verify error code | ||
| 33 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||
| 34 | ErrorLevel::Permanent); | ||
| 35 | } | ||
| 36 | |||
| 37 | ResultVal<ArchiveFormatInfo> ArchiveFactory_RomFS::GetFormatInfo(const Path& path) const { | ||
| 38 | // TODO(Subv): Implement | ||
| 39 | LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); | ||
| 40 | return ResultCode(-1); | ||
| 41 | } | ||
| 42 | |||
| 43 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_selfncch.cpp b/src/core/file_sys/archive_selfncch.cpp new file mode 100644 index 000000000..298a37a44 --- /dev/null +++ b/src/core/file_sys/archive_selfncch.cpp | |||
| @@ -0,0 +1,257 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <array> | ||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/file_sys/archive_selfncch.h" | ||
| 10 | #include "core/file_sys/errors.h" | ||
| 11 | #include "core/file_sys/ivfc_archive.h" | ||
| 12 | |||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 14 | // FileSys namespace | ||
| 15 | |||
| 16 | namespace FileSys { | ||
| 17 | |||
| 18 | enum class SelfNCCHFilePathType : u32 { | ||
| 19 | RomFS = 0, | ||
| 20 | Code = 1, // This is not supported by SelfNCCHArchive but by archive 0x2345678E | ||
| 21 | ExeFS = 2, | ||
| 22 | UpdateRomFS = 5, // This is presumably for accessing the RomFS of the update patch. | ||
| 23 | }; | ||
| 24 | |||
| 25 | struct SelfNCCHFilePath { | ||
| 26 | u32_le type; | ||
| 27 | std::array<char, 8> exefs_filename; | ||
| 28 | }; | ||
| 29 | static_assert(sizeof(SelfNCCHFilePath) == 12, "NCCHFilePath has wrong size!"); | ||
| 30 | |||
| 31 | // A read-only file created from a block of data. It only allows you to read the entire file at | ||
| 32 | // once, in a single read operation. | ||
| 33 | class ExeFSSectionFile final : public FileBackend { | ||
| 34 | public: | ||
| 35 | explicit ExeFSSectionFile(std::shared_ptr<std::vector<u8>> data_) : data(std::move(data_)) {} | ||
| 36 | |||
| 37 | ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override { | ||
| 38 | if (offset != 0) { | ||
| 39 | LOG_ERROR(Service_FS, "offset must be zero!"); | ||
| 40 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 41 | } | ||
| 42 | |||
| 43 | if (length != data->size()) { | ||
| 44 | LOG_ERROR(Service_FS, "size must match the file size!"); | ||
| 45 | return ERROR_INCORRECT_EXEFS_READ_SIZE; | ||
| 46 | } | ||
| 47 | |||
| 48 | std::memcpy(buffer, data->data(), data->size()); | ||
| 49 | return MakeResult<size_t>(data->size()); | ||
| 50 | } | ||
| 51 | |||
| 52 | ResultVal<size_t> Write(u64 offset, size_t length, bool flush, | ||
| 53 | const u8* buffer) const override { | ||
| 54 | LOG_ERROR(Service_FS, "The file is read-only!"); | ||
| 55 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 56 | } | ||
| 57 | |||
| 58 | u64 GetSize() const override { | ||
| 59 | return data->size(); | ||
| 60 | } | ||
| 61 | |||
| 62 | bool SetSize(u64 size) const override { | ||
| 63 | return false; | ||
| 64 | } | ||
| 65 | |||
| 66 | bool Close() const override { | ||
| 67 | return true; | ||
| 68 | } | ||
| 69 | |||
| 70 | void Flush() const override {} | ||
| 71 | |||
| 72 | private: | ||
| 73 | std::shared_ptr<std::vector<u8>> data; | ||
| 74 | }; | ||
| 75 | |||
| 76 | // SelfNCCHArchive represents the running application itself. From this archive the application can | ||
| 77 | // open RomFS and ExeFS, excluding the .code section. | ||
| 78 | class SelfNCCHArchive final : public ArchiveBackend { | ||
| 79 | public: | ||
| 80 | explicit SelfNCCHArchive(const NCCHData& ncch_data_) : ncch_data(ncch_data_) {} | ||
| 81 | |||
| 82 | std::string GetName() const override { | ||
| 83 | return "SelfNCCHArchive"; | ||
| 84 | } | ||
| 85 | |||
| 86 | ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode&) const override { | ||
| 87 | // Note: SelfNCCHArchive doesn't check the open mode. | ||
| 88 | |||
| 89 | if (path.GetType() != LowPathType::Binary) { | ||
| 90 | LOG_ERROR(Service_FS, "Path need to be Binary"); | ||
| 91 | return ERROR_INVALID_PATH; | ||
| 92 | } | ||
| 93 | |||
| 94 | std::vector<u8> binary = path.AsBinary(); | ||
| 95 | if (binary.size() != sizeof(SelfNCCHFilePath)) { | ||
| 96 | LOG_ERROR(Service_FS, "Wrong path size %zu", binary.size()); | ||
| 97 | return ERROR_INVALID_PATH; | ||
| 98 | } | ||
| 99 | |||
| 100 | SelfNCCHFilePath file_path; | ||
| 101 | std::memcpy(&file_path, binary.data(), sizeof(SelfNCCHFilePath)); | ||
| 102 | |||
| 103 | switch (static_cast<SelfNCCHFilePathType>(file_path.type)) { | ||
| 104 | case SelfNCCHFilePathType::UpdateRomFS: | ||
| 105 | LOG_WARNING(Service_FS, "(STUBBED) open update RomFS"); | ||
| 106 | return OpenRomFS(); | ||
| 107 | |||
| 108 | case SelfNCCHFilePathType::RomFS: | ||
| 109 | return OpenRomFS(); | ||
| 110 | |||
| 111 | case SelfNCCHFilePathType::Code: | ||
| 112 | LOG_ERROR(Service_FS, "Reading the code section is not supported!"); | ||
| 113 | return ERROR_COMMAND_NOT_ALLOWED; | ||
| 114 | |||
| 115 | case SelfNCCHFilePathType::ExeFS: { | ||
| 116 | const auto& raw = file_path.exefs_filename; | ||
| 117 | auto end = std::find(raw.begin(), raw.end(), '\0'); | ||
| 118 | std::string filename(raw.begin(), end); | ||
| 119 | return OpenExeFS(filename); | ||
| 120 | } | ||
| 121 | default: | ||
| 122 | LOG_ERROR(Service_FS, "Unknown file type %u!", static_cast<u32>(file_path.type)); | ||
| 123 | return ERROR_INVALID_PATH; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | ResultCode DeleteFile(const Path& path) const override { | ||
| 128 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 129 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 130 | } | ||
| 131 | |||
| 132 | ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override { | ||
| 133 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 134 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 135 | } | ||
| 136 | |||
| 137 | ResultCode DeleteDirectory(const Path& path) const override { | ||
| 138 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 139 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 140 | } | ||
| 141 | |||
| 142 | ResultCode DeleteDirectoryRecursively(const Path& path) const override { | ||
| 143 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 144 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 145 | } | ||
| 146 | |||
| 147 | ResultCode CreateFile(const Path& path, u64 size) const override { | ||
| 148 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 149 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 150 | } | ||
| 151 | |||
| 152 | ResultCode CreateDirectory(const Path& path) const override { | ||
| 153 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 154 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 155 | } | ||
| 156 | |||
| 157 | ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override { | ||
| 158 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 159 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 160 | } | ||
| 161 | |||
| 162 | ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override { | ||
| 163 | LOG_ERROR(Service_FS, "Unsupported"); | ||
| 164 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 165 | } | ||
| 166 | |||
| 167 | u64 GetFreeBytes() const override { | ||
| 168 | return 0; | ||
| 169 | } | ||
| 170 | |||
| 171 | private: | ||
| 172 | ResultVal<std::unique_ptr<FileBackend>> OpenRomFS() const { | ||
| 173 | if (ncch_data.romfs_file) { | ||
| 174 | return MakeResult<std::unique_ptr<FileBackend>>(std::make_unique<IVFCFile>( | ||
| 175 | ncch_data.romfs_file, ncch_data.romfs_offset, ncch_data.romfs_size)); | ||
| 176 | } else { | ||
| 177 | LOG_INFO(Service_FS, "Unable to read RomFS"); | ||
| 178 | return ERROR_ROMFS_NOT_FOUND; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | ResultVal<std::unique_ptr<FileBackend>> OpenExeFS(const std::string& filename) const { | ||
| 183 | if (filename == "icon") { | ||
| 184 | if (ncch_data.icon) { | ||
| 185 | return MakeResult<std::unique_ptr<FileBackend>>( | ||
| 186 | std::make_unique<ExeFSSectionFile>(ncch_data.icon)); | ||
| 187 | } | ||
| 188 | |||
| 189 | LOG_WARNING(Service_FS, "Unable to read icon"); | ||
| 190 | return ERROR_EXEFS_SECTION_NOT_FOUND; | ||
| 191 | } | ||
| 192 | |||
| 193 | if (filename == "logo") { | ||
| 194 | if (ncch_data.logo) { | ||
| 195 | return MakeResult<std::unique_ptr<FileBackend>>( | ||
| 196 | std::make_unique<ExeFSSectionFile>(ncch_data.logo)); | ||
| 197 | } | ||
| 198 | |||
| 199 | LOG_WARNING(Service_FS, "Unable to read logo"); | ||
| 200 | return ERROR_EXEFS_SECTION_NOT_FOUND; | ||
| 201 | } | ||
| 202 | |||
| 203 | if (filename == "banner") { | ||
| 204 | if (ncch_data.banner) { | ||
| 205 | return MakeResult<std::unique_ptr<FileBackend>>( | ||
| 206 | std::make_unique<ExeFSSectionFile>(ncch_data.banner)); | ||
| 207 | } | ||
| 208 | |||
| 209 | LOG_WARNING(Service_FS, "Unable to read banner"); | ||
| 210 | return ERROR_EXEFS_SECTION_NOT_FOUND; | ||
| 211 | } | ||
| 212 | |||
| 213 | LOG_ERROR(Service_FS, "Unknown ExeFS section %s!", filename.c_str()); | ||
| 214 | return ERROR_INVALID_PATH; | ||
| 215 | } | ||
| 216 | |||
| 217 | NCCHData ncch_data; | ||
| 218 | }; | ||
| 219 | |||
| 220 | ArchiveFactory_SelfNCCH::ArchiveFactory_SelfNCCH(Loader::AppLoader& app_loader) { | ||
| 221 | std::shared_ptr<FileUtil::IOFile> romfs_file_; | ||
| 222 | if (Loader::ResultStatus::Success == | ||
| 223 | app_loader.ReadRomFS(romfs_file_, ncch_data.romfs_offset, ncch_data.romfs_size)) { | ||
| 224 | |||
| 225 | ncch_data.romfs_file = std::move(romfs_file_); | ||
| 226 | } | ||
| 227 | |||
| 228 | std::vector<u8> buffer; | ||
| 229 | |||
| 230 | if (Loader::ResultStatus::Success == app_loader.ReadIcon(buffer)) | ||
| 231 | ncch_data.icon = std::make_shared<std::vector<u8>>(std::move(buffer)); | ||
| 232 | |||
| 233 | buffer.clear(); | ||
| 234 | if (Loader::ResultStatus::Success == app_loader.ReadLogo(buffer)) | ||
| 235 | ncch_data.logo = std::make_shared<std::vector<u8>>(std::move(buffer)); | ||
| 236 | |||
| 237 | buffer.clear(); | ||
| 238 | if (Loader::ResultStatus::Success == app_loader.ReadBanner(buffer)) | ||
| 239 | ncch_data.banner = std::make_shared<std::vector<u8>>(std::move(buffer)); | ||
| 240 | } | ||
| 241 | |||
| 242 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SelfNCCH::Open(const Path& path) { | ||
| 243 | auto archive = std::make_unique<SelfNCCHArchive>(ncch_data); | ||
| 244 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | ||
| 245 | } | ||
| 246 | |||
| 247 | ResultCode ArchiveFactory_SelfNCCH::Format(const Path&, const FileSys::ArchiveFormatInfo&) { | ||
| 248 | LOG_ERROR(Service_FS, "Attempted to format a SelfNCCH archive."); | ||
| 249 | return ERROR_INVALID_PATH; | ||
| 250 | } | ||
| 251 | |||
| 252 | ResultVal<ArchiveFormatInfo> ArchiveFactory_SelfNCCH::GetFormatInfo(const Path&) const { | ||
| 253 | LOG_ERROR(Service_FS, "Attempted to get format info of a SelfNCCH archive"); | ||
| 254 | return ERROR_INVALID_PATH; | ||
| 255 | } | ||
| 256 | |||
| 257 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_selfncch.h index 1eaf99b54..f1b971296 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_selfncch.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2017 Citra Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| @@ -17,22 +17,29 @@ | |||
| 17 | 17 | ||
| 18 | namespace FileSys { | 18 | namespace FileSys { |
| 19 | 19 | ||
| 20 | /// File system interface to the RomFS archive | 20 | struct NCCHData { |
| 21 | class ArchiveFactory_RomFS final : public ArchiveFactory { | 21 | std::shared_ptr<std::vector<u8>> icon; |
| 22 | std::shared_ptr<std::vector<u8>> logo; | ||
| 23 | std::shared_ptr<std::vector<u8>> banner; | ||
| 24 | std::shared_ptr<FileUtil::IOFile> romfs_file; | ||
| 25 | u64 romfs_offset = 0; | ||
| 26 | u64 romfs_size = 0; | ||
| 27 | }; | ||
| 28 | |||
| 29 | /// File system interface to the SelfNCCH archive | ||
| 30 | class ArchiveFactory_SelfNCCH final : public ArchiveFactory { | ||
| 22 | public: | 31 | public: |
| 23 | explicit ArchiveFactory_RomFS(Loader::AppLoader& app_loader); | 32 | explicit ArchiveFactory_SelfNCCH(Loader::AppLoader& app_loader); |
| 24 | 33 | ||
| 25 | std::string GetName() const override { | 34 | std::string GetName() const override { |
| 26 | return "RomFS"; | 35 | return "SelfNCCH"; |
| 27 | } | 36 | } |
| 28 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 37 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 29 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; | 38 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 30 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | 39 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; |
| 31 | 40 | ||
| 32 | private: | 41 | private: |
| 33 | std::shared_ptr<FileUtil::IOFile> romfs_file; | 42 | NCCHData ncch_data; |
| 34 | u64 data_offset; | ||
| 35 | u64 data_size; | ||
| 36 | }; | 43 | }; |
| 37 | 44 | ||
| 38 | } // namespace FileSys | 45 | } // namespace FileSys |
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index 4d5f62b08..9fc8d753b 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h | |||
| @@ -39,5 +39,15 @@ const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpt | |||
| 39 | const ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrorDescription::FS_GameCardNotInserted, | 39 | const ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrorDescription::FS_GameCardNotInserted, |
| 40 | ErrorModule::FS, ErrorSummary::NotFound, | 40 | ErrorModule::FS, ErrorSummary::NotFound, |
| 41 | ErrorLevel::Status); | 41 | ErrorLevel::Status); |
| 42 | const ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrorDescription::FS_IncorrectExeFSReadSize, | ||
| 43 | ErrorModule::FS, ErrorSummary::NotSupported, | ||
| 44 | ErrorLevel::Usage); | ||
| 45 | const ResultCode ERROR_ROMFS_NOT_FOUND(ErrorDescription::FS_RomFSNotFound, ErrorModule::FS, | ||
| 46 | ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 47 | const ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrorDescription::FS_CommandNotAllowed, ErrorModule::FS, | ||
| 48 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 49 | const ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrorDescription::FS_ExeFSSectionNotFound, | ||
| 50 | ErrorModule::FS, ErrorSummary::NotFound, | ||
| 51 | ErrorLevel::Status); | ||
| 42 | 52 | ||
| 43 | } // namespace FileSys | 53 | } // namespace FileSys |
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 53864a3a7..cfefbbc64 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -20,6 +20,7 @@ enum class ErrorDescription : u32 { | |||
| 20 | OS_InvalidBufferDescriptor = 48, | 20 | OS_InvalidBufferDescriptor = 48, |
| 21 | MaxConnectionsReached = 52, | 21 | MaxConnectionsReached = 52, |
| 22 | WrongAddress = 53, | 22 | WrongAddress = 53, |
| 23 | FS_RomFSNotFound = 100, | ||
| 23 | FS_ArchiveNotMounted = 101, | 24 | FS_ArchiveNotMounted = 101, |
| 24 | FS_FileNotFound = 112, | 25 | FS_FileNotFound = 112, |
| 25 | FS_PathNotFound = 113, | 26 | FS_PathNotFound = 113, |
| @@ -35,10 +36,13 @@ enum class ErrorDescription : u32 { | |||
| 35 | OutofRangeOrMisalignedAddress = | 36 | OutofRangeOrMisalignedAddress = |
| 36 | 513, // TODO(purpasmart): Check if this name fits its actual usage | 37 | 513, // TODO(purpasmart): Check if this name fits its actual usage |
| 37 | GPU_FirstInitialization = 519, | 38 | GPU_FirstInitialization = 519, |
| 39 | FS_ExeFSSectionNotFound = 567, | ||
| 40 | FS_CommandNotAllowed = 630, | ||
| 38 | FS_InvalidReadFlag = 700, | 41 | FS_InvalidReadFlag = 700, |
| 39 | FS_InvalidPath = 702, | 42 | FS_InvalidPath = 702, |
| 40 | FS_WriteBeyondEnd = 705, | 43 | FS_WriteBeyondEnd = 705, |
| 41 | FS_UnsupportedOpenFlags = 760, | 44 | FS_UnsupportedOpenFlags = 760, |
| 45 | FS_IncorrectExeFSReadSize = 761, | ||
| 42 | FS_UnexpectedFileOrDirectory = 770, | 46 | FS_UnexpectedFileOrDirectory = 770, |
| 43 | InvalidSection = 1000, | 47 | InvalidSection = 1000, |
| 44 | TooLarge = 1001, | 48 | TooLarge = 1001, |
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index 519c1f3a9..2ea956e0b 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h | |||
| @@ -26,7 +26,7 @@ namespace FS { | |||
| 26 | 26 | ||
| 27 | /// Supported archive types | 27 | /// Supported archive types |
| 28 | enum class ArchiveIdCode : u32 { | 28 | enum class ArchiveIdCode : u32 { |
| 29 | RomFS = 0x00000003, | 29 | SelfNCCH = 0x00000003, |
| 30 | SaveData = 0x00000004, | 30 | SaveData = 0x00000004, |
| 31 | ExtSaveData = 0x00000006, | 31 | ExtSaveData = 0x00000006, |
| 32 | SharedExtSaveData = 0x00000007, | 32 | SharedExtSaveData = 0x00000007, |
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 09266e8b0..74e336487 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/file_sys/archive_romfs.h" | 8 | #include "core/file_sys/archive_selfncch.h" |
| 9 | #include "core/hle/kernel/process.h" | 9 | #include "core/hle/kernel/process.h" |
| 10 | #include "core/hle/kernel/resource_limit.h" | 10 | #include "core/hle/kernel/resource_limit.h" |
| 11 | #include "core/hle/service/fs/archive.h" | 11 | #include "core/hle/service/fs/archive.h" |
| @@ -277,8 +277,8 @@ ResultStatus AppLoader_THREEDSX::Load() { | |||
| 277 | 277 | ||
| 278 | Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); | 278 | Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); |
| 279 | 279 | ||
| 280 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), | 280 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_SelfNCCH>(*this), |
| 281 | Service::FS::ArchiveIdCode::RomFS); | 281 | Service::FS::ArchiveIdCode::SelfNCCH); |
| 282 | 282 | ||
| 283 | is_loaded = true; | 283 | is_loaded = true; |
| 284 | return ResultStatus::Success; | 284 | return ResultStatus::Success; |
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 5df33f6d2..98b8259d9 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 11 | #include "core/file_sys/archive_romfs.h" | 11 | #include "core/file_sys/archive_selfncch.h" |
| 12 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/kernel/resource_limit.h" | 13 | #include "core/hle/kernel/resource_limit.h" |
| 14 | #include "core/hle/service/cfg/cfg.h" | 14 | #include "core/hle/service/cfg/cfg.h" |
| @@ -342,8 +342,8 @@ ResultStatus AppLoader_NCCH::Load() { | |||
| 342 | if (ResultStatus::Success != result) | 342 | if (ResultStatus::Success != result) |
| 343 | return result; | 343 | return result; |
| 344 | 344 | ||
| 345 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), | 345 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_SelfNCCH>(*this), |
| 346 | Service::FS::ArchiveIdCode::RomFS); | 346 | Service::FS::ArchiveIdCode::SelfNCCH); |
| 347 | 347 | ||
| 348 | ParseRegionLockoutInfo(); | 348 | ParseRegionLockoutInfo(); |
| 349 | 349 | ||