Master binary analysis patterns including disassembly

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Binary analysis patterns cover

Master binary analysis patterns including disassembly, decompilation, control flow analysis, and code pattern recognition. Use when analyzing executables, understanding compiled code, or performing static analysis on binaries.

---
name: binary-analysis-patterns
description: Master binary analysis patterns including disassembly, decompilation, control flow analysis, and code pattern recognition. Use when analyzing executables, understanding compiled code, or performing static analysis on binaries.
---

# Binary Analysis Patterns

Comprehensive patterns and techniques for analyzing compiled binaries, understanding assembly code, and reconstructing program logic.

## When to Use This Skill

- Reverse-engineering an unknown executable to understand its behavior
- Analyzing malware or obfuscated binaries with Ghidra / IDA Pro / Binary Ninja
- Recognizing common assembly idioms (function prologues, switch tables, vtable dispatch)
- Reconstructing high-level control flow from compiled code
- Identifying compiler-introduced patterns (stack canaries, PIC trampolines)

## Detailed section: Disassembly Fundamentals

Overview

Comprehensive patterns and techniques for analyzing compiled binaries, understanding assembly code, and reconstructing program logic.

Manual install (npx, ZIP)
Claude Codenpx skills add wshobson/agents --skill binary-analysis-patterns -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \ | tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/reverse-engineering/skills/binary-analysis-patterns
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/a16ed9952961d86a2fa3/binary-analysis-patterns.zip" -OutFile "$env:TEMP\binary-analysis-patterns.zip"; Expand-Archive "$env:TEMP\binary-analysis-patterns.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md7.7 KB
  • references/1 file · 2.0 KB
Read the files here
wshobson/4236bb92 files
SKILL.md
Show the full text352 lines

Binary Analysis Patterns

Comprehensive patterns and techniques for analyzing compiled binaries, understanding assembly code, and reconstructing program logic.

When to Use This Skill

  • Reverse-engineering an unknown executable to understand its behavior
  • Analyzing malware or obfuscated binaries with Ghidra / IDA Pro / Binary Ninja
  • Recognizing common assembly idioms (function prologues, switch tables, vtable dispatch)
  • Reconstructing high-level control flow from compiled code
  • Identifying compiler-introduced patterns (stack canaries, PIC trampolines)

Detailed section: Disassembly Fundamentals

Originally a 2047-byte section in this SKILL.md. Moved to references/details.md to fit Codex's 8 KB skill body cap.

Control Flow Patterns

Conditional Branches
; if (a == b)
cmp eax, ebx
jne skip_block
; ... if body ...
skip_block:

; if (a < b) - signed
cmp eax, ebx
jge skip_block    ; Jump if greater or equal
; ... if body ...
skip_block:

; if (a < b) - unsigned
cmp eax, ebx
jae skip_block    ; Jump if above or equal
; ... if body ...
skip_block:
Loop Patterns
; for (int i = 0; i < n; i++)
xor ecx, ecx           ; i = 0
loop_start:
cmp ecx, [n]           ; i < n
jge loop_end
; ... loop body ...
inc ecx                ; i++
jmp loop_start
loop_end:

; while (condition)
jmp loop_check
loop_body:
; ... body ...
loop_check:
cmp eax, ebx
jl loop_body

; do-while
loop_body:
; ... body ...
cmp eax, ebx
jl loop_body
Switch Statement Patterns
; Jump table pattern
mov eax, [switch_var]
cmp eax, max_case
ja default_case
jmp [jump_table + eax*8]

; Sequential comparison (small switch)
cmp eax, 1
je case_1
cmp eax, 2
je case_2
cmp eax, 3
je case_3
jmp default_case

Data Structure Patterns

Array Access
; array[i] - 4-byte elements
mov eax, [rbx + rcx*4]        ; rbx=base, rcx=index

; array[i] - 8-byte elements
mov rax, [rbx + rcx*8]

; Multi-dimensional array[i][j]
; arr[i][j] = base + (i * cols + j) * element_size
imul eax, [cols]
add eax, [j]
mov edx, [rbx + rax*4]
Structure Access
struct Example {
    int a;      // offset 0
    char b;     // offset 4
    // padding  // offset 5-7
    long c;     // offset 8
    short d;    // offset 16
};
; Accessing struct fields
mov rdi, [struct_ptr]
mov eax, [rdi]         ; s->a (offset 0)
movzx eax, byte [rdi+4] ; s->b (offset 4)
mov rax, [rdi+8]       ; s->c (offset 8)
movzx eax, word [rdi+16] ; s->d (offset 16)
Linked List Traversal
; while (node != NULL)
list_loop:
test rdi, rdi          ; node == NULL?
jz list_done
; ... process node ...
mov rdi, [rdi+8]       ; node = node->next (assuming next at offset 8)
jmp list_loop
list_done:

