Skip to content
HN On Hacker News ↗

Programming in the Machine Code Space: LLMs can read & write executables byte by byte

▲ 316 points • 184 comments • by fortran77 • 6d ago • HN discussion ↗

Pangram verdict · v3.3

We believe this text is mainly AI, with some human-written content.

97 %

AI likelihood · overall

AI
3% human-written 97% AI-generated
SEGMENTS · HUMAN 4 of 40
SEGMENTS · AI 36 of 40
WORD COUNT 1,664
PEAK AI % 100% · §1
Analyzed
Nov 21
backend: pangram/v3.3
Segments scanned
40 windows
avg 42 words each
Distribution
3 / 97%
human / AI fraction
Verdict
AI
Pangram v3.3

Article text · 1,664 words · 40 segments analyzed

Human AI-generated
§1 AI · 100%

Almost nobody writes machine code by hand.

§2 AI · 100%

We write source, and a compiler and linker turn it into bytes; to go back, we use disassemblers and decompilers. There are good reasons for this. x86-64 instructions vary in length, jumps are relative byte distances, and one wrong header field means the file won't load. So what can an LLM do with those bytes when it has none of these tools?Takehi et al.

§3 AI · 97%

recently showed that LLMs can read and write neural network weights directly, which they call Weight-Space Programming .

§4 AI · 100%

We ask the same question about the other artifact we treat as unreadable output: compiled code.We define Machine Code Programming as a general-purpose LLM reasoning directly about an executable's bytes, with no compiler, assembler, disassembler or execution between it and the file. We test three abilities and one real-world case:We gave the model the hex dumps of three programs we wrote ourselves, plus one real binary from FreeBSD, ministat. The LLM correctly identified what all four programs were, with only their bytes as input.The hardest case is ministat.

§5 AI · 100%

We built FreeBSD's tool at -O3, linked it statically against musl, stripped it and removed all of its own text, then hid its last three strings by setting each byte's high bit.

§6 AI · 100%

The LLM found the decoding loop, recovered the option list and described all eight options.To our surprise, the LLM even found a real bug from the bytes alone, with no access to the source. The binary has no symbols or text explaining the table. Reading the t-table as raw 64-bit floats, it noticed that the option labeled 99.5% confidence uses critical values for about 99.8%, so -c 99.5 applies a stricter test than it claims. We confirmed the bug in the original source code using Claude.For each program we ask for one new feature. The model replies with a list of byte edits, each the same length as the bytes it replaces. Hidden tests then check that the old behavior still works, that the new feature works, and that long inputs are handled correctly. All three patched programs pass every test.How does it do it?

§7 AI · 100%

Sol 6.1 treats this like a human patching a binary.

§8 AI · 100%

It finds padding, makes that padding executable by editing the segment headers, writes new code there, and overwrites existing instructions with calls into it.

§9 AI · 100%

Here is the whole wordcount patch:Now there is no binary at all. This time we ask the LLM to produce a fully functional ELF64 program from a written spec of its behavior.

§10 AI · 100%

It gets no assembler and no compiler, and must reply with every byte of the file, headers included. All three files ran and matched the reference on every case.Sol 6.1 worked out every jump, call and header field itself, with no assembler. Extending a program used 1.8 to 3.7 times fewer output tokens than writing it.Malware analysts spend hours turning a sample back into assembly or C code with disassemblers and decompilers. We give Sol 6.1 a real sample using the same prompt as Experiment 1, with no hint that it is malicious. It is a 4,608-byte PE32+ file whose only visible import is Sleep. Its other API calls are hidden behind name hashes and its strings are built on the stack.In 211 seconds, Sol 6.1 concluded that it downloads machine code and runs it in memory. Its report named a hardcoded server, 165.154.205.34 on port 443.

§11 AI · 100%

We then compared it with a public VMRay dynamic analysis of the same file , which we matched by SHA-256.

§12 AI · 100%

The sandbox contacted the same address, and requested the same URL.We made these comparisons after the run, and they cover one sample and one run. The sandbox confirms the address, the request and the download, but not the 10 s retry or the XOR key itself. Rotate-right-13 hashing is also common in public tooling, so recognition probably helped here too. We did not ask Sol 6.1 to modify malware or write any.These are early results on small programs, but they may soon challenge the foundations of reverse engineering. Disassemblers, decompilers and the assembly they produce exist to turn bytes into something a person can read. In our experiments the LLM didn't need that step: it read, patched and wrote machine code directly. These tools are still essential for human analysts, but for an LLM they may turn out to be optional.Malware analysis will also be affected. A model that works directly in machine code space can analyze a sample without first lifting it to assembly or source. That removes the slowest and most tool-dependent stage of triage, so more samples can be analyzed with less effort. Our results suggest that a general-purpose LLM can do this without being specialized for it, which could make both detection and analysis more efficient.Context size is the hard limit. A hex dump costs about 2.4 tokens per byte, so our 67 KB binary took about 163,000 tokens. A 10 MB program would need about 24 million tokens. So this one-shot approach can't read very large programs, and because our largest test was 67 KB, we don't know how quality holds up on the way to that limit.One way forward is a harness based on Recursive Language Models . An RLM keeps a long prompt outside the model's context, as a variable in a REPL, and lets the model inspect pieces of it and call itself on them. For a binary, the model could read the headers first, follow calls and jumps by offset, and hand each function to a sub-call.Reading raw bytes is an established problem in malware detection, tackled with models trained for the job such as MalConv .

§13 Human · 0%

The recent Large Byte Model extends an LLM's vocabulary with byte tokens, on the premise that LLMs "cannot process raw byte representations" .

§14 AI · 100%

Our small sample suggests that a general-purpose frontier model can now do more than that implies, at least when bytes are written out as hex.Other work applies models to assembly, including the SLaDe decompiler and Nova, a generative model for assembly .

§15 AI · 100%

The BinMetric benchmark found that challenges remain for LLMs, particularly in binary lifting and assembly synthesis .

§16 AI · 100%

Project Ire reverse engineers and classifies malware at scale, using tools such as Ghidra and angr ; it is a far larger system than our no-tools test, and the two aren't comparable.

§17 Human · 0%

We didn't find a prior account of a general-purpose LLM patching and writing working executables with no tools, though our search was not exhaustive.We repeat Experiment 4 with a different harness, opencode, and a different model, DeepSeek V4.1 Flash, whose weights are public under an MIT license.

§18 Human · 0%

It gets the same sample and the same request at high reasoning effort, with one reply and no tool calls recorded.

§19 Human · 0%

This is preliminary evidence that this ability isn't limited to closed frontier models.How does it do it? The trace shows DeepSeek reading the bytes as hex.

§20 AI · 100%

We checked three deductions against the executable.DeepSeek reached the same conclusion with about 17 times as many reasoning tokens.

§21 AI · 100%

It repeatedly revises its reading and explicitly recalls familiar API hashes. It gets nine of the 13 hidden function names right, and two of its naming errors lead it to misread the marker-file check. Read DeepSeek’s thinking This is the supplied reasoning transcript, including its false starts, revisions and incorrect guesses. It is model output, not a verified analysis.

§22 AI · 100%

The text is reproduced unchanged. We need answer detailed report no tools. Need analyze binary hex. It's Windows PE x64, likely shellcode loader / meterpreter-ish? Need reverse engineer. We must not use tools; only given hex. Need produce detailed report.

§23 AI · 100%

Let's decode.

§24 AI · 100%

PE header: MZ, PE at 0xc0. Machine 0x8664 (x64). Number sections 6? SizeOfOptionalHeader 0xf0? Characteristics 0x22 (executable, large address aware? 0x22 = executable image, large address aware).

§25 AI · 100%

Magic 0x20b PE32+. Sections: .text VA 0x1000 size raw 0x831? virtual 0x831?

§26 AI · 100%

Let's parse.

§27 AI · 100%

At 0x1c8 section table. First: Name .text, VirtualSize 0x831, VirtualAddress 0x1000, SizeOfRawData 0xa00? At 0x1d0: 31 08 00 00 = 0x831; 00 10 00 00 VA 0x1000; 00 0a 00 00 raw size 0xa00; 00 04 00 00 pointer raw 0x400; relocs 0; linenums 0; numreloc 0; characteristics 0x60000020 code execute read. .rdata at 0x1f0? Name at 0x1f8? Actually section 2 starts 0x1e8? Let's compute: section table starts 0xc0+4+20+0xf0 = 0x1c8?

§28 AI · 100%

PE offset 0xc0.

§29 AI · 100%

PE sig 4, COFF 20 -> 0xd8.

§30 AI · 100%

Optional header 0xf0?

§31 AI · 100%

At 0xd8 optional starts 0xe0? Wait optional header starts 0xd8?

§32 AI · 100%

Let's recalc.

§33 AI · 100%

At 0xc0 PE\0\0. COFF header at 0xc4: machine 64 86, numsections 03 00 (3), timestamp fe 75 3a 65, ptr sym 0, num sym 0, size opt 0xf0 at 0xd4? COFF bytes: 0xc4-0xc5 machine 0xc6-0xc7 numsections = 03 00 (3 sections) 0xc8-0xcb timestamp 0xcc-0xcf pointer symbol 0xd0-0xd3 number symbols 0xd4-0xd5 size optional 0xf0 0xd6-0xd7 characteristics 0x22 Optional at 0xd8, 0xf0 bytes -> ends 0x1c8. Section headers at 0x1c8. But data at 0x1c8 shows ".text"? Actually at 0x1c0 row: 00 00 00 00 00 00 00 00 2e 74 65 78 74 00 00 00. So section at 0x1c8 indeed name ".text".

§34 AI · 100%

Good.

§35 AI · 100%

Sections: .text VA 0x1000 vsize 0x831 rawsize 0xa00 rawptr 0x400. .rdata at 0x1f0? Name `2e 72 64 61 74 61 00 00` starting 0x1f0? Wait 0x1e8 row has 00 00 00 00 00 00 00 00 2e 72... Actually row 0x1e0: 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60. So first section header spans 0x1c8-0x1ef. Second at 0x1f0: 2e 72 64 61 74 61 00 00. vsize be 01 00 00=0x1be, VA 0x2000, rawsize 0x200, rawptr 0xe00, characteristics 0x40000040 = initialized data read.

§36 AI · 100%

Third .pdata at 0x218? Actually at 0x218 row?

§37 AI · 100%

Name .pdata: 2e 70 64 61 74 61 00 00 at 0x218.

§38 AI · 100%

vsize 0x18?

§39 AI · 100%

bytes 18 00 00 00 at 0x220? VA 0x3000, rawsize 0x200, rawptr 0x1000, chars 0x40000040. Wait Data at 0x240 onwards zeros. Hmm but 0x1000 in hex dump contains .pdata (exception directory) with entries, yes raw pdata at 0x1000?

§40 AI · 100%

But rawsize 0x200.