Skip to content

Commit cda2272

Browse files
committed
Add Makefile test target and fix string encoding
- Add 'make test' target to verify rasm2 output matches original shellcodes - Fix ARM shellcode to use .ascii instead of .string (no null terminator) - All 6 shellcodes now produce byte-exact output - Tests run automatically and report pass/fail for each shellcode
1 parent a9d3758 commit cda2272

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

libr/egg/p/sc/Makefile

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,55 @@ clean:
2020
rm -rf out
2121
rm -f *.c
2222

23-
.PHONY: all clean
23+
# Test target: verify rasm2 output matches original shellcodes
24+
test: test-shellcodes
25+
26+
test-shellcodes:
27+
@echo "Testing shellcode assembly..."
28+
@fail=0; \
29+
for rasm in asm/*.rasm; do \
30+
base=$$(basename $$rasm .rasm); \
31+
src_file="src/$$base.c"; \
32+
if [ -f "$$src_file" ]; then \
33+
expected=$$(awk '/^#if 0/,/^#endif/{next} /\\x/{gsub(/^\/\*.*\*\/ /, ""); print}' "$$src_file" | grep -o '"\\x[^"]*"' | sed 's/"//g; s/\\x//g' | tr -d '\n'); \
34+
case "$$base" in \
35+
x86-linux-binsh) \
36+
actual=$$(rasm2 -a x86 -b 32 -f "$$rasm" 2>/dev/null); \
37+
;; \
38+
x86_64-linux-binsh) \
39+
actual=$$(rasm2 -a x86 -b 64 -f "$$rasm" 2>/dev/null); \
40+
;; \
41+
x86-osx-binsh|x86-osx-suidbinsh) \
42+
actual=$$(rasm2 -a x86 -b 64 -f "$$rasm" 2>/dev/null); \
43+
;; \
44+
arm-linux-binsh) \
45+
actual=$$(rasm2 -a arm -b 32 -f "$$rasm" 2>/dev/null); \
46+
;; \
47+
thumb-linux-binsh) \
48+
actual=$$(rasm2 -a arm -f "$$rasm" 2>/dev/null); \
49+
;; \
50+
*) \
51+
echo " ⚠️ $$base: Unknown architecture, skipping"; \
52+
continue; \
53+
;; \
54+
esac; \
55+
if [ "$$actual" = "$$expected" ]; then \
56+
echo "$$base: PASS ($$actual)"; \
57+
else \
58+
echo "$$base: FAIL"; \
59+
echo " Expected: $$expected"; \
60+
echo " Got: $$actual"; \
61+
fail=$$((fail + 1)); \
62+
fi; \
63+
else \
64+
echo " ⚠️ $$base: No source file found, skipping"; \
65+
fi; \
66+
done; \
67+
if [ $$fail -eq 0 ]; then \
68+
echo "All tests passed! ✓"; \
69+
else \
70+
echo "$$fail test(s) failed ✗"; \
71+
exit 1; \
72+
fi
73+
74+
.PHONY: all clean test test-shellcodes

libr/egg/p/sc/asm/arm-linux-binsh.rasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ add r3, pc, 4 ; r3 = address of argv on stack
1616
add r1, sp, 4 ; r1 = argv pointer
1717
strb r2, [r3, 1] ; another NULL byte
1818
svc 0x900b0b ; syscall execve (syscall 0xb)
19-
.string "/bin/sh"
19+
.ascii "/bin/sh"

0 commit comments

Comments
 (0)