diff --git a/integrations/opencode-athena/rea/GHIDRA.md b/integrations/opencode-athena/rea/GHIDRA.md new file mode 100644 index 0000000..efcfeb4 --- /dev/null +++ b/integrations/opencode-athena/rea/GHIDRA.md @@ -0,0 +1,94 @@ +# Ghidra provider for OpenCode / REA + +Prepared 2026-10-15 inside the existing Alpine OpenCode container. No additional +container, Docker socket, host SSH identity, published port or service restart. +All paths below belong to the existing persistent `/root` appdata mount. + +## Pinned components + +- REA 6.5.0, existing locked npm installation. +- Official NSA Ghidra 12.1.4 public release, archive + `ghidra_12.1.4_PUBLIC_20260921.zip` (569649598 bytes). +- Source: https://github.com/NationalSecurityAgency/ghidra/releases/tag/Ghidra_12.1.4_build +- Archive SHA-256, verified against the release asset digest: + `ddac49f903da9d5bac833e5cc79395098b9c33cfd3279be5f31bd00387d2d4db`. +- Private Alpine OpenJDK 21.0.12+8, including javac. +- Private build-base/GCC 15.2.0, make, bison, flex and Bash, plus dependencies. + Exact package archive filenames and hashes are in `apk-sha256.txt`. + +Installation root: `/root/.local/share/rea` (`R` below). +Ghidra is extracted into `R/providers/ghidra_12.1.4_PUBLIC` (`G`). Restore ZIP +Unix executable permission bits when extracting using Python zipfile. +Java and Alpine dependencies are unpacked into `R/sysroot` (`S`), without +installing/replacing container system packages. Keep downloaded APKs in `R/apk`. + +The stock Ghidra Linux decompiler targets glibc. This container uses musl; +compile the bundled decompiler source for Alpine rather than assuming that a +successful file-existence check establishes executable compatibility: + +```sh +export PATH="$S/bin:$S/usr/bin:$PATH" +export LD_LIBRARY_PATH="$S/usr/lib:$S/lib" +export BISON_PKGDATADIR="$S/usr/share/bison" +export M4="$S/usr/bin/m4" +cd "$G/Ghidra/Features/Decompiler/src/decompile/cpp" +nice -n 10 make -j2 ghidra_opt \ + "CXX=g++ --sysroot=$S -B$S/usr/bin/ -std=c++11" +install -m 755 ghidra_opt "$G/Ghidra/Features/Decompiler/os/linux_x86_64/decompile" +``` + +## REA-only environment + +Preserve all other OpenCode settings and configure only `mcp.rea.environment`: + +- `GHIDRA_INSTALL_DIR=R/providers/ghidra_12.1.4_PUBLIC` +- `JAVA_HOME=R/sysroot/usr/lib/jvm/java-21-openjdk` +- PATH prepends `JAVA_HOME/bin`, `R/sysroot/bin`, `R/sysroot/usr/bin`. +- LD_LIBRARY_PATH prepends `R/sysroot/usr/lib`, `R/sysroot/lib`. + +Use actual absolute paths, not literal R/S/G. The same overrides are stored in +`R/private-env.json` for separate smoke tests. Do not commit this private file or +OpenCode configuration/installer backups; they can inherit sensitive settings. +No active OpenCode session is reloaded during this installation. A separately +verified MCP process does not establish that an already running client has +loaded the new configuration. + +## Verified result + +The Alpine native build completed successfully. Installed decompiler SHA-256: +`d9a25620ce2bbbf36199562b1b14f7253c727791381f73a73487d5fa8417ae17`. +REA doctor identifies Ghidra as available and its provider scope as healthy; +its broader environment reports missing optional providers, not a fully green +all-provider setup. The end-to-end synthetic test passed: DOS-MZ/x86, exact +identity match, two procedures, 229 characters of nonempty pseudocode. The first +pre-build analysis attempt failed; only the final native-build test is accepted. +Ghidra/Java paths were saved in the REA-only MCP environment. Other persisted +model/MCP settings were compared internally and unchanged. + +## Verification and limitations + +Run `node verify-dos.mjs` inside OpenCode. It creates a tiny synthetic DOS MZ EXE, +opens it through Ghidra's REA provider, verifies its format and SHA-256, lists +procedures and requests nonempty pseudocode. It never executes the EXE. Only +synthetic result counts are printed; its fixture and MCP child are cleaned up. +Do not treat provider discovery/doctor alone as proof of decompilation. + +DOS program support does not promise original source code, original variable +names, reliable reconstruction of packed/self-modifying code, or an executable +modern port. Analyze user binaries statically first. Actual user EXEs have not +been tested as part of installation. + +## Backup / restore + +Back up the complete persistent OpenCode `/root` mount with Unraid appdata, +including runtime, Ghidra, sysroot, configuration and private state. Athena Deck's +separate backup does not automatically include this Unraid service. Public +archives can instead be downloaded again using the pinned sources/hashes. +Re-run the native build and both REA smoke tests after changing Alpine ABI. + +For future native Debian, install a supported 64-bit JDK 21 and procps with the +native package manager, extract this pinned official Ghidra distribution and +use its supplied glibc decompiler. Set JAVA_HOME/GHIDRA_INSTALL_DIR for the actual +service account; do not copy Alpine musl libraries or its rebuilt executable +onto Debian. Reconstruct REA using the lockfile and repeat the DOS test. A fresh +Debian host restore remains untested; no native Deck installation is changed. diff --git a/integrations/opencode-athena/rea/README.md b/integrations/opencode-athena/rea/README.md index 1b3f47e..8004c9c 100644 --- a/integrations/opencode-athena/rea/README.md +++ b/integrations/opencode-athena/rea/README.md @@ -16,8 +16,8 @@ activation after restart/new session is not claimed by this preparation. - Registration: `/root/.config/opencode/opencode.jsonc`, `mcp.rea`, local stdio, command `["/root/.local/share/rea/runtime/node_modules/rea-agents/scripts/rea.mjs", "mcp"]`. - Skill: `/root/.agents/skills/reverse-engineer-anything`. -- No optional Frida dependency installed; Java/Ghidra/Hopper/IDA not installed. - Native executable decompilation requires a separate compatible provider. +- No optional Frida dependency installed; Hopper/IDA are not installed. +- Ghidra and its private Java/build dependencies: see `GHIDRA.md`. The existing Alpine BusyBox `ps` does not support REA's process-ownership query. Fetched procps-ng 4.0.6-r0 and dependencies with `apk fetch --recursive`, unpacked @@ -36,7 +36,8 @@ tools. A real `analyze_javascript_application` call succeeded on a generated two-file CommonJS fixture with summary output; fixture and temporary server were removed afterward. No user app, private input, GPU inference, or host program was used. Run `node verify.mjs` inside OpenCode to repeat this synthetic check. -This establishes static JavaScript analysis, not all 207 tools or native providers. +This establishes static JavaScript analysis, not all 207 tools. A subsequent +Ghidra DOS-MZ decompilation test also passed; see `GHIDRA.md` and `verify-dos.mjs`. ## Restore and update @@ -60,8 +61,8 @@ For a future native Debian deployment, Node plus the locked npm tree remain required; install the distribution's procps rather than using Alpine's musl sysroot and remove the private musl library override. Configure the actual service user's home and executable path, then repeat the smoke test. A fresh-host native -restore, browser-runtime inspection and executable-decompiler integration have -not been tested here. +restore and browser-runtime inspection have not been tested here. +See `GHIDRA.md` for the separately verified executable provider and its limits. Official references: https://rea.tools/get-started/ and https://github.com/morluto/rea/blob/main/docs/client-configuration.md. diff --git a/integrations/opencode-athena/rea/apk-sha256.txt b/integrations/opencode-athena/rea/apk-sha256.txt index 5128337..4ebe241 100644 --- a/integrations/opencode-athena/rea/apk-sha256.txt +++ b/integrations/opencode-athena/rea/apk-sha256.txt @@ -1,8 +1,68 @@ +052de5639df635a03cfae1d7504ed4ed75c4e2d2cfff59efc116bb847c1f4ac4 alsa-lib-1.2.15.3-r0.apk +4ad962f26fb3c68365171233fe61e3c51bbee1cab35e8dc661198233daeab0dd bash-5.3.9-r1.apk +15682887459d216585feb438bbfb7ec63e1f33e77c453f44637d2d9d8c35977d binutils-2.45.1-r1.apk +07c588c6502ece84cf6acb0ec3c6c3b592948de1e4b5590c63a17c9ec0b694f7 bison-3.8.2-r3.apk +f0823de7c6d45859aeb6a7facfc5cfbf2dadb83ad4f27c794cb6ecc74e578cee brotli-libs-1.2.0-r1.apk +3ac72e74e96150995e8d797b6c33fc3b46d69e3667c47bd0ff25ce89f9fc4eaf build-base-0.5-r4.apk +0e626fa97cf937fda7bba4ed4dde8e2f2dbb5083ac34e02180cec0c4eba9351b busybox-1.37.0-r31.apk +93f803ae5db6b729c0f66f4afba6e907ccc17d7d5f8b8c3d25bdb4636de2c48a busybox-binsh-1.37.0-r31.apk +d33f9058111586cea83cb3cca78d24efb36a45e6466fd0228f66e791f1cb79ed ca-certificates-20260909-r0.apk +4681c153c509aec126e2b9ea2c959730309b24a792d49fc8cc26fa5fa87e8fdd file-5.47-r2.apk +18694dcfa86e5ffe689e81be088ec2b7d6c632d76f645e860cec9ad8eaa32225 flex-2.6.4-r8.apk +5ffaebd9f141ac3e3fa0cc99f798f64b4c0aa16fb06a7a77e68f63f350fe23aa fortify-headers-3.0.1-r2.apk +09d76fde675a9ca3cfeb83d72fb09cb2e9ccf79b2937daa05a1af9a37a6b7815 freetype-2.14.3-r0.apk +35c39e8d3667d8603fe209dbafe67681c64b1cda66bf9c836bfb4d05b19a71fd g++-15.2.0-r5.apk +d1d482472ed91240731c60dbae8176bc1e32e1dfb694856da6759f6d32716325 gcc-15.2.0-r5.apk +b9e569173af3a34a4756d9834fab7212863bd3b74f870ea9ed217caaf6faa695 giflib-5.2.2-r2.apk +85323ef5bce8ff234736dc2d6592ea37aebdc6348a531e27430bdfe38364d256 gmp-6.3.0-r4.apk +30999fb66e296c8ea7aa102cad0d3095519b3022abb622d2951dd29367310ea9 isl26-0.26-r2.apk +7681b41486e1f2b2efce11875c839533464ae8857d30fc49130f0039c6585fdb jansson-2.15.0-r0.apk +897198ff725f7ebde749b2847d1c0b61cbee9909b4a58c4d41f999bf7ae7c74d java-cacerts-1.1-r0.apk +57c515eceec2c9221fcfe345e1704593efc0bfa7e28f7286c6443d6356983966 java-common-1.0-r2.apk +b4cb038af3c2f02bedd8456ae876c97ac0a9f29789add77871bfd6ce084ff136 lcms2-2.19-r0.apk +c5ec550c73dd7b4e81e206fdff3cf4c46b0ae1b29fec1db5cd4e12d88416abbf libatomic-15.2.0-r5.apk +407597c04b41dbfe8a05b35d45a3453e32fae7df84aed3a06ff48dd4df1338b6 libbsd-0.12.2-r0.apk +2737e2b23ed08d4911ee62cd0163b5f4bf0379cacf4dc35b23a00209584c98fd libbz2-1.0.8-r6.apk +6632d758d8f5e9ea3b650fe966f23bbf9a202f8b8dceecac93da135dec5e3689 libcrypto3-3.5.9-r0.apk +6da1a19313a40c56cac756fb11e2c4d5267831e1c22fc8323f24c943c94da6e0 libffi-3.5.2-r1.apk +393dcd32629f06d7d85409c272d142d0c082772d10b87ef55ee82f47de3be637 libgcc-15.2.0-r5.apk +563244a562f5c48b921f7f0b4a571e373cfcba65175fe2d4f752c5f975738bcd libgcc-static-15.2.0-r5.apk +e7204aad00e31d544e0a34eac5a7eb7d3586d2b7b22afd6e5907189c4e0337cc libgomp-15.2.0-r5.apk cb03919cba5624b5e8759d04f3b31913b02585355988b914bc31de4746ff5ef6 libintl-1.0-r0.apk +6299627dd0a9156a7463511e4915a6294dfb592d8b4bdf85e55265adf1b8ea04 libjpeg-turbo-3.1.3-r0.apk +1820acd299025619a848b19ac98c7996fd92c06965255898800b6a790a8b03a2 libmagic-5.47-r2.apk +f6d68d072fcefc8edd4ffe3afc341ca391f8a9a209130628fb065d98b18a2792 libmd-1.2.0-r0.apk cf8caa8a88bc4ce9d9e395567fefaf9ef7fbd55c50ae6155b35c1b58f3755023 libncursesw-6.6_p20260516-r0.apk +d16aeb0597f2bc43e0583ac9ff779388ec160c3e22568b640122e94ba55be6d7 libpng-1.6.59-r0.apk b879846fa616ed27c64c5bd15ef3647f59005cab2c95c1fc2738b64ddbcfb9e6 libproc2-4.0.6-r0.apk +14c987b556f5385a5db18376e788c75f37d85321b8dc1920d926ea7daac1d6f6 libstdc++-15.2.0-r5.apk +62ce308cdbf127dcac6eee1520a4ffec8dc98b30974653908842fe4cc7d90b43 libstdc++-dev-15.2.0-r5.apk +407f255c5af989f4e22a5e9404c4558f6fda04f14a4209a2ca1e06c3f2ba476e libtasn1-4.21.0-r0.apk +eb7adb36436d82c54f36db61dd0493010f8bd2267320a04a6ed0809dffcb0a9b libx11-1.8.13-r0.apk +3506cdba7ed916a6f814a010fbb127dbfdae4147107f64a15f5fa2651c5d8510 libxau-1.0.12-r0.apk +7935d5ad9c7137b7b3f1292d62f55f7e0cc5c919155218c3060ea46503b3f211 libxcb-1.17.0-r2.apk +2a93f44f3f85c1eda9ed53691c35d0742b5fcd8e0057cd7380934025936cbf6f libxdmcp-1.1.5-r1.apk +8afe1ee6ab8cb656e12f20dc5b7fb2d4103faee4a38298b94f26ab52e597cbc8 libxext-1.3.7-r0.apk +3fd5ba20d3d5e5b55addd6938d13769c13e8a16118940eefbc9ae424da710ca0 libxi-1.8.3-r0.apk +21953cb2122abf5a7efe47f431f5f4024869c85471f3c60e6b7e6f5107ab7316 libxrender-0.9.12-r0.apk +ba447beb24412e76ebc5ec8e8f1dabe3c76c4d66d2894da6582205ededdba717 libxtst-1.2.5-r0.apk +e163b45e0fae7b50f4abec37833a729453cea38a5d74c9ed1bdb04a475eeba70 m4-1.4.20-r1.apk +a916626a876f64c6b6fb32a6bf0fa93351d09fae0aa7684135642390da647e60 make-4.4.1-r4.apk +c2247438e163f1c11646428f07576ceb3cf3167f9a9a5c6526021f778d77adb6 mpc1-1.3.1-r1.apk +93620a803d416e8c05150fb14413796df14ea370322dff6bd106455deab15646 mpfr4-4.2.2-r0.apk 573712e2f49c15bfc20a2699f204acdfc74c772722b15e7353d768057fae0e71 musl-1.2.6-r2.apk +6831e8b9e4821dae2c9121f0641f81e543f4ac27c03144c4876980ee84e6988f musl-dev-1.2.6-r2.apk ce83be6d0bd10584a53c3a5868cc1595ce5f0f8e0b621f8f7f70b6144e521fc9 ncurses-terminfo-base-6.6_p20260516-r0.apk +94fff4b3d902b80a42db3ad3ba47e6510d0349513da102d1f4d49afa2124aaa4 openjdk21-jdk-21.0.12_p8-r0.apk +b18c79a74c378ddee4fe273ce1c31cd9e7c58cff4ceeb414fe7ec259519e9006 openjdk21-jmods-21.0.12_p8-r0.apk +d374dc31ec24ff995c9720409c3e10e0d90faaaf0bee3500b1b63b96c987bae4 openjdk21-jre-21.0.12_p8-r0.apk +0b213f025424d6e0d5fec26c4a9d4e5e4c96de9bc9f5e2d28737fe46ccd7db06 openjdk21-jre-headless-21.0.12_p8-r0.apk +134d653aeeb4ada32746fbc3e2a7ae4201f584725de9263e4f32503658f3ddd8 p11-kit-0.26.2-r0.apk +f79c696b960d974832723215431b93e21ecb29b2449892b3fd6587713f1f2f50 p11-kit-trust-0.26.2-r0.apk +723c061ea3e2c3e61b457f8f614f0b87724aeae37564ba4c1bdd41c722118187 patch-2.8-r0.apk 2510d07b3c029e7cdba1a6981fa17ac5a7b6c31e1e36df4327f46dd3aa8822eb procps-ng-4.0.6-r0.apk +766911ecb986a6c5cf0841a6b556cd1e9dbbf22b3559726de32416486cd15c81 readline-8.3.3-r1.apk 3301f6ccbeaea49cdd966c7e636898a8612fb8fe964a15f24f6d204b3944c3f3 skalibs-libs-2.15.0.0-r0.apk 497f0f1cb51f0e6c1acc338fded0dc7722b1d43ea17bdb749f0d556794f8b2d8 utmps-libs-0.1.3.3-r0.apk +63aeea03c15a2f9018f81805cfc8aa926bdf5cd68921f22149c2fbb5d0ee9f47 zlib-1.3.2-r1.apk +23c6065b0049b2406441564bcf0032515a43f78e80d76fcb85535a3803ef5d4e zstd-libs-1.5.7-r2.apk diff --git a/integrations/opencode-athena/rea/verify-dos.mjs b/integrations/opencode-athena/rea/verify-dos.mjs new file mode 100644 index 0000000..017d6da --- /dev/null +++ b/integrations/opencode-athena/rea/verify-dos.mjs @@ -0,0 +1,7 @@ +import cp from 'node:child_process';import fs from 'node:fs';import os from 'node:os';import crypto from 'node:crypto'; +const root=process.env.REA_INSTALL_ROOT||os.homedir()+'/.local/share/rea';const dir=fs.mkdtempSync(root+'/dos-smoke-'); +const code=Buffer.from([0xb8,0x34,0x12,0xe8,0x06,0x00,0xb8,0x00,0x4c,0xcd,0x21,0x90,0x40,0xc3]);const exe=Buffer.alloc(32+code.length);const words=[0x5a4d,exe.length,1,0,2,0x10,0xffff,0,0x100,0,0,0,0x1c,0];words.forEach((v,i)=>exe.writeUInt16LE(v,i*2));code.copy(exe,32);const target=dir+'/fixture.exe';fs.writeFileSync(target,exe);const hash=crypto.createHash('sha256').update(exe).digest('hex'); +const child=cp.spawn(root+'/runtime/node_modules/rea-agents/scripts/rea.mjs',['mcp'],{stdio:['pipe','pipe','pipe'],env:{...process.env,...JSON.parse(fs.readFileSync(root+'/private-env.json','utf8'))}});let buf='';const pending=new Map;child.stdout.on('data',data=>{buf+=data;let n;while((n=buf.indexOf('\n'))>=0){const line=buf.slice(0,n);buf=buf.slice(n+1);try{const j=JSON.parse(line);if(j.id&&pending.has(j.id)){pending.get(j.id)(j);pending.delete(j.id)}}catch{}}});child.stderr.resume();let seq=0;let opened=false; +const request=(method,params={})=>new Promise((resolve,reject)=>{const id=++seq;const timer=setTimeout(()=>reject(new Error('MCP timeout: '+method)),360000);pending.set(id,j=>{clearTimeout(timer);j.error?reject(new Error('MCP protocol error '+j.error.code)):resolve(j.result)});child.stdin.write(JSON.stringify({jsonrpc:'2.0',id,method,params})+'\n')}); +const call=async(name,args={})=>{const r=await request('tools/call',{name,arguments:args});const e=r.structuredContent||JSON.parse(r.content.find(c=>c.type==='text').text);if(r.isError)throw new Error('REA '+name+' failed: '+(e.error?.code||'unknown')+' '+(e.error?.category||''));const v=e.normalized_result??e;return v.result??v;}; +try{await request('initialize',{protocolVersion:'2025-11-25',capabilities:{},clientInfo:{name:'athena-rea-dos-smoke',version:'1'}});child.stdin.write(JSON.stringify({jsonrpc:'2.0',method:'notifications/initialized'})+'\n');const t=await call('open_binary',{path:target,provider_id:'ghidra'});opened=true;if(t.format!=='dos-mz'||t.sha256!==hash)throw new Error('DOS identity mismatch');const p=await call('list_procedures');if(!Array.isArray(p)||!p.length)throw new Error('No DOS procedures');const f=await call('analyze_function',{procedure:p[0].address});if(!f.pseudocode?.trim())throw new Error('Empty DOS pseudocode');console.log(JSON.stringify({success:true,format:t.format,architecture:t.architecture,identityVerified:true,procedures:p.length,pseudocodeCharacters:f.pseudocode.length}));}finally{if(opened){try{await call('close_binary')}catch{}}child.kill('SIGTERM');fs.rmSync(dir,{recursive:true,force:true})}