MCPcopy Create free account
hub / github.com/USBToolBox/kext / fixMapForTahoe

Method fixMapForTahoe

USBToolBox/USBToolBox.cpp:215–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215OSObject* USBToolBox::fixMapForTahoe(OSObject* object) {
216 OSDictionary* ports = OSDynamicCast(OSDictionary, object);
217 if (!ports) {
218 SYSTEMLOGPROV("Ports is not a dictionary, skipping");
219 return object;
220 }
221
222 OSDictionary* portsCopy = OSDynamicCast(OSDictionary, ports->copyCollection());
223 if (!portsCopy) {
224 SYSTEMLOGPROV("Failed to copy ports dictionary, skipping");
225 return object;
226 }
227 OSSafeReleaseNULL(ports);
228
229 const OSSymbol* portSymbol = OSSymbol::withCString("port");
230 const OSSymbol* usbConnectorSymbol = OSSymbol::withCString("UsbConnector");
231 const OSSymbol* portNumberSymbol = OSSymbol::withCString("usb-port-number");
232 const OSSymbol* portTypeSymbol = OSSymbol::withCString("usb-port-type");
233
234 if (OSCollectionIterator* propertyIterator = OSCollectionIterator::withCollection(portsCopy)) {
235 DEBUGLOGPROV("Starting iteration over ports");
236 while (OSSymbol* key = OSDynamicCast(OSSymbol, propertyIterator->getNextObject())) {
237 OSObject* value = portsCopy->getObject(key);
238 OSDictionary* portDict = OSDynamicCast(OSDictionary, value);
239 if (!portDict) {
240 DEBUGLOGPROV("Port %s is not a dictionary, skipping", key->getCStringNoCopy());
241 continue;
242 }
243
244 if (portDict->getObject(portNumberSymbol)) {
245 DEBUGLOGPROV("Port %s already has usb-port-number, skipping", key->getCStringNoCopy());
246 } else if (!portDict->getObject(portSymbol)) {
247 DEBUGLOGPROV("Port %s does not have port, skipping", key->getCStringNoCopy());
248 } else {
249 DEBUGLOGPROV("Port %s does not have usb-port-number, copying port to usb-port-number", key->getCStringNoCopy());
250 portDict->setObject(portNumberSymbol, portDict->getObject(portSymbol));
251 }
252
253 if (portDict->getObject(portTypeSymbol)) {
254 DEBUGLOGPROV("Port %s already has usb-port-type, skipping", key->getCStringNoCopy());
255 } else if (!portDict->getObject(usbConnectorSymbol)) {
256 DEBUGLOGPROV("Port %s does not have UsbConnector, skipping", key->getCStringNoCopy());
257 } else {
258 DEBUGLOGPROV("Port %s does not have usb-port-type, copying UsbConnector to usb-port-type", key->getCStringNoCopy());
259 portDict->setObject(portTypeSymbol, portDict->getObject(usbConnectorSymbol));
260 }
261 }
262 DEBUGLOGPROV("Successfully fixed ports");
263 OSSafeReleaseNULL(propertyIterator);
264 } else {
265 SYSTEMLOGPROV("Failed to create ports iterator!");
266 }
267
268 OSSafeReleaseNULL(portTypeSymbol);
269 OSSafeReleaseNULL(usbConnectorSymbol);
270 OSSafeReleaseNULL(portNumberSymbol);
271 OSSafeReleaseNULL(portSymbol);
272

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected