nabla-cli 0.2.1

An OSS tool for reverse engineering and binary composition analysis
Documentation
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
#![allow(dead_code)]
use crate::binary::BinaryAnalysis;
use crate::enterprise::types::{CodeLocation, SeverityLevel};
use chrono::Utc;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StaticAnalysisResult {
    pub analysis_id: Uuid,
    pub file_path: String,
    pub unsafe_functions: Vec<UnsafeFunctionFinding>,
    pub memory_issues: Vec<MemoryIssueFinding>,
    pub system_calls: Vec<SystemCallFinding>,
    pub hardening_issues: Vec<HardeningFinding>,
    pub analysis_duration_ms: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnsafeFunctionFinding {
    pub function_name: String,
    pub location: CodeLocation,
    pub risk_level: SeverityLevel,
    pub description: String,
    pub alternatives: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryIssueFinding {
    pub issue_type: MemoryIssueType,
    pub location: CodeLocation,
    pub severity: SeverityLevel,
    pub description: String,
    pub vulnerable_code: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MemoryIssueType {
    BufferOverflow,
    UseAfterFree,
    DoubleFree,
    MemoryLeak,
    IntegerOverflow,
    UnboundedRead,
    UnboundedWrite,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemCallFinding {
    pub syscall_name: String,
    pub location: CodeLocation,
    pub danger_level: SeverityLevel,
    pub reason: String,
    pub mitigation: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HardeningFinding {
    pub hardening_feature: String,
    pub status: HardeningStatus,
    pub recommendation: String,
    pub impact: SeverityLevel,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum HardeningStatus {
    Missing,
    Weak,
    Misconfigured,
    Present,
}

pub fn analyze_static_security(analysis: &BinaryAnalysis) -> StaticAnalysisResult {
    let start_time = Utc::now();

    let mut result = StaticAnalysisResult {
        analysis_id: Uuid::new_v4(),
        file_path: analysis.file_name.clone(),
        unsafe_functions: Vec::new(),
        memory_issues: Vec::new(),
        system_calls: Vec::new(),
        hardening_issues: Vec::new(),
        analysis_duration_ms: 0,
    };

    // Analyze unsafe functions from imports and symbols
    result.unsafe_functions = analyze_unsafe_functions(analysis);

    // Analyze memory-related security issues
    result.memory_issues = analyze_memory_issues(analysis);

    // Analyze dangerous system calls
    result.system_calls = analyze_system_calls(analysis);

    // Analyze hardening features
    result.hardening_issues = analyze_hardening_features(analysis);

    let end_time = Utc::now();
    result.analysis_duration_ms = (end_time - start_time).num_milliseconds() as u64;

    result
}

fn analyze_unsafe_functions(analysis: &BinaryAnalysis) -> Vec<UnsafeFunctionFinding> {
    let mut findings = Vec::new();

    // Define dangerous C functions and their safer alternatives
    let unsafe_functions: HashMap<&str, (SeverityLevel, &str, Vec<&str>)> = HashMap::from([
        (
            "strcpy",
            (
                SeverityLevel::High,
                "Buffer overflow risk - no bounds checking",
                vec!["strncpy", "strlcpy", "strcpy_s"],
            ),
        ),
        (
            "strcat",
            (
                SeverityLevel::High,
                "Buffer overflow risk - no bounds checking",
                vec!["strncat", "strlcat", "strcat_s"],
            ),
        ),
        (
            "sprintf",
            (
                SeverityLevel::High,
                "Buffer overflow risk - no size limit",
                vec!["snprintf", "sprintf_s"],
            ),
        ),
        (
            "vsprintf",
            (
                SeverityLevel::High,
                "Buffer overflow risk - no size limit",
                vec!["vsnprintf", "vsprintf_s"],
            ),
        ),
        (
            "gets",
            (
                SeverityLevel::Critical,
                "Always vulnerable to buffer overflow",
                vec!["fgets", "getline"],
            ),
        ),
        (
            "scanf",
            (
                SeverityLevel::High,
                "Format string and buffer overflow risks",
                vec!["fgets with parsing", "scanf_s"],
            ),
        ),
        (
            "sscanf",
            (
                SeverityLevel::Medium,
                "Format string risks",
                vec!["sscanf_s", "manual parsing"],
            ),
        ),
        (
            "memcpy",
            (
                SeverityLevel::Medium,
                "No overlap checking",
                vec!["memmove", "memcpy_s"],
            ),
        ),
        (
            "strncpy",
            (
                SeverityLevel::Medium,
                "May not null-terminate",
                vec!["strlcpy", "strncpy_s"],
            ),
        ),
        (
            "strncat",
            (
                SeverityLevel::Medium,
                "Complex length calculation",
                vec!["strlcat", "strncat_s"],
            ),
        ),
        (
            "realpath",
            (
                SeverityLevel::Medium,
                "Path traversal if misused",
                vec!["realpath with buffer size check"],
            ),
        ),
        (
            "mktemp",
            (
                SeverityLevel::High,
                "Race condition vulnerability",
                vec!["mkstemp", "mkdtemp"],
            ),
        ),
        (
            "tmpnam",
            (
                SeverityLevel::High,
                "Race condition vulnerability",
                vec!["tmpfile", "mkstemp"],
            ),
        ),
        (
            "alloca",
            (
                SeverityLevel::Medium,
                "Stack overflow risk",
                vec!["malloc with proper cleanup"],
            ),
        ),
        (
            "setuid",
            (
                SeverityLevel::High,
                "Privilege escalation risk",
                vec!["proper privilege dropping sequence"],
            ),
        ),
        (
            "setgid",
            (
                SeverityLevel::High,
                "Privilege escalation risk",
                vec!["proper privilege dropping sequence"],
            ),
        ),
        (
            "system",
            (
                SeverityLevel::Critical,
                "Command injection vulnerability",
                vec!["execve", "posix_spawn"],
            ),
        ),
        (
            "popen",
            (
                SeverityLevel::High,
                "Command injection risk",
                vec!["fork + exec pattern"],
            ),
        ),
        (
            "eval",
            (
                SeverityLevel::Critical,
                "Code injection vulnerability",
                vec!["safe parsing alternatives"],
            ),
        ),
        (
            "exec",
            (
                SeverityLevel::High,
                "Command injection if input not sanitized",
                vec!["execve with argument validation"],
            ),
        ),
    ]);

    // Check imports for unsafe functions
    for import in &analysis.imports {
        if let Some((severity, description, alternatives)) = unsafe_functions.get(import.as_str()) {
            findings.push(UnsafeFunctionFinding {
                function_name: import.clone(),
                location: CodeLocation {
                    file_path: analysis.file_name.clone(),
                    line_number: None,
                    column_number: None,
                    function_name: Some(import.clone()),
                    binary_offset: None,
                },
                risk_level: severity.clone(),
                description: description.to_string(),
                alternatives: alternatives.iter().map(|s| s.to_string()).collect(),
            });
        }
    }

    // Check detected symbols for unsafe functions
    for symbol in &analysis.detected_symbols {
        if let Some((severity, description, alternatives)) = unsafe_functions.get(symbol.as_str()) {
            // Avoid duplicates from imports
            if !findings.iter().any(|f| f.function_name == *symbol) {
                findings.push(UnsafeFunctionFinding {
                    function_name: symbol.clone(),
                    location: CodeLocation {
                        file_path: analysis.file_name.clone(),
                        line_number: None,
                        column_number: None,
                        function_name: Some(symbol.clone()),
                        binary_offset: None,
                    },
                    risk_level: severity.clone(),
                    description: description.to_string(),
                    alternatives: alternatives.iter().map(|s| s.to_string()).collect(),
                });
            }
        }
    }

    findings
}

fn analyze_memory_issues(analysis: &BinaryAnalysis) -> Vec<MemoryIssueFinding> {
    let mut findings = Vec::new();

    // Check for potential memory management issues based on function usage patterns
    let has_malloc = analysis.imports.iter().any(|s| s == "malloc")
        || analysis.detected_symbols.iter().any(|s| s == "malloc");
    let has_free = analysis.imports.iter().any(|s| s == "free")
        || analysis.detected_symbols.iter().any(|s| s == "free");
    let has_calloc = analysis.imports.iter().any(|s| s == "calloc")
        || analysis.detected_symbols.iter().any(|s| s == "calloc");

    // Check for memory allocation without corresponding deallocation
    if (has_malloc || has_calloc) && !has_free {
        findings.push(MemoryIssueFinding {
            issue_type: MemoryIssueType::MemoryLeak,
            location: CodeLocation {
                file_path: analysis.file_name.clone(),
                line_number: None,
                column_number: None,
                function_name: Some("malloc".to_string()),
                binary_offset: None,
            },
            severity: SeverityLevel::Medium,
            description:
                "Memory allocation detected without corresponding free() - potential memory leak"
                    .to_string(),
            vulnerable_code: None,
        });
    }

    // Check for potential integer overflow in size calculations
    let size_related_functions = ["malloc", "calloc", "realloc", "memcpy", "memset"];
    for func in &size_related_functions {
        if analysis.imports.contains(&func.to_string())
            || analysis.detected_symbols.contains(&func.to_string())
        {
            findings.push(MemoryIssueFinding {
                issue_type: MemoryIssueType::IntegerOverflow,
                location: CodeLocation {
                    file_path: analysis.file_name.clone(),
                    line_number: None,
                    column_number: None,
                    function_name: Some(func.to_string()),
                    binary_offset: None,
                },
                severity: SeverityLevel::Medium,
                description: format!(
                    "Function {} may be vulnerable to integer overflow in size calculations",
                    func
                ),
                vulnerable_code: None,
            });
        }
    }

    // Check for unbounded memory operations
    let unbounded_functions = [
        ("strcpy", MemoryIssueType::UnboundedWrite),
        ("strcat", MemoryIssueType::UnboundedWrite),
        ("sprintf", MemoryIssueType::UnboundedWrite),
        ("gets", MemoryIssueType::UnboundedRead),
    ];

    for (func, issue_type) in &unbounded_functions {
        if analysis.imports.contains(&func.to_string())
            || analysis.detected_symbols.contains(&func.to_string())
        {
            findings.push(MemoryIssueFinding {
                issue_type: issue_type.clone(),
                location: CodeLocation {
                    file_path: analysis.file_name.clone(),
                    line_number: None,
                    column_number: None,
                    function_name: Some(func.to_string()),
                    binary_offset: None,
                },
                severity: SeverityLevel::High,
                description: format!("Function {} performs unbounded memory operations", func),
                vulnerable_code: Some(format!("{}(...)", func)),
            });
        }
    }

    findings
}

fn analyze_system_calls(analysis: &BinaryAnalysis) -> Vec<SystemCallFinding> {
    let mut findings = Vec::new();

    // Define dangerous system calls and their risk levels
    let dangerous_syscalls: HashMap<&str, (SeverityLevel, &str, Option<&str>)> = HashMap::from([
        (
            "system",
            (
                SeverityLevel::Critical,
                "Command injection vulnerability",
                Some("Use execve() with proper argument validation"),
            ),
        ),
        (
            "exec",
            (
                SeverityLevel::High,
                "Potential command injection",
                Some("Validate all arguments and use execve()"),
            ),
        ),
        (
            "execl",
            (
                SeverityLevel::High,
                "Potential command injection",
                Some("Validate all arguments"),
            ),
        ),
        (
            "execlp",
            (
                SeverityLevel::High,
                "Potential command injection",
                Some("Validate all arguments and avoid PATH dependency"),
            ),
        ),
        (
            "execle",
            (
                SeverityLevel::High,
                "Potential command injection",
                Some("Validate all arguments"),
            ),
        ),
        (
            "execv",
            (
                SeverityLevel::High,
                "Potential command injection",
                Some("Validate all arguments"),
            ),
        ),
        (
            "execvp",
            (
                SeverityLevel::High,
                "Potential command injection",
                Some("Validate all arguments and avoid PATH dependency"),
            ),
        ),
        (
            "execve",
            (
                SeverityLevel::Medium,
                "Safe if arguments are validated",
                Some("Ensure all arguments are properly validated"),
            ),
        ),
        (
            "popen",
            (
                SeverityLevel::High,
                "Command injection risk",
                Some("Use fork() + execve() pattern instead"),
            ),
        ),
        (
            "fork",
            (
                SeverityLevel::Medium,
                "Resource exhaustion risk",
                Some("Implement proper process limiting"),
            ),
        ),
        (
            "setuid",
            (
                SeverityLevel::High,
                "Privilege escalation risk",
                Some("Use proper privilege dropping sequence"),
            ),
        ),
        (
            "setgid",
            (
                SeverityLevel::High,
                "Privilege escalation risk",
                Some("Use proper privilege dropping sequence"),
            ),
        ),
        (
            "seteuid",
            (
                SeverityLevel::High,
                "Privilege escalation risk",
                Some("Use proper privilege dropping sequence"),
            ),
        ),
        (
            "setegid",
            (
                SeverityLevel::High,
                "Privilege escalation risk",
                Some("Use proper privilege dropping sequence"),
            ),
        ),
        (
            "chroot",
            (
                SeverityLevel::Medium,
                "Incomplete sandboxing",
                Some("Combine with proper privilege dropping"),
            ),
        ),
        (
            "ptrace",
            (
                SeverityLevel::Medium,
                "Debugging/injection risk",
                Some("Restrict usage and validate target processes"),
            ),
        ),
        (
            "mmap",
            (
                SeverityLevel::Low,
                "Memory mapping risks",
                Some("Use appropriate flags and validate addresses"),
            ),
        ),
        (
            "mprotect",
            (
                SeverityLevel::Medium,
                "Memory protection bypass",
                Some("Avoid making pages writable and executable"),
            ),
        ),
        (
            "dlopen",
            (
                SeverityLevel::Medium,
                "Dynamic loading risk",
                Some("Validate library paths and use RTLD_NOW"),
            ),
        ),
        (
            "dlsym",
            (
                SeverityLevel::Medium,
                "Symbol resolution risk",
                Some("Validate symbol names"),
            ),
        ),
        (
            "signal",
            (
                SeverityLevel::Low,
                "Signal handling race conditions",
                Some("Use sigaction() instead"),
            ),
        ),
        (
            "alarm",
            (
                SeverityLevel::Low,
                "Signal race conditions",
                Some("Use timer_create() for better control"),
            ),
        ),
    ]);

    // Check imports and symbols for dangerous system calls
    for item in analysis
        .imports
        .iter()
        .chain(analysis.detected_symbols.iter())
    {
        if let Some((severity, reason, mitigation)) = dangerous_syscalls.get(item.as_str()) {
            findings.push(SystemCallFinding {
                syscall_name: item.clone(),
                location: CodeLocation {
                    file_path: analysis.file_name.clone(),
                    line_number: None,
                    column_number: None,
                    function_name: Some(item.clone()),
                    binary_offset: None,
                },
                danger_level: severity.clone(),
                reason: reason.to_string(),
                mitigation: mitigation.map(|s| s.to_string()),
            });
        }
    }

    findings
}

fn analyze_hardening_features(analysis: &BinaryAnalysis) -> Vec<HardeningFinding> {
    let mut findings = Vec::new();

    // Check for stack canaries (GCC stack protection)
    let has_stack_protection = analysis
        .detected_symbols
        .iter()
        .any(|s| s.contains("__stack_chk_fail") || s.contains("__stack_chk_guard"))
        || analysis
            .imports
            .iter()
            .any(|s| s.contains("__stack_chk_fail") || s.contains("__stack_chk_guard"));

    findings.push(HardeningFinding {
        hardening_feature: "Stack Canaries".to_string(),
        status: if has_stack_protection {
            HardeningStatus::Present
        } else {
            HardeningStatus::Missing
        },
        recommendation: if has_stack_protection {
            "Stack canaries are present - good security practice".to_string()
        } else {
            "Enable stack protection (-fstack-protector-strong or -fstack-protector-all)"
                .to_string()
        },
        impact: SeverityLevel::High,
    });

    // Check for position independent executable (PIE) indicators
    let metadata_str = analysis.metadata.to_string().to_lowercase();
    let has_pie = metadata_str.contains("pie") || metadata_str.contains("position independent");

    findings.push(HardeningFinding {
        hardening_feature: "Position Independent Executable (PIE)".to_string(),
        status: if has_pie {
            HardeningStatus::Present
        } else {
            HardeningStatus::Missing
        },
        recommendation: if has_pie {
            "PIE is enabled - provides ASLR benefits".to_string()
        } else {
            "Enable PIE compilation (-fPIE -pie) for ASLR protection".to_string()
        },
        impact: SeverityLevel::Medium,
    });

    // Check for RELRO (Read-Only Relocations)
    let has_relro = analysis.detected_symbols.iter().any(|s| {
        s.contains("__libc_start_main")
            && analysis.linked_libraries.iter().any(|l| l.contains("libc"))
    });

    findings.push(HardeningFinding {
        hardening_feature: "RELRO (Read-Only Relocations)".to_string(),
        status: if has_relro {
            HardeningStatus::Present
        } else {
            HardeningStatus::Missing
        },
        recommendation: if has_relro {
            "RELRO appears to be enabled - protects GOT from overwrites".to_string()
        } else {
            "Enable full RELRO (-Wl,-z,relro,-z,now) for GOT protection".to_string()
        },
        impact: SeverityLevel::Medium,
    });

    // Check for NX/DEP (Data Execution Prevention)
    let is_executable_stack = analysis
        .detected_symbols
        .iter()
        .any(|s| s.contains("execstack"));

    findings.push(HardeningFinding {
        hardening_feature: "NX/DEP (Data Execution Prevention)".to_string(),
        status: if is_executable_stack {
            HardeningStatus::Weak
        } else {
            HardeningStatus::Present
        },
        recommendation: if is_executable_stack {
            "Executable stack detected - disable with -Wl,-z,noexecstack".to_string()
        } else {
            "NX/DEP appears to be enabled - stack is non-executable".to_string()
        },
        impact: SeverityLevel::High,
    });

    // Check for format string protections
    let has_fortify = analysis.detected_symbols.iter().any(|s| {
        s.contains("__printf_chk")
            || s.contains("__sprintf_chk")
            || s.contains("__snprintf_chk")
            || s.contains("__vprintf_chk")
    });

    findings.push(HardeningFinding {
        hardening_feature: "FORTIFY_SOURCE".to_string(),
        status: if has_fortify {
            HardeningStatus::Present
        } else {
            HardeningStatus::Missing
        },
        recommendation: if has_fortify {
            "FORTIFY_SOURCE is enabled - provides runtime buffer overflow detection".to_string()
        } else {
            "Enable FORTIFY_SOURCE (-D_FORTIFY_SOURCE=2) for buffer overflow protection".to_string()
        },
        impact: SeverityLevel::Medium,
    });

    // Check for static linking (can be a hardening concern)
    findings.push(HardeningFinding {
        hardening_feature: "Dynamic Linking".to_string(),
        status: if analysis.static_linked {
            HardeningStatus::Missing
        } else {
            HardeningStatus::Present
        },
        recommendation: if analysis.static_linked {
            "Binary is statically linked - consider dynamic linking for security updates"
                .to_string()
        } else {
            "Binary uses dynamic linking - enables library security updates".to_string()
        },
        impact: SeverityLevel::Low,
    });

    findings
}

#[cfg(test)]
mod tests {
    use super::*;
    use chrono::Utc;

    fn create_test_analysis() -> BinaryAnalysis {
        BinaryAnalysis {
            id: Uuid::new_v4(),
            file_name: "test.bin".to_string(),
            format: "elf".to_string(),
            architecture: "x86_64".to_string(),
            languages: vec!["C".to_string()],
            detected_symbols: vec!["malloc".to_string(), "strcpy".to_string()],
            embedded_strings: vec![],
            suspected_secrets: vec![],
            imports: vec!["system".to_string(), "gets".to_string()],
            exports: vec![],
            hash_sha256: "test".to_string(),
            hash_blake3: None,
            size_bytes: 1024,
            linked_libraries: vec!["libc.so.6".to_string()],
            static_linked: false,
            version_info: None,
            license_info: None,
            metadata: serde_json::json!({}),
            created_at: Utc::now(),
            sbom: None,
            binary_data: None,
            entry_point: None,
            code_sections: Vec::new(),
        }
    }

    #[test]
    fn test_analyze_unsafe_functions() {
        let analysis = create_test_analysis();
        let findings = analyze_unsafe_functions(&analysis);

        assert!(!findings.is_empty());
        assert!(findings.iter().any(|f| f.function_name == "strcpy"));
        assert!(findings.iter().any(|f| f.function_name == "gets"));
        assert!(findings.iter().any(|f| f.function_name == "system"));
    }

    #[test]
    fn test_analyze_static_security() {
        let analysis = create_test_analysis();
        let result = analyze_static_security(&analysis);

        assert_eq!(result.file_path, "test.bin");
        assert!(!result.unsafe_functions.is_empty());
        assert!(!result.system_calls.is_empty());
        assert!(!result.hardening_issues.is_empty());
    }
}