/* Open and Close */
NXEventHandle NXOpenEventStatus(void)
{
    NXEventHandle 		handle = MACH_PORT_NULL;
    register kern_return_t	kr;
    io_service_t		service = MACH_PORT_NULL;
    mach_port_t			masterPort;

    do {

	kr = IOMasterPort( MACH_PORT_NULL, &masterPort );
	if( kr != KERN_SUCCESS)
	    break;

        service = IORegistryEntryFromPath( masterPort,
                    kIOServicePlane ":/IOResources/IOHIDSystem" );
	if( !service)
	    break;

        kr = IOServiceOpen( service,
			mach_task_self(),
			kIOHIDParamConnectType,
			&handle);

        IOObjectRelease( service );

    } while( false );

    return( handle );
}
Exemple #2
0
int main(int argc, char **argv)
{
  kern_return_t       result;
  
  result = IOMasterPort(bootstrap_port, &masterPort);
  if (result != KERN_SUCCESS) {
    errx(1, "Error getting the IOMaster port: %s",
         mach_error_string(result));
  }
  
  gPlatform = IORegistryEntryFromPath(masterPort, "IODeviceTree:/efi/platform");
  if (gPlatform == 0) {
    errx(1, "EFI is not supported on this system");
  }
  
  CFTypeRef data;
  result = GetOFVariable("Settings", &data);
  if (result != KERN_SUCCESS) {
    errx(1, "Clover absent or too old : %s",
         mach_error_string(result));
  }
  
  PrintConfig(data);
  CFRelease(data);
  
  IOObjectRelease(gPlatform);
  
  return 0;
}
Exemple #3
0
bool DPMSSupport::PlatformSpecificEnablePowerSaving(PowerSavingMode mode)
{
  bool status;
  // http://lists.apple.com/archives/Cocoa-dev/2007/Nov/msg00267.html
  // This is an unsupported system call that might kernel panic on PPC boxes
  // The reported OSX-PPC panic is unverified so we are going to enable this until
  // we find out which OSX-PPC boxes have problems, then add detect/disable for those boxes.
  io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
  if(!r) return false;

  switch(mode)
  {
  case OFF:
    // Turn off display
    status = (IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue) == 0);
    break;
  case STANDBY:
    // Set display to low power
    status = (IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue) == 0);
    break;
  default:
    status = false;
    break;
  }
  return status;
}
Exemple #4
0
/*
===============
IN_GetIOHandle
===============
*/
static io_connect_t IN_GetIOHandle( void )  // mac os x mouse accel hack
{
	io_connect_t  iohandle = MACH_PORT_NULL;
	kern_return_t status;
	io_service_t  iohidsystem = MACH_PORT_NULL;
	mach_port_t   masterport;

	status = IOMasterPort( MACH_PORT_NULL, &masterport );

	if ( status != KERN_SUCCESS )
	{
		return 0;
	}

	iohidsystem = IORegistryEntryFromPath( masterport, kIOServicePlane ":/IOResources/IOHIDSystem" );

	if ( !iohidsystem )
	{
		return 0;
	}

	status = IOServiceOpen( iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle );
	IOObjectRelease( iohidsystem );

	return iohandle;
}
Exemple #5
0
int
main(int argc, char **argv)
{
    kern_return_t kr;
    CFTypeRef obj;
	
    io_registry_entry_t regEntry;
	
    regEntry = IORegistryEntryFromPath(kIOMasterPortDefault, 
									   kIOServicePlane ":/IOResources/IODisplayWrangler");
	
    obj = CFRetain(kCFBooleanTrue);
    if (argc > 1)
    {
		SInt32 num = 1000 * strtol(argv[1], 0, 0);
		obj = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &num);
    }
	
    kr = IORegistryEntrySetCFProperty(regEntry, CFSTR("IORequestIdle"), obj);
	
    printf("IORegistryEntrySetCFProperty(IORequestIdle) 0x%x\n", kr);
	
    CFRelease(obj);
    IOObjectRelease(regEntry);
	
    return (0);
}
IOReturn IOAccelCreateAccelID(IOOptionBits options, IOAccelID * identifier)
{
    IOReturn err;

    if (!idConnect)
    {
        io_service_t
        service = IORegistryEntryFromPath(kIOMasterPortDefault, 
                                        kIOServicePlane ":/IOResources/IODisplayWrangler");
        if (service) 
        {
            err = IOServiceOpen(service, mach_task_self(), 0, &idConnect);
            IOObjectRelease(service);
        }
    }

    if (!idConnect)
        return (kIOReturnNotReady);

    uint64_t inData[] = { options, *identifier };
    uint64_t outData;
    uint32_t outLen = 1;
    err = IOConnectCallScalarMethod(idConnect, kAlloc,
                                 inData,   arrayCnt(inData),
                                &outData,  &outLen);
    *identifier = (IOAccelID) outData;

    return (err);
}
Exemple #7
0
QString hostId()
{
	static QString id;
	unsigned char guid[100] = "", md[SHA_DIGEST_LENGTH];

	if (!id.isEmpty())
		return id;

#if defined(Q_OS_WIN32)
#define REG_CRYPTO "SOFTWARE\\Microsoft\\Cryptography"
#define REG_GUID "MachineGuid"
	ULONG dwGuid = sizeof guid;
	HKEY hKey;

	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CRYPTO, 0,
			KEY_WOW64_64KEY|KEY_READ, &hKey) != ERROR_SUCCESS) {
		XCA_WARN("Registry Key: '" REG_CRYPTO "' not found");
	} else {
		if (RegQueryValueEx(hKey, REG_GUID, NULL, NULL,
			guid, &dwGuid) != ERROR_SUCCESS) {
			XCA_WARN("Registry Key: '" REG_CRYPTO "\\" REG_GUID
				"' not found");
		}
	}
	RegCloseKey(hKey);