Common Code Patterns

String Operations
; strlen pattern
xor ecx, ecx
strlen_loop:
cmp byte [rdi + rcx], 0
je strlen_done
inc ecx
jmp strlen_loop
strlen_done:
; ecx contains length

; strcpy pattern
strcpy_loop:
mov al, [rsi]
mov [rdi], al
test al, al
jz strcpy_done
inc rsi
inc rdi
jmp strcpy_loop
strcpy_done:

; memcpy using rep movsb
mov rdi, dest
mov rsi, src
mov rcx, count
rep movsb
Arithmetic Patterns
; Multiplication by constant
; x * 3
lea eax, [rax + rax*2]

; x * 5
lea eax, [rax + rax*4]

; x * 10
lea eax, [rax + rax*4]  ; x * 5
add eax, eax            ; * 2

; Division by power of 2 (signed)
mov eax, [x]
cdq                     ; Sign extend to EDX:EAX
and edx, 7              ; For divide by 8
add eax, edx            ; Adjust for negative
sar eax, 3              ; Arithmetic shift right

; Modulo power of 2
and eax, 7              ; x % 8
Bit Manipulation
; Test specific bit
test eax, 0x80          ; Test bit 7
jnz bit_set

; Set bit
or eax, 0x10            ; Set bit 4

; Clear bit
and eax, ~0x10          ; Clear bit 4

; Toggle bit
xor eax, 0x10           ; Toggle bit 4

; Count leading zeros
bsr eax, ecx            ; Bit scan reverse
xor eax, 31             ; Convert to leading zeros

; Population count (popcnt)
popcnt eax, ecx         ; Count set bits

Decompilation Patterns

Variable Recovery
; Local variable at rbp-8
mov qword [rbp-8], rax  ; Store to local
mov rax, [rbp-8]        ; Load from local

; Stack-allocated array
lea rax, [rbp-0x40]     ; Array starts at rbp-0x40
mov [rax], edx          ; array[0] = value
mov [rax+4], ecx        ; array[1] = value
Function Signature Recovery
; Identify parameters by register usage
func:
    ; rdi used as first param (System V)
    mov [rbp-8], rdi    ; Save param to local
    ; rsi used as second param
    mov [rbp-16], rsi
    ; Identify return by RAX at end
    mov rax, [result]
    ret
Type Recovery
; 1-byte operations suggest char/bool
movzx eax, byte [rdi]   ; Zero-extend byte
movsx eax, byte [rdi]   ; Sign-extend byte

; 2-byte operations suggest short
movzx eax, word [rdi]
movsx eax, word [rdi]

; 4-byte operations suggest int/float
mov eax, [rdi]
movss xmm0, [rdi]       ; Float

; 8-byte operations suggest long/double/pointer
mov rax, [rdi]
movsd xmm0, [rdi]       ; Double

Ghidra Analysis Tips

Improving Decompilation
// In Ghidra scripting
// Fix function signature
Function func = getFunctionAt(toAddr(0x401000));
func.setReturnType(IntegerDataType.dataType, SourceType.USER_DEFINED);

// Create structure type
StructureDataType struct = new StructureDataType("MyStruct", 0);
struct.add(IntegerDataType.dataType, "field_a", null);
struct.add(PointerDataType.dataType, "next", null);

// Apply to memory
createData(toAddr(0x601000), struct);
Pattern Matching Scripts
# Find all calls to dangerous functions
for func in currentProgram.getFunctionManager().getFunctions(True):
    for ref in getReferencesTo(func.getEntryPoint()):
        if func.getName() in ["strcpy", "sprintf", "gets"]:
            print(f"Dangerous call at {ref.getFromAddress()}")

IDA Pro Patterns

IDAPython Analysis
import idaapi
import idautils
import idc

# Find all function calls
def find_calls(func_name):
    for func_ea in idautils.Functions():
        for head in idautils.Heads(func_ea, idc.find_func_end(func_ea)):
            if idc.print_insn_mnem(head) == "call":
                target = idc.get_operand_value(head, 0)
                if idc.get_func_name(target) == func_name:
                    print(f"Call to {func_name} at {hex(head)}")

