diff options
| author | Daniel Roethlisberger <daniel@roe.ch> | 2024-12-06 16:14:16 +0100 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2025-03-18 05:15:26 -0400 |
| commit | 27a6b88c3f59621386567e224a232c9cb4511129 (patch) | |
| tree | 570d72d2dd228bcdb1171805663d7e4f6a20b398 /view/macho/objc.cpp | |
| parent | 68fe4cee9501cc1e5072e81b03f86eb985ed6b5f (diff) | |
MachO/ObjC: Avoid generating names containing non-printable chars
Avoid generating ObjC symbol names containing non-printable characters
for both 8 and 16 bit character encodings.
Diffstat (limited to 'view/macho/objc.cpp')
| -rw-r--r-- | view/macho/objc.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/view/macho/objc.cpp b/view/macho/objc.cpp index d5d417a5..5dec6e90 100644 --- a/view/macho/objc.cpp +++ b/view/macho/objc.cpp @@ -1441,12 +1441,22 @@ void ObjCProcessor::ProcessCFStrings() uint8_t* rawData = static_cast<uint8_t*>(data.GetData()); uint8_t* offsetAddress = rawData + bufferOff; uint16_t c = *reinterpret_cast<uint16_t*>(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); @@ -1456,11 +1466,26 @@ void ObjCProcessor::ProcessCFStrings() else // UTF8 / ASCII { reader.Seek(strLoc); - str = reader.ReadCString(size + 1); - 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); |
