<?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 Ramadhan Zome on Medium]]></title>
        <description><![CDATA[Stories by Ramadhan Zome on Medium]]></description>
        <link>https://medium.com/@ramadhanzome4?source=rss-2cbdfb3e53a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wVG-Bo-IbWgLnCfbPIPa0w.png</url>
            <title>Stories by Ramadhan Zome on Medium</title>
            <link>https://medium.com/@ramadhanzome4?source=rss-2cbdfb3e53a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:42:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramadhanzome4/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[Your Model Could Keep Learning. Here’s Why It Doesn’t.]]></title>
            <link>https://medium.com/@ramadhanzome4/your-model-could-keep-learning-heres-why-it-doesn-t-a158236031cd?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a158236031cd</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Wed, 11 Nov 2026 02:50:23 GMT</pubDate>
            <atom:updated>2026-11-11T02:50:23.242Z</atom:updated>
            <content:encoded><![CDATA[<p>11 Nov 2026 · <a href="https://medium.com/u/2cbdfb3e53a9">Ramadhan Zome</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DEvtk3XacE8o6dQKwsABFQ.png" /></figure><p>Every model you talk to stopped learning before you met it. Correct it, teach it, praise it: none of that changes its weights.</p><p>The usual explanation is that neural networks can’t learn continuously. Teach them something new, and they forget the old.</p><p>That story isn’t wrong, but it’s no longer the main reason. The labs already do continual learning. They just do it inside the training run, before the model ships.</p><p>In <a href="https://medium.com/@ramadhanzome4/the-pioneers-are-betting-against-llms-0be8c29c5de2">my last piece</a>, I argued that AI’s pioneers are betting on what LLMs are missing. Learning after deployment is one of those gaps. This piece is about why it’s still open, and the answer is mostly testing, trust and money, plus one hard research problem that has little to do with forgetting.</p><h3>Labs already do continual learning</h3><p>A modern model isn’t trained once. It’s trained in stages: pretraining on a huge pile of text, then fine-tuning on examples of good answers, then reinforcement learning, where the model practices and gets scored.</p><p>Each stage teaches the model something new on top of what it already knows. That’s exactly the sequential setup where forgetting shows up.</p><p>And it does show up. When OpenAI trained InstructGPT in 2022, the reinforcement learning stage made the model worse on some standard benchmarks.</p><p>The fix was to mix pretraining updates back into that stage, so the model kept rehearsing what it already knew. The final models showed only minimal regressions (<a href="https://arxiv.org/abs/2203.02155">paper</a>).</p><p>That’s replay: rehearsing old material while learning new material. It’s the oldest trick in continual learning, and neuroscientists think the brain does something similar, replaying recent experiences to fold them into long-term knowledge (<a href="https://www.sciencedaily.com/releases/2016/06/160614133609.htm">ScienceDaily</a>).</p><p>It also works at scale. A 2024 study continued pretraining LLMs on new data instead of retraining them from scratch (<a href="https://arxiv.org/abs/2403.08763v2">arXiv</a>).</p><p>Plain continued training either damaged performance on old data or adapted poorly to the new data. Re-warming the learning rate and replaying some old data fixed that. It matched full retraining in models up to 10 billion parameters, for a fraction of the compute.</p><p>So forgetting is real, but it’s an engineering problem labs manage in every training run. If a model can learn in stages before release, it could keep learning in stages after release. Something else is holding it back.</p><h3>Why the weights stay frozen</h3><h3>You can’t test a moving target</h3><p>Before a frontier model ships, labs run it through capability and safety evaluations. What was tested is what people get.</p><p>A model that updates every day would need re-testing every day. A regression could reach millions of users before anyone noticed.</p><h3>Whose lessons does it keep?</h3><p>One model serves millions of people. If it learned from all of them, it would learn from the careless and the malicious too.</p><p>A 2025 study by Anthropic, the UK AI Security Institute and the Alan Turing Institute found that about 250 poisoned documents were enough to plant a backdoor in models from 600M to 13B parameters, regardless of size (<a href="https://www.anthropic.com/research/small-samples-poison">Anthropic</a>).</p><p>The backdoor was deliberately narrow: the model produced gibberish after a trigger phrase. But the authors report similar vulnerabilities during fine-tuning, and a model that learns from its users is fine-tuning on exactly that kind of uncontrolled data.</p><p>Privacy cuts the same way. Researchers extracted hundreds of verbatim training sequences from GPT-2, including publicly posted names, phone numbers and email addresses, even when a sequence appeared in only one training document (<a href="https://arxiv.org/abs/2012.07805">arXiv</a>). A model that learned from your chat could leak it into someone else’s.</p><h3>It’s expensive</h3><p>Every update means a training run on a very large model, followed by all that testing. Doing it per user would mean storing and serving a separate version of the model for each person.</p><p>None of these is a problem with backpropagation. They’re problems of trust, safety and money.</p><h3>The part that’s really unsolved</h3><p>Solve trust and cost, and one hard problem is still left: learning a lot from very little.</p><p>A person corrected once often doesn’t repeat the mistake. Gradient descent learns by nudging weights a little at a time across many examples.</p><p>One correction is one tiny nudge, too small to change much. Push harder on that single example, and you risk overfitting to it or disturbing what the model already knows. That’s where forgetting comes back in.</p><p>This is the heart of Dwarkesh Patel’s 2025 essay on why he doesn’t think AGI is around the corner (<a href="https://www.dwarkesh.com/cp/165349588">Dwarkesh Patel</a>). His complaint isn’t that models are dumb. It’s that you can’t give them high-level feedback and have it stick, the way an employee improves on the job.</p><p>He compares prompting a model to teaching saxophone by sending each student away after one mistake and writing better notes for the next. Prompts and memory notes are those notes.</p><blockquote>The strange part is that models already adapt within a conversation. Dwarkesh describes an LLM getting much better at co-writing once he shows it what he wants, then losing all of it when the session ends.</blockquote><p>So the learning machinery exists, at least in context. What’s missing is a way to turn a few good interactions into a lasting change in the weights, without learning the wrong lesson.</p><p>Google Research’s Nested Learning work is one attempt, giving models memory that updates at several speeds, from fast to slow (<a href="https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/">Google Research</a>). For now, it’s a proof of concept.</p><h3>Where I might be wrong</h3><p><strong>Long streams might be different.</strong> The continual pretraining results cover a few large shifts in data. A model learning every day for years is a different regime.</p><p>In 2024, Richard Sutton’s group found that standard deep learning, run continually, gradually loses its ability to learn until it does no better than a shallow network (<a href="https://www.amii.ca/research/loss-of-plasticity-in-deep-continual-learning">Amii</a>). They showed it on ImageNet and reinforcement learning tasks, not frontier LLMs, but as far as public work shows, nobody has tested years of daily updates at frontier scale either.</p><p><strong>Cost might be the easy part.</strong> LoRA freezes a model’s original weights and trains small add-on matrices instead. On GPT-3, that cut trainable parameters by 10,000 times and GPU memory by 3 times, with quality on par with full fine-tuning (<a href="https://arxiv.org/abs/2106.09685v1">arXiv</a>). A small adapter per user is far cheaper than a separate model per user.</p><p><strong>Maybe it is a learning problem after all.</strong> David Silver and Richard Sutton argue that the next generation of agents will learn mainly from their own experience (<a href="https://the-decoder.com/deepmind-veteran-david-silver-raises-1b-seed-round-to-build-superintelligence-without-llms/">The Decoder</a>). Sutton’s group also concluded that gradient descent alone isn’t enough to keep learning going. If they’re right, the frozen model isn’t just a policy choice; it’s a sign the algorithm needs to change.</p><p>My bet is that the first real version will look boring: small updates trained on vetted data and tested before they go live. Less a model that learns on its own, more a model that gets patched often.</p><p>That would close part of the gap. The rest, learning the right lesson from one correction, is the part worth watching.</p><h3>Over to you</h3><p>I’d like to hear where you land on this:</p><ol><li>Would you trust an assistant that changes a little after every conversation?</li><li>Should a model learn from all its users, or should each user get their own small version?</li><li>Is the real bottleneck trust and cost, or is Sutton right that the algorithm itself has to change?</li><li>If your AI could learn one lasting thing from you, what would you want it to be?</li></ol><h3>Sources</h3><ul><li><a href="https://arxiv.org/abs/2203.02155">Training language models to follow instructions with human feedback</a>, Ouyang et al., OpenAI (2022)</li><li><a href="https://arxiv.org/abs/2403.08763v2">Simple and scalable strategies to continually pre-train large language models</a>, Ibrahim et al. (2024)</li><li><a href="https://www.sciencedaily.com/releases/2016/06/160614133609.htm">How insights into human learning can foster smarter artificial intelligence</a>, ScienceDaily (2016)</li><li><a href="https://www.anthropic.com/research/small-samples-poison">A small number of samples can poison LLMs of any size</a>, Anthropic, UK AI Security Institute and Alan Turing Institute (2025)</li><li><a href="https://arxiv.org/abs/2012.07805">Extracting training data from large language models</a>, Carlini et al. (2021)</li><li><a href="https://www.dwarkesh.com/cp/165349588">Why I don’t think AGI is right around the corner</a>, Dwarkesh Patel (2025)</li><li><a href="https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/">Introducing Nested Learning: a new ML paradigm for continual learning</a>, Google Research (2025)</li><li><a href="https://www.amii.ca/research/loss-of-plasticity-in-deep-continual-learning">Loss of plasticity in deep continual learning</a>, Dohare, Sutton et al., Amii summary of the Nature paper (2024)</li><li><a href="https://arxiv.org/abs/2106.09685v1">LoRA: Low-rank adaptation of large language models</a>, Hu et al. (2021)</li><li><a href="https://the-decoder.com/deepmind-veteran-david-silver-raises-1b-seed-round-to-build-superintelligence-without-llms/">DeepMind veteran David Silver raises $1B seed round to build superintelligence without LLMs</a>, The Decoder (2026)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a158236031cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Pioneers Are Betting Against LLMs]]></title>
            <link>https://medium.com/@ramadhanzome4/the-pioneers-are-betting-against-llms-0be8c29c5de2?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/0be8c29c5de2</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Mon, 19 Oct 2026 13:14:11 GMT</pubDate>
            <atom:updated>2026-10-19T13:14:11.713Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWjaxwvLGXN8Wq4gWCN-7w.png" /></figure><p>19 Oct 2026 · <a href="https://medium.com/u/2cbdfb3e53a9">Ramadhan Zome</a></p><p>There has never been more money, compute or talent pointed at large language models. Yet within a few months of each other, two of the most celebrated researchers in AI raised about a billion dollars each to build something else.</p><p>Yann LeCun, a Turing Award winner and Meta’s former chief AI scientist, left to build world models. David Silver, the reinforcement learning researcher behind AlphaGo, left Google DeepMind to build an agent that learns from its own experience instead of human data.</p><p>When the people who helped build the field bet against its most successful recipe, it’s worth asking why. This is my attempt at an answer.</p><p><strong>Fair warning</strong>: <em>it’s a take, not a verdict, and I might be wrong</em>.</p><h3>The view from the top</h3><p>The frontier has never been stronger, and it has never looked more alike.</p><p>The <a href="https://www.stateof.ai/">State of AI Report 2026</a>, published on October 8, calls the frontier a three-way race between Anthropic, OpenAI and Google, with different leaderboards crowning different winners (<a href="https://toolnavs.com/article/2405-state-of-ai-report-2026-is-out-a-three-lab-race-at-the-frontier-and-agents-doing">summary</a>). Stanford’s <a href="https://hai.stanford.edu/ai-index/2026-ai-index-report">2026 AI Index</a> found the top models from six developers within 25 Elo points of each other on the Arena leaderboard as of March 2026 (<a href="https://c3.unu.edu/blog/2026-stanford-ai-index-report-takeaways">summary</a>).</p><p>The tests can’t keep up either. Benchmarks meant to stay hard for years now saturate within months, and models gained 30 percentage points on Humanity’s Last Exam in a single year. Stanford’s reading is that competition is shifting from raw capability to cost and reliability.</p><p>The money isn’t slowing down. Four US hyperscalers are guiding to roughly $733 billion in combined capital spending for 2026. OpenAI and Anthropic’s combined annualized revenue reached about $105 billion by late summer, up from about $30 billion at the start of the year.</p><p>None of this looks like a field in trouble. It looks like a field where everyone runs the same recipe and arrives at roughly the same place.</p><p>But the progress is jagged. In 2025, a Gemini model won gold at the International Mathematical Olympiad. Yet the best model on ClockBench reads an analog clock correctly only about half the time, while humans manage 90%.</p><p>Robots still fail nearly nine in ten real household tasks. Hold on to that gap. It’s exactly where the pioneers are aiming.</p><h3>The people walking away</h3><p>Two of the field’s most decorated researchers have raised more than $2 billion between them to test a different recipe.</p><h3>Yann LeCun: learn how the world works</h3><p>LeCun founded Meta’s FAIR lab in 2013 and left Meta in November 2025. In March 2026, his new company, AMI Labs, raised $1.03 billion in seed funding at a $3.5 billion pre-money valuation (<a href="https://www.implicator.ai/yann-lecun-raises-1-billion-for-ami-labs-in-europes-largest-seed-round/">Implicator</a>).</p><p>His argument is blunt. LLMs predict the next word, and he told WIRED that scaling them up to human-level intelligence is “complete nonsense.” His alternative is JEPA, an architecture he proposed in 2022 that learns abstract representations of how the world behaves and throws away surface noise.</p><p>AMI plans to train on video and sensor data, not text. Its CEO says there is at least a year of research ahead before the first real-world applications.</p><h3>David Silver: learn from experience</h3><p>Silver led the work behind AlphaGo and AlphaZero, and played a central role in building Google’s Gemini models (<a href="https://the-decoder.com/deepmind-veteran-david-silver-raises-1b-seed-round-to-build-superintelligence-without-llms/">The Decoder</a>). In April 2026, his company, Ineffable Intelligence, raised $1.1 billion at a $5.1 billion valuation. The company calls it the largest seed round ever raised in Europe (<a href="https://finance.yahoo.com/sectors/technology/articles/deepmind-researcher-raises-1-1b-154450275.html">Quartz</a>).</p><p>His target is a “superlearner”: a system that discovers knowledge through its own experience instead of human-generated data. In an essay with Richard Sutton, he argues we are entering an era of experience. Experience, they write, will become the main source of improvement and eventually outgrow human data.</p><p>Ineffable has no product, no revenue and no public roadmap yet.</p><h3>Not just two people</h3><p>Fei-Fei Li’s World Labs raised $1 billion at a $5 billion valuation for its own take on world models. Ilya Sutskever’s Safe Superintelligence is exploring approaches beyond current LLMs.</p><p>Jerry Tworek, who helped build OpenAI’s reasoning models, left to start Core Automation. His view: models that can’t learn from live data will hit a ceiling.</p><h3>What I think is happening</h3><p>My read: the pioneers aren’t betting that LLMs fail. They’re betting on what LLMs are missing, and the big labs are quietly hedging on the same thing.</p><h3>Convergence means the recipe is maturing</h3><p>When every lab trains with roughly the same recipe, results bunch together. That doesn’t mean progress has stopped: the cost of hitting a given benchmark score is dropping roughly 13-fold a year (<a href="https://toolnavs.com/article/2405-state-of-ai-report-2026-is-out-a-three-lab-race-at-the-frontier-and-agents-doing">summary</a>). It means the next big jump probably won’t come from doing the same thing harder.</p><p>The State of AI report makes a similar point. What separates models next is reliability on real tasks, not leaderboard scores.</p><h3>Both bets target the same gap</h3><p>Look at what LeCun and Silver are actually chasing. LeCun wants models that understand the physical world. Silver wants agents that keep learning from experience after they’re built.</p><p>Those are exactly the places where progress looks jagged. Models that win math olympiads still misread clocks, and once they ship, they don’t learn from what happens next.</p><p>Silver’s vision even leans on world models, internal simulations that let an agent predict the results of its actions (<a href="https://the-decoder.com/deepmind-veteran-david-silver-raises-1b-seed-round-to-build-superintelligence-without-llms/">The Decoder</a>). So the “anti-LLM” side is less two rival camps than one camp with two doors.</p><h3>The incumbents are buying insurance</h3><p>Here’s the detail I find most telling. Nvidia invested in both AMI (<a href="https://www.implicator.ai/yann-lecun-raises-1-billion-for-ami-labs-in-europes-largest-seed-round/">Implicator</a>) and Ineffable. Google, whose DeepMind lab is one of the three leaders in the LLM race, also invested in Ineffable (<a href="https://finance.yahoo.com/sectors/technology/articles/deepmind-researcher-raises-1-1b-154450275.html">Quartz</a>).</p><p>Demis Hassabis, who runs Google DeepMind, has said world models could be the future of AI (<a href="https://the-decoder.com/deepmind-veteran-david-silver-raises-1b-seed-round-to-build-superintelligence-without-llms/">The Decoder</a>). It looks like the field is buying insurance.</p><h3>My guess: a merger, not a replacement</h3><p>I don’t think language models get replaced. I think they become one layer. Reasoning models are already trained with reinforcement learning on top of a language model, so the two worlds have started to merge.</p><blockquote>My bet is that the next big system combines three pieces: language, a world model and learning from experience. Language carries knowledge and communication, the world model handles physical reality, and experience keeps it improving after deployment.</blockquote><p>The real race is over who assembles it first. The incumbents have the compute and the products. The newcomers have a cleaner idea and no product deadlines.</p><h3>Where I might be wrong</h3><p>Here’s the strongest case against everything I just said.</p><p><strong>Scaling may not be done.</strong> Stanford found models improving faster than the benchmarks built to measure them, including a 30-point jump on Humanity’s Last Exam in one year. Bunched-up leaderboards might say more about saturated tests than about a ceiling.</p><p><strong>The big labs may automate their way ahead.</strong> By August 2026, Claude led 26% of Anthropic’s measured model R&amp;D work, up from under 1% in February, according to the State of AI report (<a href="https://toolnavs.com/article/2405-state-of-ai-report-2026-is-out-a-three-lab-race-at-the-frontier-and-agents-doing">summary</a>). Whatever “led” means in practice, AI that speeds up research inside the incumbents could widen their lead, not shrink it.</p><p><strong>The alternatives are years away.</strong> LeCun himself expects general-purpose systems to take three to five years (<a href="https://www.implicator.ai/yann-lecun-raises-1-billion-for-ami-labs-in-europes-largest-seed-round/">Implicator</a>). Reinforcement learning shone in games with fixed rules and a clear score at the end, which the real world rarely offers.</p><p><strong>Some of this is hype money.</strong> Even AMI’s CEO predicted world models would become a fundraising buzzword, with every startup soon claiming to build one. A billion-dollar seed round proves investors believe in a person, not that the person is right.</p><h3>Over to you</h3><p>I’d like to be argued with on this one. A few questions for the comments:</p><ol><li>Are LeCun and Silver early, or just wrong?</li><li>Will the next big leap come from inside the top three labs, or from a newcomer?</li><li>Can a model that stops learning the day it ships ever be called intelligent?</li><li>With a billion dollars to bet on one path, which would you pick: scaling LLMs, world models or learning from experience?</li></ol><h3>Sources</h3><ul><li><a href="https://toolnavs.com/article/2405-state-of-ai-report-2026-is-out-a-three-lab-race-at-the-frontier-and-agents-doing">State of AI Report 2026 is out: a three-lab race at the frontier</a>, ToolNavs summary of the <a href="https://www.stateof.ai/">full report</a></li><li><a href="https://c3.unu.edu/blog/2026-stanford-ai-index-report-takeaways">What the 2026 Stanford AI Index Report tells us about the state of AI</a>, UNU summary of the <a href="https://hai.stanford.edu/ai-index/2026-ai-index-report">full report</a></li><li><a href="https://www.implicator.ai/yann-lecun-raises-1-billion-for-ami-labs-in-europes-largest-seed-round/">Yann LeCun raises $1 billion for AMI Labs in Europe’s largest seed round</a>, Implicator</li><li><a href="https://finance.yahoo.com/sectors/technology/articles/deepmind-researcher-raises-1-1b-154450275.html">DeepMind researcher raises $1.1B for Ineffable Intelligence</a>, Quartz</li><li><a href="https://the-decoder.com/deepmind-veteran-david-silver-raises-1b-seed-round-to-build-superintelligence-without-llms/">DeepMind veteran David Silver raises $1B seed round to build superintelligence without LLMs</a>, The Decoder</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0be8c29c5de2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GPU DRAM Architecture, Explained Simply]]></title>
            <link>https://medium.com/genaitrail/gpu-dram-architecture-explained-simply-a4eb4c4d8dcb?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4eb4c4d8dcb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[computer-architecture]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 01:55:26 GMT</pubDate>
            <atom:updated>2026-09-28T01:55:26.268Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1AsieIXZHe6hzGNxVnI1lQ.jpeg" /><figcaption><a href="https://blogs.nvidia.com/blog/first-gpu-gaming-ai/">https://blogs.nvidia.com/blog/first-gpu-gaming-ai/</a></figcaption></figure><p>I’ve gotten a sudden interest in GPUs lately, which makes sense given my interest in low level architectures. I’ll try to keep this as simple as possible, no jargon.</p><p>A GPU’s main job is computation, and because it can perform many computations in parallel, it’s especially well suited to matrix math.</p><p>Say you have a very busy restaurant. One waiter serving a large number of tables gets overworked, orders get delayed, the kitchen backs up, customers get frustrated. That overworked waiter is exactly the CPU’s problem, a CPU has only a few very capable cores, each handling one task at a time, one after another.</p><p>A GPU takes the opposite approach. Instead of one master chef handling every order alone, it hires thousands of simpler workers and has them all work at once. In GPU terms, the smallest unit of work is a thread, one worker doing one small task. But these workers don’t act alone. 32 threads are grouped into a warp, and all 32 execute the same instruction at the same time, in lockstep, like a team of 32 waiters trained to move together instead of independently. Warps themselves are grouped into thread blocks, and each thread block gets assigned to one Streaming Multiprocessor, or SM.</p><p>Think of an SM as one station in the restaurant, with its own dedicated team working that section. A modern Ampere generation GPU can have dozens of these SMs running at once.</p><p>All these workers need ingredients to cook with. Where does the GPU actually keep the data they work on? That’s the classic memory question, and it works a little differently than you’d expect.</p><p><strong>The Kitchen’s Pantry: GPU Memory</strong></p><p>GPUs talk to memory through a Memory Controller, which routes requests from the SMs over a memory bus to the DRAM chips. Think of the DRAM as a warehouse where we keep ingredients, and the memory bus as the conveyor system that carries them from the warehouse to the workers. Give it exact instructions, and it delivers what you asked for.</p><p>The faster that memory is, the better we can keep up with orders. Otherwise, more frustrated customers. GPU memory comes in two types, GDDR (used in client GPUs like the RTX 3080, and also in some server GPUs like the A6000) and HBM (used in server GPUs like the A100).</p><p>These two aren’t built the same way. GDDR sits flat around the GPU core, individual chips laid out in a plane, each connected to the core over its own slice of the memory bus. HBM stacks multiple DRAM dies vertically on top of each other instead, trading some of GDDR’s raw per pin speed for a much wider, higher bandwidth connection packed into a smaller footprint. Since GDDR is the one we’re focused on here, let’s crack one of those chips open and see what’s inside.</p><p><strong>Inside the Pantry: How GDDR Is Organized</strong></p><p>Each GDDR chip is split into independent channels, commonly two 16 bit channels per chip, sometimes ganged together so they act like one 32 bit channel. Each channel has its own set of banks, typically 16 of them, basically separate shelves in that section of the pantry.</p><p>Inside a bank sit the DRAM cells, the actual ingredients we’re after. Cells are arranged in rows, and a row is what you read from or write to through the row buffer, a small staging area roughly 1 to 2 KB in size. Think of the row buffer as the counter where an order gets set out before a waiter carries it off.</p><p>Before we get to the commands that move data around, it’s worth zooming into what a single DRAM cell actually is. Strip it down and you’ve got two parts, a capacitor and a transistor. The capacitor is basically a tiny jar of water, it either holds a charge or it doesn’t, and that’s your one bit. Full jar means 1, empty jar means 0. The transistor sitting next to it works like a gate, it’s what lets the row buffer reach in and pour that water out or pour new water in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z2YPUG3SqRjBJP54KJ6v3A.jpeg" /><figcaption>GDDR6 DRAM Organization. Credit: <a href="https://gururaj-s.github.io/assets/pdf/SEC25_GPUHammer.pdf">https://gururaj-s.github.io/assets/pdf/SEC25_GPUHammer.pdf</a></figcaption></figure><p>Here’s the part that trips people up. To read a jar, the row buffer pours the water out and checks how much came out. That empties the jar. So right after reading, the row buffer pours the same amount straight back in, restoring it to exactly what it was. Read, then immediate rewrite, every single time, automatically.</p><p>Writing works almost the same way, just with an extra step. You can’t reach into one jar in isolation, the whole shelf, meaning the whole row, gets pulled onto the tray first. Once every jar on that shelf is sitting there, the one jar you actually wanted to change gets emptied or filled to its new value. Then the entire tray slides back onto the shelf, all jars together, the one you changed and every other jar on that row along for the ride whether you touched it or not.</p><p>So both directions come down to the same physical dance, whole row out, one thing happens to it, whole row back in. That’s why you can’t change a single bit in DRAM without briefly touching every other bit sitting in that same row.</p><p>One more thing worth mentioning. Since these jars leak a little on their own just sitting there, even a cell nobody touches will slowly forget what it was holding. That’s exactly why refreshing exists, it’s not cleanup, it’s the pantry doing its rounds and topping off every jar before it drains completely.</p><p>And because these charges are so small, they’re occasionally flipped by outside interference, stray cosmic rays being the textbook example, and a bit silently changes value with nobody touching it. Server GPUs guard against this with ECC memory, which keeps a handful of extra bits around purely to catch and correct these random flips before they turn into a real problem.</p><p><strong>Moving the Ingredients: ACT, READ/WRITE, PRE, REF</strong></p><p>Now with the pantry laid out and the cells understood, here’s how the memory controller actually pulls data out of it.</p><p>To grab data, the memory controller issues an ACT (Activate) command, which opens a row and copies its contents into the row buffer. Once that row is open, READ or WRITE commands can pull or push a specific column inside it, basically pointing at exactly which item on the counter you want.</p><p>You can’t open a second row in the same bank while another is still open, so a PRE (Precharge) command closes the current row before a new one can be activated. There’s a minimum wait, somewhere around 45 to 50 ns, this is the row cycle time, tRC, between two activations to the same bank, so the pantry doesn’t get its orders crossed.</p><p>REF, refresh, is the periodic command that handles the leaking capacitor problem from before. Rather than refreshing the whole chip at once, it happens in small bursts every few microseconds, and the entire chip gets fully refreshed within about 64 ms.</p><p>Put a real example on it. The A6000 uses GDDR6 with a 384 bit memory bus. Each chip contributes 32 bits, so 384 divided by 32 gives you 12 chips working the pantry at once.</p><p><strong>Stepping Outside the Pantry: A100 and HBM</strong></p><p>If GDDR is a pantry with shelves laid out around the kitchen, HBM is more like a walk in freezer built straight up. The A100 uses HBM2e arranged in stacked dies, physically six stacks on the chip but only five active, yield reasons, each stack connected over roughly a 1024 bit interface. Add that up across five stacks and you get a bus over ten times wider than the A6000’s GDDR6, which is how HBM hits terabyte per second bandwidth despite running at a lower clock. Wide and stacked instead of fast and flat.</p><p><strong>Why any of this matters</strong></p><p>It’s easy to think of a GPU as just “the AI chip” and stop there, but almost every bottleneck in training or running large models traces back to this exact plumbing. Matrix multiplication is cheap for a GPU. Feeding thousands of threads fast enough that they’re never sitting idle waiting on a row to open is the actual hard problem. Understanding ACT, PRE, and row buffers isn’t trivia, it’s the difference between a GPU running near its theoretical peak and one that’s quietly starved most of the time.</p><p>If you want to see where this same row buffer mechanism turns into an actual security bug, I am wiritng a separate piece on Row Hammer, how hammering one row can flip bits in a row that was never touched.</p><p>Written by 52 61 6D 61 64 68 61 6E 20 5A 6F 6D 65</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><p>👉 Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></p><p>👉 Follow us: <a href="https://medium.com/genaitrail"><strong>Medium</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4eb4c4d8dcb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/genaitrail/gpu-dram-architecture-explained-simply-a4eb4c4d8dcb">GPU DRAM Architecture, Explained Simply</a> was originally published in <a href="https://medium.com/genaitrail">GenAITrail</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Row Hammer: How Reading Memory Fast Enough Breaks Memory That Was Never Touched]]></title>
            <link>https://grain.saltindex.com/row-hammer-how-reading-memory-fast-enough-breaks-memory-that-was-never-touched-61ca7125e3fe?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/61ca7125e3fe</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[computer-security]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Sun, 27 Sep 2026 19:12:30 GMT</pubDate>
            <atom:updated>2026-09-30T03:48:15.542Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*bnkziVzVU33V4OJZ2eE6Xg.jpeg" /><figcaption><a href="https://www.linkedin.com/pulse/ddr-row-hammer-attack-aryan-chauhan/">https://www.linkedin.com/pulse/ddr-row-hammer-attack-aryan-chauhan/</a></figcaption></figure><p>I wasn’t looking for this, I stumbled into it while writing about GPU memory. It’s a side effect of how DRAM physically works, and once you see the mechanism it’s hard to unsee.</p><p>Quick recap on the physical setup, because Row Hammer only makes sense once this clicks. Each bit in DRAM lives in a tiny capacitor, basically a jar that’s either full, 1, or empty, 0. Jars are packed extremely close together on a chip, row after row, to fit billions of them into a small space. To read a jar, the hardware activates its row, pulls the value into a staging area called the row buffer, then writes that same value straight back into the jar before closing the row again. That’s normal operation. Nothing unusual, nothing broken.</p><p><strong>So what’s actually going wrong</strong></p><p>Here’s the part that isn’t obvious until someone points it out. Activating a row isn’t a gentle, isolated action. Electrically, it’s more like a small jolt through that section of the chip. One activation, one jolt, is nothing, the jars nearby don’t even notice.</p><p>But do it fast, over and over, targeting the same row again and again, and those tiny jolts start to add up. Jars physically next to the row being hammered can leak a little charge each time, not because anyone touched them, just from being close enough to feel the vibration. The original 2014 research that gave this bug its name found this wasn’t some rare fluke either, on the DDR3 chips they tested, roughly one in every 1,700 cells turned out to be susceptible, and a bit flip could show up after somewhere around 139,000 rapid accesses to a neighboring row. Not exotic at all, just fast and repetitive.</p><p>A stronger version of the attack, called double-sided hammering, doesn’t just hammer one neighbor, it hammers both rows sitting on either side of the target row at once. Squeezing the victim row from both directions leaks more charge faster than hammering just one side, which makes the flip more reliable and faster to trigger.</p><p><strong>Why this is actually dangerous</strong></p><p>A flipped bit sounds small, but memory holds everything, variables, pointers, permission flags, the stuff that decides what a program is and isn’t allowed to do. This stopped being theoretical fast. In 2015, Google’s Project Zero turned it into two working privilege escalation exploits, one broke out of a sandboxing mechanism entirely, the other ran as a completely unprivileged Linux process and used the bug to manipulate page tables, the exact structures that map which memory a process is allowed to touch, ending in full unrestricted access to a machine’s physical memory.</p><p>What makes it worse is that none of the software involved has to be buggy. The Project Zero code was just a normal, correctly written program hammering memory fast. The exploit lives entirely below the software layer, in the physics of the chip, which is also exactly why it kept spreading to new platforms afterward. In 2016, researchers used it to root Android phones. Nearly a decade later, in 2024, it showed up on AMD Zen chips and on DDR5 for the first time, and separately on RISC-V hardware, the first time anyone had demonstrated it there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*lpUsSQ2vdLRknN-lj93kFg.jpeg" /><figcaption><a href="https://opensource.googleblog.com/2021/11/Open%20source%20DDR%20controller%20framework%20for%20mitigating%20Rowhammer.html">https://opensource.googleblog.com/2021/11/Open%20source%20DDR%20controller%20framework%20for%20mitigating%20Rowhammer.html</a></figcaption></figure><p><strong>How it actually gets pulled off</strong></p><p>The tricky part for an attacker is that you can’t just hammer any row and expect useful results. You need the target row, the one holding data you want to flip, to physically sit next to the row you’re hammering, and modern systems scramble physical memory layout to make that harder to line up. Early exploits also leaned on a CPU instruction that flushes data out of cache, since hammering only works on values sitting in DRAM, not cached copies, so attackers had to force cache misses on every single access. Later research got around needing that instruction at all, using carefully patterned memory access instead, which is part of why a JavaScript version of the attack, running inside a browser tab with no special privileges, turned out to be possible too.</p><p><strong>What actually stops it</strong></p><p>A few defenses exist, layered rather than relying on any single fix. Refreshing memory more often helps, since a shorter window between refreshes gives leaked charge less time to accumulate before it’s topped back up, research found dropping the refresh interval to roughly a seventh of the usual 64 ms brought disturbance errors close to zero, though that comes at the cost of power and performance.</p><p>Target Row Refresh goes further, having the memory chip itself track how many times each row gets activated within a set time window, and if that count crosses a defined threshold, it proactively refreshes the neighboring rows before they get disturbed. It sounds airtight, but it hasn’t stayed airtight. Newer attacks have specifically been built to find the blind spots in exactly this kind of counter-based defense, and by 2020 researchers showed that even DDR4 chips marketed as protected were still exploitable. By 2025, a similar bypass had been demonstrated against Target Row Refresh on modern DDR5.</p><p>ECC memory, the same error correction used against cosmic ray bit flips, helps too, but it’s not a clean fix either. Standard ECC is built to reliably catch a single flipped bit and detect two, but Row Hammer can flip more than two bits in the same memory word at once, and researchers have shown that precisely targeted three-bit flips can slip past that kind of correction entirely, unnoticed.</p><p>None of these make the problem disappear, they raise the bar. Which is why Row Hammer keeps resurfacing in new forms years after it was first discovered. It’s not a bug you patch once, it’s a physical property of packing memory this dense, and packing memory dense is exactly what every new generation of DRAM keeps doing.</p><p><strong>Why it’s worth understanding</strong></p><p>Row Hammer is a good reminder that security bugs don’t only live in code. Sometimes the vulnerability is baked into the physics of the hardware itself, invisible from the software side entirely. You can audit every line of a program and find nothing wrong, because the actual flaw is a handful of atoms leaking charge into their neighbors a little faster than expected.</p><p>Written by 52 61 6D 61 64 68 61 6E 20 5A 6F 6D 65</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61ca7125e3fe" width="1" height="1" alt=""><hr><p><a href="https://grain.saltindex.com/row-hammer-how-reading-memory-fast-enough-breaks-memory-that-was-never-touched-61ca7125e3fe">Row Hammer: How Reading Memory Fast Enough Breaks Memory That Was Never Touched</a> was originally published in <a href="https://grain.saltindex.com/">Salt Index</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The NVIDIA A100: When GPU Architecture Becomes Part of the Research Method]]></title>
            <link>https://medium.com/@ramadhanzome4/the-nvidia-a100-when-gpu-architecture-becomes-part-of-the-research-method-4474c5ada123?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4474c5ada123</guid>
            <category><![CDATA[nvidia-a100]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Mon, 14 Sep 2026 13:19:20 GMT</pubDate>
            <atom:updated>2026-09-14T13:19:20.806Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jP16K0_0obXIGFxzPO0UIQ.jpeg" /></figure><p>A GPU is often described with one number: how many teraFLOPS it delivers. Useful, but incomplete.</p><p>For machine-learning researchers, the important question is not only, “How fast is this GPU?” It is, “What experiments become possible because this GPU exists?”</p><p>The NVIDIA A100, based on the Ampere architecture, was important because it improved several constraints at once: matrix computation, memory capacity, memory bandwidth, multi-GPU communication, and resource sharing. Together, those features changed the practical scale of deep-learning research. <a href="https://www.nvidia.com/en-us/data-center/a100/">NVIDIA A100 specifications</a></p><h3>More Than a Faster Calculator</h3><p>Deep-learning training is mostly repeated matrix multiplication. Every forward pass, backward pass, and optimizer update involves large numbers of these operations.</p><p>The A100 contains third-generation Tensor Cores, specialised hardware designed to accelerate this kind of matrix computation. It supports formats including FP16, BF16, and TensorFloat-32 (TF32). TF32 is especially interesting because it allows many existing FP32-style deep-learning workloads to use Tensor Core acceleration without requiring the researcher to redesign the entire model around low precision. <a href="https://www.nvidia.com/content/dam/en-zz/Solutions/Data-Center/nvidia-ampere-architecture-whitepaper.pdf">NVIDIA’s Ampere architecture whitepaper</a></p><p>In practice, this means that a researcher can train more iterations per day, test more hyperparameters, and run more ablations before a deadline arrives. That sounds mundane, but it is often the difference between a model that is merely implemented and a model that is actually evaluated.</p><h3>Memory Is Often the Real Limit</h3><p>Compute speed is only one bottleneck. Many modern models fail before training starts because they do not fit in GPU memory.</p><p>The A100 was available in 40 GB and 80 GB configurations. The 80 GB model also provides very high memory bandwidth, reaching roughly 2 TB/s depending on the variant. This matters for workloads with long sequences, large batch sizes, large embedding tables, or multiple model components. <a href="https://images.nvidia.com/data-center/a100/a100-datasheet.pdf">NVIDIA A100 datasheet</a></p><p>For a researcher, more memory creates choices:</p><ul><li>Increase batch size to obtain more contrastive-learning negatives.</li><li>Use longer input sequences instead of aggressively truncating data.</li><li>Train larger models without splitting them across several GPUs.</li><li>Keep more data prefetched and reduce time spent waiting for memory transfers.</li></ul><p>The last point is easy to miss. A powerful GPU is still wasted if it waits for data from storage or system memory. Good model design, efficient data loading, and GPU memory are part of the same system.</p><h3>TFLOPS Do Not Guarantee Fast Training</h3><p>A100 performance figures are peak theoretical values. Real training speed depends on many other factors:</p><ul><li>Is the model using Tensor Core-friendly operations?</li><li>Is mixed precision enabled correctly?</li><li>Is the GPU waiting for the DataLoader?</li><li>Is storage fast enough?</li><li>Are batch sizes large enough to use the GPU efficiently?</li><li>Is the GPU shared with other users?</li></ul><p>This is why profiling matters. A model can run on an A100 and still train slowly if preprocessing is inefficient or the CPU cannot prepare batches quickly enough.</p><p>The lesson is simple: hardware performance is a pipeline problem, not only a GPU problem.</p><h3>One GPU, Several Researchers</h3><p>A particularly useful A100 feature in shared university labs is Multi-Instance GPU, or MIG. MIG can partition one A100 into as many as seven hardware-isolated GPU instances. Each instance receives dedicated compute and memory resources. <a href="https://developer.nvidia.com/blog/getting-the-most-out-of-the-nvidia-a100-gpu-with-multi-instance-gpu/">NVIDIA’s MIG overview</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NPnLAR-B81ICrCg1U8IEA.jpeg" /></figure><p>This matters because not every experiment needs an entire 80 GB GPU. Small preprocessing tests, debugging runs, linear probes, and inference jobs can use smaller GPU partitions, while larger pretraining jobs can use the full device.</p><p>MIG creates extra compute by dividing an existing GPU. But it can make a shared research environment more predictable and fair, because one user’s small experiment does not need to occupy an entire accelerator.</p><h3>Scaling Beyond One GPU</h3><p>For large training jobs, A100 systems can use NVLink to connect GPUs at much higher bandwidth than ordinary PCIe communication. NVIDIA lists up to 600 GB/s of NVLink bandwidth for supported A100 systems. <a href="https://www.nvidia.com/en-us/data-center/a100/">NVIDIA A100 platform details</a></p><p>This is important for distributed training, where GPUs repeatedly exchange gradients. Without fast communication, adding GPUs can produce disappointing speed gains because the system spends too much time synchronising.</p><p>However, multi-GPU training is not automatically better. It introduces added complexity: distributed data loading, checkpointing, communication overhead, and reproducibility concerns. A single well-used A100 is often more valuable for early research than several badly coordinated GPUs.</p><h3>The Research Lesson</h3><p>The A100 is valuable because it reduces the cost of asking better questions. A researcher can test more data representations, compare more baselines, repeat experiments with different random seeds, and run controlled ablations instead of relying on one expensive training run.</p><p>A powerful GPU should not encourage careless experimentation. It should enable more rigorous experimentation.</p><p>The A100 made that rigor more practical for deep learning, large-scale data analysis, and scientific computing. Its legacy is not only faster training, but a wider space of experiments that researchers can realistically afford to attempt.</p><p><em>Written by </em><em>52 61 6D 61 64 68 61 6E 20 5A 6F 6D 65</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4474c5ada123" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond the Chatbot: How Self-Attention Learns Structure by Accident]]></title>
            <link>https://medium.com/@ramadhanzome4/beyond-the-chatbot-how-self-attention-learns-structure-by-accident-a63baf7fdc1f?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a63baf7fdc1f</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[self-attention]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 16:12:33 GMT</pubDate>
            <atom:updated>2026-09-08T16:15:50.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzUhfHLVuP3CDlegTw8DyQ.jpeg" /></figure><p>If you work in machine learning today, you are inevitably working with Transformers. But beneath the high-level APIs of Hugging Face and PyTorch lies a remarkably elegant mathematical engine — one that often discovers structure in data without ever being told that structure exists.</p><p>To understand why this architecture is so versatile, we have to strip away the abstraction and walk step-by-step through the math: from tokenization to the matrix multiplication that powers self-attention.</p><h3>1. The Vocabulary Building Block: Byte-Pair Encoding (BPE)</h3><p>Before a forward pass can even begin, sequential data — whether it’s English text or a stream of bytes — must be mapped to discrete mathematical representations. Tokenization historically faced a trade-off:</p><ul><li><strong>Word-level tokenization</strong> leads to massive, sparse embedding spaces and Out-Of-Vocabulary (OOV) errors when encountering variations like “hyper-running.”</li><li><strong>Character-level tokenization</strong> avoids OOV errors completely but forces the model to learn meaning from overly granular, context-poor inputs, stretching the sequence length to computationally expensive extremes.</li></ul><p>Modern models solve this using sub-word tokenization, primarily via <strong>Byte-Pair Encoding (BPE)</strong>. BPE is a data compression technique that iteratively merges the most frequently occurring byte or character pairs into single tokens. In practice, it operates on raw bytes rather than characters, which is why it handles code, rare languages, and binary data gracefully.</p><p>Consider a simplified training corpus containing two words: “hat” (frequency: 3) and “cat” (frequency: 2).</p><ol><li><strong>Initialization:</strong> The corpus is split into characters. The base vocabulary is simply [&quot;h&quot;, &quot;a&quot;, &quot;t&quot;, &quot;c&quot;].</li><li><strong>Iteration 1:</strong> The algorithm computes pair frequencies. The adjacent pair “a t” appears 5 times across the corpus. It merges them to create “at”. The vocabulary expands to [&quot;h&quot;, &quot;a&quot;, &quot;t&quot;, &quot;c&quot;, &quot;at&quot;].</li><li><strong>Iteration 2:</strong> It recalculates frequencies. The pair “h at” appears 3 times. They merge into “hat”. The vocabulary is now [&quot;h&quot;, &quot;a&quot;, &quot;t&quot;, &quot;c&quot;, &quot;at&quot;, &quot;hat&quot;].</li></ol><p>This merging process continues until the vocabulary reaches a pre-defined limit. The result is a highly optimized dictionary where common sequences become single tokens, while rare sequences are broken down into logical sub-units.</p><h3>2. Static Embeddings vs. Dynamic Context</h3><p>A common architectural confusion is the distinction between how a model learns its vocabulary versus how it learns context. These are handled by entirely different weight matrices.</p><p><strong>The Embedding Matrix (Static Definitions)</strong></p><p>Once BPE defines the vocabulary, every token ID is mapped to a row in an embedding matrix. If the vocabulary has 50,000 tokens and the model dimension (d_model) is 512, this matrix is 50,000 × 512. During backpropagation, the model updates these vectors to cluster semantically similar tokens together in latent space. However, these vectors are static during inference: the token for “bank” will always retrieve the exact same 512-dimensional vector, regardless of whether the input is “river bank” or “bank account.”</p><p><strong>The Attention Weights (Dynamic Context)</strong></p><p>To inject context, the Transformer uses projection matrices (W_q, W_k, W_v). These matrices do not store static definitions; they learn structural and sequential rules. They dynamically shift the representation of a token based on its surroundings.</p><h3>3. The Math of Self-Attention</h3><p>Self-attention is the mechanism that computes this dynamic context. It utilizes three learned weight matrices to project the input embeddings into three distinct representations:</p><ul><li><strong>Query (Q):</strong> The representation of the current token looking for context.</li><li><strong>Key (K):</strong> The representation of a token offering context to others.</li><li><strong>Value (V):</strong> The actual information the token will pass along if selected.</li></ul><p>Let’s execute the math on a simple sequence: “cat sat”.</p><p>Instead of sequential processing, we stack our input embeddings as rows in a matrix X. For this example, let the model dimension be 3.</p><pre>X = [ 1  2  0 ]  &lt;-- &quot;cat&quot;<br>    [ 0  1  1 ]  &lt;-- &quot;sat&quot;</pre><h3>Parallel Projection</h3><p>We project X into Queries and Keys by taking the dot product with our learned weight matrices (W_q and W_k). Let the projection dimension (d_k) be 2.</p><pre>Q = X · W_q = [ 1  2  0 ] · [ 1  0 ] = [ 1  2 ]<br>              [ 0  1  1 ]   [ 0  1 ]   [ 1  1 ]<br>                            [ 1  0 ]</pre><pre>K = X · W_k = [ 1  2  0 ] · [ 0  1 ] = [ 2  1 ]<br>              [ 0  1  1 ]   [ 1  0 ]   [ 1  1 ]<br>                            [ 0  1 ]</pre><p>Notice that Row 1 of Q represents the Query for “cat”, and Row 2 represents the Query for “sat”. The computation happens in a single, highly parallelizable matrix multiplication.</p><h3>The Attention Score (Scaled Dot-Product)</h3><p>To determine how much focus every token should allocate to every other token, we compute the similarity between all Queries and all Keys by multiplying Q by the transpose of K (K^T).</p><pre>Similarity = Q · K^T = [ 1  2 ] · [ 2  1 ] = [ 4  3 ]<br>                       [ 1  1 ]   [ 1  1 ]   [ 3  2 ]</pre><p>The resulting matrix provides the raw attention scores:</p><ul><li>Position [0,0] (value: 4) is the attention &quot;cat&quot; pays to itself.</li><li>Position [0,1] (value: 3) is the attention &quot;cat&quot; pays to &quot;sat&quot;.</li></ul><p>Before normalization, these scores are scaled down by dividing by √d_k. This keeps the dot products from growing too large as the dimension increases, which would otherwise push softmax into regions with vanishing gradients. With d_k = 2, that’s a factor of about 1.41 — small here, but essential at real model dimensions of 64 or 128.</p><h3>Softmax Normalization</h3><p>Finally, we apply the Softmax function row-wise. This normalizes the scaled scores into a probability distribution where each row sums to 1.0.</p><pre>Attention = Softmax(Q · K^T / √d_k) = [ 0.73  0.27 ]<br>                                      [ 0.73  0.27 ]</pre><p>We can read the network’s internal routing directly from this matrix: when constructing a new context-aware representation for “cat”, it pulls roughly 73% of its information from itself, and 27% from “sat”. <em>(In this toy example both rows come out identical because of the specific weights we chose; in a trained model, every row is distinct.)</em></p><h3>The Value Projection: What Actually Gets Passed Along</h3><p>Attention weights alone are just routing scores. The final step determines what information travels along those routes. We compute the Value matrix the same way, then take a weighted sum of the value vectors using the attention probabilities:</p><pre>V = X · W_v<br>Output = Attention · V</pre><p>Each token’s new representation is therefore a weighted mixture of every token’s Value vector — with the mixture proportions decided by how strongly its Query matched each Key. This Output matrix, not the attention weights, is what flows into the next layer. Self-attention is a routing mechanism wrapped around a weighted average.</p><h3>One More Ingredient: Positional Encodings</h3><p>There is a subtle problem with everything above: the attention computation itself doesn’t know word order. “cat sat” and “sat cat” produce the same Q, K, and V, and therefore the same output.</p><p>Transformers escape this trap by adding <strong>positional encodings</strong> to the input embeddings before the first layer — vectors that encode each token’s position in the sequence. Word order enters through the input, and every layer above preserves it. Any claim about attention “understanding grammar” is really a claim about the whole pipeline, positional information included.</p><h3>What the Attention Matrix Actually Tells Us</h3><p>It’s tempting to read attention weights as the model’s explanation — to say “the matrix is the parser” because scores often align with syntactic relationships like adjectives attending to their nouns. This happens often enough to be meaningful, but it isn’t guaranteed.</p><p>Research on attention interpretability has shown that individual attention weights are not always faithful explanations of a model’s decisions; sometimes high attention coincides with strong syntactic structure, sometimes it doesn’t. The honest claim is narrower and still impressive: trained attention matrices frequently encode structural relationships resembling syntax, as an emergent byproduct of optimizing a prediction objective — not because any grammatical rule was ever hardcoded.</p><h3>4. Why the Same Engine Works Everywhere</h3><p>Once you see self-attention as a general mechanism for weighting sequential dependencies — <em>“which earlier elements matter for interpreting this element?”</em> — its domain-agnosticism makes sense.</p><p>The same machinery that resolves ambiguity in language (which “bank”?) also works on source code, protein sequences, audio, and time series, because they all share the property that meaning depends on context spread across a sequence. What changes between domains is the tokenization and the training objective; the Q·K^T routing and the weighted Value mixture stay exactly the same.</p><h3>5. Implementing It in Code</h3><p>Here is that exact mathematical flow translated into PyTorch, complete with scaling and the Value step:</p><pre>import math<br>import torch<br>import torch.nn.functional as F<br><br># 1. Setup the inputs and weights from our example<br>X = torch.tensor([[1., 2., 0.],<br>                  [0., 1., 1.]])<br>W_q = torch.tensor([[1., 0.],<br>                    [0., 1.],<br>                    [1., 0.]])<br>W_k = torch.tensor([[0., 1.],<br>                    [1., 0.],<br>                    [0., 1.]])<br>W_v = torch.tensor([[1., 0.],<br>                    [0., 1.],<br>                    [0., 1.]])<br><br># 2. Parallel Projection (Matrix Multiplication)<br>Q = X @ W_q<br>K = X @ W_k<br>V = X @ W_v<br><br># 3. Scaled Attention Scores (Dot Product + scaling)<br>d_k = Q.size(-1)<br>scores = (Q @ K.T) / math.sqrt(d_k)<br><br># 4. Softmax Normalization (across rows)<br>attention = F.softmax(scores, dim=-1)<br><br># 5. Weighted sum of Values<br>output = attention @ V<br>print(&quot;Attention Weights:&quot;)<br>print(attention)<br>print(&quot;\nSelf-Attention Output:&quot;)<br>print(output)</pre><h3>Conclusion</h3><p>The brilliance of the Transformer architecture lies in framing sequential relationships as linear algebra. By utilizing Byte-Pair Encoding, models can ingest vast, complex vocabularies without buckling under OOV errors. By utilizing matrix multiplication for self-attention, they bypass the sequential bottlenecks of RNNs while their routing weights — trained purely to minimize a prediction loss — frequently reorganize themselves into something that looks suspiciously like structure.</p><p>No one tells the model what a noun is, or that position matters, or which context should win. The math finds it anyway. That’s the real story hiding beneath the API.</p><p><em>Written by </em><em>52 61 6D 61 64 68 61 6E 20 5A 6F 6D 65</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a63baf7fdc1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RWX Memory in Windows: What Read, Write, and Execute Really Mean]]></title>
            <link>https://medium.com/@ramadhanzome4/rwx-memory-in-windows-what-read-write-and-execute-really-mean-4897c49d3b76?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4897c49d3b76</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[windows-memory-management]]></category>
            <category><![CDATA[windows-internals]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 16:39:25 GMT</pubDate>
            <atom:updated>2026-08-11T16:39:25.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8cTTlg9cY3SJMmjCN2B6og.png" /></figure><p>There are few things in a malware-analysis report that attract attention as quickly as <strong>RWX</strong>.</p><p>You open a PE file, inspect its sections, and find something like:</p><pre>.text    RWX</pre><p>Or, while analysing a running process, you find a memory region marked:</p><pre>PAGE_EXECUTE_READWRITE</pre><p>It is tempting to stop there.</p><p>RWX means Read, Write, Execute. Therefore, suspicious.</p><p>But that explanation skips most of what is actually interesting.</p><p>What does it mean for memory to be executable in the first place? Where do these permissions come from? Is an RWX PE section the same thing as an RWX memory region? And why is Windows generally uncomfortable with memory that is both writable and executable?</p><p>To answer those questions, it helps to follow RWX from the executable file all the way down to the processor.</p><h3>Start with virtual memory</h3><p>A process does not normally work directly with physical RAM addresses.</p><p>When a program accesses an address, it is using a <strong>virtual address</strong>. The processor and operating system work together to translate that address to a physical location.</p><p>A simplified view looks like this:</p><pre>Program<br>   │<br>   │ virtual address<br>   ▼<br>CPU<br>   │<br>   ▼<br>Page tables<br>   │<br>   ▼<br>Physical memory</pre><p>The important part is that the translation is not simply:</p><blockquote><em>“This virtual address points to that physical address.”</em></blockquote><p>The mapping also carries information about how the memory can be accessed.</p><p>Memory is divided into pages, and those pages can have different protection attributes.</p><p>That is where the three letters come from.</p><p><strong>R</strong> means the page can be read.</p><p><strong>W</strong> means the page can be written to.</p><p><strong>X</strong> means the processor can fetch instructions from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*OXO2GFJqxer9_wjFqlanqA.png" /></figure><p>The last one is particularly important.</p><p>When a CPU executes a program, it repeatedly fetches instructions from memory, decodes them, and executes them. If the page containing those instructions is not executable, the processor cannot simply treat the bytes as code.</p><p>So X is not really “the program can run this memory” in some abstract sense. It is a permission associated with the memory through which the processor’s instruction-fetch mechanism operates.</p><h3>Code and data are supposed to be different things</h3><p>Consider an ordinary program.</p><p>Its machine code needs to be executable:</p><pre>.text<br>RX</pre><p>Its writable variables need to be writable:</p><pre>.data<br>RW</pre><p>The distinction is deliberate.</p><p>You generally want code to be executable without being modified, and data to be modifiable without being executable.</p><p>That gives us:</p><pre>           Read        Write     Execute<br>Code          ✓        ✗          ✓<br>Data          ✓        ✓          ✗</pre><p>RWX removes that separation:</p><pre>             Read        Write    Execute<br>RWX region     ✓        ✓          ✓</pre><p>The same memory can now be modified and used as a source of instructions.</p><p>That does not automatically make it malicious. But from a security perspective, it is an interesting property because the boundary between <strong>data and executable code</strong> has been weakened.</p><p>This is one reason modern systems have mechanisms such as DEP and hardware support for non-executable memory.</p><h3>The PE file complicates the picture</h3><p>If you’re analysing Windows malware, you will usually encounter RWX first through the <strong>Portable Executable (PE)</strong>format.</p><p>A PE contains sections.</p><p>For example:</p><pre>.text<br>.data<br>.rsrc<br>.reloc</pre><p>The section headers contain a Characteristics field with flags describing how the section is intended to be used.</p><p>Among them are:</p><pre>IMAGE_SCN_MEM_READ<br>IMAGE_SCN_MEM_WRITE<br>IMAGE_SCN_MEM_EXECUTE</pre><p>A conventional executable might therefore have something roughly like:</p><pre>.text     READ + EXECUTE<br>.data     READ + WRITE<br>.rsrc     READ</pre><p>This makes sense.</p><p>.text contains executable code.</p><p>.data contains writable program data.</p><p>.rsrc contains resources such as icons, manifests, and other embedded information.</p><p>So when a PE contains a section with:</p><pre>READ + WRITE + EXECUTE</pre><p>it is reasonable to ask why.</p><p>But there is a distinction here that is easy to miss.</p><p><strong>The PE file is not the running process.</strong></p><h3>An RWX section is not the same thing as an RWX memory region</h3><p>This is probably the most important distinction when analysing RWX.</p><p>The PE exists on disk.</p><p>The process exists in virtual memory.</p><p>The relationship is roughly:</p><pre>PE file<br>  │<br>  │ Windows loader<br>  ▼<br>Process address space<br>  │<br>  ▼<br>Virtual memory pages</pre><p>The PE section characteristics provide information that the loader uses when creating the image in memory. But once the process is running, memory can exist that was not simply present as a static RWX section in the original file.</p><p>That means two different questions can be asked.</p><p><strong>Static analysis:</strong></p><blockquote><em>Does the PE contain a section with executable and writable characteristics?</em></blockquote><p><strong>Dynamic analysis:</strong></p><blockquote><em>Does the running process currently contain memory that is executable and writable?</em></blockquote><p>They are not equivalent questions.</p><p>A PE can have no obvious RWX section and still create executable writable memory during execution.</p><p>Conversely, seeing an unusual section characteristic does not tell you everything about what the process will actually do with that memory.</p><h3>Windows can change memory protection</h3><p>Windows provides mechanisms for changing the protection of virtual-memory pages.</p><p>One of the relevant APIs is VirtualProtect.</p><p>At a conceptual level, this allows a program to change a region from one protection state to another.</p><p>For example:</p><pre>RW<br>│<br>│ memory is writable<br>│<br>▼<br>RX<br>│<br>│ memory is now executable<br>│<br>▼<br>execution</pre><p>A program does not necessarily need a region to remain RWX permanently.</p><p>It can instead have a region that is writable while something is being prepared and then make it executable afterward.</p><p>This is much closer to the security principle known as <strong>W^X — Write XOR Execute</strong>:</p><blockquote><em>A region should ideally be writable or executable, rather than simultaneously both.</em></blockquote><p>The principle is simple, but real software is messier.</p><h3>Why would legitimate software ever need this?</h3><p>Because executable code does not always have to come entirely from a static executable file.</p><p>Modern software sometimes generates code at runtime.</p><p>A <strong>Just-In-Time compiler</strong>, for example, generates machine code while a program is running.</p><p>The runtime has to deal with a fundamental problem:</p><blockquote><strong><em>How do you create code in memory and then execute it?</em></strong></blockquote><p>This is one reason why executable memory is not automatically suspicious.</p><p>If you see an executable writable region, you need context.</p><p>A browser, language runtime, security product, or other legitimate application may have perfectly reasonable reasons for unusual memory behaviour.</p><p>So:</p><pre>RWX detected</pre><p>is a <strong>signal</strong>.</p><p>It is not a verdict.</p><h3>The interesting case is often the transition</h3><p>Suppose a process contains a region that is RWX.</p><p>That’s interesting.</p><p>But suppose instead that you observe:</p><pre>RW<br> ↓<br>RX</pre><p>during execution.</p><p>Now you have a behavioural event.</p><p>Something was writable.</p><p>Then its protection changed.</p><p>Now it is executable.</p><p>That raises a much more useful question:</p><blockquote><strong><em>What happened in between?</em></strong></blockquote><p>Was legitimate code generated?</p><p>Was some runtime component doing normal work?</p><p>Was executable content unpacked?</p><p>Was memory being used in a way that is inconsistent with the program’s expected behaviour?</p><p>This is where dynamic analysis becomes much more informative than simply looking for the string “RWX” in a PE report.</p><p>A static scanner gives you a snapshot.</p><p>A dynamic analysis can give you a sequence:</p><pre>t0       t1       t2       t3</pre><pre>RW  →   RW  →   RX  →   RX<br>                 │<br>                 └── executable after modification</pre><p>That sequence tells you something about what the process actually did.</p><h3>RWX and the CPU</h3><p>There is another layer beneath Windows.</p><p>Eventually, these permissions have to mean something to the processor.</p><p>When software accesses memory, the CPU performs address translation using the system’s memory-management hardware. The page tables provide the mappings and associated access information.</p><p>Very roughly:</p><pre>Virtual address<br>      │<br>      ▼<br>Page-table lookup<br>      │<br>      ▼<br>Physical page<br>      │<br>      └── access permitted?</pre><p>For a normal data read, the system needs to permit reading.</p><p>For a write, writing must be permitted.</p><p>For an instruction fetch, execution must be permitted.</p><p>If the required access is not allowed, the access cannot simply continue as though nothing happened.</p><p>This is why memory protection is more than a convention.</p><p>It is enforced as part of the hardware-supported memory-management system.</p><h3>So where does DEP fit?</h3><p><strong>Data Execution Prevention (DEP)</strong> is based around the idea that memory containing data should not automatically be executable.</p><p>This sounds obvious today, but it represents an important security boundary.</p><p>If an attacker manages to place unexpected bytes into a writable memory region, a non-executable page makes it harder to simply treat those bytes as instructions.</p><p>That gives us a useful distinction:</p><pre>Writable memory<br>       │<br>       └── data can be modified</pre><pre>Executable memory<br>       │<br>       └── CPU can fetch instructions</pre><p>The security goal is to avoid unnecessarily combining the two.</p><p>RWX does exactly that.</p><p>It says, in effect:</p><pre>&quot;This page can be modified,<br>and the CPU can execute from it.&quot;</pre><p>That is why defenders pay attention to it.</p><h3>But RWX is not the whole story</h3><p>A simplistic malware detector could use:</p><pre>RWX section?<br>    │<br>    ├── Yes → Malware<br>    └── No  → Benign</pre><p>That would be a terrible classifier.</p><p>Memory permissions exist in context.</p><p>A better analysis might combine:</p><pre>RWX characteristics<br>        +<br>section size<br>        +<br>entropy<br>        +<br>location<br>        +<br>imports<br>        +<br>PE structure<br>        +<br>runtime behaviour<br>        +<br>memory-protection transitions</pre><p>Now RWX becomes one piece of evidence rather than a conclusion.</p><p>This is particularly important because malware authors and legitimate software both operate within the same Windows memory model.</p><p>The interesting question is not simply whether a program can create executable memory.</p><p>It is <strong>why it does so, when it does so, and what happens afterward</strong>.</p><h3>One small flag, several layers of the system</h3><p>This is what makes RWX more interesting than it initially appears.</p><p>At the PE level, we have section characteristics:</p><pre>IMAGE_SCN_MEM_READ<br>IMAGE_SCN_MEM_WRITE<br>IMAGE_SCN_MEM_EXECUTE</pre><p>At the Windows memory-management level, we have protections such as:</p><pre>PAGE_READWRITE<br>PAGE_EXECUTE_READ<br>PAGE_EXECUTE_READWRITE</pre><p>At the hardware level, we have virtual-to-physical translation and permission checks associated with memory accesses.</p><p>And at the malware-analysis level, we have the observable behaviour:</p><pre>Static PE<br>   ↓<br>Memory mapping<br>   ↓<br>Protection changes<br>   ↓<br>Instruction execution</pre><p>The same three letters appear at different points in that chain, but they are not necessarily describing exactly the same thing.</p><p>That is the part that is easy to lose when RWX is reduced to a line in a malware-scanning report.</p><h3>The useful way to think about RWX</h3><p>I would not treat RWX as:</p><blockquote><strong><em>“malware memory.”</em></strong></blockquote><p>I’d treat it as a question:</p><blockquote><strong><em>Why does this program have memory that is simultaneously writable and executable?</em></strong></blockquote><p>Sometimes the answer is completely legitimate.</p><p>Sometimes it is worth investigating further.</p><p>And sometimes the interesting evidence isn’t the existence of RWX at all, but the sequence of memory operations that produced it.</p><p>That is the bigger lesson.</p><p>RWX is really a small window into the relationship between <strong>a PE file, Windows virtual memory, CPU permissions, and program behaviour</strong>.</p><p>Once those layers are separated, the three letters become much more useful.</p><h3>References</h3><ul><li><a href="https://learn.microsoft.com/en-us/windows/win32/debug/pe-format?utm_source=chatgpt.com">Microsoft Learn — PE Format</a> — PE sections and IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE, and IMAGE_SCN_MEM_EXECUTE.</li><li><a href="https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualprotect?utm_source=chatgpt.com">Microsoft Learn — VirtualProtect function</a> — Changing protection on committed virtual-memory pages.</li><li><a href="https://learn.microsoft.com/en-us/windows/win32/memory/virtual-address-space?utm_source=chatgpt.com">Microsoft Learn — Virtual Address Space</a> — Process virtual address spaces and page-table-based address translation.</li><li><a href="https://learn.microsoft.com/fil-ph/windows/win32/memory/data-execution-prevention?utm_source=chatgpt.com">Microsoft Learn — Data Execution Prevention</a> — How Windows prevents execution from protected data pages.</li><li><a href="https://learn.microsoft.com/uk-ua/windows-hardware/drivers/gettingstarted/virtual-address-spaces?utm_source=chatgpt.com">Microsoft Learn — Virtual Address Spaces (Windows Drivers)</a> — Pages and virtual address spaces on 64-bit Windows.</li></ul><p><strong>Written by:</strong></p><blockquote><strong>6152 616D 6864 6E61 4120 6164 206D 6F5A 656D</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4897c49d3b76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PE Overlays: A Small Thing Worth Writing About]]></title>
            <link>https://medium.com/@ramadhanzome4/pe-overlays-a-small-thing-worth-writing-about-056c39ce3774?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/056c39ce3774</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Mon, 27 Jul 2026 11:35:26 GMT</pubDate>
            <atom:updated>2026-07-27T11:38:42.094Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJgpN9NCf5TjqloO1ua2aQ.jpeg" /></figure><p>I wrote this code this morning and honestly wasn’t sure if I even wanted to push it, or write anything about it. This afternoon I sat with it a bit longer, went back and forth a few times, and after a while just decided, alright, here we are.</p><h3>What’s an overlay, anyway?</h3><p>A PE (Portable Executable) file has a predictable structure: a DOS header, an NT header, a section table, and then the sections themselves, laid out on disk according to that table. Every parser, disassembler, and PE-aware tool reads up through the last section and stops.</p><p>Nothing stops you from appending extra bytes after that last section ends, though. Those bytes aren’t part of any section, aren’t mapped into memory unless the program explicitly goes looking for them, and most tools never bother checking.</p><p>That trailing space is called the overlay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*32jrunvL-X_zTLVREHZdcw.png" /></figure><h3>How malware creators use it</h3><p>Legitimate software leans on this constantly, self-extracting archives append the actual archive data past a small extractor stub, installers do the same with resource data. Malware creators lean on the exact same mechanism, just with different intent.</p><p>A loader or dropper can stash an encrypted second-stage payload in the overlay, completely outside any section, so any tool that hashes or scans .text and .data never sees it. Packers and crypters do this at runtime too: the visible executable is a thin stub, and the actual payload just sits past the last section, read back in when the program runs. It&#39;s a cheap, effective way to smuggle something past a scanner that was only ever built to look at declared sections.</p><h3>Protecting yourself: for everyone else</h3><p>You don’t need to know any of the technical detail below to stay safe from this. The overlay itself isn’t the danger, it’s just where the payload rides along. The same basic habits that protect you from any malicious executable still apply:</p><ul><li>Don’t run .exe files from sources you don&#39;t trust, cracked software, random email attachments, &quot;free&quot; versions of paid tools.</li><li>If Windows shows a signature warning or blocks a file with SmartScreen, don’t override it just to get past the popup.</li><li>Keep Windows Defender (or whatever antivirus you use) turned on and updated. It won’t catch a fully custom hidden payload every time, but it catches most of what’s actually out there.</li><li>If a file feels oddly large for what it claims to be, a tiny “image viewer” that’s 40MB, for example, that’s worth being suspicious of before you run it.</li></ul><p>For the non technical people, you can end here.</p><h3>Protecting yourself: for analysts</h3><p>If you’re the one actually looking at a suspicious binary:</p><ul><li>Don’t trust a scan that only covers declared sections. Always check whether file size &gt; (end of last section), and treat a large gap as worth a closer look.</li><li>Before flagging anything, check the Security data directory. If a digital signature is present, its offset lands in that same trailing space, so subtract it out first or you’ll flag every signed binary as suspicious.</li><li>Hash the overlay content separately and check it against known payload or packer signatures, rather than hashing the whole file as one blob.</li><li>Compare overlay size to what’s typical for that file type. A tiny installer with a multi-megabyte overlay is a much stronger signal than a large overlay on a large archive.</li><li>Tools like PEStudio or CFF Explorer will show you overlay size at a glance, worth a quick look before deeper static or dynamic analysis.</li></ul><p>None of this is exotic, it’s mostly just remembering that “end of the last section” isn’t “end of the file.”</p><h3>The bug I actually hit</h3><p>My first version calculated the end of the PE by walking the section table and taking the highest PointerToRawData + SizeOfRawData. Anything past that, I called overlay.</p><p>That’s wrong for signed binaries, for the reason above. Authenticode signatures live in a structure pointed to by the Security directory entry, and unlike almost every other directory entry in a PE file, this one stores a raw file offset instead of an RVA. That offset lands right after the last section, physically indistinguishable from a real overlay.</p><p>Without accounting for it, my tool flagged every signed executable as suspicious, when it was just finding a normal certificate table. The fix: check the Security directory entry, and if it’s set, fold its end offset into the boundary before deciding what’s actually left over.</p><h3>The logic</h3><p>Four steps, same in both versions:</p><ol><li>Parse the DOS header, follow e_lfanew to the NT header.</li><li>Walk the section table, track the highest PointerToRawData + SizeOfRawData.</li><li>Check the Security directory entry, extend the boundary if it’s present.</li><li>Anything past that final offset, against the real file size, is the overlay.</li></ol><p>The only part worth pasting here is step 3, since that’s the fix. In C:</p><pre>IMAGE_DATA_DIRECTORY sec_dir = nt.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY];<br>if (sec_dir.VirtualAddress != 0) {<br>    uint32_t sig_end = sec_dir.VirtualAddress + sec_dir.Size;<br>    if (sig_end &gt; pe_end) pe_end = sig_end;<br>}</pre><p>And in Python, using pefile:</p><pre>sec_dir = pe.OPTIONAL_HEADER.DATA_DIRECTORY[pefile.DIRECTORY_ENTRY[&#39;IMAGE_DIRECTORY_ENTRY_SECURITY&#39;]]<br>if sec_dir.VirtualAddress != 0:<br>    pe_end_offset = max(pe_end_offset, sec_dir.VirtualAddress + sec_dir.Size)</pre><p>Full source, both versions, headers and validation included, is in the repo below:</p><p><a href="https://github.com/RamadhanAdam/sco-pe/tree/main/tools">sco-pe/tools</a></p><h3>Where this goes next</h3><p>This is a small piece of a bigger project: <a href="https://github.com/RamadhanAdam/sco-pe">sco-pe</a>, a C library I&#39;m building to parse and analyze Windows PE files.</p><p>If you want to take it further:</p><ul><li>A YARA rule flagging binaries with unusually large overlays relative to file size</li><li>Hashing overlay content against known payload signatures</li><li>Folding this into a proper scope subcommand instead of a standalone script</li></ul><p>Repo’s open, contributions and issues genuinely welcome.</p><p>Written by:</p><blockquote><strong>6152 616D 6864 6E61 4120 6164 206D 6F5A 656D</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=056c39ce3774" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authenticode Checks Who Signed a PE File. Nothing Checks Whether It’s True.]]></title>
            <link>https://medium.com/@ramadhanzome4/authenticode-checks-who-signed-a-pe-file-nothing-checks-whether-its-true-6ad4ccc8fbe6?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ad4ccc8fbe6</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Sun, 12 Jul 2026 19:36:36 GMT</pubDate>
            <atom:updated>2026-07-12T19:36:36.125Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mpsdVApQZMmApwPGEwv3vQ.jpeg" /></figure><p>Windows has exactly one cryptographic mechanism for verifying a PE file is trustworthy. It’s optional, enforced only in specific contexts, and it operates on a completely different data domain than the structural fields the loader parses to run your code.</p><h3>What Authenticode actually verifies</h3><p>Authenticode, formally part of the Windows Code Signing infrastructure, answers one narrowly scoped question: <strong>did this file come from whoever it claims to come from, and has it remained unmodified since the signer produced it.</strong></p><p>Mechanically, that’s a hash computed over most of the file — byte range [0, CertificateTable start] and [CertificateTable end, end-of-file] — explicitly excluding the certificate data block itself (since it contains the signature, which would obviously change the hash), and by convention excluding the checksum field (since it’s supposed to be recomputable, not part of the signed content).</p><p>That hash is then compared against a signature produced with the signer’s private key, a signature that’s chained up through one or more intermediate certificates to a root certificate trusted by the operating system (Microsoft, a trusted third-party CA, the user’s own enterprise PKI, etc.). If the chain validates and the signature matches the hash, Authenticode has done its job: it has cryptographically confirmed that the bytes the loader is about to process were produced by the entity whose certificate is in the chain.</p><p>This is a strong guarantee about provenance. It is not a guarantee about the file’s contents, structure, or behavior. Authenticode doesn’t parse a section header. It doesn’t know what a SizeOfImage field means. It doesn&#39;t validate that an executable section is actually executable code, or that an import table entry points to a real function, or that the declared entry point lies within the .text section. It doesn&#39;t even know that sections exist — it just hashes raw bytes and compares against a signature.</p><p>This is the critical gap: <strong>Authenticode is a provenance signature. It doesn’t sign the file’s claims about what it contains, only that those specific bytes came from a specific source.</strong></p><h3>What I proved by building the counterexample</h3><p>I assembled a completely unsigned PE file — zero certificate, zero signature, zero chain of trust — with a perfectly self-consistent internal structure. Every offset correct, every size field matching its corresponding data, every section header coherent with every other header. The Windows loader loaded it and executed it without a single complaint, no security warning beyond the generic SmartScreen “this is an uncommon file” dialog for unsigned downloads (which isn’t a code-signing check, it’s a reputation heuristic).</p><p>The loader doesn’t require Authenticode to function. It requires the structural fields to be arithmetically coherent — the offsets need to point to places that exist, the sizes need to be large enough to contain their data — but it doesn’t require any cryptographic signature on those fields. It doesn’t require anyone to have declared themselves responsible for the file’s structure. An unsigned, structurally valid PE is sufficient to get the loader to map sections into memory and jump to the entry point.</p><p>This is the inverse of what most explanations of PE security imply. Most articles say “Windows verifies PE files,” meaning “Authenticode can verify PE files, when configured to do so.” What’s actually true is: <strong>“Windows verifies some PE files’ signatures in some contexts, and runs all PE files that pass structural parsing, signatures or not.”</strong></p><h3>What the loader actually checks</h3><p>The loader’s structural verification is real but narrow:</p><ol><li>Magic values: MZ and PE\0\0 are checked. Get these wrong and the loader refuses the file outright.</li><li>e_lfanew: Trusted completely. The loader jumps to this offset and expects to find the PE signature. Get this wrong and everything downstream is misparsed — the COFF header lands on garbage, all subsequent offsets are wrong, load failure or undefined behavior.</li><li>SectionAlignment and FileAlignment: Used directly to compute where each section maps in memory and where to read it from disk. Trusted without verification.</li><li>Section headers: Each section’s VirtualAddress, VirtualSize, PointerToRawData, and SizeOfRawData are used to map the section into memory. No check that these values make sense relative to each other or to the file size.</li><li>Import Directory and IAT: Walked and parsed to resolve DLL/function pairs. No check that the function names are real, that the DLLs exist, that the import addresses are ever used by the code.</li><li>Entry point: AddressOfEntryPoint is jumped to directly. No check that it lies within an executable section. No check that it actually contains executable code.</li></ol><p>None of this is a security check in the cryptographic or policy sense. It’s a layout check: “do these offsets and sizes make internal sense?” It is not “do these offsets and sizes describe what the file claims to contain?” A section can have Characteristics claiming it&#39;s initialized data while its actual bytes are packed, encrypted, or malicious code. The loader reads the flag, applies the matching memory protection, and moves on — the section&#39;s actual content is whatever the loader read from disk, regardless of what the field claimed.</p><h3>Why this gap is the actual mechanism for most PE-based attacks</h3><p>A significant fraction of static-analysis heuristics used in malware triage detect exactly this gap: cases where a binary stays inside the boundaries the loader checks while staying outside any semantic claim it makes about itself.</p><p>Entry point outside .text — the loader just jumps to the RVA specified, doesn&#39;t care which section contains it. Section containing executable code but declared as &quot;initialized data&quot; — the loader applies read/write protection based on the field, but the code still executes. Import table entries that don&#39;t correspond to any call instruction in the code — the loader resolves them anyway, fills the IAT, and if the code never calls them, nobody notices. Timestamps that don&#39;t match the claimed compilation date — the loader doesn&#39;t check. Checksums that are wrong — the loader doesn&#39;t read them. Rich Header (an undocumented, XOR&#39;d compiler fingerprint embedded in the file) claiming a different compiler than what actually generated the binary — the loader doesn&#39;t parse it.</p><p>None of these are violations the loader enforces. They’re exploited by malware authors specifically because they’re gaps: places where structural validation is weak enough that the file can do one thing while claiming another. Authenticode, where it’s actually checked (not on a plain double-click, only under specific policy settings), sits on top of this same permissive file. Authenticode signs the actual bytes, validating that the bytes haven’t changed since signature. It says nothing about whether those bytes’ internal structure coherently represents what they claim.</p><p>Two separate documents. Two separate mechanisms. One optional and context-dependent, the other mandatory and passed by any file with internally consistent offsets — and the mandatory one is a much weaker gate than most writing about PE security acknowledges.</p><p>6152 616D 6864 6E61 4120 6164 206D 6F5A 656D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad4ccc8fbe6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Wrote a Windows PE File From Scratch, in Assembly]]></title>
            <link>https://medium.com/@ramadhanzome4/i-wrote-a-windows-pe-file-from-scratch-in-assembly-d011cb0097cb?source=rss-2cbdfb3e53a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d011cb0097cb</guid>
            <category><![CDATA[x86-assembly]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[portable-executable]]></category>
            <category><![CDATA[binary]]></category>
            <dc:creator><![CDATA[Ramadhan Zome]]></dc:creator>
            <pubDate>Fri, 03 Jul 2026 13:51:47 GMT</pubDate>
            <atom:updated>2026-07-03T13:51:47.079Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UulBX7_pX8ThsE0_eQuQ4A.jpeg" /><figcaption>source : <a href="https://unsplash.com/photos/woman-in-black-coat-standing-in-front-of-mirror-WGeO6dW5GZM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditShareLink">unsplash</a></figcaption></figure><blockquote>AI From First Principles has one piece left — Transformers, from the ground up. After that I’m diverting: technical reports, reverse engineering, malware analysis, AI security.</blockquote><p>I built a Windows PE executable completely from scratch, with no compiler, no linker, no section directives doing layout for me. Every DOS header field, every NT header field, every section header, every import table entry, hand-assembled in NASM with -f bin, byte by byte, addresses computed by hand. The result is a real, working Win64 GUI binary: it pops a MessageBoxA asking &quot;Do you want to continue?&quot;, branches on Yes or No, and exits 0 or 1 accordingly. Code: <a href="https://github.com/RamadhanAdam/raw-pe">github.com/RamadhanAdam/raw-pe</a>.</p><p>This is the format in depth, field by field, and the specific bug that took the binary from “assembles with zero warnings” to 0xc0000005 at address zero.</p><h3>DOS header — 64 bytes almost none of which matter anymore</h3><p>Every PE opens with IMAGE_DOS_HEADER, a structure inherited wholesale from MS-DOS. It exists so DOS, and 16-bit Windows, could recognize a file it couldn&#39;t execute and print &quot;This program cannot be run in DOS mode&quot; instead of interpreting 64-bit instructions as 8086 opcodes and hanging.</p><p>4D 5A — &quot;MZ&quot; — Mark Zbikowski&#39;s initials, one of the original DOS architects. Every .exe on every Windows machine, including mine, still opens with these two bytes.</p><p>The next eighteen fields — e_cblp (bytes on last page), e_cp (pages in file), e_crlc (relocations), e_cparhdr (header size in paragraphs), e_minalloc/e_maxalloc (extra paragraphs needed), e_ss/e_sp (initial stack segment/pointer), e_csum (checksum), e_ip/e_cs (initial instruction pointer/code segment), e_lfarlc (relocation table offset), e_ovno (overlay number), plus reserved arrays e_res[4] and e_res2[10] — describe how a segmented 16-bit executable gets relocated and loaded by the DOS loader. None of it is read by the NT loader at all. I set every one of them to zero. There&#39;s exactly one field in the entire 64-byte structure that the modern loader actually consumes:</p><pre>dd 0x00000080   ; e_lfanew — offset to the NT header</pre><p>e_lfanew is a 4-byte pointer whose only job is telling LoadLibrary/CreateProcess where the real headers start, so it can skip the DOS-era structure entirely. Mine is 0x80. If this field is off by even four bytes, the loader reads the COFF File Header from the wrong byte offset — meaning Machine, NumberOfSections, SizeOfOptionalHeader, Characteristics, all of it, get parsed from whatever bytes happen to sit there instead. NASM will assemble that file with zero complaints, because e_lfanew is just a dd value to the assembler — there&#39;s no semantic check that it actually points at a PE\0\0 signature. You only find out it&#39;s wrong when the loader either refuses the file outright or, worse, parses a header that happens to look coincidentally valid and does something undefined.</p><p>Between the DOS header and the NT headers sits the DOS stub — 64 bytes in my build holding the ASCII string &quot;This program must be run under Win32.&quot;, right-padded with zeros. This is genuinely optional; an all-zero stub of the same length works identically, since nothing about the DOS stub&#39;s <em>content</em> is checked, only that e_lfanew correctly points past whatever sits there.</p><h3>PE signature and COFF File Header</h3><p>At offset 0x80: dd 0x00004550 — &quot;PE\0\0&quot; in little-endian, meaning the bytes on disk are 50 45 00 00. This is the second and last magic-value check the loader performs on the front matter.</p><p>Immediately after, the 20-byte IMAGE_FILE_HEADER:</p><pre>dw 0x8664       ; Machine — IMAGE_FILE_MACHINE_AMD64<br>dw 0x0004       ; NumberOfSections<br>dd 0x6A443E92   ; TimeDateStamp<br>dd 0x00000000   ; PointerToSymbolTable — obsolete for images<br>dd 0x00000000   ; NumberOfSymbols — obsolete for images<br>dw 0x00F0       ; SizeOfOptionalHeader<br>dw 0x0223       ; Characteristics</pre><p>Machine = 0x8664 tells the loader (and every disassembler downstream) to decode this as x86-64, not x86, ARM, or IA64 — this single field is why file-type detection in tools like file and PE-bear works reliably even without an extension. NumberOfSections = 4 has to exactly match the number of IMAGE_SECTION_HEADER entries that follow — get this wrong and the loader either stops reading sections early (silently dropping a section from its internal table) or reads past your real section headers into whatever bytes come next and interprets them as a fifth, garbage section. TimeDateStamp is a Unix epoch value nothing in the loader validates for plausibility — it can be any 32-bit value, including a date in 1970 or 2099, and the file loads identically either way. This is also, worth noting for anyone doing malware triage, a field trivially and commonly forged, which is why timestamp-based attribution always needs corroborating signals.</p><p>SizeOfOptionalHeader = 0x00F0 (240 bytes) is arithmetic you have to get exactly right: 24 bytes of standard fields, plus 88 bytes of Windows-specific fields, plus 16 data directories × 8 bytes each (128 bytes) = 240. Characteristics = 0x0223 is a bitfield: RELOCS_STRIPPED | EXECUTABLE_IMAGE | LARGE_ADDRESS_AWARE | DEBUG_STRIPPED. Setting RELOCS_STRIPPEDhere without actually providing a .reloc section — which I did — is a decision with a real consequence I&#39;ll come back to.</p><h3>Optional Header, not really optional, and where the two coordinate systems are born</h3><p>IMAGE_OPTIONAL_HEADER64 starts with Magic = 0x020B, which distinguishes PE32+ (64-bit) from PE32&#39;s 0x010B — this single value changes how several downstream fields are sized, since PE32+ uses 8-byte fields for ImageBase, stack/heap reserve and commit sizes, where PE32 uses 4.</p><p>The two fields that decide the entire shape of the problem this article is actually about:</p><pre>dd 0x00001000   ; SectionAlignment<br>dd 0x00000200   ; FileAlignment</pre><p>SectionAlignment is the granularity sections are spaced at once mapped into a process&#39;s virtual address space — 0x1000, one x86-64 page. This isn&#39;t an arbitrary round number; it&#39;s forced by the hardware. The MMU applies page-table protection bits (execute, write, read) at page granularity. You cannot have half a page executable and half read-only. So every section boundary, in memory, is forced onto a 4 KB boundary regardless of how small the section&#39;s actual content is — a one-byte .bss section still consumes a full page.</p><p>FileAlignment is the granularity sections are packed at on disk — 0x200, 512 bytes, a holdover from disk sector size, with no hardware constraint forcing it beyond &quot;the loader has to be able to seek and read chunks efficiently.&quot; This is why a tiny section that occupies a full page in memory can occupy as little as one 512-byte chunk on disk.</p><p>The direct consequence: RVA (offset from ImageBase, the in-memory addressing scheme) and PointerToRawData (file-offset addressing scheme) diverge for any layout where the sections aren&#39;t coincidentally sized to exact page multiples. Here&#39;s the concrete layout I built:</p><p>SectionPointerToRawDataVirtualAddress (RVA)Disk→memory gapheaders0x0000x000—.text0x4000x1000+0xC00.data0x6000x2000+0x1A00.bssnone (0 bytes on disk)0x3000—.idata0x8000x4000+0x3800</p><p>.text and .idata: 0x800 − 0x400 = 0x400 bytes apart on disk. 0x4000 − 0x1000 = 0x3000 bytes apart in memory. A factor of twelve difference, between the exact same two sections, purely a function of which addressing axis you&#39;re standing on.</p><p>Further down the Optional Header, the remaining Windows-specific fields I had to set correctly with no compiler defaulting them for me: ImageBase = 0x140000000 (the standard 64-bit preferred load address for non-DLL images — chosen specifically to be well above the 4 GB boundary so 32-bit pointer truncation bugs surface immediately rather than silently succeeding), SizeOfImage = 0x5000 (has to be ≥ the highest RVA plus its section&#39;s size, across every section — I initially forgot to extend this after adding .idata and had to go back and fix it), SizeOfHeaders = 0x400 (has to exactly equal where .text&#39;s PointerToRawData begins, since it&#39;s literally defining &quot;everything before the first section&quot;), Subsystem = 0x0002(IMAGE_SUBSYSTEM_WINDOWS_GUI — this single value is why the process detaches from a console shell immediately on launch instead of blocking on stdio), and NumberOfRvaAndSizes = 0x00000010 (16 — the data directory count, which has to match how many 8-byte RVA/Size pairs actually follow, or the loader either truncates or overreads the directory array).</p><h3>Data directories — sixteen RVA/Size pairs, most of them zero, two load-bearing</h3><p>The 128 bytes of data directories are what tell the loader where to find specific structures inside the sections you’ve already laid out. Fourteen of mine are 0, 0. Two aren&#39;t:</p><pre>dd (import_dir - idata_start) + 0x4000<br>dd 0x0000003C   ; Import Table: RVA, Size = 60 bytes (3 × 20-byte descriptors)</pre><pre>dd (user32_iat - idata_start) + 0x4000<br>dd 0x00000020   ; IAT: RVA, Size = 32 bytes (2 DLLs × 16 bytes each)</pre><p>import_dir - idata_start is intra-section symbolic math — both labels live inside .idata, so NASM&#39;s flat file-offset computation and the real runtime RVA computation agree, since nothing separates two labels in the same section except contiguous bytes, identically, in both file and memory representations. Add 0x4000, .idata&#39;s base RVA, and you get the correct data directory entry. This pattern — intra-section symbolic offset plus a hardcoded section base RVA — is safe everywhere in this file. It is specifically <em>cross</em>-section references that break, which is the entire subject of the next section.</p><h3>The section header table — 40 bytes per entry, and every number has to independently agree</h3><p>Each IMAGE_SECTION_HEADER is 40 bytes: an 8-byte name, VirtualSize, VirtualAddress, SizeOfRawData, PointerToRawData, two obsolete relocation/linenumber pointer+count pairs (zero for images), and Characteristics. Four of these, one per section, and every numeric field in every one of them has to be independently correct <em>and</em> consistent with the corresponding Optional Header fields — nothing cross-validates this for you at assemble time.</p><p>Concretely, for .idata:</p><pre>db &quot;.idata&quot;,0,0<br>dd (idata_end - idata_start)                              ; VirtualSize<br>dd 0x00004000                                              ; VirtualAddress<br>dd ((idata_end - idata_start + 0x1FF) / 0x200) * 0x200     ; SizeOfRawData<br>dd 0x00000800                                               ; PointerToRawData</pre><p>SizeOfRawData has to be FileAlignment-rounded — I computed it as ((size + 0x1FF) / 0x200) * 0x200, integer-division rounding up to the next 512-byte multiple, since the actual byte count almost never lands exactly on a boundary. PointerToRawData = 0x800 has to exactly match where I actually placed the times (0x800 - ($ - $$)) db 0 padding directive earlier in the file — two independent statements of the same fact, in two different places in the source, with nothing forcing them to agree except me getting both right by hand.</p><p>Mistakes I made here that NASM never flagged: SizeOfImage not extended after adding .idata (the loader would have refused to reserve enough address space for the last section); SizeOfInitializedData not summing .idata&#39;s rounded size (a field nothing actually enforces at load time on most systems, but wrong regardless); SizeOfHeaders and the earlier sections&#39; PointerToRawData values going stale after I inserted the .idata section header into the table, since every earlier calculation had assumed a 3-section header block. Every one of these assembled cleanly, every time.</p><h3>The import table — INT, IAT, and how a hand-written binary finds MessageBoxA</h3><p>A PE that calls external code doesn’t embed real addresses, because user32.dll and kernel32.dll load at different base addresses on every machine and potentially every run (system DLLs are ASLR-relocated). Instead, .idata holds a <em>request</em>, and the loader fills in the real address before your first instruction ever executes.</p><p>The Import Directory Table is an array of 20-byte IMAGE_IMPORT_DESCRIPTOR structures, one per imported DLL, terminated by a fully zeroed 20-byte entry — a null terminator I forgot on my first pass, since nothing about assembling the file without it produces an error; the table simply has no declared end, and the loader either walks into adjacent bytes and misinterprets them as a phantom DLL descriptor, or (depending on loader version and what garbage happens to follow) fails more subtly.</p><p>Each descriptor:</p><pre>dd (user32_int - idata_start) + 0x4000   ; OriginalFirstThunk — RVA to the INT<br>dd 0x00000000                             ; TimeDateStamp — 0 = not bound<br>dd 0x00000000                             ; ForwarderChain<br>dd (user32_name - idata_start) + 0x4000  ; Name — RVA to &quot;user32.dll&quot;<br>dd (user32_iat - idata_start) + 0x4000   ; FirstThunk — RVA to the IAT</pre><p>OriginalFirstThunk and FirstThunk point to two parallel arrays — the Import Name Table and the Import Address Table — that start out byte-identical. Each entry in both is an 8-byte thunk (PE32+) that, pre-load, points to a Hint/Name structure: a 2-byte ordinal hint followed by the null-terminated ASCII function name, &quot;MessageBoxA&quot; or &quot;ExitProcess&quot; in my case. The hint is a soft optimization — a suggested starting index into the DLL&#39;s export ordinal table so the loader can skip straight there instead of doing a full name comparison against every export; 0 means &quot;no hint, do a normal name lookup,&quot; which is what I used.</p><p>At load time, the loader walks the INT, resolves each name against the target DLL’s export table, and — critically — overwrites the <em>IAT</em> copy (not the INT) with the real resolved function address. The INT stays untouched as a record of what was requested; the IAT becomes a table of real, callable pointers. This is exactly why call [rel user32_iat], dereferencing the IAT slot, is correct in intent — you&#39;re supposed to call through that pointer, letting the loader&#39;s resolved value be whatever ends up there. The bug wasn&#39;t in that logic. It was in how the <em>address of</em> user32_iat itself got computed.</p><h3>Where it broke: RIP-relative addressing computed on the wrong axis</h3><pre>call [rel user32_iat]</pre><p>[rel label] encodes as an opcode plus a signed 32-bit displacement (disp32). At runtime: effective_address = RIP_of_next_instruction + disp32. NASM&#39;s -f bin output format has no notion of sections at all — the entire output is one contiguous byte stream to it, starting at address 0, and every label&#39;s &quot;address&quot; for the purpose of computing that displacement is its raw file byte offset. That&#39;s exactly correct for two labels inside the same section. It is wrong for two labels in different sections, because — as established above — .text and .idata sit 0x400 bytes apart on disk and 0x3000 bytes apart in memory. NASM computed disp32 using the disk distance. The CPU, at runtime, added that same disp32 to RIP, which is a memory address, not a file offset — producing a target address 0x2C00 short of where user32_iat actually lives in memory. That address landed on an unmapped or unrelated page. The CPU dereferenced it as a function pointer, jumped, and the process died: 0xc0000005, access violation, fault offset 0x0000000000000000, faulting module unknown — not a crash inside a recognizable function, a jump straight to address zero, consistent with reading a garbage 8-byte value that happened to decode as zero and calling through it.</p><p>The same wrong-axis computation independently broke mov rdx, message (.text → .data) and mov [result], rax (.text → .bss) — every cross-section reference I&#39;d written using flat symbolic labels was wrong for the identical reason, simultaneously.</p><p>Fix: stop trusting the assembler’s flat-address model for anything crossing a section boundary. Compute the absolute virtual address by hand — ImageBase + section_RVA + intra_section_offset — as a value NASM can still resolve at assemble time (it&#39;s all compile-time constants), load it as a 64-bit immediate, and dereference explicitly:</p><pre>; broken — file-offset delta used as if it were a runtime RVA delta<br>call [rel user32_iat]</pre><pre>; fixed — absolute VA, computed at assemble time, loaded as an immediate<br>mov rax, 0x140000000 + 0x4000 + (user32_iat - idata_start)<br>call [rax]</pre><p>Both versions assembled with zero warnings, both times. There is nothing in x86–64’s instruction encoding that distinguishes “correct RIP-relative displacement” from “incorrect RIP-relative displacement” — both are syntactically and semantically valid instructions to the ISA. The only thing that exposes the difference is executing the instruction against the actual memory layout the loader built, which happens strictly after assembly, strictly after the loader has already committed to mapping your sections at their declared RVAs.</p><h3>A second, scarier failure after the fix</h3><p>After the fix, the exact same crash — 0xc0000005, fault offset 0x0 — recurred on a later run of what I&#39;d confirmed was the corrected binary (AppTimeStamp in Event Viewer&#39;s Details tab matched the current PE header&#39;s TimeDateStamp exactly, ruling out a stale cached copy).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clTx592EySVCxkBRGr5SoA.png" /></figure><p>Two explanations, not mutually exclusive: most likely, a duplicate msgbox (1).exe sitting in the same download folder got launched by mistake. But worth stating regardless of which one actually happened: this binary sets RELOCS_STRIPPED and ships no .reloc section, while hardcoding absolute VAs against a fixed ImageBase. If the loader ever can&#39;t map the image at 0x140000000 — address space contention, a security mitigation forcing relocation, anything — and silently rebases it without applying relocations it was never given, every hardcoded 0x140000000 + ... constant baked into .text now points at stale memory. Same crash signature, and specifically intermittent, gated on system memory conditions at launch. Deleting the duplicate file and reproducing cleanly across several runs pointed at the first explanation. The second one stays true regardless, and it&#39;s the actual reason a production PE needs a .reloc section — not a nice-to-have, a structural requirement the moment you can&#39;t guarantee your preferred base address.</p><p>Code: [<a href="http://github.com/RamadhanAdam/raw-pe">github.com/RamadhanAdam/raw-pe</a>]</p><p>6152 616D 6864 6E61 4120 6164 206D 6F5A 656D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d011cb0097cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>