| 207 | |
| 208 | |
| 209 | Ref<Settings> UniversalViewType::GetLoadSettingsForData(BinaryView* data) |
| 210 | { |
| 211 | FatHeader fatHeader; |
| 212 | vector<FatArch64> fatArchEntries; |
| 213 | bool isFat64; |
| 214 | string errorMsg; |
| 215 | if (!g_universalViewType->ParseHeaders(data, fatHeader, fatArchEntries, isFat64, errorMsg)) |
| 216 | return nullptr; |
| 217 | |
| 218 | if (!fatArchEntries.size()) // TODO other validation? |
| 219 | return nullptr; |
| 220 | |
| 221 | Ref<Settings> settings = Settings::Instance(GetUniqueIdentifierString()); |
| 222 | settings->RegisterGroup("loader", "Load Options"); |
| 223 | settings->RegisterSetting("loader.universal.architectures", |
| 224 | R"({ |
| 225 | "title" : "Universal Mach-O Multi-Architecture Binary Description", |
| 226 | "type" : "string", |
| 227 | "default" : "[]", |
| 228 | "description" : "Describes the available object files in the Universal Multi-Architecture binary.", |
| 229 | "readOnly" : true |
| 230 | })"); |
| 231 | |
| 232 | Ref<Settings> entrySettings = Settings::Instance(GetUniqueIdentifierString()); |
| 233 | entrySettings->RegisterGroup("loader", "Load Options"); |
| 234 | entrySettings->RegisterSetting("loader.macho.universalImageOffset", |
| 235 | R"({ |
| 236 | "title" : "Universal Mach-O Object File Offset", |
| 237 | "type" : "number", |
| 238 | "default" : 0, |
| 239 | "description" : "The offset to the object file within the Universal Mach-O file.", |
| 240 | "minValue" : 0, |
| 241 | "maxValue" : 18446744073709551615, |
| 242 | "readOnly" : true |
| 243 | })"); |
| 244 | |
| 245 | rapidjson::Document entries(rapidjson::kArrayType); |
| 246 | int count = 0; |
| 247 | for (const auto& entry : fatArchEntries) |
| 248 | { |
| 249 | rapidjson::Value result(rapidjson::kObjectType); |
| 250 | bool is64Bit; |
| 251 | string archDesc = ArchitectureToString(entry.cputype, entry.cpusubtype, is64Bit); |
| 252 | string bitDesc = is64Bit ? "64-bit" : "32-bit"; |
| 253 | result.AddMember("id", count++, entries.GetAllocator()); |
| 254 | result.AddMember("architecture", archDesc, entries.GetAllocator()); |
| 255 | result.AddMember("is64Bit", is64Bit, entries.GetAllocator()); |
| 256 | result.AddMember("binaryViewType", "Mach-O", entries.GetAllocator()); |
| 257 | result.AddMember("description", "Mach-O " + bitDesc + " executable " + archDesc, entries.GetAllocator()); |
| 258 | result.AddMember("offset", ToLE64(entry.offset), entries.GetAllocator()); |
| 259 | result.AddMember("size", ToLE64(entry.size), entries.GetAllocator()); |
| 260 | entrySettings->UpdateProperty("loader.macho.universalImageOffset", "default", ToLE64(entry.offset)); |
| 261 | result.AddMember("loadSchema", entrySettings->SerializeSchema(), entries.GetAllocator()); |
| 262 | entries.PushBack(result, entries.GetAllocator()); |
| 263 | } |
| 264 | |
| 265 | rapidjson::StringBuffer buffer; |
| 266 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
nothing calls this directly
no test coverage detected