VirtualBox

Changeset 26331 in vbox


Ignore:
Timestamp:
Feb 8, 2010 4:17:35 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57415
Message:

SMC: read OSK from the device

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r26313 r26331  
    156156
    157157    return S_OK;
     158}
     159
     160static int getSmcDeviceKey(IMachine* pMachine, BSTR * aKey)
     161{
     162    int rc;
     163
     164# if defined(RT_OS_DARWIN)
     165    char aKeyBuf[65];
     166
     167    rc = DarwinSmcKey(aKeyBuf, sizeof aKeyBuf);
     168    if (SUCCEEDED(rc))
     169    {
     170        Bstr(aKeyBuf).detachTo(aKey);
     171        return rc;
     172    }
     173#endif
     174
     175    return pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey"), aKey);
    158176}
    159177
     
    540558        rc = CFGMR3InsertInteger(pInst, "Trusted",   1);     /* boolean */   RC_CHECK();
    541559        rc = CFGMR3InsertNode(pInst,    "Config", &pCfg);                    RC_CHECK();
    542         rc = pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey"), tmpStr2.asOutParam()); RC_CHECK();
     560        rc = getSmcDeviceKey(pMachine,   tmpStr2.asOutParam());              RC_CHECK();
    543561        rc = CFGMR3InsertString(pCfg,   "DeviceKey", Utf8Str(tmpStr2).raw());RC_CHECK();
    544562    }
  • trunk/src/VBox/Main/Makefile.kmk

    r25946 r26331  
    588588VBoxC_LDFLAGS.darwin = \
    589589        -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/components/VBoxC.dylib \
    590         -exported_symbols_list $(PATH_VBoxC)/VBoxC.def
     590        -exported_symbols_list $(PATH_VBoxC)/VBoxC.def \
     591        -framework IOKit
    591592ifdef VBOX_USE_VCC80
    592593 VBoxC_LDFLAGS.win = /MANIFEST
  • trunk/src/VBox/Main/darwin/iokit.cpp

    r25991 r26331  
    16791679}
    16801680
     1681int DarwinSmcKey(char* aKey, uint32_t iKeySize)
     1682{
     1683    int rc;
     1684    /* Based on Amith Singh SMC reading code sample in OS X Book */
     1685    typedef struct {
     1686        uint32_t   key;
     1687        uint8_t    __d0[22];
     1688        uint32_t   datasize;
     1689        uint8_t    __d1[10];
     1690        uint8_t    cmd;
     1691        uint32_t   __d2;
     1692        uint8_t    data[32];
     1693    } AppleSMCBuffer_t;
     1694
     1695
     1696    if (iKeySize < 65)
     1697        return VERR_INTERNAL_ERROR;
     1698
     1699    io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
     1700                                                       IOServiceMatching("AppleSMC"));
     1701    if (!service)
     1702        return VERR_INTERNAL_ERROR;
     1703
     1704    io_connect_t port = (io_connect_t)0;
     1705    kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
     1706    IOObjectRelease(service);
     1707    if (kr != kIOReturnSuccess)
     1708        return VERR_INTERNAL_ERROR;
     1709
     1710
     1711    AppleSMCBuffer_t inputStruct = { 0, {0}, 32, {0}, 5, }, outputStruct;
     1712    size_t outputStructCnt = sizeof(outputStruct);
     1713    char osk[65];
     1714
     1715    for (int i = 0; i < 2; i++)
     1716    {
     1717        inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
     1718        kr = IOConnectCallStructMethod((mach_port_t)port,
     1719                                       (uint32_t)2,
     1720                                       (const void*)&inputStruct,
     1721                                       sizeof(inputStruct),
     1722                                       (void*)&outputStruct,
     1723                                       &outputStructCnt);
     1724        if (kr != kIOReturnSuccess)
     1725            return VERR_INTERNAL_ERROR;
     1726
     1727        for (int j=0; j<32; j++)
     1728            aKey[j + i*32] = outputStruct.data[j];
     1729    }
     1730
     1731    aKey[64] = 0;
     1732
     1733    return rc;
     1734}
     1735
    16811736#ifdef STANDALONE_TESTCASE
    16821737/**
     
    17961851}
    17971852#endif
    1798 
    1799 
  • trunk/src/VBox/Main/darwin/iokit.h

    r23134 r26331  
    8787PDARWINDVD      DarwinGetDVDDrives(void);
    8888PDARWINETHERNIC DarwinGetEthernetControllers(void);
     89int             DarwinSmcKey(char* aKey, uint32_t iKeySize);
    8990RT_C_DECLS_END
    9091
    9192#endif
    92 
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette