Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. /*
  2. * smc_read.c: Written for Mac OS X 10.5. Compile as follows:
  3. *
  4. * gcc -Wall -o smc_read smc_read.c -framework IOKit
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <IOKit/IOKitLib.h>
  9.  
  10. typedef struct {
  11. uint32_t key;
  12. uint8_t __d0[22];
  13. uint32_t datasize;
  14. uint8_t __d1[10];
  15. uint8_t cmd;
  16. uint32_t __d2;
  17. uint8_t data[32];
  18. } AppleSMCBuffer_t;
  19.  
  20. int
  21. main(void)
  22. {
  23. io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
  24. IOServiceMatching("AppleSMC"));
  25. if (!service)
  26. return -1;
  27.  
  28. io_connect_t port = (io_connect_t)0;
  29. kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
  30. IOObjectRelease(service);
  31. if (kr != kIOReturnSuccess)
  32. return kr;
  33.  
  34. AppleSMCBuffer_t inputStruct = { 'OSK0', {0}, 32, {0}, 5, }, outputStruct;
  35. size_t outputStructCnt = sizeof(outputStruct);
  36.  
  37. kr = IOConnectCallStructMethod((mach_port_t)port, (uint32_t)2,
  38. (const void*)&inputStruct, sizeof(inputStruct),
  39. (void*)&outputStruct, &outputStructCnt);
  40. if (kr != kIOReturnSuccess)
  41. return kr;
  42.  
  43. int i = 0;
  44. for (i = 0; i < 32; i++)
  45. printf("%c", outputStruct.data[i]);
  46.  
  47. inputStruct.key = 'OSK1';
  48. kr = IOConnectCallStructMethod((mach_port_t)port, (uint32_t)2,
  49. (const void*)&inputStruct, sizeof(inputStruct),
  50. (void*)&outputStruct, &outputStructCnt);
  51. if (kr == kIOReturnSuccess)
  52. for (i = 0; i < 32; i++)
  53. printf("%c", outputStruct.data[i]);
  54.  
  55. printf("\n");
  56.  
  57. return IOServiceClose(port);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement