<?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 0xor0ne on Medium]]></title>
        <description><![CDATA[Stories by 0xor0ne on Medium]]></description>
        <link>https://medium.com/@0xor0ne?source=rss-288aae063d05------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*J67OsIeA31fU6fYGwENDlg.jpeg</url>
            <title>Stories by 0xor0ne on Medium</title>
            <link>https://medium.com/@0xor0ne?source=rss-288aae063d05------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:35:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xor0ne/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[CyberSecurity Digest #3: Beginners Cryptography, Makefiles, Home Routers and Car Infotainment…]]></title>
            <link>https://medium.com/@0xor0ne/cybersecurity-digest-3-beginners-cryptography-makefiles-home-routers-and-car-infotainment-4292aed6661b?source=rss-288aae063d05------2</link>
            <guid isPermaLink="false">https://medium.com/p/4292aed6661b</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[0xor0ne]]></dc:creator>
            <pubDate>Wed, 05 Jul 2023 17:02:19 GMT</pubDate>
            <atom:updated>2023-07-05T17:02:19.655Z</atom:updated>
            <content:encoded><![CDATA[<h3>CyberSecurity Digest #3: Beginners Cryptography, Makefiles, Home Routers and Car Infotainment Hacking</h3><p><a href="https://medium.com/@0xor0ne/cybersecurity-digest-2-fuzzing-isa-in-ghidra-wi-fi-mitm-and-guarded-regions-dd46fcb6b53f">Previous episode</a> explored embedded system fuzzing, Ghidra internals for adding new ISAs, man-in-the-middle attacks in W-Fi networks and guarded regions used by anti-cheat Windows engines.</p><p>This time we are going to talk about:</p><ul><li>An introduction series to cryptography for beginners;</li><li>A great research about “home routers” vulnerability research and exploitation;</li><li>A journey into car infotainment hacking; and</li><li>A great resource for learning Makefiles.</li></ul><h3>Cryptography Series for Beginners</h3><p>In the three blog posts listed below, the author <a href="https://twitter.com/sergioprado">@sergioprado</a> introduces the basic concepts of cryptography and provides hands-on examples focused on (embedded) Linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yNfikRB6kgIH1U1btxZLg.png" /></figure><p>The first blog post is dedicated to introducing the basic terminology used in cryptography and the concepts of symmetric and asymmetric encryption. While the second blog post is more focused on showing examples of how to create symmetric encryption keys in Linux (openssl) and how to use them to encrypt/decrypt data using AES with different encryption modes (ECB, CBC). The last blog post is instead dedicated to asymmetric encryption/decryption with related examples.</p><p>If you are a beginner and interested in learning the basics of cryptography you should check these blog posts out:</p><ul><li><a href="https://sergioprado.blog/introduction-to-encryption-for-embedded-linux-developers/">Introduction to encryption for embedded Linux developers</a></li><li><a href="https://sergioprado.blog/a-hands-on-approach-to-symmetric-key-encryption/">A hands-on approach to symmetric-key encryption</a></li><li><a href="https://sergioprado.blog/asymmetric-key-encryption-and-digital-signatures-in-practice/">Asymmetric-Key Encryption and Digital Signatures in Practice</a></li></ul><h3>Home Routers Hacking</h3><p><a href="https://twitter.com/alexjplaskett">@alexjplaskett</a> and <a href="https://twitter.com/_mccaulay">@_mccaulay</a> presented a very interesting research at HITB 2023 conference entitled <a href="http://conference.hitb.org/files/hitbsecconf2023ams/materials/D1T1%20-%20Your%20Not%20So%20Home%20Office%20-%20Soho%20Hacking%20at%20Pwn2Own%20-%20McCaulay%20Hudson%20&amp;%20Alex%20Plaskett.pdf">Your not so “Home Office” — SOHO Hacking at Pwn2Own</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*912nEe80EviDlf3niAo4Dg.png" /></figure><p>The slides describe the journey the research team did regarding the security analysis of a few home/office routers (Netgear, TP-Link, Synology and Ubiquity). The presentation starts by introducing the software and hardware high level analysis of the routers and then it goes into a little bit of details regarding the vulnerabilities they found and how they exploited them.</p><p>For sure <a href="http://conference.hitb.org/files/hitbsecconf2023ams/materials/D1T1%20-%20Your%20Not%20So%20Home%20Office%20-%20Soho%20Hacking%20at%20Pwn2Own%20-%20McCaulay%20Hudson%20&amp;%20Alex%20Plaskett.pdf">a nice presentation</a> for anyone interested in embedded/IoT devices vulnerability research and exploitation.</p><p>Note however that all the vulnerabilities presented in the slides have already been patched by the corresponding vendors.</p><h3>Makefiles Guide</h3><p>I believe that knowing the basics of how Makefiles work is always a good idea for any software developer (regardless of the actual programming language used).</p><p>The guide <a href="https://makefiletutorial.com/">Learn Makefiles With the tastiest examples</a> is perfect for this purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hFcdWPeh0I8CzeMDAveLMw.png" /></figure><p>It provides an overview of the main features required for starting writing and understanding Makefiles without overwhelming the reader with too many details. <a href="https://makefiletutorial.com/">The guide</a> provides a solid knowledge base to build upon.</p><h3>Car Infotainment Hacking</h3><p>This (for now) 6 parts blog post series on car infotainment system hacking by user greenluigi1 is a must-read for anyone interested in automotive hacking, reverse engineering, and, in general, cyber security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qx6yjDgZwN_sTfLEH_FQHA.png" /></figure><p>Here are the links to the posts of the series:</p><ul><li><a href="https://programmingwithstyle.com/posts/howihackedmycar/">How I Hacked my Car</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart2/">Making a Backdoor</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart3/">Making Software</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart4/">CAN Bus/Micom Access</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart5/">How I Hacked my Car Again</a></li><li><a href="https://programmingwithstyle.com/posts/myhackedcarisdoomed/">Nothing to it but to Doom it</a></li></ul><p>The first few blogs are probably a little bit outdated but still interesting and useful reading.</p><h3>References:</h3><p>Cryptography for beginners:</p><ul><li><a href="https://sergioprado.blog/introduction-to-encryption-for-embedded-linux-developers/">Introduction to encryption for embedded Linux developers</a></li><li><a href="https://sergioprado.blog/a-hands-on-approach-to-symmetric-key-encryption/">A hands-on approach to symmetric-key encryption</a></li><li><a href="https://sergioprado.blog/asymmetric-key-encryption-and-digital-signatures-in-practice/">Asymmetric-Key Encryption and Digital Signatures in Practice</a></li></ul><p>SOHO Hacking</p><ul><li><a href="http://conference.hitb.org/files/hitbsecconf2023ams/materials/D1T1%20-%20Your%20Not%20So%20Home%20Office%20-%20Soho%20Hacking%20at%20Pwn2Own%20-%20McCaulay%20Hudson%20&amp;%20Alex%20Plaskett.pdf">Your not so “Home Office” — SOHO Hacking at Pwn2Own</a></li></ul><p>Makefile</p><ul><li><a href="https://makefiletutorial.com/">Learn Makefiles With the tastiest examples</a></li></ul><p>Car Infotainment Hacking</p><ul><li><a href="https://programmingwithstyle.com/posts/howihackedmycar/">Part 1</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart2/">Part 2</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart3/">Part 3</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart4/">Part 4</a></li><li><a href="https://programmingwithstyle.com/posts/howihackedmycarpart5/">Part 5</a></li><li><a href="https://programmingwithstyle.com/posts/myhackedcarisdoomed/">Part 6</a></li></ul><blockquote><a href="https://twitter.com/0xor0ne">0xor0ne</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4292aed6661b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rust Notes: Unique and NonNull]]></title>
            <link>https://medium.com/@0xor0ne/rust-notes-unique-and-nonnull-380a261bc689?source=rss-288aae063d05------2</link>
            <guid isPermaLink="false">https://medium.com/p/380a261bc689</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[0xor0ne]]></dc:creator>
            <pubDate>Thu, 29 Jun 2023 16:01:53 GMT</pubDate>
            <atom:updated>2023-06-29T16:01:53.891Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*WI6hLRE1-giKT500uBW1fg.png" /></figure><h3>Unique</h3><p>Unique&lt;T&gt; is a pointer type in Rust that is commonly used internally by Rust to represent the unique ownership semantics and is useful for building abstractions like Box&lt;T&gt;, Vec&lt;T&gt;, String, and HashMap&lt;K, V&gt;.</p><p>In the standard library is declared in <a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ptr/unique.rs#L35">core/src/ptr/unique.rs</a> as:</p><pre>pub struct Unique&lt;T: ?Sized&gt; {<br>    pointer: NonNull&lt;T&gt;,<br>    _marker: PhantomData&lt;T&gt;,<br>}</pre><p>Unique&lt;T&gt; is a non-null, covariant, unique pointer. Here&#39;s what these terms mean:</p><ul><li>Non-null: It’s guaranteed to never be NULL.</li><li>Covariant: This is a property that allows it to be used with subtypes and supertypes. In Rust, the covariance of Unique&lt;T&gt; is used for example to ensure that Box&lt;T&gt; is covariant with T.</li><li>Unique: It represents that there’s only a single owner of the pointee.</li></ul><p>This combination of properties allows Rust to make certain assumptions that can enable optimizations in code. For example, because Unique&lt;T&gt; pointers are non-null and unique, Rust&#39;s optimizer can assume that dereferencing a Unique&lt;T&gt; is always safe and that the pointee will not be modified or moved by any other part of the code.</p><p>Please note that Unique&lt;T&gt; is an internal implementation detail of Rust&#39;s standard library. As such, it&#39;s not a type that you&#39;ll typically use directly in your own code. Instead, you&#39;d use types like Box&lt;T&gt;, Vec&lt;T&gt;, and so on, which are built using Unique behind the scenes.</p><p>For example, Box&lt;T&gt; is declared in the standard library in <a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs#L195">alloc/src/boxed.rs</a> as:</p><pre>pub struct Box&lt;<br>    T: ?Sized,<br>    #[unstable(feature = &quot;allocator_api&quot;, issue = &quot;32838&quot;)] A: Allocator = Global,<br>&gt;(Unique&lt;T&gt;, A);</pre><h3>PhantomData</h3><p>As shown above, Unique&lt;T&gt; has a field _marker of type PhantomData&lt;T&gt;.</p><p>PhantomData&lt;T&gt; in Rust is a type that&#39;s used to indicate that a particular generic type T is a part of a data structure, even if T isn&#39;t used in the data structure.</p><p>PhantomData&lt;T&gt; plays a critical role in the Rust compiler&#39;s ability to understand ownership, borrowing, and lifetimes, and it&#39;s important when creating complex data structures or when dealing with raw pointers.</p><p>Now, Unique&lt;T&gt; is typically used with PhantomData because Unique&lt;T&gt; itself does not &quot;own&quot; its pointee in Rust&#39;s type system. The actual ownership is often expressed using PhantomData.</p><p>In the declaration of Unique&lt;T&gt; struct, PhantomData&lt;T&gt; expresses that it &quot;owns&quot; a T, even though the T isn&#39;t actually used in the struct. This tells the Rust compiler that when a Unique&lt;T&gt; is dropped, it might drop a T, so it shouldn&#39;t allow the T to be used afterwards.</p><p>Without the PhantomData&lt;T&gt;, Rust&#39;s type system would not understand that Unique&lt;T&gt; owns a T, and this could potentially lead to undefined behavior.</p><p>In summary, PhantomData&lt;T&gt; and Unique&lt;T&gt; are often used together in Rust to express complex ownership relationships that Rust&#39;s type system can&#39;t express on its own.</p><p>For more details about PhantomData see <a href="https://medium.com/@0xor0ne/rust-notes-phantomdata-505757bf56a7">Rust Notes: PhantomData</a>.</p><h3>NonNull</h3><p>Also, Unique&lt;T&gt; does not store a raw pointer directly. Instead, it as a field pointer of type NonNull&lt;T&gt;.</p><p>In Rust, NonNull&lt;T&gt; is a wrapper of a raw pointer that is guaranteed to not be NULL. It&#39;s essentially the same as a *mut T, but with the added invariant that it&#39;s not null.</p><p>Raw pointers in Rust are typically used when interacting with C code or when building unsafe Rust abstractions. However, null pointers can often cause bugs and crashes, so NonNull&lt;T&gt; is provided as a way to ensure that a raw pointer is never null.</p><p>This gives some safety guarantees in that you don’t have to check for null before using it. But keep in mind, even though it can’t be null, using a NonNull&lt;T&gt; is still unsafe because it doesn&#39;t give you any of the borrowing or lifetime guarantees that references (&amp;T and &amp;mut T) do.</p><p>Here’s an example of how NonNull&lt;T&gt; might be used:</p><pre>use std::ptr::NonNull;</pre><pre>let mut value = 10;<br>let pointer = NonNull::new(&amp;mut value as *mut _);</pre><pre>if let Some(ptr) = pointer {<br>    unsafe {<br>        *ptr.as_ptr() = 20;<br>    }<br>    assert_eq!(value, 20);<br>}</pre><p>In this example, NonNull::new is used to create a new NonNull&lt;T&gt;. Then, NonNull::as_ptr is used to get the raw pointer, which can be dereferenced and modified in an unsafe block.</p><h3>References</h3><ul><li><a href="https://medium.com/@0xor0ne/rust-notes-phantomdata-505757bf56a7">Rust Notes: PhandomData</a></li></ul><blockquote>0xor0ne</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=380a261bc689" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CyberSecurity Digest #2: Fuzzing, ISA in Ghidra, Wi-Fi MiTM and Guarded Regions]]></title>
            <link>https://medium.com/@0xor0ne/cybersecurity-digest-2-fuzzing-isa-in-ghidra-wi-fi-mitm-and-guarded-regions-dd46fcb6b53f?source=rss-288aae063d05------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd46fcb6b53f</guid>
            <category><![CDATA[fuzzing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ghidra]]></category>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[information-security]]></category>
            <dc:creator><![CDATA[0xor0ne]]></dc:creator>
            <pubDate>Wed, 28 Jun 2023 17:02:02 GMT</pubDate>
            <atom:updated>2023-06-28T17:02:02.681Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to the second issue of “CyberSecurity Digest”. The first episode explored Linux kernel modules development and syscall tables and methodologies for electrical scooter reverse engineering. In case you missed it, you can find it <a href="https://medium.com/@0xor0ne/cybersecurity-and-infotech-digest-1-412c82352539">here</a>.</p><p>This time we are going to talk about:</p><ul><li>Man-in-the-middle (MITM) attacks in Wi-Fi networks using forged ICMP redirect messages;</li><li>An in depth analysis of a Windows anti-cheat system internals.</li><li>A new interesting architecture agnostic fuzzing framework;</li><li>A writeup on how to add a new ISA to Ghidra.</li></ul><h3>Wi-Fi, Rogue APs and ICMP Redirects</h3><p>In the paper <a href="https://csis.gmu.edu/ksun/publications/WiFi_Interception_SP23.pdf">Man-in-the-Middle Attacks without Rogue AP: When WPAs Meet ICMP Redirects</a> by Xuewei Feng, Qi Li, Kun Sun, Yuxiang Yang, and Ke Xu, the authors discuss a novel method for executing man-in-the-middle (MitM) attacks on Wi-Fi Protected Access (WPA) networks without needing to set up a rogue access point (AP).</p><p>They explore the cross-layer interactions between WPAs and ICMP in Wi-Fi networks and show that an attacker can use ICMP redirects to reroute a victim’s traffic through their device, effectively creating a MitM scenario.</p><p>The implications are for example that the security features provided by WPA2 and WPA3 can be broken by the ICMP errors handling at the IP layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*FYf1xhyy3T0mVA7TdZWMHg.png" /></figure><p>The authors conducted extensive experiments to validate their findings and investigate which operating systems and software configuration are affected by the proposed attack (including Windows, Linux and Android).</p><p>Overall, <a href="https://csis.gmu.edu/ksun/publications/WiFi_Interception_SP23.pdf">this is a paper</a> worth reading for anyone interested in Wi-Fi network security.</p><h3>Vanguard Anti-Cheat System Internals</h3><p>The blog post <a href="https://reversing.info/posts/guardedregions/">In-depth analysis on Valorant’s Guarded Regions</a> by <a href="https://twitter.com/Xyrem256">@Xyrem256</a> discusses the advanced anti-cheat system, Vanguard, developed by Riot Games for their game Valorant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*0Kj9cFoeyPkneqL__5p4tg.png" /></figure><p>The author explores how Vanguard uses innovative techniques, based on guarded regions, to protect game variables from external access, making cheating extremely difficult. Any attempt to bypass these mechanisms usually results in a system page fault.</p><p>The blog post goes into detail on how memory management works and how these guarded regions work. Definitely, a good reading for anyone interested in game anti-cheating technologies and Windows reverse engineering techniques.</p><p>Go and <a href="https://reversing.info/posts/guardedregions/">check it out!</a></p><h3>Icicle Fuzzing Framework</h3><p>In the paper <a href="https://arxiv.org/pdf/2301.13346.pdf">Icicle: A Re-Designed Emulator for Grey-Box Firmware Fuzzing</a>, the authors Michael Chesser, Surya Nepal and Damith C. Ranasinghe introduce a new multi-architecture emulation based fuzzing framework called Icicle. The framework uses an architecture-agnostic mechanism for adding instrumentation and has been integrated with AFL++ and Fuzzware for implementing a coverage-guided greybox fuzzer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66vhxPDP3YuIPRySdsirjg.png" /></figure><p>The authors performed extensive experiments for measuring the efficacy of their framework and also provide the source code on <a href="https://github.com/icicle-emu/icicle">GitHub</a>. Another cool thing is that the <a href="https://github.com/icicle-emu/icicle-emu/tree/master">core emulator</a> of Icicle is implemented in Rust.</p><p>For sure this is an interesting paper for anyone interested in fuzzing and especially embedded devices fuzzing.</p><h3>Adding an ISA to Ghidra</h3><p>The blog post titled <a href="https://trenchant.io/expanding-the-dragon-adding-an-isa-to-ghidra/">Expanding the Dragon: Adding an ISA to Ghidra</a> discusses the process of adding a new Instruction Set Architecture (ISA) to Ghidra, the famous software reverse engineering (SRE) framework.</p><p>The blog post is organized as a tutorial teaching the steps required for adding a new CPU to Ghidra. In the process, it also introduces SLEIGH, a Ghidra specific DSL used as a processor specification language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*GSN1h6aZVAS6FcFbp_5syw.png" /></figure><p>An interesting reading for anyone interested in reverse engineering and in learning a little bit more about Ghidra internals.</p><p>Go and <a href="https://trenchant.io/expanding-the-dragon-adding-an-isa-to-ghidra/">check it out!</a></p><h3>References:</h3><ul><li><a href="https://csis.gmu.edu/ksun/publications/WiFi_Interception_SP23.pdf">Man-in-the-Middle Attacks without Rogue AP: When WPAs Meet ICMP Redirects</a></li><li><a href="https://reversing.info/posts/guardedregions/">In-depth analysis on Valorant’s Guarded Regions</a></li><li><a href="https://arxiv.org/pdf/2301.13346.pdf">Icicle: A Re-Designed Emulator for Grey-Box Firmware Fuzzing</a></li><li><a href="https://github.com/icicle-emu/icicle">gitHub repository</a></li><li><a href="https://trenchant.io/expanding-the-dragon-adding-an-isa-to-ghidra/">Expanding the Dragon: Adding an ISA to Ghidra</a></li></ul><blockquote><a href="https://twitter.com/0xor0ne">0xor0ne</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd46fcb6b53f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rust Notes: String and &str]]></title>
            <link>https://medium.com/@0xor0ne/rust-notes-string-and-str-20a636c12d4d?source=rss-288aae063d05------2</link>
            <guid isPermaLink="false">https://medium.com/p/20a636c12d4d</guid>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ghidra]]></category>
            <dc:creator><![CDATA[0xor0ne]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 16:15:56 GMT</pubDate>
            <atom:updated>2023-06-25T16:15:56.099Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post introduces the concepts of String type and the borrowed counterpart &amp;str, a.k.a. string slices, highlighting their differences. It then goes on to present a few internal implementation details.</p><h3>String</h3><p>String is an owned grownable UTF-8 encoded string. The term &quot;owned&quot; means that a variable s of type String has ownership over the content of the string. When s goes out of scope the owned string is dropped.</p><pre>...<br>{ // New scope<br>    let s: String = String::from(&quot;My string&quot;); // &quot;My string&quot; is owned by s<br>    ...<br>} // End of scope, `s` and the owned string &quot;My string&quot; are dropped<br>...</pre><p>Internally in the standard library, <a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/string.rs#L365">String is defined as</a>:</p><pre>pub struct String {<br>    vec: Vec&lt;u8&gt;,<br>}</pre><p>Yes, exactly, a String is just a vector of bytes (u8). However, the standard library implementation of Stringensures that the array of bytes pointed by vec actually contains only valid UTF-8 bytes.</p><h3>&amp;str</h3><p>str is a &quot;string slice&quot;, a sequence of bytes in memory that is known to be valid UTF-8 text. It&#39;s a primitive type in Rust and most of the time is used in its borrowed form &amp;str.</p><p>The reason for this is that str is not a Sized type, meaning that its size is not known statically (at compile time) and the Rust compiler must know the size of all the local variables in order to guarantee the security features provided by the Rust language.</p><p>In fact, if you try to create an owned version of str:</p><pre>fn main() {<br>    let s: &amp;str = &quot;My string&quot;;<br>    let owned_str: str = *s;<br>}</pre><p>when you build the provided code snippet (cargo build), the compiler will return the following error (tested on MacOS, Rust v1.70.0):</p><pre>error[E0277]: the size for values of type `str` cannot be known at compilation time<br> --&gt; src/main.rs:3:9<br>  |<br>3 |     let owned_str = *s;<br>  |         ^^^^^^^^^ doesn&#39;t have a size known at compile-time<br>  |<br>  = help: the trait `Sized` is not implemented for `str`<br>  = note: all local variables must have a statically known size<br>  = help: unsized locals are gated as an unstable feature<br><br>For more information about this error, try `rustc --explain E0277`.</pre><p>I.e., str does not implement Sized trait and therefore its size is not known statically at compile time.</p><p>The borrowed form &amp;str instead is just a reference and its size is always known statically at compile time. To be more precise &amp;str is a &quot;fat pointer&quot;, i.e., a reference to a dynamically sized type (DST) (the str) which contains both a pointer to the data plus some information that makes the DST &quot;complete&quot; (i.e., the length of the str).</p><p>This can be seen with a simple example. Let’s consider the following simple code:</p><pre>fn foo(s: &amp;str) {<br>    println!(&quot;{}&quot;, s);<br>}<br><br>fn main() {<br>    let s = String::from(&quot;My string&quot;);<br>    let ss: &amp;str = &amp;s[0..5];<br>    foo(&amp;ss);<br>}</pre><p>and compile it in debug mode (cargo build).</p><p>Now we can run the resulting executable in a debugger and place a breakpoint just before the call to foo function (the screenshot below shows the Ghidra debugger running on an Apple MacBook pro laptop with ARM CPU).</p><figure><img alt="Ghidra debugger screenshot" src="https://cdn-images-1.medium.com/max/1024/1*4t34ZGOzRgV_LGFokXgoDg.png" /></figure><p>The string slice (&amp;str) ss is created by the instruction at address 0x1000056cc (bl &lt;&gt;::index) and placed on the stack (as expected considering that ss is a local variable). As we said above, ss is a fat pointer and contains both a pointer to the (sub)string data and the length information. For example, this can be observed in the debugger console in the bottom left corner of the image above:</p><ul><li>The stack pointer, printed with register read sp, points to 0x000000016bddad60;</li><li>The slice length information, printed with x/1gx $sp+0x10, is 0x5;</li><li>The pointer to the (sub)string data, printed with x/1gx $sp+0x8, points to 0x00006000004ac010;</li><li>We can print the value pointed by this address with memory read -s1 -fc -c 9 0x00006000004ac010 and verify that this address is actually the location of the expected string s. In fact, in this case, the value returned by the debugger command is &quot;My string&quot;.</li></ul><h3>&amp;String</h3><p>Note that if s is a variable of type String, &amp;s is just a reference to String (i.e., &amp;String). Conceptually is the same thing that happens when you have a variable v of type Vec&lt;T&gt; and you take a reference &amp;v. You end up with a reference to Vec&lt;T&gt;.</p><p>This can be seen with the following snippet of code used for printing the variables’ type:</p><pre>fn print_type_of&lt;T&gt;(_: &amp;T) {<br>    println!(&quot;{}&quot;, std::any::type_name::&lt;T&gt;())<br>}<br><br>fn main() {<br>    let s: String = String::from(&quot;My string&quot;);<br>    let s_ref = &amp;s;<br>    let s_str = s.as_str();<br><br>    print_type_of(&amp;s);<br>    print_type_of(&amp;s_ref);<br>    print_type_of(&amp;s_str);<br>}</pre><p>the corresponding output is:</p><pre>alloc::string::String<br>&amp;alloc::string::String<br>&amp;str</pre><p>Note the &amp; in front of the second line in the output.</p><p>A reference to String (&amp;String) is a different thing than &amp;str. However, &amp;String can be often automatically coerced to &amp;str.</p><h3>Quick Wrap up</h3><pre>// Create a String type from a string literal<br>let s = String::from(&quot;My string&quot;);<br>// Create an empty String type<br>let empty_s = String::new();<br>// Create a string from a vector of bytes<br>let hello_vec = vec![72, 101, 108, 108, 111];<br>let hello_string = String::from_utf8(hello_vec).unwrap();<br>// Create an owned String from a string slice<br>let s: String = &quot;My string&quot;.to_owned()<br>// String literal (str), valid for the duration of the entire program<br>let my_string: &amp;&#39;static str = &quot;My string&quot;;<br>// Same thing as above, but shorter<br>let my_string = &quot;My string&quot;;<br>// Given a String, create a string slice containing the whole String<br>let s = String::from(&quot;My string&quot;);<br>let ss: &amp;str = s.as_str();</pre><h3>References</h3><ul><li><a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/string.rs#L365">String definition</a></li></ul><blockquote>0xor0ne</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20a636c12d4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CyberSecurity Digest #1: Linux Kernel Programming, Syscall Tables and Scooters Reverse Engineering]]></title>
            <link>https://medium.com/@0xor0ne/cybersecurity-and-infotech-digest-1-412c82352539?source=rss-288aae063d05------2</link>
            <guid isPermaLink="false">https://medium.com/p/412c82352539</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[0xor0ne]]></dc:creator>
            <pubDate>Wed, 21 Jun 2023 17:01:35 GMT</pubDate>
            <atom:updated>2023-06-22T08:35:11.152Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to the first edition of “CyberSecurity Digest”. This blog post series aims to be your learning gateway, delivering the most enriching, high-quality technical content in the world of Information Technology and Cybersecurity. Regardless of whether the insights are new or old, the focus of this blog post series is on the impact they can have on your understanding and knowledge growth.</p><p>In this episode we will see:</p><ul><li>A great free book for learning Linux kernel modules development;</li><li>A journey into electrical scooter reverse engineering;</li><li>A cool website with handy Linux syscall tables.</li></ul><h3>Modern Linux Kernel Module Development</h3><p>The first great resource is the free book <a href="https://sysprog21.github.io/lkmpg/">The Linux Kernel Module Programming Guide</a> by Peter Jay Salzman, Michael Burian, Ori Pomerantz, Bob Mottram, Jim Huang (and many other contributors on <a href="https://github.com/sysprog21/lkmpg">GitHub</a>).</p><p>This guide was originally developed for Linux kernel version 2.2 but was recently updated to recent kernel versions (v5.x). It’s not exactly on par with the current kernel version (at the time of writing we are approaching the release of version 6.4) but the vast majority of the concept explained in this guide are portable to the lastet Linux kernel version.</p><p>Throughout this book, you will learn a lot of things, too many to list them all. However, just to give you a glimpse, the book will teach you what system calls are:</p><pre>#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER <br>static asmlinkage long our_sys_openat(const struct pt_regs *regs) <br>#else <br>static asmlinkage long our_sys_openat(int dfd, const char __user *filename, <br>                                      int flags, umode_t mode) <br>#endif <br>{ <br>    int i = 0; <br>    char ch; <br> <br>    if (__kuid_val(current_uid()) != uid) <br>        goto orig_call; <br> <br>    /* Report the file, if relevant */ <br>    pr_info(&quot;Opened file by %d: &quot;, uid); <br>    do { <br>#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER <br>        get_user(ch, (char __user *)regs-&gt;si + i); <br>#else <br>        get_user(ch, (char __user *)filename + i); <br>#endif <br>        i++; <br>        pr_info(&quot;%c&quot;, ch); <br>    } while (ch != 0); <br>    pr_info(&quot;\n&quot;); <br> <br>orig_call: <br>    /* Call the original sys_openat - otherwise, we lose the ability to <br>     * open files. <br>     */ <br>#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER <br>    return original_call(regs); <br>#else <br>    return original_call(dfd, filename, flags, mode); <br>#endif <br>}</pre><p>This guide is an absolute must-read weather you are interested in becoming a Linux kernel developer or just if you want to learn a little bit more about Linux internals (or operating systems in general).</p><p>Go and <a href="https://sysprog21.github.io/lkmpg/">check it out</a>.</p><h3>Xiaomi Brightway Scooters Hacking</h3><p><a href="https://robocoffee.de/?p=436">Hacking Brightway scooters: A case study</a> is a detailed analysis of the Xiaomi 3 Lite electric scooter, produced by Brightway Innovation Intelligent Technology (Suzhou) Co., Ltd. The author dissects the scooter’s hardware and software, focusing on its security features and potential for modification.</p><p>The blog post is a great opportunity for learning new stuff and methodologies for reversing embedded hardware. The author dismantles the scooter and provides insights into its inner workings, including the pairing and activation procedure, available registers, command and message format, and the structure of the serial numbers.</p><figure><img alt="Components involved in the scooter communication" src="https://cdn-images-1.medium.com/max/1024/1*0Hy2DlPHv941Ddt_KcB1LA.png" /></figure><p>After having identified all the hardware component (mainly the SoCs RTL8762C and LKS32MC08x) the authors continues with a discussion of UART communications between the scooter’s internal components and the possibility of flashing custom firmware using SWD ports.</p><p>For sure a <a href="https://robocoffee.de/?p=436">blog post</a> to read for anyone interested in reverse engineering and embedded devices.</p><h3>Useful Syscall Tables</h3><p><a href="https://syscalls.mebeim.net/?table=x86/64/x64/v6.3">syscalls.mebeim.net</a>, is a comprehensive online reference for Linux system call tables across various architectures and kernel versions. System calls are a crucial part of any operating system, serving as interfaces between user-space applications and the kernel, and are critical for understanding system-level programming, operating system design, and also cybersecurity.</p><p>The screenshot example reported below shows the system call table for the x86–64 architecture using version 6.3 of the x64 kernel. It lists all the system calls available in this architecture and kernel version along with their associated function signatures and numbers.</p><figure><img alt="syscalls.mebeim.net example" src="https://cdn-images-1.medium.com/max/1024/1*mBVAsT2atDljP3w-huvY_w.png" /></figure><p>The <a href="https://syscalls.mebeim.net/?table=x86/64/x64/v6.3">website</a> is useful for developers, system administrators, and cybersecurity professionals who need to understand or use system calls in their work. It can serve as a valuable resource for troubleshooting, system development, and security research.</p><h3>Honorable Mentions</h3><p>A couple of honorable mentions for this episode go to:</p><ul><li><a href="https://www.riverloopsecurity.com/blog/2020/03/hw-101-emmc/">Hardware Hacking 101: Identifying and Dumping EMMC Flash</a>: provides an overview of eMMC, or embedded MultiMediaCard, a type of flash storage widely used in consumer electronics. It discusses the basic structure of eMMC, its usage in devices, and the process of how it can be accessed and analyzed for data recovery or forensic purposes.</li><li><a href="https://dangerouspayload.com/2018/10/24/emmc-data-recovery-from-damaged-smartphone/">EMMC Data Recovery From Damaged Smartphone</a>: discusses a case study of data recovery from a damaged smartphone using eMMC (embedded MultiMediaCard) chip-off forensics. It explains the process of physical extraction of the memory chip, reading the chip using a specialized reader, and finally recovering the user data, demonstrating the value and effectiveness of this technique in digital forensics.</li></ul><h3>References</h3><ul><li><a href="https://sysprog21.github.io/lkmpg/">The Linux Kernel Module Programming Guide</a></li><li><a href="https://robocoffee.de/?p=436">Hacking Brightway scooters: A case study</a></li><li><a href="https://syscalls.mebeim.net/?table=x86/64/x64/v6.3">Linux kernel syscall tables</a></li><li><a href="https://www.riverloopsecurity.com/blog/2020/03/hw-101-emmc/">Hardware Hacking 101: Identifying and Dumping EMMC Flash</a></li><li><a href="https://dangerouspayload.com/2018/10/24/emmc-data-recovery-from-damaged-smartphone/">EMMC Data Recovery From Damaged Smartphone</a></li></ul><blockquote><a href="https://twitter.com/0xor0ne">0xor0ne</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=412c82352539" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rust Notes: PhantomData]]></title>
            <link>https://medium.com/@0xor0ne/rust-notes-phantomdata-505757bf56a7?source=rss-288aae063d05------2</link>
            <guid isPermaLink="false">https://medium.com/p/505757bf56a7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[0xor0ne]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 19:58:31 GMT</pubDate>
            <atom:updated>2023-06-15T20:43:44.347Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post will first introduce the “theoretical” concepts of the Rust PhantomData&lt;T&gt; type and then explore a few real-world examples showcasing its practical applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-RxL2tZ5SCUR75TtLthdA.png" /></figure><h3>What is PhantomData&lt;T&gt;</h3><p>As stated in the <a href="https://doc.rust-lang.org/std/marker/struct.PhantomData.html">official documentation</a>, PhantomData&lt;T&gt; is a Zero Sized Type (ZST) that consumes no space and simulates the presence of a field of the given type T. It is a marker type used to give the compiler information that is useful for the purpose of static analysis and necessary to have correct <a href="https://doc.rust-lang.org/nomicon/subtyping.html">variance</a> and <a href="https://doc.rust-lang.org/nomicon/dropck.html">drop checking</a>.</p><p>As a quick example, it is possbile to define a structure like this:</p><pre>struct PdStruct&lt;T&gt; {<br>    data: i32,<br>    pd: PhantomData&lt;T&gt;,<br>}</pre><p>in this case, the field pd, whose type is PhantomData&lt;T&gt;, does not increase the size of structure PdStruct&lt;T&gt;but tells the compiler to treat PdStruct&lt;T&gt; as if it owns T, even though the latter is not actually used in the structure itself. So, for example, the compiler knows that when a value of type PdStruct&lt;T&gt; is dropped also T could be potentially dropped.</p><p>PhantomData&lt;T&gt; is commonly used with raw pointers, unused lifetime parameters and unused type parameters. Examples for each of the three cases are provided below.</p><h3>Raw Pointers and PhantomData&lt;T&gt;</h3><p>Let’s consider at the following code snippet:</p><pre>use std::marker::PhantomData;<br><br>struct MyRawPtrStruct&lt;T&gt; {<br>    ptr: *mut T,<br>    _marker: PhantomData&lt;T&gt;,<br>}<br><br>impl&lt;T&gt; MyRawPtrStruct&lt;T&gt; {<br>    fn new(t: T) -&gt; MyRawPtrStruct&lt;T&gt; {<br>        let t = Box::new(t);<br>        MyRawPtrStruct {<br>            ptr: Box::into_raw(t),<br>            _marker: PhantomData,<br>        }<br>    }<br>}<br><br>...</pre><p>In the example, MyRawPtrStruct is a simple smart pointer that owns a heap-allocated T. Rust compiler can&#39;t automatically infer the lifetime or ownership detail of the raw pointer ptr. The example usesPhantomData&lt;T&gt; to express the fact that MyRawPtrStruct owns a T, even though T doesn&#39;t actually appear in the struct (it&#39;s behind a raw pointer). This helps the Rust compiler correctly infer the drop order and other ownership-related properties.</p><h3>Unused Lifetime Parameters and PhandomData&lt;T&gt;</h3><p>For the unused lifetime parameters, let’s consider the following Window structure definition:</p><pre>use std::marker::PhantomData;<br><br>struct Window&lt;&#39;a, T: &#39;a&gt; {<br>    start: *const T,<br>    end: *const T,<br>    phantom: PhantomData&lt;&amp;&#39;a T&gt;,<br>}</pre><p>Fields start and end are raw pointers. They point to the start and end of a window of T values, but they don&#39;t carry any lifetime information. This means that Rust&#39;s borrow checker can&#39;t use them to enforce the lifetime &#39;a.</p><p>Field phantom is a PhantomData marker that carries the lifetime &#39;a. This tells Rust&#39;s borrow checker that the Window struct is logically tied to data of lifetime &#39;a, even though it doesn&#39;t actually store any references of type &amp;&#39;a T.</p><p>This ensures that the data pointed by the window won’t be dropped while the window is still in use. Without PhantomData, Rust wouldn&#39;t know about the lifetime relationship and couldn&#39;t, for example, protect against use-after-free bugs. In other words, PhantomData&lt;&amp;&#39;a T&gt; is used to express that Window behaves as it has a reference to a T with lifetime &#39;a, which helps Rust enforce the correct ownership and borrowing rules.</p><p>Also, as an additional information, note that here Window become <a href="https://doc.rust-lang.org/nomicon/subtyping.html">covariant</a> over &#39;a and T.</p><h3>Unused Type Parameters and PhantomData&lt;T&gt;</h3><p>In this case PhantomData&lt;T&gt; is used to indicate what type of data a struct is &quot;tied&quot; to:</p><pre>struct ExternalResource&lt;R&gt; {<br>   resource_handle: *mut (),<br>   resource_type: PhantomData&lt;R&gt;,<br>}</pre><p>This case arises frequently when implementing Foreign Function Interfaces (FFIs). Refer to the <a href="https://doc.rust-lang.org/std/marker/struct.PhantomData.html#unused-type-parameters">standard library documentation example</a> for more information.</p><h3>Real World Examples of PhantomData&lt;T&gt;</h3><p>This section illustrates a few real world usage examples of PhantomData&lt;T&gt; taken directly from the Rust standard library (presented code snippets refer to Rust v1.70.0).</p><h4>BorrowedFd</h4><p>BorrowedFd is the borrowed version of an OwnedFd (owned file descriptor) and in the standard library it is defined in <a href="https://github.com/rust-lang/rust/blob/81c02da94e5f5ec1ec4732e75049c3a3cb4d6c7a/library/std/src/os/fd/owned.rs#L38">std/src/os/fd/owned.rs</a> as:</p><pre>pub struct BorrowedFd&lt;&#39;fd&gt; {<br>    fd: RawFd,<br>    _phantom: PhantomData&lt;&amp;&#39;fd OwnedFd&gt;,<br>}</pre><p>Here the PhantomData field (_phantom) is used to tell the Rust compiler that BorrowedFd is tied to the lifetime of the OwnedFd where BorrowedFd has been borrowed from (even though BorrowedFd doesn&#39;t actually hold a reference to OwnedFd). This is important for ensuring that OwnedFd isn&#39;t dropped while BorrowedFd is still in use.</p><h4>Iter&lt;T&gt;</h4><p>Iterator over a Slice [T] is defined in the standard library in <a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/slice/iter.rs#L62">core/src/slice/iter.rs</a> as:</p><pre>pub struct Iter&lt;&#39;a, T: &#39;a&gt; {<br>    ptr: NonNull&lt;T&gt;,<br>    end: *const T,<br>    _marker: PhantomData&lt;&amp;&#39;a T&gt;,<br>}</pre><p>In this case, PhantomData&lt;&amp;&#39;a T&gt; is used to indicate that the structure Iter is tied to the lifetime &#39;a. This is important because it tells Rust compiler that Iter can&#39;t outlive the references it might have to T (data T is only pointed by the two raw pointers ptr and end that carry no lifetimes information). This is crucial for Rust&#39;s guarantee of memory safety.</p><h4>Rc&lt;T&gt;</h4><p>As a last example, we can see that also Rc&lt;T&gt;, defined by the standard library in <a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/rc.rs#L316">alloc/src/rc.rs</a>, contains a PhantomData field:</p><pre>pub struct Rc&lt;T: ?Sized&gt; {<br>    ptr: NonNull&lt;RcBox&lt;T&gt;&gt;,<br>    phantom: PhantomData&lt;RcBox&lt;T&gt;&gt;,<br>}</pre><p>PhantomData is used here to tell the drop checker that dropping Rc&lt;T&gt; may cause a value of type T to be dropped.</p><p>A more in depth explanation of why PhantomData is actually required in Rc can be found in <a href="https://stackoverflow.com/a/58034644">this StackOverflow answer</a> and in <a href="https://doc.rust-lang.org/nomicon/phantom-data.html#an-exception-the-special-case-of-the-standard-library-and-its-unstable-may_dangle">this section of the Rustonomicon</a>.</p><h3>Additional Information</h3><p>This section provides a few links to external resources that you may find useful to deepen your knowledge about PhantomData.</p><p>In the standard libray, PhantomData is defined in <a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/marker.rs#L692">core/src/marker.rs</a> as:</p><pre>pub struct PhantomData&lt;T: ?Sized&gt;;</pre><p>Being a Zero Sized Type (ZST), PhantomData&lt;T&gt; occupy no space and is aligned at one byte, i.e.,:</p><ul><li>size_of::&lt;PhantomData&lt;T&gt;&gt;() == 0</li><li>align_of::&lt;PhantomData&lt;T&gt;&gt;() == 1</li></ul><p>PhantomData type is also strongly related to the Drop-Check (dropck) rule and the #[may_dangle] unstable attribute. To learn more about this see <a href="https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md">RFC769</a> where dropck has been introduced and <a href="https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md">RFC1238</a> and <a href="https://github.com/rust-lang/rfcs/blob/master/text/1327-dropck-param-eyepatch.md">RFC1327</a> where dropck has been further refined.</p><p>Note also that <a href="https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md">RFC1238</a> introduced rules that changed the circumstances in which PhantomData&lt;T&gt; and #[may_dangle] are required. For example, they are used in the standard library to implement a sounding Vec&lt;T&gt;type which does not have to comply withthe overly restrictive drop check rule (for further information see the <a href="https://doc.rust-lang.org/nomicon/phantom-data.html#generic-parameters-and-drop-checking">dedicated section in the Rustonomicon</a>)</p><p>For an intuitive explanation and a deep dive on how PhantomData&lt;T&gt; works in Vec&lt;T&gt; definition, see <a href="https://stackoverflow.com/a/42721125">this stackoverflow answer</a>.</p><p>Finally, another interesting usage of the PhandomData type is to implement the <a href="http://cliffle.com/blog/rust-typestate/">typestate pattern</a>, in particular the state type parameter variant.</p><h3>References</h3><ul><li><a href="https://doc.rust-lang.org/std/marker/struct.PhantomData.html">Rust standard library documentation on </a><a href="https://doc.rust-lang.org/std/marker/struct.PhantomData.html">PhantomData&lt;T&gt;</a></li><li><a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/marker.rs#L692">PhantomData definition</a></li><li><a href="https://github.com/rust-lang/rust/blob/81c02da94e5f5ec1ec4732e75049c3a3cb4d6c7a/library/std/src/os/fd/owned.rs#L38">BorrowedFd definition</a></li><li><a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/slice/iter.rs#L62">Iter definition</a></li><li><a href="https://doc.rust-lang.org/nomicon/subtyping.html">Subtyping and Variance</a></li><li><a href="https://doc.rust-lang.org/nomicon/dropck.html">Drop Check</a></li><li><a href="https://github.com/rust-lang/rust/blob/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/rc.rs#L316">Rc definition</a></li><li><a href="https://stackoverflow.com/a/58034644">PhantomData and </a><a href="https://stackoverflow.com/a/58034644">Rc (StackOverflow answer)</a></li><li><a href="https://doc.rust-lang.org/nomicon/phantom-data.html#an-exception-the-special-case-of-the-standard-library-and-its-unstable-may_dangle">PhantomData and </a><a href="https://doc.rust-lang.org/nomicon/phantom-data.html#an-exception-the-special-case-of-the-standard-library-and-its-unstable-may_dangle">may_dangle (Rustonomicon)</a></li><li><a href="http://cliffle.com/blog/rust-typestate/">Typestate pattern</a></li><li><a href="https://stackoverflow.com/a/42721125">Vec&lt;T&gt; and </a><a href="https://stackoverflow.com/a/42721125">PhantomData</a></li><li><a href="https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md">RFC769: sound generic drop</a></li><li><a href="https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md">RFC1238: nonparametric dropck</a></li><li><a href="https://github.com/rust-lang/rfcs/blob/master/text/1327-dropck-param-eyepatch.md">RFC1327: dropck param eyepatch</a></li><li><a href="https://doc.rust-lang.org/nomicon/phantom-data.html#generic-parameters-and-drop-checking">Generic parameters, Drop Checking and </a><a href="https://doc.rust-lang.org/nomicon/phantom-data.html#generic-parameters-and-drop-checking">may_dangle (Rustonomicon)</a></li><li><a href="https://doc.rust-lang.org/std/marker/struct.PhantomData.html#unused-type-parameters">Unused type parameters (</a><a href="https://doc.rust-lang.org/std/marker/struct.PhantomData.html#unused-type-parameters">PhantomData&lt;T&gt;)</a></li></ul><blockquote><a href="https://twitter.com/0xor0ne">0xor0ne</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=505757bf56a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>