#elif defined(Q_OS_MAC)
	io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(
				kIOMasterPortDefault, "IOService:/");
	CFStringRef uuidCf = (CFStringRef)IORegistryEntryCreateCFProperty(
				ioRegistryRoot, CFSTR(kIOPlatformUUIDKey),
				kCFAllocatorDefault, 0);

	snprintf((char*)guid, sizeof guid, "%s", CCHAR(
		QString::fromUtf16(CFStringGetCharactersPtr(uuidCf))
	));

	IOObjectRelease(ioRegistryRoot);
	CFRelease(uuidCf);

#else
	QString mach_id;
	QStringList dirs; dirs <<
			"/etc" << "/var/lib/dbus" << "/var/db/dbus";
	foreach(QString dir, dirs) {
		QFile file(dir + "/machine-id");
		if (file.open(QIODevice::ReadOnly)) {
			QTextStream in(&file);
			mach_id = in.readLine().trimmed();
			file.close();
		}
		qDebug() << "ID:" << mach_id;
		if (!mach_id.isEmpty()) {
			snprintf((char*)guid, sizeof guid, "%s", CCHAR(mach_id));
			break;
		}
	}
int main() {
    io_registry_entry_t registryEntry =
        IORegistryEntryFromPath(kIOMasterPortDefault, 
	    "IOService:/IOResources/IODisplayWrangler");
    if(!registryEntry) return 1;
    int err = IORegistryEntrySetCFProperty(registryEntry,
        CFSTR("IORequestIdle"), kCFBooleanTrue);
    IOObjectRelease(registryEntry);
    return err;
}
Exemple #9
0
Boolean dimDisplayNow(void) 
{
    io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
    if (!entry) return 0;
    
    OSErr err = IORegistryEntrySetCFProperty(entry, CFSTR("IORequestIdle"), kCFBooleanTrue);
    IOObjectRelease(entry);

    return (err == noErr);
}
Exemple #10
0
int main (int argc, char *argv[]) {
	io_registry_entry_t io = IORegistryEntryFromPath(kIOMasterPortDefault, kIOServicePlane ":/IOResources/IODisplayWrangler");
	if (io != MACH_PORT_NULL) {
		usleep(300000);
		IORegistryEntrySetCFProperty(io, CFSTR("IORequestIdle"), kCFBooleanTrue);
		IOObjectRelease(io);
		return 0;
	}
	return 1;
}
void DiskArbitrationEventPublisher::DiskAppearedCallback(DADiskRef disk,
                                                         void* context) {
  auto ec = createEventContext();

  CFDictionaryRef disk_properties = DADiskCopyDescription(disk);
  CFTypeRef devicePathKey;
  if (!CFDictionaryGetValueIfPresent(
          disk_properties, kDADiskDescriptionDevicePathKey, &devicePathKey)) {
    CFRelease(disk_properties);
    return;
  }

  auto device_path = stringFromCFString((CFStringRef)devicePathKey);
  ec->device_path = device_path;

  auto entry =
      IORegistryEntryFromPath(kIOMasterPortDefault, device_path.c_str());
  if (entry == MACH_PORT_NULL) {
    CFRelease(disk_properties);
    return;
  }

  auto protocol_properties = (CFDictionaryRef)IORegistryEntryCreateCFProperty(
      entry,
      CFSTR(kIOPropertyProtocolCharacteristicsKey_),
      kCFAllocatorDefault,
      kNilOptions);

  if (protocol_properties != nullptr) {
    CFDataRef path = (CFDataRef)CFDictionaryGetValue(
        protocol_properties, CFSTR(kVirtualInterfaceLocation_));
    if (path != nullptr) {
      ec->path = stringFromCFData(path);
      // extract checksum once on the whole disk and not for every partition
      if (CFBooleanGetValue((CFBooleanRef)CFDictionaryGetValue(
              disk_properties, kDADiskDescriptionMediaWholeKey))) {
        ec->checksum = extractUdifChecksum(ec->path);
      }
    } else {
      // There was no interface location.
      ec->path = getProperty(kDADiskDescriptionDevicePathKey, disk_properties);
    }
    CFRelease(protocol_properties);
  } else {
    ec->path = "";
  }

  if (ec->path.find("/[email protected]") == std::string::npos) {
    // This is not an internal SSD.
    fire("add", ec, disk_properties);
  }

  CFRelease(disk_properties);
  IOObjectRelease(entry);
}
//from libmobilegestalt.dylib
CFDataRef copyDataFromChosen(CFStringRef key)
{
    io_registry_entry_t chosen = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/chosen");
    if (chosen)
    {
        CFDataRef res = IORegistryEntryCreateCFProperty(chosen, key, kCFAllocatorDefault, 0);
        IOObjectRelease(chosen);
        return res;
    }
    return NULL;
}
Exemple #13
0
QueryData genPlatformInfo(QueryContext& context) {
    auto rom = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/rom");
    if (rom == 0) {
        return {};
    }

    CFMutableDictionaryRef details = nullptr;
    IORegistryEntryCreateCFProperties(
        rom, &details, kCFAllocatorDefault, kNilOptions);
    IOObjectRelease(rom);

    // Success is determined by the details dictionary existence.
    if (details == nullptr) {
        return {};
    }

    Row r;
    r["vendor"] = getIOKitProperty(details, "vendor");
    r["volume_size"] = getIOKitProperty(details, "fv-main-size");
    r["size"] = getIOKitProperty(details, "rom-size");
    r["date"] = getIOKitProperty(details, "release-date");
    r["version"] = getIOKitProperty(details, "version");

    {
        auto address = getIOKitProperty(details, "fv-main-address");
        auto value = boost::lexical_cast<size_t>(address);

        std::stringstream hex_id;
        hex_id << std::hex << std::setw(8) << std::setfill('0') << value;
        r["address"] = "0x" + hex_id.str();
    }

    {
        std::vector<std::string> extra_items;
        auto info = getIOKitProperty(details, "apple-rom-info");
        std::vector<std::string> info_lines;
        iter_split(info_lines, info, boost::algorithm::first_finder("%0a"));
        for (const auto& line : info_lines) {
            std::vector<std::string> details;
            iter_split(details, line, boost::algorithm::first_finder(": "));
            if (details.size() > 1) {
                boost::trim(details[1]);
                if (details[0].find("Revision") != std::string::npos) {
                    r["revision"] = details[1];
                }
                extra_items.push_back(details[1]);
            }
        }
        r["extra"] = osquery::join(extra_items, "; ");
    }

    CFRelease(details);
    return {r};
}
Exemple #14
0
bool DPMSSupport::PlatformSpecificDisablePowerSaving()
{
  // http://lists.apple.com/archives/Cocoa-dev/2007/Nov/msg00267.html
  // This is an unsupported system call that might kernel panic on PPC boxes
  // The reported OSX-PPC panic is unverified so we are going to enable this until
  // we find out which OSX-PPC boxes have problems, then add detect/disable for those boxes.
  io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
  if(!r) return false;

  // Turn display on
  return (IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanFalse) == 0);
}
Exemple #15
0
io_connect_t IORegisterForSystemPower ( void * refcon,
                                        IONotificationPortRef * thePortRef,
                                        IOServiceInterestCallback callback,
                                        io_object_t * root_notifier )
{
    io_connect_t                fb = IO_OBJECT_NULL;
    IONotificationPortRef       notify = NULL;
    kern_return_t               kr;
    io_service_t                obj = IO_OBJECT_NULL;
     
    *root_notifier = IO_OBJECT_NULL;

    notify = IONotificationPortCreate(MACH_PORT_NULL);

    obj = IORegistryEntryFromPath( IO_OBJECT_NULL,
                    kIOPowerPlane ":/IOPowerConnection/IOPMrootDomain");

    if( obj == IO_OBJECT_NULL) goto failure_exit;
    
    kr = IOServiceOpen( obj,mach_task_self(), 0, &fb);

    if ( (kr != kIOReturnSuccess) || (fb == IO_OBJECT_NULL) )  {
        goto failure_exit;
    }

    kr = IOServiceAddInterestNotification(
                            notify,obj,kIOAppPowerStateInterest,
                            callback,refcon,root_notifier);

    IOObjectRelease(obj);
    if ( kr == KERN_SUCCESS ) {
        // Successful exit case
        *thePortRef = notify;
        return fb;
    }
    
failure_exit:    
    if ( obj != IO_OBJECT_NULL) {
        IOObjectRelease(obj);
    }
    if ( notify != NULL) {
        IONotificationPortDestroy(notify);
    }
    if ( fb != IO_OBJECT_NULL) {
        IOServiceClose(fb);
    }
    if ( *root_notifier != IO_OBJECT_NULL) {
        IOObjectRelease(*root_notifier);
    }
    
    return IO_OBJECT_NULL;
}
//--------------------------------------------------------------
// get a unique machine id
void getPlatformUUID(
  char* buf, 
  int bufSize) 
{
  io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
  
  CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, 
    CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
  IOObjectRelease(ioRegistryRoot);
  
  CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman);
  CFRelease(uuidCf);    
}
Exemple #17
0
IOKitDevice::IOKitDevice(const QString &udi)
    : d(new IOKitDevicePrivate)
{
    io_registry_entry_t entry = IORegistryEntryFromPath(
                                    kIOMasterPortDefault,
                                    udi.toLocal8Bit().constData());

    if (entry == MACH_PORT_NULL) {
        qDebug() << Q_FUNC_INFO << "Tried to create Device from invalid UDI" << udi;
        return;
    }

    d->init(udi, entry);
}
CFStringRef copy_devicetree_option(CFStringRef key) {
    io_registry_entry_t entry;
    CFStringRef option;
    
    entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options");
    if(!entry) {
        printf("unable to get registry entry for IODeviceTree:/options\n");
        return NULL;
    }
    
    option = IORegistryEntryCreateCFProperty(entry, key, kCFAllocatorDefault, 0);
    IOObjectRelease(entry);
    
    return option;
}
QString FingerprintUtils::getMachineFingerprintString() {
    QString uuidString;
#ifdef Q_OS_LINUX
    // sadly need to be root to get smbios guid from linux, so 
    // for now lets do nothing.
#endif //Q_OS_LINUX

#ifdef Q_OS_MAC
    io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
    CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
    IOObjectRelease(ioRegistryRoot);
    uuidString = QString::fromCFString(uuidCf);
    CFRelease(uuidCf); 
    qCDebug(networking) << "Mac serial number: " << uuidString;
#endif //Q_OS_MAC

#ifdef Q_OS_WIN
    HKEY cryptoKey;
    
    // try and open the key that contains the machine GUID
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &cryptoKey) == ERROR_SUCCESS) {
        DWORD type;
        DWORD guidSize;

        const char* MACHINE_GUID_KEY = "MachineGuid";

        // try and retrieve the size of the GUID value
        if (RegQueryValueEx(cryptoKey, MACHINE_GUID_KEY, NULL, &type, NULL, &guidSize) == ERROR_SUCCESS) {
            // make sure that the value is a string
            if (type == REG_SZ) {
                // retrieve the machine GUID and return that as our UUID string
                std::string machineGUID(guidSize / sizeof(char), '\0');

                if (RegQueryValueEx(cryptoKey, MACHINE_GUID_KEY, NULL, NULL,
                                    reinterpret_cast<LPBYTE>(&machineGUID[0]), &guidSize) == ERROR_SUCCESS) {
                    uuidString = QString::fromStdString(machineGUID);
                }
            }
        }

        RegCloseKey(cryptoKey);
    }

