diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index 23f5178a..730dc8ae 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -223,8 +223,11 @@ namespace skyline { throw exception("Span size is less than Out type size (0x{:X}/0x{:X})", span::size_bytes(), sizeof(Out)); } - constexpr std::string_view as_string(indexType length = 0) { - return std::string_view(reinterpret_cast(span::data()), length ? length : span::size_bytes()); + /** + * @param nullTerminated If true and the string is null-terminated, a view of it will be returned (not including the null terminator itself), otherwise the entire span will be returned as a string view + */ + constexpr std::string_view as_string(bool nullTerminated = false) { + return std::string_view(reinterpret_cast(span::data()), nullTerminated ? (std::find(span::begin(), span::end(), 0) - span::begin()) : span::size_bytes()); } template diff --git a/app/src/main/cpp/skyline/crypto/key_store.cpp b/app/src/main/cpp/skyline/crypto/key_store.cpp index bc8ac242..2b0b9bed 100644 --- a/app/src/main/cpp/skyline/crypto/key_store.cpp +++ b/app/src/main/cpp/skyline/crypto/key_store.cpp @@ -21,9 +21,8 @@ namespace skyline::crypto { std::vector::iterator lineEnd; while ((lineEnd = std::find(lineStart, fileContent.end(), '\n')) != fileContent.end()) { auto keyEnd{std::find(lineStart, lineEnd, '=')}; - if (keyEnd == lineEnd) { + if (keyEnd == lineEnd) throw exception("Invalid key file"); - } std::string_view key(&*lineStart, keyEnd - lineStart); std::string_view value(&*(keyEnd + 1), lineEnd - keyEnd - 1); diff --git a/app/src/main/cpp/skyline/gpu/syncpoint.h b/app/src/main/cpp/skyline/gpu/syncpoint.h index 702eb609..36cc940e 100644 --- a/app/src/main/cpp/skyline/gpu/syncpoint.h +++ b/app/src/main/cpp/skyline/gpu/syncpoint.h @@ -7,7 +7,7 @@ namespace skyline { namespace constant { - constexpr size_t MaxHwSyncpointCount{192}; //!< The maximum number of HOST1X syncpoints on t210 + constexpr size_t MaxHwSyncpointCount{192}; //!< The maximum number of host1x syncpoints on T210 } namespace gpu { diff --git a/app/src/main/cpp/skyline/kernel/svc.cpp b/app/src/main/cpp/skyline/kernel/svc.cpp index e02365fa..a6a342cc 100644 --- a/app/src/main/cpp/skyline/kernel/svc.cpp +++ b/app/src/main/cpp/skyline/kernel/svc.cpp @@ -325,7 +325,7 @@ namespace skyline::kernel::svc { return; } - memory::Permission permission{*reinterpret_cast(&state.ctx->registers.w3)}; + auto permission{*reinterpret_cast(&state.ctx->registers.w3)}; if ((permission.w && !permission.r) || (permission.x && !permission.r)) { state.logger->Warn("svcMapSharedMemory: 'permission' invalid: {}{}{}", permission.r ? "R" : "-", permission.w ? "W" : "-", permission.x ? "X" : "-"); state.ctx->registers.w0 = result::InvalidNewMemoryPermission; @@ -358,7 +358,7 @@ namespace skyline::kernel::svc { return; } - memory::Permission permission{*reinterpret_cast(&state.ctx->registers.w3)}; + auto permission{*reinterpret_cast(&state.ctx->registers.w3)}; if ((permission.w && !permission.r) || (permission.x && !permission.r)) { state.logger->Warn("svcCreateTransferMemory: 'permission' invalid: {}{}{}", permission.r ? "R" : "-", permission.w ? "W" : "-", permission.x ? "X" : "-"); state.ctx->registers.w0 = result::InvalidNewMemoryPermission; @@ -584,7 +584,8 @@ namespace skyline::kernel::svc { } void ConnectToNamedPort(DeviceState &state) { - std::string_view port(state.process->GetPointer(state.ctx->registers.x1), sizeof(service::ServiceName)); + constexpr u8 portSize = 0x8; //!< The size of a port name string + std::string_view port(span(state.process->GetPointer(state.ctx->registers.x1), portSize).as_string(true)); KHandle handle{}; if (port.compare("sm:") >= 0) { diff --git a/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp index e27e67b2..e65dedec 100644 --- a/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KTransferMemory.cpp @@ -59,7 +59,7 @@ namespace skyline::kernel::type { nSize = nSize ? nSize : size; - ChunkDescriptor chunk{host ? hostChunk : *state.os->memory.GetChunk(address)}; + auto chunk{host ? hostChunk : *state.os->memory.GetChunk(address)}; chunk.address = nAddress; chunk.size = nSize; MemoryManager::ResizeChunk(&chunk, nSize); diff --git a/app/src/main/cpp/skyline/services/common/parcel.cpp b/app/src/main/cpp/skyline/services/common/parcel.cpp index 088df106..15c71484 100644 --- a/app/src/main/cpp/skyline/services/common/parcel.cpp +++ b/app/src/main/cpp/skyline/services/common/parcel.cpp @@ -13,10 +13,10 @@ namespace skyline::service { constexpr u8 tokenLength{0x50}; // The length of the token on BufferQueue parcels data.resize(header.dataSize - (hasToken ? tokenLength : 0)); - memcpy(data.data(), buffer.data() + header.dataOffset + (hasToken ? tokenLength : 0), header.dataSize - (hasToken ? tokenLength : 0)); + std::memcpy(data.data(), buffer.data() + header.dataOffset + (hasToken ? tokenLength : 0), header.dataSize - (hasToken ? tokenLength : 0)); objects.resize(header.objectsSize); - memcpy(objects.data(), buffer.data() + header.objectsOffset, header.objectsSize); + std::memcpy(objects.data(), buffer.data() + header.objectsOffset, header.objectsSize); } Parcel::Parcel(const DeviceState &state) : state(state) {} @@ -34,8 +34,8 @@ namespace skyline::service { throw exception("The size of the parcel exceeds maxSize"); buffer.as() = header; - memcpy(buffer.data() + header.dataOffset, data.data(), data.size()); - memcpy(buffer.data() + header.objectsOffset, objects.data(), objects.size()); + std::memcpy(buffer.data() + header.dataOffset, data.data(), data.size()); + std::memcpy(buffer.data() + header.objectsOffset, objects.data(), objects.size()); return totalSize; } diff --git a/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp b/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp index bd880287..37cdc6e8 100644 --- a/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp +++ b/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp @@ -16,6 +16,7 @@ namespace skyline::vfs { } size_t CtrEncryptedBacking::Read(span output, size_t offset) { + size_t size{output.size()}; if (size == 0) return 0; diff --git a/app/src/main/java/emu/skyline/KeyReader.kt b/app/src/main/java/emu/skyline/KeyReader.kt index a01b88b9..5d9ba695 100644 --- a/app/src/main/java/emu/skyline/KeyReader.kt +++ b/app/src/main/java/emu/skyline/KeyReader.kt @@ -32,7 +32,8 @@ object KeyReader { return false val fileName = DocumentFile.fromSingleUri(context, uri)!!.name - if ("keys" != fileName?.substringAfterLast('.')) return false + if (fileName?.substringAfterLast('.')?.startsWith("keys")?.not() ?: false) + return false val tmpOutputFile = File("${context.filesDir.canonicalFile}/${keyType.fileName}.tmp") @@ -76,11 +77,9 @@ object KeyReader { } private fun isHexString(str : String) : Boolean { - for (c in str) { - if (!(c in '0'..'9' || c in 'a'..'f' || c in 'A'..'F')) { + for (c in str) + if (!(c in '0'..'9' || c in 'a'..'f' || c in 'A'..'F')) return false - } - } return true } }