Skip to content

Instantly share code, notes, and snippets.

@gordonturner
Last active November 13, 2020 14:52
Show Gist options
  • Save gordonturner/c33bcc935e32f9fa6695 to your computer and use it in GitHub Desktop.
Save gordonturner/c33bcc935e32f9fa6695 to your computer and use it in GitHub Desktop.

Revisions

  1. gordonturner revised this gist Mar 7, 2016. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions KVM OSX Guest SMC Read.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    KVM OSX Guest SMC Read
    ======================

    - 2015-02-20: OX 10.11.1 on Apple hardware works
    - 2015-02-20: OX 10.10.5 on Apple hardware can successfully build
    - NOTE: Credit and thanks to Amit Singh
    - Reference:

    @@ -90,7 +90,17 @@ gcc -Wall -o smc_read smc_read.c -framework IOKit
    ./smc_read
    ```

    - On 2015-12-09 output is a constant value
    - On 2015-12-09 output is:

    ```
    ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc
    ```

    - Reference:

    http://www.osxbook.com/book/bonus/chapter7/tpmdrmmyth/

    https://bbs.archlinux.org/viewtopic.php?id=162768


    Error Compiling
  2. gordonturner revised this gist Mar 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion KVM OSX Guest SMC Read.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    KVM OSX Guest SMC Read
    ======================

    - 2015-02-20: OX 10.10.5 on Apple hardware works
    - 2015-02-20: OX 10.11.1 on Apple hardware works
    - NOTE: Credit and thanks to Amit Singh
    - Reference:

  3. gordonturner revised this gist Feb 20, 2016. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion KVM OSX Guest SMC Read.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    - 2015-12-09: OX 10.10.5 on Apple hardware works
    KVM OSX Guest SMC Read
    ======================

    - 2015-02-20: OX 10.10.5 on Apple hardware works
    - NOTE: Credit and thanks to Amit Singh
    - Reference:

  4. gordonturner revised this gist Feb 20, 2016. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions KVM OSX Guest SMC Read.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,5 @@
    - 2016-02-20 with OX 10.11.3 works
    - OSX, running on Apple hardware

    - 2015-12-09: OX 10.10.5 on Apple hardware works
    - NOTE: Credit and thanks to Amit Singh

    - Reference:

    http://www.osxbook.com/book/bonus/chapter7/tpmdrmmyth/
  5. gordonturner revised this gist Feb 20, 2016. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions KVM OSX Guest SMC Read.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@

    - OSX, running on Apple hardware
    - 2016-02-20 with OX 10.11.3 works

    - OSX, running on Apple hardware

    - NOTE: Credit and thanks to Amit Singh

  6. gordonturner renamed this gist Feb 20, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. gordonturner created this gist Feb 20, 2016.
    112 changes: 112 additions & 0 deletions KVM OSX Guest SMC Read
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,112 @@

    - OSX, running on Apple hardware
    - 2016-02-20 with OX 10.11.3 works


    - NOTE: Credit and thanks to Amit Singh

    - Reference:

    http://www.osxbook.com/book/bonus/chapter7/tpmdrmmyth/


    Build
    -----

    - Create `smc_read.c` and paste in code:

    ```
    vi smc_read.c
    ```

    ```
    /*
    * smc_read.c: Written for Mac OS X 10.5. Compile as follows:
    *
    * gcc -Wall -o smc_read smc_read.c -framework IOKit
    */

    #include <stdio.h>
    #include <IOKit/IOKitLib.h>

    typedef struct {
    uint32_t key;
    uint8_t __d0[22];
    uint32_t datasize;
    uint8_t __d1[10];
    uint8_t cmd;
    uint32_t __d2;
    uint8_t data[32];
    } AppleSMCBuffer_t;

    int
    main(void)
    {
    io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
    IOServiceMatching("AppleSMC"));
    if (!service)
    return -1;

    io_connect_t port = (io_connect_t)0;
    kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
    IOObjectRelease(service);
    if (kr != kIOReturnSuccess)
    return kr;

    AppleSMCBuffer_t inputStruct = { 'OSK0', {0}, 32, {0}, 5, }, outputStruct;
    size_t outputStructCnt = sizeof(outputStruct);

    kr = IOConnectCallStructMethod((mach_port_t)port, (uint32_t)2,
    (const void*)&inputStruct, sizeof(inputStruct),
    (void*)&outputStruct, &outputStructCnt);
    if (kr != kIOReturnSuccess)
    return kr;

    int i = 0;
    for (i = 0; i < 32; i++)
    printf("%c", outputStruct.data[i]);

    inputStruct.key = 'OSK1';
    kr = IOConnectCallStructMethod((mach_port_t)port, (uint32_t)2,
    (const void*)&inputStruct, sizeof(inputStruct),
    (void*)&outputStruct, &outputStructCnt);
    if (kr == kIOReturnSuccess)
    for (i = 0; i < 32; i++)
    printf("%c", outputStruct.data[i]);

    printf("\n");

    return IOServiceClose(port);
    }
    ```

    - Compile:

    ```
    gcc -Wall -o smc_read smc_read.c -framework IOKit
    ```

    - Run:

    ```
    ./smc_read
    ```

    - On 2015-12-09 output is a constant value


    Error Compiling
    ---------------

    - Error message:

    ```
    2015-12-09 19:47:32.799 xcodebuild[9169:2013175] [MT] PluginLoading: Required plug-in compatibility UUID 7265231C-39B4-402C-89E1-16167C4CC990 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/OFPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs
    ```

    - Confirm that Xcode command line tools are installed:

    ```
    xcode-select --install
    ```