# Rename functions based on strings
def auto_rename():
    for s in idautils.Strings():
        for xref in idautils.XrefsTo(s.ea):
            func = idaapi.get_func(xref.frm)
            if func and "sub_" in idc.get_func_name(func.start_ea):
                # Use string as hint for naming
                pass

Best Practices

Analysis Workflow
  1. Initial triage: File type, architecture, imports/exports
  2. String analysis: Identify interesting strings, error messages
  3. Function identification: Entry points, exports, cross-references
  4. Control flow mapping: Understand program structure
  5. Data structure recovery: Identify structs, arrays, globals
  6. Algorithm identification: Crypto, hashing, compression
  7. Documentation: Comments, renamed symbols, type definitions
Common Pitfalls
  • Optimizer artifacts: Code may not match source structure
  • Inline functions: Functions may be expanded inline
  • Tail call optimization: jmp instead of call + ret
  • Dead code: Unreachable code from optimization
  • Position-independent code: RIP-relative addressing
1---
2name: binary-analysis-patterns
3description: Master binary analysis patterns including disassembly, decompilation, control flow analysis, and code pattern recognition. Use when analyzing executables, understanding compiled code, or performing static analysis on binaries.
4---
5 
6# Binary Analysis Patterns
7 
8Comprehensive patterns and techniques for analyzing compiled binaries, understanding assembly code, and reconstructing program logic.
9 
10## When to Use This Skill
11 
12- Reverse-engineering an unknown executable to understand its behavior
13- Analyzing malware or obfuscated binaries with Ghidra / IDA Pro / Binary Ninja
14- Recognizing common assembly idioms (function prologues, switch tables, vtable dispatch)
15- Reconstructing high-level control flow from compiled code
16- Identifying compiler-introduced patterns (stack canaries, PIC trampolines)
17 
18## Detailed section: Disassembly Fundamentals
19 
20Originally a 2047-byte section in this SKILL.md. Moved to `references/details.md` to fit Codex's 8 KB skill body cap.
21 
22## Control Flow Patterns
23 
24### Conditional Branches
25 
26```asm
27; if (a == b)
28cmp eax, ebx
29jne skip_block
30; ... if body ...
31skip_block:
32 
33; if (a < b) - signed
34cmp eax, ebx
35jge skip_block ; Jump if greater or equal
36; ... if body ...
37skip_block:
38 
39; if (a < b) - unsigned
40cmp eax, ebx
41jae skip_block ; Jump if above or equal
42; ... if body ...
43skip_block:
44```
45 
46### Loop Patterns
47 
48```asm
49; for (int i = 0; i < n; i++)
50xor ecx, ecx ; i = 0
51loop_start:
52cmp ecx, [n] ; i < n
53jge loop_end
54; ... loop body ...
55inc ecx ; i++
56jmp loop_start
57loop_end:
58 
59; while (condition)
60jmp loop_check
61loop_body:
62; ... body ...
63loop_check:
64cmp eax, ebx
65jl loop_body
66 
67; do-while
68loop_body:
69; ... body ...
70cmp eax, ebx
71jl loop_body
72```
73 
74### Switch Statement Patterns
75 
76```asm
77; Jump table pattern
78mov eax, [switch_var]
79cmp eax, max_case
80ja default_case
81jmp [jump_table + eax*8]
82 
83; Sequential comparison (small switch)
84cmp eax, 1
85je case_1
86cmp eax, 2
87je case_2
88cmp eax, 3
89je case_3
90jmp default_case
91```
92 
93## Data Structure Patterns
94 
95### Array Access
96 
97```asm
98; array[i] - 4-byte elements
99mov eax, [rbx + rcx*4] ; rbx=base, rcx=index
100 
101; array[i] - 8-byte elements
102mov rax, [rbx + rcx*8]
103 
104; Multi-dimensional array[i][j]
105; arr[i][j] = base + (i * cols + j) * element_size
106imul eax, [cols]
107add eax, [j]
108mov edx, [rbx + rax*4]
109```
110 
111### Structure Access
112 
113```c
114struct Example {
115 int a; // offset 0
116 char b; // offset 4
117 // padding // offset 5-7
118 long c; // offset 8
119 short d; // offset 16
120};
121```
122 
123```asm
124; Accessing struct fields
125mov rdi, [struct_ptr]
126mov eax, [rdi] ; s->a (offset 0)
127movzx eax, byte [rdi+4] ; s->b (offset 4)
128mov rax, [rdi+8] ; s->c (offset 8)
129movzx eax, word [rdi+16] ; s->d (offset 16)
130```
131 
132### Linked List Traversal
133 
134```asm
135; while (node != NULL)
136list_loop:
137test rdi, rdi ; node == NULL?
138jz list_done
139; ... process node ...
140mov rdi, [rdi+8] ; node = node->next (assuming next at offset 8)
141jmp list_loop
142list_done:
143```
144 
145## Common Code Patterns
146 
147### String Operations
148 
149```asm
150; strlen pattern
151xor ecx, ecx
152strlen_loop:
153cmp byte [rdi + rcx], 0
154je strlen_done
155inc ecx
156jmp strlen_loop
157strlen_done:
158; ecx contains length
159 
160; strcpy pattern
161strcpy_loop:
162mov al, [rsi]
163mov [rdi], al
164test al, al
165jz strcpy_done
166inc rsi
167inc rdi
168jmp strcpy_loop
169strcpy_done:
170 
171; memcpy using rep movsb
172mov rdi, dest
173mov rsi, src
174mov rcx, count
175rep movsb
176```
177 
178### Arithmetic Patterns
179 
180```asm
181; Multiplication by constant
182; x * 3
183lea eax, [rax + rax*2]
184 
185; x * 5
186lea eax, [rax + rax*4]
187 
188; x * 10
189lea eax, [rax + rax*4] ; x * 5
190add eax, eax ; * 2
191 
192; Division by power of 2 (signed)
193mov eax, [x]
194cdq ; Sign extend to EDX:EAX
195and edx, 7 ; For divide by 8
196add eax, edx ; Adjust for negative
197sar eax, 3 ; Arithmetic shift right
198 
199; Modulo power of 2
200and eax, 7 ; x % 8
201```
202 
203### Bit Manipulation
204 
205```asm
206; Test specific bit
207test eax, 0x80 ; Test bit 7
208jnz bit_set
209 
210; Set bit
211or eax, 0x10 ; Set bit 4
212 
213; Clear bit
214and eax, ~0x10 ; Clear bit 4
215 
216; Toggle bit
217xor eax, 0x10 ; Toggle bit 4
218 
219; Count leading zeros
220bsr eax, ecx ; Bit scan reverse
221xor eax, 31 ; Convert to leading zeros
222 
223; Population count (popcnt)
224popcnt eax, ecx ; Count set bits
225```
226 
227## Decompilation Patterns
228 
229### Variable Recovery
230 
231```asm
232; Local variable at rbp-8
233mov qword [rbp-8], rax ; Store to local
234mov rax, [rbp-8] ; Load from local
235 
236; Stack-allocated array
237lea rax, [rbp-0x40] ; Array starts at rbp-0x40
238mov [rax], edx ; array[0] = value
239mov [rax+4], ecx ; array[1] = value
240```
241 
242### Function Signature Recovery
243 
244```asm
245; Identify parameters by register usage
246func:
247 ; rdi used as first param (System V)
248 mov [rbp-8], rdi ; Save param to local
249 ; rsi used as second param
250 mov [rbp-16], rsi
251 ; Identify return by RAX at end
252 mov rax, [result]
253 ret
254```
255 
256### Type Recovery
257 
258```asm
259; 1-byte operations suggest char/bool
260movzx eax, byte [rdi] ; Zero-extend byte
261movsx eax, byte [rdi] ; Sign-extend byte
262 
263; 2-byte operations suggest short
264movzx eax, word [rdi]
265movsx eax, word [rdi]
266 
267; 4-byte operations suggest int/float
268mov eax, [rdi]
269movss xmm0, [rdi] ; Float
270 
271; 8-byte operations suggest long/double/pointer
272mov rax, [rdi]
273movsd xmm0, [rdi] ; Double
274```
275 
276## Ghidra Analysis Tips
277 
278### Improving Decompilation
279 
280```java
281// In Ghidra scripting
282// Fix function signature
283Function func = getFunctionAt(toAddr(0x401000));
284func.setReturnType(IntegerDataType.dataType, SourceType.USER_DEFINED);
285 
286// Create structure type
287StructureDataType struct = new StructureDataType("MyStruct", 0);
288struct.add(IntegerDataType.dataType, "field_a", null);
289struct.add(PointerDataType.dataType, "next", null);
290 
291// Apply to memory
292createData(toAddr(0x601000), struct);
293```
294 
295### Pattern Matching Scripts
296 
297```python
298# Find all calls to dangerous functions
299for func in currentProgram.getFunctionManager().getFunctions(True):
300 for ref in getReferencesTo(func.getEntryPoint()):
301 if func.getName() in ["strcpy", "sprintf", "gets"]:
302 print(f"Dangerous call at {ref.getFromAddress()}")
303```
304 
305## IDA Pro Patterns
306 
307### IDAPython Analysis
308 
309```python
310import idaapi
311import idautils
312import idc
313 
314# Find all function calls
315def find_calls(func_name):
316 for func_ea in idautils.Functions():
317 for head in idautils.Heads(func_ea, idc.find_func_end(func_ea)):
318 if idc.print_insn_mnem(head) == "call":
319 target = idc.get_operand_value(head, 0)
320 if idc.get_func_name(target) == func_name:
321 print(f"Call to {func_name} at {hex(head)}")
322 
323# Rename functions based on strings
324def auto_rename():
325 for s in idautils.Strings():
326 for xref in idautils.XrefsTo(s.ea):
327 func = idaapi.get_func(xref.frm)
328 if func and "sub_" in idc.get_func_name(func.start_ea):
329 # Use string as hint for naming
330 pass
331```
332 
333## Best Practices
334 
335### Analysis Workflow
336 
3371. **Initial triage**: File type, architecture, imports/exports
3382. **String analysis**: Identify interesting strings, error messages
3393. **Function identification**: Entry points, exports, cross-references
3404. **Control flow mapping**: Understand program structure
3415. **Data structure recovery**: Identify structs, arrays, globals
3426. **Algorithm identification**: Crypto, hashing, compression
3437. **Documentation**: Comments, renamed symbols, type definitions
344 
345### Common Pitfalls
346 
347- **Optimizer artifacts**: Code may not match source structure
348- **Inline functions**: Functions may be expanded inline
349- **Tail call optimization**: `jmp` instead of `call` + `ret`
350- **Dead code**: Unreachable code from optimization
351- **Position-independent code**: RIP-relative addressing
352 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
SkillSecurity guidance and vulnerability review for codebasesSecurity auditcloudflare/security-audit-skill · by cloudflareSecurity guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.★ 26.1k GitHub starsMCPYou need to audit Active Directory security postureAd security reviewerVoltAgent/awesome-claude-code-subagents · by VoltAgentUse this agent when you need to audit Active Directory security posture, evaluate privilege escalation risks, review identity delegation patterns, or assess authentication protocol hardening.★ 25.2k GitHub starsSkillApply modern web development best practices for securityaddyosmani/web-quality-skills · by addyosmaniApply modern web development best practices for security, compatibility, and code quality. Use when asked to "apply best practices", "security audit", "modernize code", "code quality review", or "check for vulnerabilities".★ 2.8k GitHub starsSkillHelps Claude write secure web applicationsSecure Coding Guide for Web ApplicationsBehiSecc/VibeSec-Skill · by BehiSeccThis skill helps Claude write secure web applications. Use this when working on any web application or when a user requests a scan or audit to ensure security best practices are followed.★ 1.3k GitHub starsMCPReviews completed implementation against governing securitySecurity reviewershinpr/claude-code-workflows · by shinprReviews completed implementation against governing security requirements and the reachable trust model. Use after implementation or when security review/security check/vulnerability check is requested. Returns only must-fix findings with the smallest sufficient corrections.★ 687 GitHub starsSkillAccount-based marketing for B2B SaaSAccount-Based Marketing Operationsshalintripathi/saas-marketing-agents · by shalintripathiAccount-based marketing for B2B SaaS. Use this skill to build a target account list, tier it 1:1 / 1:few / 1:many, size it against sales capacity, turn intent and engagement signals into plays, write the multi-channel orchestration contract each tier runs on, and measure the program in account coverage, penetration and pipeline instead of MQLs. Also triggers on: ABM, account-based marketing, target account list, TAL, named accounts, account tiering, 1:1 ABM, one-to-few, programmatic ABM, account selection, ideal customer profile fit, intent data, buying signals, 6sense, Bombora, Demandbase, account penetration, account coverage, sales and marketing alignment on accounts, enterprise account program.★ 20 GitHub stars

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars