When tracking down the cause of an incident, you sometimes need to confirm what calculation a library without source or an old executable performs.
Unlike the JavaScript app covered in Part 4, a native binary is machine code, so reading it as pseudocode requires an external decompiler such as Ghidra, Hopper, or IDA.
A decompiler is a tool that turns machine code back into C-like
pseudocode
, and pseudocode is not the original source but an approximation made easier for people to read.
In this post I follow REA's native analysis flow with a C program I wrote myself.
Because I know the original program, I can compare exactly how accurate the decompiled result is.
This post assumes you installed rea-agents in Part 4, and you can paste the commands in order from top to bottom.
You need jq, so if you do not have it, install it first with brew install jq.
๐จโ๐ป
The lab environment, as of November 23, 2026, is macOS 26.3.1 (arm64), Apple clang, rea-agents 6.10.1, Ghidra 12.2, and Temurin JDK 25.0.5.1.
All output and screenshots in this post come from running things myself in this environment.
Field names and results may differ as versions change.
The target is a short program that adds up the byte values of a string.
Create a working folder and write sample.c with a heredoc (a shell syntax that writes several lines into a file as is).
์์ ํด๋์ sample.c ๋ง๋ค๊ธฐ
mkdir -p ~/rea-lab/native && cd ~/rea-lab/nativecat > sample.c <<'EOF' #include <stdio.h> #include <string.h>static int checksum(const char *s) { int sum = 0; for (size_t i = 0; i < strlen(s); i++) sum += (unsigned char)s[i]; return sum;}int main(int argc, char **argv) { const char *msg = argc > 1 ? argv[1] : "hello rea"; printf("%s: %d\n", msg, checksum(msg)); return 0;}EOF
To see the difference between optimization levels, I compiled it two ways.
-O0 turns optimization off, -O2 is a typical release-level optimization, and I added debug information (-g) to the -O0 build.
Terminal writing sample.c with a heredoc, compiling with clang -O0 -g and -O2, and printing sizes 33832 sample_O0, 33480 sample_O2 and the sample_O0.dSYM folder
The sizes were 33,832 bytes for sample_O0 and 33,480 bytes for sample_O2.
sample_O0, built with -g, also gets a sample_O0.dSYM debug folder.
The size of sample_O0 may vary by a few bytes depending on the folder path you compile in, apparently because the path goes into the debug map.
๐
On Linux the same commands produce an ELF binary instead of Mach-O, and the debug information goes inside the executable without a .dSYM folder.
So the security settings items, the underscores in symbol names, and the address values later in this post will come out differently.
On Windows the format is PE, and REA's Ghidra integration on Windows is experimental according to the installation guideโ.
Results of running sample_O0 and sample_O2: hello rea: 876 twice, abc: 294 twice, and the file command showing both files are Mach-O 64-bit executable arm64
Both binaries produced the same values, hello rea: 876 and abc: 294, and both are arm64 Mach-O executables.
Since I know the original, I can later compare how closely the decompiled output restores the checksum function.
Even without a decompiler, REA can read a binary's headers and check its security settings.
It is a feature you can use right away to confirm that basic protection options are on in the binaries you ship.
9 rows of inspect-binary-hardening results: pie enabled, allow_stack_execution disabled, no_heap_execution disabled, restrict_segment disabled, code_signature_present enabled (This is presence, not validity), encrypted disabled, arm64e disabled, stack_protector unknown, hardened_runtime unknown, and a last line O0 == O2
The results for the arm64 Mach-O binaries were as follows, and the -O0 and -O2 results were identical.
Item
State
Basis
pie
enabled
MH_PIE flag set
allow_stack_execution
disabled
Flag cleared
no_heap_execution
disabled
Flag cleared
restrict_segment
disabled
No __RESTRICT segment
code_signature_present
enabled
LC_CODE_SIGNATURE present
encrypted
disabled
No encryption command
arm64e
disabled
CPU subtype is arm64
stack_protector
unknown
No __stack_chk_fail symbol
hardened_runtime
unknown
Not read by this check
There are two things to watch out for when reading the results.
code_signature_present
It means a signature
exists
, not that it is
valid
.
REA also writes "presence, not validity" in the basis.
stack_protector: unknown
It does not mean there is no protection.
This sample has no fixed-size arrays, so the compiler most likely had no reason to insert stack protection code.
REA only says it could not find the symbol and does not draw a conclusion.
For hardened_runtime, it points to another check (inspect_signature) as the next step.
Now for the main analysis flow.
REA's basic order is rea analyze โ rea search โ rea decompile โ rea xrefs โ rea instructions, and you choose the engine with --provider.
Running rea analyze with the Hopper provider ends with exit=1 after 36.562 seconds: error Analysis failed, code cleanup_incomplete, stage launch, primary_error provider_unavailable, launcher exit_code 2, stderr Cannot launch Hopper! The handler some object is not defined.
It ended with exit code 1 after waiting about 37 seconds (36.562 seconds).
The error code was cleanup_incomplete, the stage launch, and the root error provider_unavailable.
The launcher's standard error contained Cannot launch Hopper! and The handler some object is not defined.
Hopper's Untitled window and license sheet open right after the failure, with the text Thank you for your interest in Hopper Disassembler and the buttons Try the Demo, Purchase a License, Offline Activation, Validate License
Right after the failure, a Hopper window and a license sheet were open on screen.
Closing the demo and license windows and trying again gave the same result.
It confirmed that
doctor reporting healthy does not guarantee that actual analysis will work
, and since I never found the cause, I switched the engine to Ghidra.
Downloading the 543MB ghidra_12.2_PUBLIC_20261016.zip with curl in 15 seconds, with the shasum -a 256 result 2c2cd776...a7be67 matching the sha256 digest from the GitHub releases API
The zip was 543MB, and its SHA-256 2c2cd776db3c1f6a097ba418922378ac3649cadd5e844a6f5f088ae628a7be67 matched the value listed in the release.
On Linux use sha256sum instead of shasum -a 256, and in Windows PowerShell use Get-FileHash.
If the values match, unzip it into ~/Applications.
์์ถ ํด์
mkdir -p ~/Applications && cd ~/Applicationsunzip -q ~/Downloads/rea-ghidra-dl/ghidra_12.2_PUBLIC_20261016.zipls ~/Applications/ghidra_12.2_PUBLIC
Next is JDK 25.
I downloaded Eclipse Temurin 25 (the macOS aarch64 JDK) and put it in ~/Applications/jdk-25.
I used the archive instead of the installer (.pkg)
so as not to change the system Java
.
Below is an example that fetches the latest Temurin 25 through the Adoptium API, and you should compare the downloaded file's checksum with the value on the Adoptium Temurin download pageโ.
On Linux and Windows, replace the mac/aarch64 part of the URL with something like linux/x64 or windows/x64.
The Windows build downloads as a zip file, and on both operating systems the unzipped folder has bin directly inside without Contents/Home.
JDK 25(Temurin) ๋ฐ๊ธฐ
mkdir -p ~/Downloads/rea-jdk-dl && cd ~/Downloads/rea-jdk-dlcurl -fL -o temurin25.tar.gz "https://api.adoptium.net/v3/binary/latest/25/ga/mac/aarch64/jdk/hotspot/normal/eclipse"shasum -a 256 temurin25.tar.gztar -xzf temurin25.tar.gzmv jdk-25*/ ~/Applications/jdk-25
Check the version requirements and the installation state.
JDK ์๊ตฌ ๋ฒ์ ํ์ธ
cd ~/Applicationsgrep -E 'application.(version|java.min)' ghidra_12.2_PUBLIC/Ghidra/application.propertiesjava -version 2>&1 | head -n 1jdk-25/Contents/Home/bin/java -versionls ghidra_12.2_PUBLIC/Ghidra/Features/Decompiler/os/
application.java.min=25 and application.version=12.2 in application.properties, default java openjdk 17.0.16, the jdk-25 java Temurin 25.0.5.1+2, and the Decompiler/os folder containing only linux_x86_64 and win_x86_64
Ghidra's configuration file says application.java.min=25.
The default java is 17.0.16, and the newly downloaded JDK is Temurin 25.0.5.1+2.
The decompiler folder contains only linux_x86_64 and win_x86_64, with no mac_arm_64.
So build the ARM64 decompiler yourself.
You need the Xcode command line tools (xcode-select --install).
According to REA's installation guideโ, the official release archive only contains native binaries for Windows and Linux x64, so Linux ARM64 also has to be built the same way.
ARM64 ๋ค์ดํฐ๋ธ ๋์ปดํ์ผ๋ฌ ๋น๋
cd ~/Applications/ghidra_12.2_PUBLIC/support/gradleJAVA_HOME=~/Applications/jdk-25/Contents/Home ./gradlew buildNativesls ../../Ghidra/Features/Decompiler/build/os/mac_arm_64/
Rerunning gradlew buildNatives shows BUILD SUCCESSFUL in 1s, 14 actionable tasks: 3 executed, 11 up-to-date, decompile and sleigh in the mac_arm_64 folder, and the first build log's BUILD SUCCESSFUL in 1m 6s with 14 executed
The first build took 1 minute 6 seconds and ran all 14 tasks.
The screenshot is a rerun after the build was already done, so it finished in 1 second, and I put the first build log at the bottom.
You are done when decompile and sleigh appear in the output folder mac_arm_64.
REA also notes in the limitations of its results that "macOS sessions need a matching native decompiler, and REA does not build it."
Passing environment variables and checking status ๐
REA finds Ghidra and the JDK through GHIDRA_INSTALL_DIR and JAVA_HOME.
I did not touch the shell configuration file (.zshrc) and used export
only in the terminal window used for the lab
.
The settings disappear when you close the window.
์ด ํฐ๋ฏธ๋ ์ฐฝ์์๋ง ํ๊ฒฝ๋ณ์ ์ค์
cd ~/rea-lab/nativeexport GHIDRA_INSTALL_DIR=$HOME/Applications/ghidra_12.2_PUBLICexport JAVA_HOME=$HOME/Applications/jdk-25/Contents/Home
Prefixing each command has the same effect.
In Windows PowerShell, set them with $env:GHIDRA_INSTALL_DIR = "..." instead of this syntax.
rea doctor results after setting the environment variables: ghidra, ghidra-platform darwin, ghidra-architecture arm64, ghidra-installation, ghidra-version 12.2, ghidra-headless, ghidra-native_decompiler, and ghidra-java 25.0.5.1 64-bit JDK are all healthy
All the Ghidra items (platform, architecture, installation, version 12.2, headless, native decompiler, Java 25.0.5.1) turned healthy.
The overall healthy is still false, because IDA, JADX, and Kuna are missing and the client registrations are in a drift state.
First analyze both binaries with analyze.
Run all the following commands in the same terminal window (the one with the environment variables set).
rea analyze (O0, O2)
time rea analyze sample_O0 --provider ghidra --json > analyze_O0.jsontime rea analyze sample_O2 --provider ghidra --json > analyze_O2.jsonfor f in analyze_O0.json analyze_O2.json; do echo -n "$f "; jq -c '.normalized_result | {procedure_count, string_count, segment_count, image_base}' $f; done
rea analyze run times of 10.382 and 10.048 seconds; analyze_O0.json has procedure_count 6, string_count 22, segment_count 9, image_base 0x100000000, and analyze_O2.json has procedure_count 5, string_count 16, segment_count 9
Each command took about 10 seconds (10.382 and 10.048 seconds).
It found 6 functions in the -O0 binary and 5 in the -O2 binary, and 22 and 16 strings respectively.
Searching for checksum with search shows the difference right away.
search results: sample_O0 has address 0x1000004f0, value _checksum, and sample_O2 is an empty array. Decompiling with checksum without an underscore, and with _checksum on O2, gives invalid_request, Unknown Ghidra procedure name or address errors
Command
sample_O0
sample_O2
search checksum --kind procedures
_checksum @ 0x1000004f0
No results
decompile --procedure _checksum
Success
Unknown Ghidra procedure name or address
Function count
6
5
๐
If you pass it without the underscore, as in --procedure checksum, it fails with invalid_request even on -O0 (third line of the screenshot above).
On Mach-O an underscore is prepended to C function names, so the symbol is _checksum, and main also had to be passed as _main.
In the Ghidra GUI's Symbol Tree, the same function appears as checksum without the underscore.
Ghidra pseudocode for _checksum in sample_O0 obtained with rea decompile (int _checksum(char *param_1), local_1c, local_28, while(true), _strlen) and the limitation text Pseudocode is Ghidra decompiler output, not original source
Ghidra ์์ฌ์ฝ๋: sample_O0 _checksum
int _checksum(char *param_1){ size_t sVar1; ulong local_28; // ์๋ณธ์ i int local_1c; // ์๋ณธ์ sum local_1c = 0; local_28 = 0; while( true ) { sVar1 = _strlen(param_1); // ๋ฐ๋ณต๋ง๋ค strlen ํธ์ถ if (sVar1 <= local_28) break; local_1c = local_1c + (uint)(byte)param_1[local_28]; local_28 = local_28 + 1; } return local_1c;}
Comparing it with the original shows exactly what information is lost in compilation (variable names, comments, the original structure).
The variable names sum, i, and s became local_1c, local_28, and param_1, and the for statement turned into while(true) with break.
Still,
the behavior is the same as the original.
It calls strlen on every iteration and adds the bytes as unsigned values.
REA also notes in its result that "pseudocode is Ghidra decompiler output, not original source."
What optimization changed: comparing -O0 and -O2 ๐
The -O2 binary has no _checksum.
That is because the function was
inlined
into main.
Inlining is an optimization in which the compiler expands the function body directly at the call site instead of calling the function.
First I used xrefs to find where strlen is called.
An xref (cross-reference) is information about what refers to a given function or piece of data.
xrefs _strlen results: O0 0x100000518, 0x10000057c, 0x100004008; O2 0x10000048c, 0x10000066c, 0x100004008; and the O0 _checksum references 0x1000004bc and 0x1000080a2
Each binary returned three addresses, but
only the first one is an actual call in code
.
The second address (O0 0x10000057c, O2 0x10000066c) is the _strlen stub inside the __stubs section, and 0x100004008 is a __got entry.
You can tell them apart by matching them against the segment ranges in the analyze results.
On -O0, 0x100000518 is inside _checksum (0x1000004f0 to 0x100000567), and on -O2, 0x10000048c is inside main.
Next are the size and instruction count of main, and the bl (call) instructions.
main ํฌ๊ธฐยท๋ช ๋ น์ด ์์ ํธ์ถ ๋ช ๋ น
for b in sample_O0 sample_O2; do rea instructions $b --procedure _main --provider ghidra --json > instr_${b}_main.json; jq -c --arg b $b '.normalized_result | {binary: $b, name: .procedure.name, bytes: .procedure.body.total_bytes, instructions: (.instructions|length)}' instr_${b}_main.json; donejq -r '.normalized_result.instructions[]' instr_sample_O0_main.json | grep -E '\bbl\b'jq -r '.normalized_result.instructions[]' instr_sample_O2_main.json | grep -E '\bbl\b'
rea instructions results: sample_O0 main is named entry, 144 bytes, 36 instructions; sample_O2 main is entry, 504 bytes, 126 instructions. O0 has bl 0x1000004f0 and bl 0x100000568, O2 has bl 0x100000664 and bl 0x100000658
sample_O0
sample_O2
main size
144 bytes
504 bytes
main instruction count
36
126
checksum call
bl 0x1000004f0
None (inlined)
strlen call site
Inside the _checksum loop (0x100000518)
Before the loop in main (0x10000048c)
The -O0main calls _checksum (0x1000004f0) and the printf stub.
The -O2main calls only the strlen stub and the printf stub, with no checksum call.
On -O0, the loop condition calls strlen on every iteration, so a string of length n costs O(nยฒ).
On -O2, it is called once before the loop and the value is reused as the length, so the cost is O(n).
Because the string does not change inside the loop, the compiler hoisted the call out of the loop.
The sample_O2 main pseudocode is 326 lines, with matches on line 2 undefined8 entry(int param_1,long param_2), line 103 sVar1 = _strlen(param1), line 122 sVar1 & 0xffffffffffffffc0, and line 285 sVar1 & 0xfffffffffffffff8, plus an excerpt of the branches after the _strlen call
The pseudocode is 326 lines long.
The summing loop is
vectorized
and splits into three paths depending on the length.
Vectorization is an optimization that rewrites a loop so that several bytes are processed together in a single instruction.
A loop that processes 64 bytes at a time
sVar1 & 0xffffffffffffffc0 (line 122) computes the length rounded down to a multiple of 64.
A loop that processes the remainder 8 bytes at a time
sVar1 & 0xfffffffffffffff8 (line 285) computes the length rounded down to a multiple of 8.
A tail loop that processes the rest 1 byte at a time
Ghidra ์์ฌ์ฝ๋: sample_O2 main (์๋ถ๋ถ ๋ฐ์ท)
Ghidra spells this part out as byte extraction operations and dozens of int accumulators (iVar19 to iVar83).
The fact that it was originally a single for statement does not show up in the pseudocode.
A person has to read it back out of the structure.
Ghidra also showed main under the name entry in both binaries, and search main finds it through the alias _main.
๐จโ๐ป
For highly optimized binaries, the pseudocode becomes hard to read even when it is accurate.
In that case, look at the assembly with rea instructions at the same time and identify the loop units first from the mask constants and branch conditions, and you can recover the structure quickly.
REA runs Ghidra headless (from the command line without a GUI).
If you want to see the same results directly in Ghidra's interface, create a project and open it.
You can do the import and auto-analysis in one go with the headless analyzer bundled with Ghidra.
Importing sample_O0 and sample_O2 into the rea-lab project with analyzeHeadless, showing Analysis succeeded, Save succeeded, Import succeeded, and DWARF expression warnings logged at ERROR level for sample_O0
Both files ended with Import succeeded.
For sample_O0, lines saying it could not handle DWARF expressions (such as DW_OP_reg29) are logged at ERROR level, but the analysis itself succeeds.
Open the Ghidra interface with ghidraRun.
You must run it in a window where JAVA_HOME points to JDK 25, and on Windows use ghidraRun.bat in the same folder.
Ghidra GUI ์ด๊ธฐ
~/Applications/ghidra_12.2_PUBLIC/ghidraRun
Ghidra project window launched with ghidraRun, titled Ghidra: NO ACTIVE PROJECT, with the status bar Ghidra startup complete (3502 ms)
The first window has no project open.
From the menu choose
File > Open Project
and select ~/rea-lab/ghidra-proj/rea-lab.gpr.
You can also pass the project file as an argument to open it directly.
Ghidra window with the rea-lab project open, titled Ghidra: rea-lab, with sample_O0 and sample_O2 in the Active Project list and the status bar Ghidra startup complete (3819 ms)
Double-click sample_O0 in the project list to open the CodeBrowser.
Click
Symbol Tree > Functions > checksum
on the left, and the pseudocode appears in the Decompile window on the right.
Ghidra CodeBrowser with the checksum function of sample_O0 selected. Functions in the left Symbol Tree list _printf, _strlen, checksum, main; the middle Listing shows the int __cdecl checksum(char * s) function header and XREFs for the locals local_1c and local_28; the right Decompile: checksum window shows the pseudocode int checksum(char *s), while( true ), sVar1 = _strlen(s)
The loop structure and local_1c and local_28 are the same as in the rea decompile result.
There are two differences: the function name appears as checksum without the underscore, and the parameter name shows up as the original s instead of param_1.
This appears to be
because the GUI project read the debug information (DWARF) added with -g and recovered the parameter name
.
Source line markers in the Listing such as sample.c:13 also come from the same debug information.
In the same CodeBrowser, open sample_O2 and go to entry (= _main) to see the vectorized main.
Ghidra CodeBrowser with sample_O2 open. The middle Listing shows the arm64 assembly of the entry function (sub sp,sp,#0x30, bl _strlen, and so on); the right Decompile: entry window shows iVar68 to iVar83 declarations, param1 = hello rea, sVar1 = _strlen(param1), and the if (sVar1 < 8) branch
The middle Listing window shows the assembly of the entry function, and the Decompile window on the right shows the same pseudocode seen with rea decompile.
After the accumulator variable declarations (iVar68 through iVar83 and uVar84 through uVar90) come sVar1 = _strlen(param1); and the length branches.
Finally, I checked whether the decompiled result is really correct.
I moved the -O0 pseudocode almost as is into a rewritten C function, fed the same inputs to it and the two original binaries, and compared the outputs.
This kind of verification, feeding the same inputs to the original and a reimplementation and comparing the outputs, is called
I picked 14 inputs.
They include no argument, an empty string, UTF-8 strings such as Korean and emoji, and bytes at or above 0x80.
I also added inputs of length 7, 8, 63, 64, and 65
to cross the boundaries of the vectorized loops
, plus 1,000-character inputs.
The comparison script targets zsh, and its first line, the shebang that specifies the shell, is written separately with printf.
Compile and run it.
On Linux, install zsh first, or rewrite the script in bash syntax before running it.
ํ๋ค์ค ์ปดํ์ผ๊ณผ ์ฐจ๋ถ ํ ์คํธ ์คํ
sed -n '6,16p' harness/checksum_recovered.cclang -O0 -o harness/checksum_recovered harness/checksum_recovered.c && ./harness/difftest.sh
The checksum_recovered function body and difftest.sh output: for all 14 inputs from no-arg to high-bytes the O0, O2, and harness values match and PASS, with the last line PASS=14 FAIL=0
Input
Bytes
O0
O2
Reimplementation
Empty string
0
0
0
0
hello rea
9
876
876
876
Korean UTF-8
25
4368
4368
4368
Emoji UTF-8
9
1575
1575
1575
Length 63
63
7560
7560
7560
Length 64
64
7744
7744
7744
Length 65
65
7930
7930
7930
1,000 Korean characters
3000
543250
543250
543250
Bytes at or above 0x80
4
766
766
766
The table shows only some of them, and
for all 14 inputs the entire output line matched byte for byte
(PASS=14 FAIL=0).
It is important to be precise about what this result means.
I restored one small function with the same behavior as the original and confirmed there was no difference on the inputs I chose.
It is not a proof that the outputs match for every input
, and because I knew the original source, choosing the inputs was easy.
That is why the DX-Ball showcaseโ published by the REA project uses 3,205 behavior comparisons together with a check that the compiled 63 bytes match.
Even without an engine, I could check the binary's security settings right away.
Decompilation, on the other hand, depended heavily on the installation state of the external engine: Hopper never ran, and Ghidra only worked after setting up JDK 25 and the native build.
Once connected, REA returned function search, decompilation, and reference tracing in a consistent format and listed the limitations with every result.
inspect-binary-hardening works without an engine, and unknown should be read as "judgment withheld," not "absent."
On macOS ARM64 you need Ghidra 12.2, JDK 25, and a decompiler you built yourself.
On Mach-O, pass function names with an underscore, as in _checksum.
On -O2, inlining and vectorization can make functions disappear or the pseudocode grow long, so cross-check with xrefs and instructions.
Recovered code can only be trusted after verifying it with differential testing.
This lab confirmed that
REA is not a tool that replaces the engine but one that connects engines you have already installed so an agent can use them
.
Part 9 summarizes the security issues that arise when handling these tools and their targets.