#endif //Q_OS_WIN

    return uuidString;

}
CFTypeRef
myIORegistryEntryCopyProperty(const char * path, CFStringRef prop)
{
    io_registry_entry_t 	service;
    CFTypeRef			val;

    service = IORegistryEntryFromPath(kIOMasterPortDefault, path);
    if (service == MACH_PORT_NULL) {
	return (NULL);
    }
    val = IORegistryEntryCreateCFProperty(service, prop,
					  kCFAllocatorDefault,
					  kNilOptions);
    IOObjectRelease(service);
    return (val);
}
Exemple #21
0
io_connect_t IOPMFindPowerManagement( mach_port_t master_device_port )
{
    io_connect_t    fb;
    kern_return_t    kr;
    io_service_t    obj = MACH_PORT_NULL;

    obj = IORegistryEntryFromPath( master_device_port, 
                        kIOPowerPlane ":/IOPowerConnection/IOPMrootDomain");
    if( obj ) {
        kr = IOServiceOpen( obj,mach_task_self(), 0, &fb);
        if ( kr == kIOReturnSuccess ) {
            IOObjectRelease(obj);
            return fb;
        }
        IOObjectRelease(obj);
    }
    return 0;
}
Exemple #22
0
void DeviceNotification( void *		refCon,
                         io_service_t 	service,
                         natural_t 	messageType,
                         void *		messageArgument )
{
    if (messageType == kIOMessageServiceIsTerminated)
    {
        printf("Device 0x%08x removed.\n", service);

        // Run lock via idle
        //
        printf("Yubikey removed. Lock the screen.\n");
        io_registry_entry_t reg = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
        if (reg) {
            IORegistryEntrySetCFProperty(reg, CFSTR("IORequestIdle"), kCFBooleanTrue);
            IOObjectRelease(reg);
        }

    }
}
Exemple #23
0
boolean_t IOPMSleepEnabled ( void ) 
{
    io_registry_entry_t         root;
    boolean_t                   flag = false;
    CFTypeRef                   data = NULL;
    
    root = IORegistryEntryFromPath(MACH_PORT_NULL, 
                    kIOPowerPlane ":/IOPowerConnection/IOPMrootDomain");
    if ( !root ) return false;
    
    data = IORegistryEntryCreateCFProperty(
                            root, CFSTR("IOSleepSupported"),
                            kCFAllocatorDefault, kNilOptions);
    if ( data ) {
        flag = true;
        CFRelease(data);
    }

    IOObjectRelease(root);
    return flag;
}
CFDictionaryRef
myIORegistryEntryCopyValue(const char * path)
{
    io_registry_entry_t 	service;
    kern_return_t       	status;
    CFMutableDictionaryRef	properties = NULL;

    service = IORegistryEntryFromPath(kIOMasterPortDefault, path);
    if (service == MACH_PORT_NULL) {
	return (NULL);
    }
    status = IORegistryEntryCreateCFProperties(service,
					       &properties,
					       kCFAllocatorDefault,
					       kNilOptions);
    if (status != KERN_SUCCESS) {
	properties = NULL;
    }
    IOObjectRelease(service);
    return (properties);
}
Exemple #25
0
void
COSXScreen::enter()
{
	showCursor();

	if (m_isPrimary) {
		CGSetLocalEventsSuppressionInterval(0.0);
		
		// enable global hotkeys
		//setGlobalHotKeysEnabled(true);
	}
	else {
		// reset buttons
		m_buttonState.reset();

		// patch by Yutaka Tsutano
		// wakes the client screen
		// http://synergy-foss.org/spit/issues/details/3287#c12
		io_registry_entry_t entry = IORegistryEntryFromPath(
			kIOMasterPortDefault,
			"IOService:/IOResources/IODisplayWrangler");
		if (entry != MACH_PORT_NULL) {
			IORegistryEntrySetCFProperty(entry, CFSTR("IORequestIdle"), kCFBooleanFalse);
			IOObjectRelease(entry);
		}

		// avoid suppression of local hardware events
		// [email protected]
		CGSetLocalEventsFilterDuringSupressionState(
								kCGEventFilterMaskPermitAllEvents,
								kCGEventSupressionStateSupressionInterval);
		CGSetLocalEventsFilterDuringSupressionState(
								(kCGEventFilterMaskPermitLocalKeyboardEvents |
								kCGEventFilterMaskPermitSystemDefinedEvents),
								kCGEventSupressionStateRemoteMouseDrag);
	}

	// now on screen
	m_isOnScreen = true;
}
boolean_t IOHIDEventSystemStatistics::open(IOHIDSessionRef session, IOOptionBits options)
{
    CFTypeRef            bootArgs = nil;
    io_registry_entry_t  entry    = IO_OBJECT_NULL;
    
    (void)session;
    (void)options;
    
    entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options");
    if(entry){
        bootArgs = IORegistryEntryCreateCFProperty(entry, CFSTR("boot-args"), nil, 0);
        if (bootArgs){
            if (CFGetTypeID(bootArgs) == CFStringGetTypeID()){
                CFRange         findRange;
                CFStringRef     bootArgsString = (CFStringRef)bootArgs;
                
                findRange = CFStringFind(bootArgsString, CFSTR("opposing-button-logging"), 0);
                
                if (findRange.length != 0)
                    _logButtonFiltering = true;
            }
            CFRelease(bootArgs);
            IOObjectRelease(entry);
        }
    }
    
    if (_logButtonFiltering) {
        _logStrings = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
        _asl = asl_open("ButtonLogging", "Button Filtering Information", 0);
        
        _logfd = ::open("/var/mobile/Library/Logs/button.log", O_CREAT | O_APPEND | O_RDWR, 0644);
        
        if ((_logfd != -1) && (_asl != NULL))
            asl_add_log_file(_asl, _logfd);
    }

    return true;
}
Exemple #27
0
int main(int argc, char *argv[])
{
	io_registry_entry_t root = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
	if (!root)
	{
		printf("IORegistryEntry \"IOIOService:/\" not found.\n");
		return 0;
	}

	CFTypeRef bootLog = IORegistryEntryCreateCFProperty(root, CFSTR("boot-log"), kCFAllocatorDefault, 0);
	if (!bootLog)
	{
		printf("\"boot-log\" property not found.\n");
		return 0;
	}
	//CFShow(bootLog);
	const UInt8 *msglog = CFDataGetBytePtr((CFDataRef)bootLog);
	if (msglog)
		printf("%s\n", msglog);
    
    CFRelease(bootLog);
	return 0;
}
Status genUnlockIdent(CFDataRef& uuid) {
  auto chosen =
      IORegistryEntryFromPath(kIOMasterPortDefault, kIODeviceTreeChosenPath_);
  if (chosen == MACH_PORT_NULL) {
    return Status(1, "Could not open IOKit DeviceTree");
  }

  CFMutableDictionaryRef properties = nullptr;
  auto kr = IORegistryEntryCreateCFProperties(
      chosen, &properties, kCFAllocatorDefault, kNilOptions);
  IOObjectRelease(chosen);

  if (kr != KERN_SUCCESS) {
    return Status(1, "Could not get IOKit chosen properties");
  }

  if (properties == nullptr) {
    return Status(1, "Could not load IOKit properties");
  }

  CFTypeRef unlock_ident = nullptr;
  if (CFDictionaryGetValueIfPresent(
          properties, CFSTR("efilogin-unlock-ident"), &unlock_ident)) {
    if (CFGetTypeID(unlock_ident) != CFDataGetTypeID()) {
      return Status(1, "Unexpected data type for unlock ident");
    }
    uuid = CFDataCreateCopy(kCFAllocatorDefault, (CFDataRef)unlock_ident);
    if (uuid == nullptr) {
      return Status(1, "Could not get UUID");
    }
    CFRelease(properties);
    return Status(0, "ok");
  }

  return Status(1, "Could not get unlock ident");
}
Exemple #29
0
// Like open().  Return non-negative integer handle, only used by the
// functions below.  type=="ATA" or "SCSI".  The return value is
// an index into the devices[] array.  If the device can't be opened,
// sets errno and returns -1.
// Acceptable device names are:
// /dev/disk*
// /dev/rdisk*
// disk*
// IOService:*
// IODeviceTree:*
int deviceopen(const char *pathname, char *type){
  size_t devnum;
  const char *devname;
  io_object_t disk;
  
  if (strcmp (type, "ATA") != 0)
    {
      errno = EINVAL;
      return -1;
    }
  
  // Find a free device number.
  for (devnum = 0; devnum < sizeof (devices) / sizeof (devices[0]); devnum++)
    if (! devices[devnum].ioob)
      break;
  if (devnum == sizeof (devices) / sizeof (devices[0]))
    {
      errno = EMFILE;
      return -1;
    }
  
  devname = NULL;
  if (strncmp (pathname, "/dev/rdisk", 10) == 0)
    devname = pathname + 6;
  else if (strncmp (pathname, "/dev/disk", 9) == 0)
    devname = pathname + 5;
  else if (strncmp (pathname, "disk", 4) == 0)
    // allow user to just say 'disk0'
    devname = pathname;

  // Find the device.
  if (devname)
    {
      CFMutableDictionaryRef matcher;
      matcher = IOBSDNameMatching (kIOMasterPortDefault, 0, devname);
      disk = IOServiceGetMatchingService (kIOMasterPortDefault, matcher);
    }
  else
    {
      disk = IORegistryEntryFromPath (kIOMasterPortDefault, pathname);
    }

  if (! disk)
    {
      errno = ENOENT;
      return -1;
    }
  
  // Find a SMART-capable driver which is a parent of this device.
  while (! is_smart_capable (disk))
    {
      IOReturn err;
      io_object_t prevdisk = disk;

      // Find this device's parent and try again.
      err = IORegistryEntryGetParentEntry (disk, kIOServicePlane, &disk);
      if (err != kIOReturnSuccess || ! disk)
	{
	  errno = ENODEV;
	  IOObjectRelease (prevdisk);
	  return -1;
	}
    }
  
  devices[devnum].ioob = disk;

  {
    SInt32 dummy;
  
    devices[devnum].plugin = NULL;
    devices[devnum].smartIf = NULL;

    // Create an interface to the ATA SMART library.
    if (IOCreatePlugInInterfaceForService (disk,
					   kIOATASMARTUserClientTypeID,
					   kIOCFPlugInInterfaceID,
					   &devices[devnum].plugin,
					   &dummy) == kIOReturnSuccess)
      (*devices[devnum].plugin)->QueryInterface
	(devices[devnum].plugin,
	 CFUUIDGetUUIDBytes ( kIOATASMARTInterfaceID),
         (void **)&devices[devnum].smartIf);
  }
  
  return devnum;
}
Exemple #30
0
/* hid_open_path()
 *
 * path must be a valid path to an IOHIDDevice in the IOService plane
 * Example: "IOService:/AppleACPIPlatformExpert/[email protected]/AppleACPIPCI/[email protected],7/AppleUSBEHCI/PLAYSTATION(R)3 [email protected]/[email protected]/IOUSBHIDDriver"
 */
