mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 09:11:52 +01:00
Improve span::as_string
and other minor fixes
This commit is contained in:
parent
97ac45d83b
commit
7ad86ec46f
@ -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<char *>(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<char *>(span::data()), nullTerminated ? (std::find(span::begin(), span::end(), 0) - span::begin()) : span::size_bytes());
|
||||
}
|
||||
|
||||
template<typename Out, size_t OutExtent = std::dynamic_extent>
|
||||
|
@ -21,9 +21,8 @@ namespace skyline::crypto {
|
||||
std::vector<char>::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);
|
||||
|
@ -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 {
|
||||
|
@ -325,7 +325,7 @@ namespace skyline::kernel::svc {
|
||||
return;
|
||||
}
|
||||
|
||||
memory::Permission permission{*reinterpret_cast<memory::Permission *>(&state.ctx->registers.w3)};
|
||||
auto permission{*reinterpret_cast<memory::Permission *>(&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<memory::Permission *>(&state.ctx->registers.w3)};
|
||||
auto permission{*reinterpret_cast<memory::Permission *>(&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<char>(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<char>(state.ctx->registers.x1), portSize).as_string(true));
|
||||
|
||||
KHandle handle{};
|
||||
if (port.compare("sm:") >= 0) {
|
||||
|
@ -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);
|
||||
|
@ -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<ParcelHeader>() = 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;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace skyline::vfs {
|
||||
}
|
||||
|
||||
size_t CtrEncryptedBacking::Read(span<u8> output, size_t offset) {
|
||||
size_t size{output.size()};
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user