Exploring Thermal Related Stuff in iDevices using Open-Source Tool
The document discusses thermal sensors in iOS devices, specifically focusing on the iPhone 6 and the use of open-source tools for exploring these sensors. It highlights the number and types of thermal sensors in various iPhone models, the methods for accessing this data via iOS APIs, and the challenges faced during development. Additionally, the paper emphasizes the importance of thermal control in modern devices and provides insights into the underlying technical mechanisms.
Overview of thermal sensors and control mechanisms in iOS. Discusses software and hardware tools including IOKit and class-dump for analyzing thermal data.
Details on thermal management systems, their components, and control processes used in recent iOS updates. Discusses runtime information and PID control.
Exploration of various tools like cycript, lldb for process exploration, and debugging. Emphasizes open-source tools for interacting with iOS devices.
Includes references for further reading on related tools, methods, and historical background on iOS thermal management.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Who am I? ▶“ 我是 Guá-sī 一个 tsi ̍t-ê 寫 siá code 个 ê 人 lâng, 我个苦 guá-ê-khóo 攏 lóng 寫佇 siá-tī 面頂 bīn-tíng” – Somebody I Don’t Know His Name, COSCUP 2017 ▶ Learnt to use open source on a VAX-11/780 running 4.3BSD, before the term “open source” was coined ▶ Learnt a bit Pe̍h-ōe-jī about the same time ▶ feel free to interrupt me anytime
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . More Thermal ControlRelated Mechanisms I ▶ There is /usr/libexec/thermalmonitord in iOS 13 (/usr/libexec/mobilewatchdog in iOS 12.x), which collects thermal information and does thermal-throttling when necessary. ▶ The thermalmonitord is mainly written in Objective-C (how to know that? there are Objective-C sections in Mach-O). ▶ Mach-O has been around for more than 30 years.There are many tools we can used to inspect Mach-O files. E.g., if you know binutils, llvm-based binutils. ▶ class-dump, one of the interesting Mach-O tools, could extract Objective-C class related information (including protocols and methods) from Mach-O files and convert those them to Objective-C headers. ▶ class-dump thermalmonitord of iPhone 8 running iOS 13.3 (class-dump thermalmonitord -H -o /tmp/thermal_headers), we can get more than 100 headers.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . peeking running systemswith cycript I ▶ attaching cycript to a running system process is a bit more complicated after iOS 12. We could start from a wrapper called cycrun, https://www.reddit.com/r/ jailbreakdevelopers/comments/b1r5kq/question_is_ cycript_coming_to_ios_12_unc0ver_jb/ ▶ with cyrun+cycript, ▶ cyrun -x thermalmonitord -e ▶ then where to start, singleton ones are less intrusive and easier ▶ as you see, we can get productObj ▶ as you can see, the thermalmonitord uses HID sensors.
21.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . peeking running systemswith cycript II Listing 2: Cyrun ~ root # cyrun −x thermalmonitord −e applicationName : thermalmonitord i s running (64) executableName : thermalmonitord b u n d l e I d e n t i f i e r : Cycript i s active : thermalmonitord Device i s passcode locked Tweak Mode Success , Cycript was already active f o r the Process . You may now run c y c r i p t −r 127.0.0.1:8556 cy# tgs = [ TGraphSampler sharedInstance ] #”<TGraphSampler : 0x104f04330 >” cy# tgs−>productObj #”<tm0148f449e0ff00c77f11492610c521ce : 0x104f04090 >” cy# tgs−> __defineGetter__ extratGraphDataSources __defineSetter__ gotDataToLogToLiteMode __lookupGetter__ hasOwnProperty __lookupSetter__ i s I n t e r n a l __proto__ isPrototypeOf _appleCareState isa _appleCareStateLastLogged lastLogTimestamp _powerlogQueue listOfSupervisorControl _powerlogSubkeyController_Components listofComponentControl _powerlogSubkeyController_HiP previousThermalSensorValues _powerlogSubkeyController_Hotspots productObj _powerlogSubkeyController_LiteMode propertyIsEnumerable _powerlogSubkeyController_MiscExternalState tGraphDataString _powerlogSubkeyController_MiscInternalState toLocaleString _powerlogSubkeyController_Sensors t o S t r i n g _powerlogSubkeyController_Sensors_Components valueOf constructor
22.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . peeking running systemswith cycript III Listing 3: Cycript HidSensos cy# hs = [ HidSensors sharedInstance ] #”<HidSensors : 0x10582bac0 >” cy# new Instance ( hs−>_tempSensors ) [ 0 ] #”+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++n RegistryID : 0x0000000100000277 n B u i l t I n : 1n Product : Avg : PMGR SOC Die Temp Sensor0 n LocationID : 1416114273n VendorID : 0n ProductID : 0n CountryCode : 0n PrimaryUsagePage : 65280n PrimaryUsage : 5n DeviceUsagePairs : n DeviceUsagePage : 65280n DeviceUsage : 5n +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++n ” cy#
23.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other tools I ▶binutils and other hacking tools, such as lsof ▶ lldb/gdb on devices: Apple used to ship “fat” gdb and lldb, but not anymore(?). LLDB allows using Objective-C style syntax (most iOS programmers before Swift was introduced know Objective-C). ▶ remote debbuging: either cross building or native building of lldb could be an ostacle, if you are not afraind of using remote debugging, they (debuggserver and lldb) are open source too. Example usage (my iMAC: 192.168.1.80, the iPhone: 192.168.1.115) 1. install debuggerserver on your iDevice. Then, run debugserver 192.168.1.80:5555 --attach=thermalmonitord to wait for connection from 192.168.1.80 to port 5555 of this devices.
24.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other tools II 2.on you host, launch lldb, then use platform select remote-ios and process connect connect://192.168.1.115:5555 to connect to the debugserver on the remote device. You should see something like Listing 4 3. we can examine TGraphSampler as in Listing 5 4. and HidSenors as in Listing 6 ▶ NOTE: DON’T interrupt the thermalmonitord too long, otherwise the device will reboot. Listing 4: connect to debugserver from lldb ( l l d b ) platform select remote−ios Platform : remote−ios Connected : no SDK Path : ” / Users / freedom / Library / Developer / Xcode / iOS DeviceSupport /13.3 (17C54 ) ” SDK Roots : [ 0] ” / Users / freedom / Library / Developer / Xcode / iOS DeviceSupport /13.3 (17C54 ) ” ( l l d b ) process connect connect ://192.168.1.115:5555 Process 64 stopped * thread #1 , queue = ’com. apple . main−thread ’ , stop reason = signal SIGSTOP frame #0: 0x0000000184864634 libsystem_kernel . dylib ‘ mach_msg_trap + 8 libsystem_kernel . dylib ‘ mach_msg_trap : −> 0x184864634 <+8>: r e t
25.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other tools III libsystem_kernel. dylib ‘ mach_msg_overwrite_trap : 0x184864638 <+0>: mov x16 , #−0x20 0x18486463c <+4>: svc #0x80 0x184864640 <+8>: r e t Target 0: ( thermalmonitord ) stopped . Listing 5: TGraphSampler ( l l d b ) expr TGraphSampler * $tgs = [ TGraphSampler sharedInstance ] ( l l d b ) p * $tgs ( TGraphSampler ) $0 = { NSObject = { isa = TGraphSampler } productObj = 0x0000000103e03f80 listofComponentControl = 0x0000000103e041a0 @”9 elements ” listOfSupervisorC ontrol = 0x0000000103e041d0 @”12 elements ” extratGraphDataSources = 0x0000000103e04520 tGraphDataString = 0x0000000000000000 i s I n t e r n a l = fa ls e gotDataToLogToLiteMode = fa ls e lastLogTimestamp = 38967673125 previousThermalSensorValues = { [ 0 ] = 0 [ 1 ] = 0 [ 2 ] = 0 [ 3 ] = 0 [ 4 ] = 0 [ 5 ] = 0 [ 6 ] = 0