-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarble
More file actions
executable file
·586 lines (518 loc) · 16.9 KB
/
Copy pathmarble
File metadata and controls
executable file
·586 lines (518 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#!/bin/bash
#
# marble - Unified launcher for Marble Framework
#
# Usage:
# ./marble # Launch the TUI (default)
# ./marble tui # Launch the TUI explicitly
# ./marble mibster # Run mibster directly
# ./marble mender # Run mender directly
# ./marble validator # Run validator directly
# ./marble ml # Run ML CLI (mibster_ml.py)
# ./marble ml <cmd> # Run specific ML command (analyze, generate, etc.)
# ./marble build # Build all tools
# ./marble build --clean # Clean + rebuild
# ./marble status # Show build status
# ./marble test # Run round-trip test harness
# ./marble init <name> # Scaffold a new Marble project
# ./marble registry <cmd> [args] # Manage QIHSE algorithm registry
# ./marble cmake [args] # Build with CMake instead of Make
# ./marble appimage # Package as AppImage
# ./marble api [--port 5000] # Start REST API server (Flask)
# ./marble api --fastapi [--port 5000] # Start REST API server (FastAPI + WebSocket)
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
print_ok() { echo -e "${GREEN}[OK]${NC} $1"; }
print_fail() { echo -e "${RED}[!!]${NC} $1"; }
print_info() { echo -e "${YELLOW}[..]${NC} $1"; }
print_ml() { echo -e "${CYAN}[ML]${NC} $1"; }
show_status() {
echo ""
echo "Marble Framework - Status"
echo "========================="
echo ""
# C++ tools
if [[ -f "LinuxPort/mibster" ]]; then
print_ok "mibster (obfuscator)"
else
print_fail "mibster (not built - run: ./marble build)"
fi
if [[ -f "LinuxPort/mender" ]]; then
print_ok "mender (restore)"
else
print_fail "mender (not built)"
fi
if [[ -f "LinuxPort/validator" ]]; then
print_ok "validator (verifier)"
else
print_fail "validator (not built)"
fi
# TUI
if [[ -f "LinuxTUI/marble-tui" ]]; then
print_ok "marble-tui (unified TUI)"
else
print_fail "marble-tui (not built - run: ./marble build)"
fi
# ML pipeline
if [[ -d "ml" ]] && [[ -f "ml/mibster_ml.py" ]]; then
print_ml "ML pipeline scripts found"
if command -v python3 >/dev/null 2>&1; then
print_ok "python3 available"
else
print_fail "python3 not found (required for ML pipeline)"
fi
if [[ -f "ml/data/features.json" ]]; then
print_ml " Phase 0-1: features extracted"
else
print_info " Phase 0-1: not run yet"
fi
if [[ -f "ml/data/validation_baseline.json" ]]; then
print_ml " Phase 3: validation baseline exists"
else
print_info " Phase 3: not run yet"
fi
if [[ -f "ml/data/synthetic/dataset.jsonl" ]]; then
local count
count=$(wc -l < "ml/data/synthetic/dataset.jsonl" 2>/dev/null || echo "0")
print_ml " Phase 4: $count synthetic algorithms"
else
print_info " Phase 4: not run yet"
fi
if [[ -f "ml/data/synthetic/train.jsonl" ]]; then
local tcount
tcount=$(wc -l < "ml/data/synthetic/train.jsonl" 2>/dev/null || echo "0")
print_ml " Phase 5: $tcount training examples ready"
else
print_info " Phase 5: not run yet"
fi
else
print_fail "ML pipeline not found (ml/ directory missing)"
fi
echo ""
}
do_build() {
local clean_flag=""
local no_tui=""
while [[ $# -gt 0 ]]; do
case $1 in
--clean) clean_flag="--clean"; shift ;;
--no-tui) no_tui="--no-tui"; shift ;;
*) shift ;;
esac
done
echo "Building Marble Framework..."
./build.sh $clean_flag $no_tui
}
run_tui() {
if [[ ! -f "LinuxTUI/marble-tui" ]]; then
print_fail "marble-tui not built. Run: ./marble build"
exit 1
fi
exec ./LinuxTUI/marble-tui
}
run_mibster() {
if [[ ! -f "LinuxPort/mibster" ]]; then
print_fail "mibster not built. Run: ./marble build"
exit 1
fi
exec ./LinuxPort/mibster "$@"
}
run_mender() {
if [[ ! -f "LinuxPort/mender" ]]; then
print_fail "mender not built. Run: ./marble build"
exit 1
fi
exec ./LinuxPort/mender "$@"
}
run_validator() {
if [[ ! -f "LinuxPort/validator" ]]; then
print_fail "validator not built. Run: ./marble build"
exit 1
fi
exec ./LinuxPort/validator "$@"
}
run_ml() {
if [[ ! -f "ml/mibster_ml.py" ]]; then
print_fail "ML pipeline not found."
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
print_fail "python3 not found."
exit 1
fi
cd ml
if [[ $# -eq 0 ]]; then
python3 mibster_ml.py --help
else
python3 mibster_ml.py "$@"
fi
}
run_test() {
if [[ ! -f "LinuxPort/mibster" ]]; then
print_fail "mibster not built. Run: ./marble build"
exit 1
fi
if [[ ! -f "LinuxPort/mender" ]]; then
print_fail "mender not built. Run: ./marble build"
exit 1
fi
if [[ ! -f "LinuxPort/validator" ]]; then
print_fail "validator not built. Run: ./marble build"
exit 1
fi
local TMPDIR
TMPDIR=$(mktemp -d /tmp/marble_test_XXXXXX)
local SHARED_DIR="$(pwd)/LinuxPort/Shared"
local PASS=0
local FAIL=0
echo ""
echo "Marble Framework — Round-Trip Test Harness"
echo "============================================"
echo " Temp dir: $TMPDIR"
echo ""
# Step 1: Copy test project
echo -n " [1/6] Copy test project... "
cp -r LinuxPort/test_project/* "$TMPDIR/" 2>/dev/null || true
mkdir -p "$TMPDIR/output"
print_ok "done"
# Step 2: Run mibster
echo -n " [2/6] Obfuscate with mibster... "
if ./LinuxPort/mibster "$TMPDIR" "$SHARED_DIR" "$TMPDIR/output" > "$TMPDIR/mibster.log" 2>&1; then
print_ok "pass"
PASS=$((PASS + 1))
else
print_fail "fail"
FAIL=$((FAIL + 1))
cat "$TMPDIR/mibster.log" | head -20
echo " mibster log: $TMPDIR/mibster.log"
fi
# Step 3: Compile obfuscated output
echo -n " [3/6] Compile obfuscated output... "
if g++ -I"$SHARED_DIR" "$TMPDIR/test_sample.cpp" -o "$TMPDIR/test_bin" 2> "$TMPDIR/compile.log"; then
print_ok "pass"
PASS=$((PASS + 1))
else
print_fail "fail"
FAIL=$((FAIL + 1))
cat "$TMPDIR/compile.log" | head -20
fi
# Step 4: Run validator
echo -n " [4/6] Validate no plaintext in binary... "
if [[ -f "$TMPDIR/output/MarbleReceipt.txt" ]] && [[ -f "$TMPDIR/test_bin" ]]; then
if ./LinuxPort/validator "$TMPDIR/output/MarbleReceipt.txt" "$TMPDIR/test_bin" > "$TMPDIR/validator.log" 2>&1; then
print_ok "pass"
PASS=$((PASS + 1))
else
print_fail "fail (plaintext found!)"
FAIL=$((FAIL + 1))
cat "$TMPDIR/validator.log" | head -20
fi
else
print_fail "skip (receipt or binary missing)"
FAIL=$((FAIL + 1))
fi
# Step 5: Run mender to restore
echo -n " [5/6] Restore with mender... "
if ./LinuxPort/mender "$TMPDIR" > "$TMPDIR/mender.log" 2>&1; then
print_ok "pass"
PASS=$((PASS + 1))
else
print_fail "fail"
FAIL=$((FAIL + 1))
fi
# Step 6: Diff restored vs original
echo -n " [6/6] Verify restored files match original... "
if diff -q LinuxPort/test_project/test_sample.cpp "$TMPDIR/test_sample.cpp" > /dev/null 2>&1; then
print_ok "pass"
PASS=$((PASS + 1))
else
print_fail "fail (files differ)"
FAIL=$((FAIL + 1))
diff LinuxPort/test_project/test_sample.cpp "$TMPDIR/test_sample.cpp" | head -20
fi
echo ""
echo " Results: ${GREEN}$PASS passed${NC}, ${RED}$FAIL failed${NC}"
if [[ $FAIL -eq 0 ]]; then
print_ok "ALL TESTS PASSED"
rm -rf "$TMPDIR"
else
print_fail "SOME TESTS FAILED (temp dir preserved: $TMPDIR)"
exit 1
fi
# Trinary algorithm tests
echo ""
echo " Trinary Algorithm Tests:"
if [[ -f "LinuxPort/test_trinary" ]]; then
if LinuxPort/test_trinary > /dev/null 2>&1; then
print_ok " Trinary round-trip tests PASSED"
else
print_fail " Trinary round-trip tests FAILED"
LinuxPort/test_trinary
exit 1
fi
else
echo " (test_trinary not built, building...)"
if (cd LinuxPort && g++ -std=c++11 -I Marbler -o test_trinary test_trinary.cpp Marbler/TrinaryLogic.cpp 2>/dev/null); then
if LinuxPort/test_trinary > /dev/null 2>&1; then
print_ok " Trinary round-trip tests PASSED"
else
print_fail " Trinary round-trip tests FAILED"
LinuxPort/test_trinary
exit 1
fi
else
print_fail " Could not build test_trinary"
fi
fi
}
run_init() {
local project_name="$1"
if [[ -z "$project_name" ]]; then
echo "Usage: marble init <project-name>"
exit 1
fi
if [[ -e "$project_name" ]]; then
print_fail "'$project_name' already exists"
exit 1
fi
local SHARED_DIR="$(pwd)/LinuxPort/Shared"
echo ""
echo "Creating Marble project: $project_name"
echo ""
mkdir -p "$project_name/src"
# .marbleignore
cat > "$project_name/.marbleignore" << 'IGNOREEOF'
# Files/directories to exclude from obfuscation
test/
third_party/
build/
*.test.cpp
*.test.c
IGNOREEOF
print_ok ".marbleignore"
# Marble.h symlink
ln -s "$SHARED_DIR/Marble.h" "$project_name/Marble.h"
print_ok "Marble.h -> $SHARED_DIR/Marble.h"
# Sample source file
cat > "$project_name/src/main.cpp" << 'CPPEOF'
#include <stdio.h>
#include "../Marble.h"
int main() {
CARBLE greeting[] = "Hello from Marble!";
CARBLE secret[] = "This is a secret string";
CARBLE msg[] = "Obfuscation protects your strings";
printf("%s\n", greeting);
printf("%s\n", secret);
printf("%s\n", msg);
return 0;
}
CPPEOF
print_ok "src/main.cpp"
# Simple Makefile
cat > "$project_name/Makefile" << 'MAKEEOF'
CXX = g++
CXXFLAGS = -Wall -O2 -I.
all: app
app: src/main.cpp
$(CXX) $(CXXFLAGS) -o app src/main.cpp
clean:
rm -f app
# Obfuscate with: marble mibster . <path-to-Shared> ./output
# Restore with: marble mender .
# Validate with: marble validator ./output/MarbleReceipt.txt ./app
MAKEEOF
print_ok "Makefile"
# README
cat > "$project_name/README.md" << 'MDEOF'
# Project: <name>
Built with the [Marble Framework](https://github.com/) for string obfuscation.
## Build
```bash
make
```
## Obfuscate
```bash
marble mibster . <marble-shared-dir> ./output
make clean && make # rebuild with obfuscated strings
marble validator ./output/MarbleReceipt.txt ./app # verify
```
## Restore
```bash
marble mender .
```
MDEOF
sed -i "s/<name>/$project_name/" "$project_name/README.md"
print_ok "README.md"
echo ""
print_ok "Project created: $project_name"
echo " cd $project_name && make"
}
show_help() {
cat << 'EOF'
Marble Framework - Unified Launcher
====================================
Usage:
marble [command] [args...]
Commands:
(none) / tui Launch the unified TUI (default)
mibster <args> Run mibster obfuscator directly
mender <args> Run mender restore tool directly
validator <args> Run validator directly
ml [cmd] [args] Run ML pipeline CLI (mibster_ml.py)
build [options] Build all tools (--clean, --no-tui)
status Show build + pipeline status
test Run round-trip test harness
init <name> Scaffold a new Marble project
registry <cmd> Manage QIHSE algorithm registry (sync, list, query, history, rollback, tag)
cmake [args] Build with CMake (e.g. cmake --static for static build)
appimage Package Marble Framework as an AppImage
api [--port P] Start REST API server (Flask, default: port 5000)
api --fastapi Start FastAPI server (async, WebSocket, Swagger UI)
api --grpc Start gRPC server (streaming, high-performance)
llvm-pass Build LLVM IR obfuscation pass plugin
help Show this help
ML Commands (via: marble ml <cmd>):
analyze Phase 0: AST parsing + variance analysis
extract Phase 1: Feature extraction + vector store
validate Phase 3: Z3 symbolic + entropy + round-trip + detection validation
detect Detection-aware validation (YARA evasion checking)
camouflage Entropy camouflage + build fingerprint randomization
rltrain RL training loop for obfuscation generation
hwkey Hardware-bound key derivation (TPM/SGX)
raft Distributed registry with Raft consensus
receipt Self-destructing receipts with TTL
dashboard Web dashboard for ML pipeline monitoring
generate Phase 2: Generate new algorithms
factory Phase 4: Synthetic data factory
prepare Phase 5: LoRA training preparation
pipeline Run all phases end-to-end
inject Generate + inject into Marble.h framework
interactive Online interactive generation (accept/reject/inject)
dedup Find and report structurally duplicate algorithms
novel-generate Generate novel algorithms via LoRA-trained model
cnsa CNSA 2.0 compliance audit, enforcement, PQC readiness
predict Detection-rate predictor (train/predict ML scoring)
sbom SBOM generation (CycloneDX) + Sigstore binary signing
tui Terminal UI dashboard (Rich/Textual)
ptest Property-based round-trip testing
plugin Plugin SDK loader (load/test/list runtime scramblers)
adversarial Adversarial generation loop (generate→predict→mutate→evade)
kms Key rotation & KMS integration (Vault/AWS KMS)
fips FIPS 140-3 provider status and enforcement
onnx ONNX export (LoRA model + detection predictor)
registry Unified algorithm registry (builtin + plugins)
gen-wrappers Auto-generate plugin wrappers for built-in algorithms
Examples:
marble # Launch TUI
marble mibster ./project ./Shared ./output
marble mibster --dry-run ./project ./Shared ./output
marble ml generate --family XOR --count 5
marble ml inject --family BUMP --direction backward
marble ml interactive
marble ml dedup --threshold 0.05
marble ml novel-generate --count 20 --temperature 0.9
marble ml detect
marble ml camouflage fingerprint --seed 42
marble ml camouflage full --input obf.cpp --output camo.cpp
marble ml rltrain --episodes 100 --mode lightweight
marble build --clean
marble test
marble init myproject
marble registry sync
marble registry list
marble registry history MBL_FORLOOP_XOR1
marble registry rollback MBL_FORLOOP_XOR1 --to v1
marble cmake --static
marble api --port 5000
marble appimage
marble status
EOF
}
# ─── Main ────────────────────────────────────────────────────────────────────
case "${1:-tui}" in
tui)
run_tui
;;
mibster)
shift
run_mibster "$@"
;;
mender)
shift
run_mender "$@"
;;
validator)
shift
run_validator "$@"
;;
ml)
shift
run_ml "$@"
;;
build)
shift
do_build "$@"
;;
test)
run_test
;;
init)
shift
run_init "$@"
;;
registry)
shift
python3 "$SCRIPT_DIR/ml/registry_sync.py" "$@"
;;
cmake)
shift
BUILD_DIR="$SCRIPT_DIR/LinuxPort/build"
mkdir -p "$BUILD_DIR"
STATIC_FLAG=""
for arg in "$@"; do
if [ "$arg" = "--static" ]; then
STATIC_FLAG="-DBUILD_STATIC=ON"
fi
done
cmake -S "$SCRIPT_DIR/LinuxPort" -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release $STATIC_FLAG
make -C "$BUILD_DIR" -j$(nproc)
echo "CMake build complete. Binaries in $BUILD_DIR/"
;;
api)
shift
if [ "${1:-}" = "--fastapi" ]; then
shift
python3 "$SCRIPT_DIR/ml/fastapi_server.py" "$@"
elif [ "${1:-}" = "--grpc" ]; then
shift
python3 "$SCRIPT_DIR/ml/grpc_server.py" "$@"
else
python3 "$SCRIPT_DIR/ml/api.py" "$@"
fi
;;
appimage)
bash "$SCRIPT_DIR/build_appimage.sh"
;;
llvm-pass)
make -C "$SCRIPT_DIR/LinuxPort" llvm-pass
;;
status)
show_status
;;
help|--help|-h)
show_help
;;
*)
echo "Unknown command: $1"
show_help
exit 1
;;
esac