
올인원 macOS 바이너리 분석: Mach-O 파싱, ARM64 디스어셈블리, 코드 서명, 디버깅.
Mach-O 파싱, ARM64 디스어셈블리, 프로세스 디버깅을 제공하는 네이티브 macOS 바이너리 분석 도구입니다. 외부 의존성 없이 전적으로 Swift로 구축되었습니다.
| 기능 | 설명 |
|---|---|
| Mach-O 파싱 | 헤더, 세그먼트, 섹션, 심볼, dylibs, 문자열 |
| 코드 서명 | Entitlements, CDHash, 서명 정보, 팀 ID |
| ARM64 디스어셈블리 | PAC 주석을 포함한 전체 명령어 디코더 |
| 프로세스 디버깅 | 프로세스 연결(attach), 중단점, 메모리, 레지스터 |
| Swift 라이브러리 | 자신의 프로젝트에 임베드 |
| JSON 출력 | 스크립트 작성에 적합한 출력 형식 |
# 빌드
swift build
# 바이너리 파싱
swift run machscope parse /bin/ls
# macOS 앱 파싱
swift run machscope parse /Applications/Calculator.app/Contents/MacOS/Calculator
# entitlements 확인
swift run machscope parse /Applications/Safari.app/Contents/MacOS/Safari --entitlements
# JSON 출력
swift run machscope parse /bin/ls --json
brew install sadopc/tap/machscope
git clone https://github.com/sadopc/machscope.git
cd MachScope
swift build -c release
sudo cp .build/release/machscope /usr/local/bin/
Mach-O 바이너리 구조를 분석합니다:
# 기본 분석
machscope parse /bin/ls
# 전체 분석
machscope parse /bin/ls --all
# 특정 섹션
machscope parse /path/to/binary --symbols
machscope parse /path/to/binary --dylibs
machscope parse /path/to/binary --strings
machscope parse /path/to/binary --signatures
machscope parse /path/to/binary --entitlements
# 스크립트 작성을 위한 JSON 출력
machscope parse /bin/ls --json --all > analysis.json
ARM64 코드를 디스어셈블합니다:
# 함수 목록
machscope disasm /bin/ls --list-functions
# 주소에서 디스어셈블리
machscope disasm /bin/ls --address 0x100003f40 --length 50
# 명령어 바이트 표시
machscope disasm /bin/ls --show-bytes
사용 가능한 기능을 확인합니다:
machscope check-permissions
출력:
Feature Status Notes
------------------------------------------------------------
Static Analysis ✓ Ready No special permissions needed
Disassembly ✓ Ready No special permissions needed
Debugger ✗ Denied Missing debugger entitlement
실행 중인 프로세스에 연결합니다(서명 필요):
# 먼저 디버거 entitlement로 서명하세요
codesign --force --sign - --entitlements Resources/MachScope.entitlements .build/debug/machscope
# 시스템 설정 > 개인정보 보호 및 보안에서 개발자 도구 활성화
# 프로세스에 연결
machscope debug <pid>
Package.swift에 MachScope를 추가하세요:
dependencies: [
.package(url: "https://github.com/sadopc/machscope.git", from: "1.0.0")
]
그런 다음 코드에서 사용하세요:
import MachOKit
import Disassembler
// 바이너리 파싱
let binary = try MachOBinary(path: "/bin/ls")
print("CPU: \(binary.header.cpuType)")
print("Segments: \(binary.segments.count)")
// Entitlements 확인
if let signature = try binary.parseCodeSignature(),
let entitlements = signature.entitlements {
for key in entitlements.keys {
print("\(key): \(entitlements[key] ?? "nil")")
}
}
// 디스어셈블리
let disasm = ARM64Disassembler(binary: binary)
let result = try disasm.disassembleFunction("_main", from: binary)
for instruction in result.instructions {
print(disasm.format(instruction))
}
MachScope/
├── Sources/
│ ├── MachOKit/ # 핵심 Mach-O 파싱 라이브러리
│ ├── Disassembler/ # ARM64 명령어 디코더
│ ├── DebuggerCore/ # 프로세스 디버깅
│ └── MachScope/ # CLI 애플리케이션
├── Tests/ # 테스트 스위트 (319+ 테스트)
├── Resources/ # 코드 서명용 Entitlements
└── docs/ # 문서
MachScope의 주요 장점: Swift 네이티브 라이브러리를 자신만의 도구에 임베드할 수 있습니다.
MIT 라이선스 — 자세한 내용은 LICENSE를 참조하세요.
기여를 환영합니다! 먼저 기여 가이드를 읽어 주세요.
# 제출 전 테스트 실행
swift test
# 코드 포맷
xcrun swift-format -i -r Sources/ Tests/
Swift로 ❤️를 담아 만들었습니다
| 도구 | 언어 | 라이브러리? | ARM64 PAC | 디버거 |
|---|
| MachScope | Swift | ✅ 예 | ✅ 예 | ✅ 예 |
| otool | C | ❌ 아니요 | ❌ 아니요 | ❌ 아니요 |
| objdump | C | ❌ 아니요 | ❌ 아니요 | ❌ 아니요 |
| jtool2 | C | ❌ 아니요 | ✅ 예 | ❌ 아니요 |
| Hopper | — | ❌ 아니요 | ✅ 예 | ❌ 아니요 |