<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Billy Ellis on Medium]]></title>
        <description><![CDATA[Stories by Billy Ellis on Medium]]></description>
        <link>https://medium.com/@bellis1000?source=rss-63f878bdfa21------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0FEDOacmN4qkN7ZTn2ZvBQ@2x.jpeg</url>
            <title>Stories by Billy Ellis on Medium</title>
            <link>https://medium.com/@bellis1000?source=rss-63f878bdfa21------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 00:58:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bellis1000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Memory Visualiser Tool for iOS Security Research]]></title>
            <link>https://bellis1000.medium.com/a-memory-visualiser-tool-for-ios-security-research-bd8bb8c334c6?source=rss-63f878bdfa21------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd8bb8c334c6</guid>
            <dc:creator><![CDATA[Billy Ellis]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 12:17:55 GMT</pubDate>
            <atom:updated>2022-01-01T18:02:20.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nujL7NOwKQCNXBIRIrtmVg.png" /></figure><p>Happy New Year!🥳</p><p>In this post I want to share a recent project of mine — a memory visualiser tool for iOS security researchers.</p><p>I’m releasing an early demo version of this tool starting today, so if you’re interested, be sure to go to <a href="https://zygosec.com/membuddy.html">https://zygosec.com/membuddy.html</a> and try it out.</p><p>The tool is membuddy — a GUI application for macOS that allows you to visualise and track the memory of a target process.</p><p>My inspiration for this visualisation tool came from the countless diagrams found in researchers blogs that depict the relationship between structures in memory when describing a vulnerability or exploit strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*54zScCATCQ8Ht4jF.png" /><figcaption>Source <a href="https://googleprojectzero.blogspot.com/2019/08/in-wild-ios-exploit-chain-3.html">https://googleprojectzero.blogspot.com/2019/08/in-wild-ios-exploit-chain-3.html</a></figcaption></figure><p>These diagrams are incredibly useful when trying to understand a complex idea or relationship between multiple data structures in a target process.</p><p>I wanted to build something that could generate a similar visual representation of memory, but in real-time and when actually debugging an exploit, or working on general analysis of a running process.</p><p>The membuddy macOS app connects to a server running on the iOS device (or theoretically another target system).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ii56yaTS7gxvQeBJwYMxA.png" /></figure><p>Once connected to the target, the macOS app will request memory from the server and display it in the GUI. You can browse the process memory in the memory explorer window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZerbP8Aby6EJpeHZAV2iQ.png" /></figure><p>Much like a standard debugger interface, here you can browse the bytes of memory with the ASCII representation to the right. In the screenshot above we are viewing the Mach header of the iOS kernel process.</p><p>Clicking on values in the memory dump gives you the option to modify the value, or view nested memory if this value is recognised as a pointer.</p><p><strong>Note</strong>: Okay – so the current pointer detection isn’t at all smart. It just checks for the presence of the F’s in the upper bits, so be careful trying to read from something that isn’t <em>actually</em> a pointer because you’ll likely panic)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*TwtWqKgNINkNKjG1NSGF7w.png" /></figure><p>You can also create a new ‘block’ for any memory address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BtvEwNjs61eT8j8T6YL_Tw.png" /></figure><p>This adds a visual block view representing this memory area to the canvas on the right-hand side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qo4Dy2NcX3dACNHEQPEAug.png" /></figure><p>Blocks can also be customised in a few ways. This includes, setting a block name (a label to essentially annotate that particular block), setting a structure type (display struct member names alongside the values) and resizing the block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LgOgZXT6689DQ02KEVdZJQ.png" /></figure><p>With the customisations applied to block in the screenshot above, we can see that this block is representing the XNU proc structure for the kernel process.</p><p>We can interact with block data in the same ways we do in the memory viewer — you can modify values and view memory at addresses.</p><p>The values displayed on each of the blocks are kept in-sync with the live memory of the target process. Memory is refreshed every 1 second by re-requesting memory from the membuddy server.</p><p>Creating a second block that branches from a pointer in the first block adds a visual line connecting the two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ukkspDbyg7McHKFDh4HeWA.png" /></figure><p>Complex arrangements can be made by creating and connecting multiple blocks in the block canvas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nRluISSwvu7t1OpVpL0yew.png" /></figure><p>The blocks can be freely moved around the canvas, and connection lines remain connected to the blocks. This makes the relationship between different memory areas easy to understand.</p><p>Connection lines update accordingly when pointers change to point to new memory.</p><p>We can demonstrate this by replacing the XNU ucred structure on an iOS app.</p><p>For those who are unfamiliar, an app’s ucred holds the credentials and sandbox restrictions associated with the process, so replacing this with a more privileged process’ ucred essentially un-sandboxes the app.</p><p>The following short video shows how we can use membuddy to swap out the ucred.</p><p>https://m.youtube.com/watch?v=zD4AmOa3HBA</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FzD4AmOa3HBA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DzD4AmOa3HBA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FzD4AmOa3HBA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc6a0ca89dcb4f3f86255deac8ec1a9d/href">https://medium.com/media/fc6a0ca89dcb4f3f86255deac8ec1a9d/href</a></iframe><p>The changes in the block connections are reflected in the arrangement of the lines, and the affect this has on the iOS app’s sandbox is apparent thanks to the failure &amp; success alerts displayed when trying to open a connection to a sandbox-protected IOKit user client.</p><p>The membuddy tool is in a proof-of-concept state right now. There’s plenty of bugs to be fixed, and refinements to be made. However, as I mentioned, if you’re interested in trying it you can download an early version of the beta at <a href="https://zygosec.com/membuddy.html">https://zygosec.com/membuddy.html</a>.</p><p>Feedback welcome,</p><p>— Billy Ellis @bellis1000</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd8bb8c334c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Disabling ASLR on 64-bit iOS]]></title>
            <link>https://bellis1000.medium.com/disabling-aslr-on-64-bit-ios-3567a993a459?source=rss-63f878bdfa21------2</link>
            <guid isPermaLink="false">https://medium.com/p/3567a993a459</guid>
            <dc:creator><![CDATA[Billy Ellis]]></dc:creator>
            <pubDate>Sun, 10 Oct 2021 07:53:36 GMT</pubDate>
            <atom:updated>2021-10-10T07:53:36.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfgmjLzm9gY3bA2rRde8Uw.png" /></figure><p><strong>Tl;dr</strong>: <em>There’s a special flag you can add to a process’s </em><em>proc structure. Any child process then spawned by the process will be loaded into memory without ASLR.</em></p><p>In my last blog post, where I discussed the ASLR implementation in the iOS kernel, you may remember me writing about this important detail regarding 64-bit iPhones:</p><blockquote>…in fact, 64-bit iOS enforces it. If you’ve ever dealt with ASLR on 64-bit iOS, you may have noticed that compiling a binary with -fno-pie (to disable position independent code) has no effect — all processes are launched with ASLR regardless.</blockquote><p>(Read the original blog here — <a href="https://bellis1000.medium.com/aslr-the-ios-kernel-how-virtual-address-spaces-are-randomised-d76d14dc7ebb">https://bellis1000.medium.com/aslr-the-ios-kernel-how-virtual-address-spaces-are-randomised-d76d14dc7ebb</a>)</p><p>I wrote this implying that there is <em>no way to disable ASLR</em> for user-space processes on 64-bit iOS, without statically patching the kernel and booting with a bootROM exploit (which is a bit of a hassle).</p><p>This is actually <strong>not </strong>true, as I’ve only recently discovered. So I’m writing this short follow-up post to discuss further :)</p><h4><strong>32-bit vs 64-bit approach</strong></h4><p>As a recap, in the last post I demonstrated a method of completely disabling ASLR on iOS by patching the kernel code in a running 32-bit iOS kernel. On 64-bit iOS, patching kernel code is not as straightforward as on 32-bit due to extra restrictions such as KPP/KTRR.</p><p>There was also another method I touched on in the previous post — to compile binaries with the -fno-pie flag. While not disabling ASLR system-wide, this flag will stop the compiled binary from launching with ASLR in effect. This <em>does not work</em> on 64-bit iOS however. For whatever reason, this flag is ignored on 64-bit iOS and so any binary compiled with it will still have ASLR enabled.</p><p>At the time the last blog post was published, I had only considered these two methods for disabling ASLR.</p><p>However, as it turns out there is a <em>third</em> way to disable ASLR that actually works on 64-bit iOS.</p><p>This third method does not require any modification to kernel code, nor does it require any special compile flags. All we need is a jailbroken device with task-for-pid-zero access.</p><h4>The 64-bit method</h4><p>It might sound like I’m ‘bigging’ this up a bit. I shouldn’t be. After all, this is nothing crazy, not like a new iOS 0day or some ground-breaking discovery. It’s possible people have already been using this method. I just haven’t seen anything online about it, and all other researchers I’ve spoken with didn’t suggest it.</p><p>It’s technically already public knowledge, and that’s actually how I first found out about it.</p><p>While browsing XNU source code one day I stumbled upon the following comment in the function posix_spawn() in the file kern_exec.c.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6keAPebpD3IQgJVS536z0A.png" /></figure><p>The comment here is describing the meaning of a specific flag value that processes can have present on their proc structure.</p><p>The last part of the comment details how we can disable ASLR.</p><blockquote>… or if P_DISABLE_ASLR was inherited from the parent process.</blockquote><p>During the early stages of process creation on iOS, new processes inherit the entire proc structure from the process that initiated its execution (the ‘parent process’).</p><p>The majority of processes’ parent on iOS will be launchd. So, if we believe the above comment to be true, in theory we should be able to disable ASLR for most processes/apps by setting this special P_DISABLE_ASLR flag in launchd&#39;s proc structure.</p><p>New processes launched by launchd will then inherit this special flag, and when mapped into memory, the kernel will not bother generating an ASLR slide for them.</p><p>All proc structures are stored on the kernel heap, which of course <em>must</em> <em>be writeable</em>, so we’ll have no issues regarding memory protections like we would if we tried modifying kernel code like with the 32-bit method.</p><p>The P_DISABLE_ASLR constant is one of the multiple possible flag bits that can be set on the p_flag property of a proc structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWyUbvFB0PIorFX30zrcug.png" /></figure><p>Depending on your iOS kernel version, the offset to this flag will differ slightly. On my iOS 12 device, the p_flag was at offset 0x13c from the start of a given proc structure.</p><p>The definitions for all of the flag options (including P_DISABLE_ASLR) can be found in the file proc.h in the XNU source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4fNcRxIu-vFqOfCAZn0kg.png" /></figure><p>As we can see, the constant P_DISABLE_ASLR is defined as value 0x1000 (only bit 12 is set).</p><p>There’s probably some interesting functionality to be discovered messing with the other available flags here also, so feel free to explore those.</p><p>Setting the P_DISABLE_ASLR flag on an arbitrary process is straightforward enough.</p><p>With kernel memory access granted to us by task-for-pid-zero, we can locate an arbitrary proc structure, and then directly write into the memory from user-space to add this special flag.</p><p>I have a video on my YouTube channel discussing proc structures in more detail, and how to locate them in the kernel memory here — <a href="https://www.youtube.com/watch?v=iXAlfTDSmwU&amp;t=406s&amp;ab_channel=BillyEllis">https://www.youtube.com/watch?v=iXAlfTDSmwU&amp;t=406s&amp;ab_channel=BillyEllis</a>.</p><p>Essentially, we can locate the proc structure for a given process by starting with the kernel’s <em>own</em> proc structure (which is at a hard-coded kernel address) and then following the proc-&gt;next pointer until we arrive at the desired proc structure, checking the proc-&gt;p_ppid value along the way against the process’s PID that we’re searching for.</p><p>Once the P_DISABLE_ASLR flag has been added to the p_flag variable in launchd&#39;s proc, all apps and processes launched via launchd from this point on will be free of ASLR.</p><p>It’s also a good idea to apply the flag to sh (so that binaries you run through terminal also have ASLR disabled), as well as any other process that <em>might</em> launch a child process.</p><p>Below is an example output after adding the flag to launchd and sh. As you can see by the size of the pointers, this is a 64-bit iOS device and ASLR is not in effect :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xgWIs5Yz03KggYxwXTlH1w.png" /></figure><p>So yeah, turns out it isn’t too difficult to disable ASLR on 64-bit iOS after all.</p><p>For those of you who have contacted me in the past regarding my exploit challenges on 64-bit, you’ll be pleased to know that using this method you will be able to follow along the same way as you would on 32-bit devices (no need to add an info-leak in the earlier challenges).</p><p>Check out the challenges here if you’re interested in learning exploit development on ARM — <a href="https://github.com/Billy-Ellis/Exploit-Challenges">https://github.com/Billy-Ellis/Exploit-Challenges</a></p><p>For anyone wishing to disable ASLR for another reason, hopefully this aids your research.</p><p>Have a look at part 1 of this blog if you’re interested in how the kernel actually generates the ASLR slide and applies it to processes — <a href="https://bellis1000.medium.com/aslr-the-ios-kernel-how-virtual-address-spaces-are-randomised-d76d14dc7ebb">https://bellis1000.medium.com/aslr-the-ios-kernel-how-virtual-address-spaces-are-randomised-d76d14dc7ebb</a></p><p>Feedback always welcome. Thanks :)</p><p>— Billy Ellis @bellis1000</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3567a993a459" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASLR & the iOS Kernel — How virtual address spaces are randomised]]></title>
            <link>https://bellis1000.medium.com/aslr-the-ios-kernel-how-virtual-address-spaces-are-randomised-d76d14dc7ebb?source=rss-63f878bdfa21------2</link>
            <guid isPermaLink="false">https://medium.com/p/d76d14dc7ebb</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[aslr]]></category>
            <dc:creator><![CDATA[Billy Ellis]]></dc:creator>
            <pubDate>Sun, 06 Dec 2020 11:36:29 GMT</pubDate>
            <atom:updated>2020-12-06T13:25:48.052Z</atom:updated>
            <content:encoded><![CDATA[<h3>ASLR &amp; the iOS Kernel — How virtual address spaces are randomised</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NOH0rBTBYD0T29-KZ7jzvA.png" /></figure><p>In this blog post I want to take a look at ASLR and how the iOS kernel implements it for user-space processes.</p><p>We’ll cover:</p><ul><li>what ASLR actually is and how it aims to mitigate exploitation</li><li>how the iOS kernel implements ASLR for apps &amp; processes that are executed on the device</li><li>a short experiment you can try that involves patching the iOS kernel to disable ASLR across all user-space processes!</li></ul><h4><strong>What is ASLR?</strong></h4><p>ASLR stands for ‘Address Space Layout Randomisation’ — it is a security mitigation found in pretty much all systems today.</p><p>It aims to make it difficult for an exploit developer to locate specific parts of a program in memory by randomising the memory address space of the program each time it is launched.</p><p>This results in the exploit developer not being able to predict the memory location of variables and functions within their target, adding a layer of difficulty to common exploit techniques like Return Oriented Programming.</p><p>The way ASLR implements this randomisation is by <em>sliding</em> the entire process address space by a given amount. This given amount is known as the ‘slide’ or the ‘offset’.</p><p>The following diagram aims to illustrate how a process <em>without</em> ASLR compares to a process <em>with</em> ASLR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*poVLblqLoGLLFgP--O2f0A.png" /></figure><p>Looking at the diagram, Process A is loaded into memory at a static virtual address — 0x10000. Process A will <em>always</em> be loaded into memory starting at the same base address due to the lack of ASLR. This means that an attacker can easily predict where specific variables and functions will be in memory.</p><p>Process B, on the other hand, is loaded into memory at starting at base address 0x14c00. This base address is dynamically calculated — every time Process B is launched, a slide value is generated at random and added to the static base address.</p><p>In the diagram the random slide value used is 0x4c00. This value is added to the static base address — 0x10000 — which results in a new, randomised, base address.</p><p>0x10000 + 0x4c00 = 0x14c00</p><p>Every time Process B is launched, a new slide value will be chosen at random and therefore the base address (and the address of everything else in the binary) will be different each time.</p><p>Unlike with Process A, an attacker <em>cannot</em> easily determine where in memory specific variables and functions will be located in Process B. This is the goal of ASLR.</p><p>Note that the <em>entire</em> address space is shifted by the slide amount, resulting in variables and functions still being located at the same <em>relative</em> position to each other. This means that if the memory location of a single variable or function can be leaked, the address of everything else in the process can easily be calculated, thus defeating ASLR altogether.</p><p>Exploit developers often rely on an information leak vulnerability — a bug that leaks a pointer from the target process — in order to defeat ASLR using this method.</p><h4>ASLR on iOS</h4><p>On iOS (and on most other operating systems) ASLR is implemented for both the kernel and the user-land processes.</p><p>The kernel’s ASLR slide is randomised on every reboot. The slide value is generated by iBoot, the second stage boot-loader, during the boot process.</p><p>For user-land processes, the ASLR slide is randomised every time a process is executed. Every user-space process has a unique slide. The slide value is generated by the kernel during the binary loading routine.</p><p>In this blog post we will be focusing <em>only</em> on the user-land ASLR in iOS, and more specifically how the kernel implements it.</p><p>The iOS kernel is based on XNU, and XNU is open source. This makes it fairly easy to look into how parts of the iOS kernel work as we can refer directly to the source code.</p><p>The iOS kernel isn’t a direct result of compiling XNU however. Apple adds new, iOS-specific, code to XNU and these parts are kept closed source, although referring to the XNU source code is generally still very useful for getting a high-level understanding of parts of the iOS kernel code base.</p><p>The function load_machfile() in bsd/kern/mach_loader.c in XNU is responsible for parsing a given Mach-O file (the executable format used on iOS) and setting up a new task, loading it into memory etc. Every time you open an app or run a binary on your iPhone, this function is called in the kernel.</p><p>It’s in this function that the ASLR slide for the new process is generated.</p><p>In load_machfile(), after the initial setup of creating a new pmap and vm_map for the to-be process, we reach the code responsible for generating the ASLR slide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b78UDZZEquYNmy8g23Ym9A.png" /></figure><p>There’s actually two ASLR slide values being generated here — one for the new process and one for dyld. Both are generated in the same way.</p><p>Firstly, a random 32-bit value is generated by the call to random().</p><p>Secondly, this random value is ‘trimmed’ down so that it does not exceed the maximum slide value. On 32-bit, this value gets trimmed down to just one byte. On 64-bit it’s two.</p><p>Thirdly, the trimmed value is shifted left by an amount depending on the host’s page size.</p><p>The resulting value is the ASLR slide.</p><p>For example:</p><ol><li>random() returns 0x3910fb29</li></ol><p>2. Value 0x3910fb29 is trimmed down to 0x29(assuming 32-bit OS)</p><p>3. Byte 0x29 is shifted left by 0x12 (the page shift amount)</p><p>The resulting 0x29000 is the ASLR slide value that will be used for this new process.</p><p>Shortly after the slide values are generated, load_machfile() calls into another function — parse_machfile(). This function is much larger and proceeds to load each Mach-O segment into the virtual memory space, perform code-signing-related tasks and ultimately launch the new process.</p><p>To see ASLR in effect, compile the following program on your iOS device.</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;</pre><pre>char *str = &quot;HELLO ASLR&quot;;</pre><pre>int main() {</pre><pre>    printf(&quot;ptr %p\n&quot;, str);</pre><pre>    return 0;<br>}</pre><p>This code prints a pointer (using the %p format specifier) to a static char array stored in the binary.</p><p>Compile this code using the -fpie flag. This flag enables the code to be ‘position independent’ — essentially meaning it supports address space randomisation.</p><p>This should actually be enabled automatically and, in fact, 64-bit iOS enforces it. If you’ve ever dealt with ASLR on 64-bit iOS, you may have noticed that compiling a binary with -fno-pie (to disable position independent code) has no effect — all processes are launched with ASLR regardless.</p><p>If you run the above program a few times, you’ll notice that the pointer to the static char array changes on each new execution. This is due to a new slide value being generated by the kernel each time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IcRYGIYEA9iBfVYhgyle9Q.png" /></figure><p>You may also notice that the three right-most hexadecimal digits remain the same — this makes sense as we know from the kernel code that the format of the slide value will always be 0xXX000.</p><h4>Patching the iOS kernel</h4><p>A nice experiment you can try given the knowledge above is to actually patch the iOS kernel so that ASLR is disabled system wide.</p><p>This is fairly straightforward to do — only a single instruction needs to be changed in the kernel in order for the ASLR slide to always be set to 0x0.</p><p>With a patch like this applied, all apps and processes executed (even those compiled with -fpie) will be mapped into memory at their static binary mapping.</p><p>This can even be potentially useful for other debugging/reversing tasks on iOS — having ASLR disabled at the kernel level can save you time having to recompile programs with the -fno-pie flag, or having to modify AppStore apps in order to run them without ASLR.</p><p>Unfortunately, due to KPP/KTRR on 64-bit iOS preventing us from writing to the __TEXT segment (the code section) of the kernel, we’ll be limited to using a 32-bit jailbroken device for this exercise.</p><p>You <em>could</em> apply the same patch in a static 64-bit kernel cache and boot the custom kernel on a device using an exploit like checkm8. But in this blog I’ll stick to patching it dynamically on 32-bit iOS 9.0 on my iPhone 5C.</p><p>Yeah, I guess 32-bit iOS is a bit redundant these days, but oh well. It’s still a cool little experiment to try out.</p><p>The first step is to locate the load_machfile() function in the iOS kernel for your chosen device.</p><p>Unfortunately the symbol for this function isn’t available in the RELEASE kernels so I had to locate it by searching for specific instruction patterns and using cross-references from other functions that <em>do</em> have symbols.</p><p>Locating the specific code is beyond the scope of this post, but if you’d like to see a similar reverse engineering task where I go into detail about locating a specific part of kernel code, check out my previous blog — <a href="https://medium.com/@bellis1000/exploring-the-ios-screen-frame-buffer-a-kernel-reversing-experiment-6cbf9847365">https://medium.com/@bellis1000/exploring-the-ios-screen-frame-buffer-a-kernel-reversing-experiment-6cbf9847365</a></p><p>Here’s a snippet of the assembly code (taken from Ghidra) responsible for generating the ASLR slide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*2h8Bwo2SlWalsbxCEjovcg.png" /></figure><p>This is from the same part of code in the load_machfile() function that we looked at previously. The same three steps used to generate the slide are handled here, although for the initial random value generation, read_random() is being called instead of random().</p><p>There’s quite a bit of flexibility here with how we go about applying a patch to this — we just need to set the slide value to 0x0, every time. That’s the aim. It doesn’t really matter how we do it.</p><p>You could:</p><ul><li>NOP-out this whole section of code so there’s no random generation at all</li><li>patch read_random() to always return 0x0, so the random number isn’t <em>actually</em> random</li><li>overwrite the random slide value with 0x0 right after it is generated</li></ul><p>The method I‘m choosing is to patch the instruction bic r0, r1, 0x80000000. This instruction performs a bitwise AND operation on R1 and value 0x80000000. This is the last time the slide value (held in R0) is modified before it is passed to vm_map_page_shift().</p><p>If we can set the value to 0x0 just before the call to vm_map_page_shift() we will effectively disable ASLR. If the value is 0x0, shifting it by <em>any</em> amount — left or right — will still result in 0x0.</p><p>The ARM instruction bic r0, r1, 0x80000000 is represented by four bytes — 21 f0 00 40. This part of the kernel is actually in Thumb mode (making use of a combination of 16-bit and 32-bit instructions) so we must be careful to replace the instruction with the <em>same amount of bytes</em> to avoid messing up the alignment.</p><p>The instruction I want to replace it with is movs r0, 0x0 — this will reset the value of R0 to 0x0, thus overwriting the random bytes used for the slide.</p><p>However, this instruction is represented by only <em>two</em> bytes — 00 20— not four.</p><p>This isn’t really a problem though. All we need to do is replace the bic r0, r1, 0x80000000 instruction with <em>two</em> of the movs r0, 0x0 instructions so that we make up the amount of bytes.</p><p>So essentially:</p><pre>bic r0, r1, 0x80000000</pre><p>becomes:</p><pre>movs r0, 0x0<br>movs r0, 0x0</pre><p>The first time movs r0, 0x0 is executed, R0 will be set to zero. The second time it is executed nothing happens. It essentially acts as a NOP (no-operation) instruction. It does the exact same thing <em>again</em>, leaving no visible change in the register state.</p><p>I wrote a program that applies this patch to the kernel using vm_write() from the Mach API.</p><p>I have the instructions hard-coded — both the bic r0, r1, 0x80000000 and the <em>two</em> movs r0, 0x0 joined together.</p><pre>#define DISABLE_BYTES       0x20002000 // movs r0, 0x0 x 2<br>#define ENABLE_BYTES        0x4000f021 // bic r0, r1, 0x80000000</pre><p>This allows me to easily disable <em>and</em> re-enable ASLR. All I have to do is patch the instruction with DISABLE_BYTES to disable ASLR, and un-patch the instruction by restoring the original bytes (using ENABLE_BYTES) to enable it again.</p><p>I also have the address of the target instruction.</p><pre>#define INSTR_TO_PATCH_ADDR 0x802a3cc4</pre><p>This address is specific to the iOS 9.0 kernel for iPhone5,4. If you want to try this yourself, you’ll need the address of this same instruction but for whichever kernel and device you’re using.</p><p>The code then simply reads from the instruction address to determine whether or not ASLR is currently enabled or disabled, and then applies the patch by writing the <em>opposite</em> set of bytes to toggle it.</p><p>Below is the code for this program.</p><pre>    uint32_t slide = get_kernel_slide();<br>    printf(&quot;[+] KASLR slide is %08x\n&quot;, slide);</pre><pre>    uint32_t current_bytes = do_kernel_read(INSTR_TO_PATCH_ADDR + slide);</pre><pre>    printf(&quot;[+] Current bytes %08x\n&quot;, current_bytes);</pre><pre>    if (current_bytes == ENABLE_BYTES) {<br>        do_kernel_write(INSTR_TO_PATCH_ADDR + slide, DISABLE_BYTES);<br>        printf(&quot;[+] Patched ASLR random instruction. ASLR disabled.\n&quot;);<br>    } else {<br>        do_kernel_write(INSTR_TO_PATCH_ADDR + slide, ENABLE_BYTES);<br>        printf(&quot;[+] Patched ASLR random instruction. ASLR enabled again.\n&quot;);<br>    }</pre><p>Note: the functions get_kernel_slide(), do_kernel_read() &amp; do_kernel_write() are all wrapper functions for Mach API calls that I have written. The code for these will be available on Github.</p><p>Now to see this code in action!</p><p>We’ll first run the test program a few times to verify that ASLR is enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jf5oPv-QCJSbECsoejzTqA.png" /></figure><p>The addresses are randomised each time. Now we run the pwn_aslr program to patch the kernel code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fumpO5CnpJW_5NApgbQqmQ.png" /></figure><p>The bic r0, r1, 0x80000000 instruction has been patched and ASLR has been disabled. Now we re-run the test program to verify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75SOANMMfSkWM6MoF5_DBg.png" /></figure><p>Now the addresses are static! The kernel patch worked and ASLR is no longer in effect.</p><p>Here’s a quick demo video showing the above in real time <a href="https://youtu.be/D_pnGfTMYUI">https://youtu.be/D_pnGfTMYUI</a>.</p><p>The code for this tool is available on my Github if you want to explore it yourself. As I mentioned, you’ll need to find the address of the kernel instruction you want to patch for the specific device + kernel combination you’re using, unless you’re using iOS 9.0 on iPhone5,4.</p><p>You could also probably implement something similar on 64-bit if you use <a href="https://twitter.com/qwertyoruiopz">Luca Todesco</a>’s KPP bypass or <a href="https://twitter.com/_bazad">Brandon Azad</a>’s A11 KTRR bypass.</p><p>Link to the code — <a href="https://github.com/Billy-Ellis/aslr-kernel-patch">https://github.com/Billy-Ellis/aslr-kernel-patch</a></p><p>Feedback always welcome. Thanks!</p><p>— Billy Ellis @bellis1000</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d76d14dc7ebb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the iOS screen frame-buffer– a kernel reversing experiment]]></title>
            <link>https://bellis1000.medium.com/exploring-the-ios-screen-frame-buffer-a-kernel-reversing-experiment-6cbf9847365?source=rss-63f878bdfa21------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cbf9847365</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[kernel]]></category>
            <dc:creator><![CDATA[Billy Ellis]]></dc:creator>
            <pubDate>Sat, 18 Jan 2020 20:41:53 GMT</pubDate>
            <atom:updated>2020-02-15T13:53:07.875Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Exploring the iOS screen framebuffer– a kernel reversing experiment</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_X7-f8w33-urqCdM2FXVA.jpeg" /></figure><p>It’s been over two years since I last published a blog, so I thought I’d give this another go in 2020 and kick it off by writing about an iOS-related project I’ve been working on over the last couple weeks – a reverse engineering task involving the iOS screen frame-buffer.</p><p>First of all, my inspiration to start looking at this came shortly after the release of the checkra1n jailbreak for the iPhone 5S – iPhone X. If you haven’t yet played with checkra1n, check it out here – https://checkra.in/.</p><p>One of the things checkra1n does during the jailbreaking process is display a series of debug messages on the phone’s screen to let the user know about the progress of the jailbreak, and allow them to see what went wrong in the event of the jailbreak failing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjFLr08PX7_8r4y6I9AGvA.jpeg" /></figure><p>These debug messages are written to the display over the top of the standard boot screen. I was intrigued by this and started to wonder how the checkra1n team had implemented it. I heard some phrases thrown around online mentioning the use of a “framebuffer” and that the jailbreak tool was somehow “writing” to it.</p><p>So I set myself the challenge of figuring out how this worked and how I could replicate this in order render some characters on the screen by directly manipulating the pixels.</p><h4><strong>Locating the iOS frame-buffer in kernel memory</strong></h4><p>The first step towards reaching my goal of writing custom characters to the screen was to find where in memory the screen pixel data was stored.</p><p>The checkra1n tool manipulates pixels in the framebuffer during the iBoot stage of the boot process, which is why we see the debug messages printed over the Apple boot-logo. I decided to take a different approach and focus on an already-booted iPhone.</p><p>The only difference meant dealing with kernel memory as opposed to iBoot memory, and dealing with the kernel memory seemed like the simpler approach as I could get started right away without having to construct a fully patched boot-chain etc.</p><p>I started digging around to find where the iOS kernel holds the screen pixel data in memory. Knowing this memory location would allow me to write to it (assuming I’m using a jailbroken device with a TFP0 patch) resulting in the colour of the pixels changing.</p><p>My first thought was to see if there was some kind of framebuffer symbol within the iOS kernel.</p><p>I opened a decrypted kernelcache file (for this, I’m using an iPhone3,1 iOS 7.1.2 kernel) in Hopper disassembler and searched for “framebuffer” but no luck :(</p><p>Despite not finding any symbols, Hopper did find a string containing “framebuffer”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*NIkg8erZ5wqvsThsd1puAA.png" /></figure><p>This string appeared to be some kind of debug message coming from the function initialize_screen. I went to the XNU source code to confirm this function actually existed and found it in the file <a href="https://github.com/apple/darwin-xnu/blob/a449c6a3b8014d9406c2ddbdc81795da24aa7443/osfmk/console/video_console.c">https://github.com/apple/darwin-xnu/blob/a449c6a3b8014d9406c2ddbdc81795da24aa7443/osfmk/console/video_console.c</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EcsN9HT9nJjEPvpfwmOENA.png" /></figure><p>Looking at the first few lines of code in this function it is clear that this function is responsible for setting up the device’s screen and assigning values for the width, height, colour depth etc.</p><p>The first argument to this function is a pointer to a PE_Video structure. I went to where this struct was defined (in <a href="https://github.com/apple/darwin-xnu/blob/master/pexpert/pexpert/pexpert.h">https://github.com/apple/darwin-xnu/blob/master/pexpert/pexpert/pexpert.h</a>) and found that it holds some information about the host’s screen, including the width, height, colour depth and a base address of where in memory the pixel data actually lies.</p><pre>struct PE_Video {        <br>    unsigned long   v_baseAddr;     /* Base address of video memory */        <br>    unsigned long   v_rowBytes;     /* Number of bytes per pixel row */        <br>    unsigned long   v_width;        /* Width */        <br>    unsigned long   v_height;       /* Height */        <br>    unsigned long   v_depth;        /* Pixel Depth */        <br>    unsigned long   v_display;      /* Text or Graphics */ <br>    char  v_pixelFormat[64]; <br>    unsigned long v_offset; /* offset into video memory to start at */ <br>    unsigned long v_length; /* length of video memory (0 for v_rowBytes * v_height) */ <br>    unsigned char v_rotate; /* Rotation: 0:normal, 1:right 90, 2:left 180, 3:left 90 */ <br>    unsigned char v_scale; /* Scale Factor for both X &amp; Y */ <br>    char  reserved1[2];<br>#ifdef __LP64__ <br>    long  reserved2;<br>#else <br>    long  v_baseAddrHigh;<br>#endif<br>};</pre><p>If I could find this structure sitting in the kernel memory I’d be able to follow the v_baseAddr pointer and find the raw pixel data.</p><p>I followed the first XREF from the debug string I had found in the iOS kernelcache and landed in the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HsIxDKF8wOos_UUpv0F5Yw.png" /></figure><p>If this code was part of initialize_screen then I’d have a chance at finding the address of this PE_Video structure in here.</p><p>There was no symbol for initialize_screen in the binary so I couldn’t tell for sure if the code I had found myself in was actually initialize_screen but a couple of observations between the disassembly and the source code left me pretty confident that it probably was.</p><p>I did a bit of digging and found out that the PE_Video structure is only used when setting up the screen initially, and that the screen information was actually held somewhere else after the kernel had properly started.</p><p>The values passed in through the PE_Video structure are copied over to a global vc_info structure named vinfo further down in the code.</p><p>Looking at the definition for vc_info we can see that it is similar to the PE_Video structure in terms of the information it holds about the screen:</p><pre>struct vc_info{ <br>    unsigned int v_height; /* pixels */ <br>    unsigned int v_width; /* pixels */ <br>    unsigned int v_depth; <br>    unsigned int v_rowbytes; <br>    unsigned long v_baseaddr; <br>    unsigned int v_type; <br>    char  v_name[32]; <br>    uint64_t v_physaddr; <br>    unsigned int v_rows;  /* characters */ <br>    unsigned int v_columns; /* characters */ <br>    unsigned int v_rowscanbytes; /* Actualy number of bytes used for     display per row*/ <br>    unsigned int v_scale;  <br>    unsigned int v_rotate; <br>    unsigned int v_reserved[3];<br>};</pre><p>The vinfo structure is assigned its values between calls to simple_lock and simple_unlock in initialize_screen.</p><pre>if (vc_progress) { <br>    simple_lock(&amp;vc_progress_lock); <br>    vinfo = new_vinfo; <br>    simple_unlock(&amp;vc_progress_lock); <br>}</pre><p>Locating this code in the disassembly was relatively easy as we had some pretty clear ‘markers’ to look out for — the lock and unlock functions.</p><p>Here is the disassembly of the above code in the iOS kernel (note: in the kernel version I was using for this, the lock and unlock functions used were actually _lck_spin_lock and _lck_spin_unlock instead of simple_lock and simple_unlock):</p><pre>8011c688         <strong>blx</strong>        _lck_spin_lock                                      <br>8011c68c         <strong>ldr</strong>        r0, [sp, #-0x8 + 56]<br>8011c68e         <strong>add.w</strong>      r1, fp, #0x8<br>8011c692         <strong>str.w</strong>      r0, [fp]<br>8011c696         <strong>ldr</strong>        r0, [sp, #-0x8 + 20]<br>8011c698         <strong>str.w</strong>      r0, [fp, #0x4]<br>8011c69c         <strong>ldr</strong>        r0, [sp, #-0x8 + 52]<br>8011c69e         <strong>stm.w</strong>      r1, {r0, r8, sl}<br>8011c6a2         <strong>ldr</strong>        r0, [sp, #-0x8 + 24]<br>8011c6a4         <strong>str.w</strong>      r0, [fp, #0x14]<br>8011c6a8         <strong>movs</strong>       r0, #0x0<br>8011c6aa         <strong>strb.w</strong>     r0, [fp, #0x18]<br>8011c6ae         <strong>ldr</strong>        r0, [sp, #-0x8 + 28]<br>8011c6b0         <strong>vld1.8</strong>     {d16, d17}, [r0]<br>8011c6b4         <strong>add</strong>        r0, sp, #0x54<br>8011c6b6         <strong>vld1.32</strong>    {d18, d19}, [r0]<br>8011c6ba         <strong>ldr</strong>        r0, [sp, #-0x8 + 36]<br>8011c6bc         <strong>vst1.8</strong>     {d16, d17}, [r0]<br>8011c6c0         <strong>ldr</strong>        r0, [sp, #-0x8 + 40]<br>8011c6c2         <strong>vst1.8</strong>     {d18, d19}, [r0]<br>8011c6c6         <strong>ldr</strong>        r0, [sp, #-0x8 + 60]<br>8011c6c8         <strong>str.w</strong>      r0, [fp, #0x3c]<br>8011c6cc         <strong>str.w</strong>      r5, [fp, #0x38]<br>8011c6d0         <strong>ldr</strong>        r0, [sp, #-0x8 + 88]<br>8011c6d2         <strong>vldr</strong>       d16, [sp, #-0x8 + 80]<br>8011c6d6         <strong>str.w</strong>      r0, [fp, #0x48]<br>8011c6da         <strong>ldr</strong>        r0, [sp, #-0x8 + 32]<br>8011c6dc         <strong>vstr</strong>       d16, [fp, #0x40]<br>8011c6e0         <strong>str.w</strong>      r0, [fp, #0x4c]<br>8011c6e4         <strong>add</strong>        r0, sp, #0x38<br>8011c6e6         <strong>vld1.32</strong>    {d16, d17}, [r0]<br>8011c6ea         <strong>ldr</strong>        r0, [sp, #-0x8 + 44]<br>8011c6ec         <strong>vst1.64</strong>    {d16, d17}, [r0, #0x80]<br>8011c6f0         <strong>mov</strong>        r0, r6<br>8011c6f2         <strong>blx</strong>        _lck_spin_unlock</pre><p>The series of STR and LDR instructions in the above assembly code are copying each of the values out of the PE_Video struct over to the new vc_info struct.</p><p>I decided to go to the same code in Ghidra, in pseudo code view, as it helped display the memory addresses that were being written to a little clearer.</p><pre>_lck_spin_lock(&amp;DAT_8037d714);<br>DAT_8037f260 = uStack104;<br>DAT_8037f268 = uStack108;<br>uRam8037f278 = 0;<br>uRam8037f29c = uStack100;<br>uRam8037f2b0 = CONCAT44(uStack96,uStack96);<br>uRam8037f2b8 = CONCAT44(uStack92,uStack92);<br>DAT_8037f264 = uVar12;<br>DAT_8037f26c = uVar14;<br>DAT_8037f270 = iVar15;<br>uRam8037f274 = uVar11;<br>uRam8037f298 = uVar7;<br>_DAT_8037f2a0 = uVar4;<br>DAT_8037f2a8 = iVar5;<br>uRam8037f2ac = uVar10;<br>_lck_spin_unlock(&amp;DAT_8037d714);</pre><p>The address 0x8037f260 is written to first, on the line DAT_8037f260 = uStack104;. This is actually the base address of the vc_info structure in memory. All other addresses written to in the above code are relative to this address.</p><p>Taking this address, adding the KASLR slide and reading some bytes from it produced the following output:</p><pre>Billys-N90AP:/var/mobile root# ./kernread 0x9B17F260 0x50<br>0x9b17f260: 000003c0 00000280 00000020 00000a00 | � �<br>0x9b17f270: 92e31000 00000000 00000000 ffff0000 | ��   ��</pre><p>Nice! This definitely looks like it is the vc_info structure.</p><p>We can confirm that this is the case by comparing the values against the struct definition — the 3c0 and 280 (in hex) should represent the screen height and width in pixels. This checks out as I’m using an iPhone with a 3.5 inch display, so the decimal conversions of these values (960 and 640) are accurate.</p><p>The 5th value in the memory dump is what I was looking for — the v_baseaddr pointer to the start of the raw pixel data. Reading from this memory, we see a bunch of ffffffff values.</p><pre>Billys-N90AP:/var/mobile root# ./kernread 0x92e31000 0x100<br>0x92e31000: ffffffff ffffffff ffffffff ffffffff | ���� ���� ����<br>0x92e31010: ffffffff ffffffff ffffffff ffffffff | ���� ���� ���� <br>0x92e31020: ffffffff ffffffff ffffffff ffffffff | ���� ���� ���� <br>0x92e31030: ffffffff ffffffff ffffffff ffffffff | ���� ���� ���� <br>0x92e31040: ffffffff ffffffff ffffffff ffffffff | ���� ���� ����</pre><p>This is because at the time of reading the memory, I had an app open on the iPhone’s screen with a white background, so these ffffffff values are representing those white pixels.</p><p>However, when I read from the same memory when on the home screen, we get a different result:</p><pre>Billys-N90AP:/var/mobile root# ./kernread 0x92e31000 0x100<br>0x92e31000: ff162341 ff162342 ff172442 ff152241 | �#A �#B �$B �&quot;A<br>0x92e31010: ff152342 ff162342 ff162341 ff162241 | �#B �#B �#A �&quot;A<br>0x92e31020: ff172341 ff162241 ff172341 ff162241 | �#A �&quot;A �#A �&quot;A<br>0x92e31030: ff172240 ff172341 ff172241 ff172140 | �&quot;@ �#A �&quot;A �!@<br>0x92e31040: ff172141 ff172341 ff16203e ff152041 | �!A �#A � &gt; � A</pre><p>These values are representing the blues and greens found on the default iOS 7 wallpaper on the SpringBoard.</p><h4>Manipulating the pixels</h4><p>Now that we know exactly where the screen pixel values are held in kernel memory, we can move on to actually manipulating them.</p><p>I started by writing a small program that writes some black and white pixels to the screen, just to test that any changes I made to the memory actually affected what was being displayed on the screen.</p><p>The result looked something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n6iVGG1QHlHwlI595lwrPQ.jpeg" /></figure><p>So now I had confirmed that this was indeed the framebuffer and changes to the memory resulted in changes to what we see on the device’s screen almost immediately.</p><p>Cool! Now we can look at actually rendering something potentially useful.</p><h4><strong>Rendering characters</strong></h4><p>The next step was to figure out how to actually render alpha-numeric characters so we can print our own text strings over the display.</p><p>I did some more digging around the XNU source and found some functions that appeared to be responsible for rendering characters on the screen. One of these functions was vc_render_char.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BOGvR00_n_FyZg4SlX8mmA.png" /></figure><p>This function follows an algorithm that renders a specific character on the screen. The font used here is the iso_font which is the same font that is used during the verbose boot mode on iOS and macOS. It is defined as a 256*16 byte array in the file <a href="https://github.com/apple/darwin-xnu/blob/master/osfmk/console/iso_font.c">https://github.com/apple/darwin-xnu/blob/master/osfmk/console/iso_font.c</a>.</p><p>The algorithm to render the characters works by taking a desired character — say ‘A’ — and using its ASCII code (65) multiplied by the desired character height in pixels and using it as an index into the iso_font array.</p><p>A series of bit-shifts and bitwise ANDs are then performed on the values to produce an output value. Depending on this output value, either a black or white pixel is written to the framebuffer.</p><p>I wrote some code to test if I could generate a character based on this algorithm, using the iso_font. The output was as follows:</p><pre>~/Documents/dev ./print_char<br>1 1 1 1 1 1 1 1<br>1 1 1 1 1 1 1 1<br>1 0 0 0 0 0 1 1<br>0 0 1 1 1 0 0 1<br>0 0 1 1 1 0 0 1<br>0 0 1 1 1 0 0 1<br>0 0 0 0 0 0 0 1<br>0 0 1 1 1 0 0 1<br>0 0 1 1 1 0 0 1<br>0 0 1 1 1 0 0 1<br>0 0 1 1 1 0 0 1<br>0 0 1 1 1 0 0 1<br>1 1 1 1 1 1 1 1<br>1 1 1 1 1 1 1 1<br>1 1 1 1 1 1 1 1<br>~/Documents/dev</pre><p>Looking closely at the above output, you can see that the 0 characters create the shape of a capital A and the 1 characters act as a background.</p><p>To translate this to screen pixel data all we have to do is render a white pixel when the value returned is a 0 and a black pixel when the value returned is a 1.</p><p><strong>Final outcome</strong></p><p>As a result of the above research, I managed write a program that allows me to render arbitrary text strings to the iPhone’s screen by directly modifying the framebuffer pixels!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GH6gsh2BPEf6NEp1mMOfUw.jpeg" /></figure><p>I guess this research doesn’t have any real practical use, but it was a fun project to work on and the end result looks pretty cool ;)</p><p>If you want to try running this code on your own jailbroken device, you can find the code for my fb_write tool here <a href="https://github.com/Billy-Ellis/framebuffer_write">https://github.com/Billy-Ellis/framebuffer_write</a>.</p><p>Right now the offsets are hard-coded for the iPhone3,1 running iOS 7.1.2, but you can add your own for other devices you want to try this on.</p><p>Hopefully you enjoyed this post and got something out of it! Feedback is welcome — you can contact me @bellis1000 on Twitter or billy@zygosec.com via e-mail.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cbf9847365" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>