hid_device * HID_API_EXPORT hid_open_path(const char *path)
{
	hid_device *dev = NULL;
	io_registry_entry_t entry = MACH_PORT_NULL;

	dev = new_hid_device();

	/* Set up the HID Manager if it hasn't been done */
	if (hid_init() < 0)
		return NULL;

	/* Get the IORegistry entry for the given path */
	entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
	if (entry == MACH_PORT_NULL) {
		/* Path wasn't valid (maybe device was removed?) */
		goto return_error;
	}

	/* Create an IOHIDDevice for the entry */
	dev->device_handle = IOHIDDeviceCreate(kCFAllocatorDefault, entry);
	if (dev->device_handle == NULL) {
		/* Error creating the HID device */
		goto return_error;
	}

	/* Open the IOHIDDevice */
	IOReturn ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
	if (ret == kIOReturnSuccess) {
		char str[32];

		/* Create the buffers for receiving data */
		dev->max_input_report_len = (CFIndex) get_max_report_length(dev->device_handle);
		dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t));

		/* Create the Run Loop Mode for this device.
		   printing the reference seems to work. */
		sprintf(str, "HIDAPI_%p", dev->device_handle);
		dev->run_loop_mode = 
			CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);
		
		/* Attach the device to a Run Loop */
		IOHIDDeviceRegisterInputReportCallback(
			dev->device_handle, dev->input_report_buf, dev->max_input_report_len,
			&hid_report_callback, dev);
		IOHIDDeviceRegisterRemovalCallback(dev->device_handle, hid_device_removal_callback, dev);

		/* Start the read thread */
		pthread_create(&dev->thread, NULL, read_thread, dev);

		/* Wait here for the read thread to be initialized. */
		pthread_barrier_wait(&dev->barrier);
		
		IOObjectRelease(entry);
		return dev;
	}
	else {
		goto return_error;
	}

return_error:
	if (dev->device_handle != NULL)
		CFRelease(dev->device_handle);

	if (entry != MACH_PORT_NULL)
		IOObjectRelease(entry);

	free_hid_device(dev);
	return NULL;
}