From 25cc02431b61097b2adfc2fbc493b648b0300c3b Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 10 Mar 2025 11:05:40 -0400 Subject: [SharedCache] Refactor Shared Cache In absence of a better name, this commit refactors the shared cache code. --- objectivec/objc.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'objectivec/objc.cpp') diff --git a/objectivec/objc.cpp b/objectivec/objc.cpp index 4267ae23..68956a2c 100644 --- a/objectivec/objc.cpp +++ b/objectivec/objc.cpp @@ -1509,12 +1509,22 @@ void ObjCProcessor::ProcessCFStrings(std::optional imageName) uint8_t* rawData = static_cast(data.GetData()); uint8_t* offsetAddress = rawData + bufferOff; uint16_t c = *reinterpret_cast(offsetAddress); - if (c == 0x20) + if (c == 0x20) { str.push_back('_'); - else if (c < 0x80) + } else if (c == '\r') { + str.push_back('\\'); + str.push_back('r'); + } else if (c == '\n') { + str.push_back('\\'); + str.push_back('n'); + } else if (c == '\t') { + str.push_back('\\'); + str.push_back('t'); + } else if (c > 0x20 && c < 0x80) { str.push_back(c); - else + } else { str.push_back('?'); + } } DefineObjCSymbol( DataSymbol, Type::ArrayType(Type::WideCharType(2), size + 1), "ustr_" + str, strLoc, true); @@ -1524,11 +1534,26 @@ void ObjCProcessor::ProcessCFStrings(std::optional imageName) else // UTF8 / ASCII { reader->Seek(strLoc); - str = reader->ReadCString(); - for (auto& c : str) + std::string rawStr = reader->ReadCString(size + 1); + str = ""; + for (signed char c : rawStr) { - if (c == ' ') - c = '_'; + if (c == 0x20) { + str.push_back('_'); + } else if (c == '\r') { + str.push_back('\\'); + str.push_back('r'); + } else if (c == '\n') { + str.push_back('\\'); + str.push_back('n'); + } else if (c == '\t') { + str.push_back('\\'); + str.push_back('t'); + } else if (c > 0x20 || c < 0) { + str.push_back(c); + } else { + str.push_back('?'); + } } DefineObjCSymbol(DataSymbol, Type::ArrayType(Type::IntegerType(1, true), str.size() + 1), "cstr_" + str, strLoc, true); -- cgit v1.3.1