An open API service indexing awesome lists of open source software.

https://github.com/arhadnane/binary-analysis-tool

A comprehensive binary analysis tool built in C# capable of analyzing, converting, and disassembling binary data with a command-line interface.
https://github.com/arhadnane/binary-analysis-tool

binary-analysis capstone cli-tool csharp disassembler dotnet entropy-analysis file-analysis file-signatures forensics hash-calculations hex-dump malware-analysis pe-analysis reverse-engineering security-tools static-analysis string-extraction

Last synced: 6 months ago
JSON representation

A comprehensive binary analysis tool built in C# capable of analyzing, converting, and disassembling binary data with a command-line interface.

Awesome Lists containing this project

README

          

# ๐Ÿ” Versatile Binary Analyzer

A comprehensive binary analysis tool built in C# (.NET 7) capable of analyzing, converting, and disassembling binary data with a command-line interface.

## โœจ Features

### ๐Ÿš€ Core Capabilities
- **Binary-to-text/ASCII conversion** - Complete binary parsing and text extraction
- **File signature detection** - Automatic file type recognition via magic numbers
- **x86/x64 disassembly** - Integrated disassembly capabilities using Capstone.NET
- **Entropy calculation** - Shannon entropy analysis for data classification
- **Format decoding** - Support for Base64, Hex, and other common encodings
- **CLI interface** - Full command-line interface with multiple analysis modes

### ๐Ÿ“Š Analysis Features
- **Hash calculation** (MD5, SHA256)
- **String extraction** with encoding detection
- **Byte frequency analysis**
- **Heuristic classification** (text, executable, compressed)
- **PE file analysis** for Windows executables
- **Pattern searching** and data analysis
- **Metadata extraction** from various file types

### ๐Ÿ“ Supported File Types
- **Images**: PNG, JPEG, GIF, BMP, TIFF
- **Documents**: PDF, RTF
- **Archives**: ZIP, RAR, 7Z, TAR, GZIP
- **Executables**: PE (Windows), ELF (Linux), Mach-O (macOS)
- **Audio/Video**: MP3, MP4, AVI, WAV
- **Raw data**: Entropy analysis and hex dump

## ๐Ÿ› ๏ธ Installation

### Prerequisites
- .NET 7.0 SDK or higher
- Visual Studio Code with C# extension (recommended)
- Windows/Linux/macOS

### Setup
```bash
git clone https://github.com/arhadnane/Binary-analysis-tool.git
cd "Binary analysis tool"
cd BinaryAnalyzer
dotnet restore
dotnet build
```

## ๐Ÿ’ป Usage

### Basic Commands
```bash
# Quick analysis (default)
dotnet run --

# Quick analysis mode
dotnet run -- --quick

# Detailed analysis report
dotnet run -- --detailed

# Hexadecimal dump view
dotnet run -- --hexdump
```

### Usage Examples
```bash
# Analyze a Windows executable
dotnet run -- C:\Windows\System32\notepad.exe --detailed

# Quick analysis of an image
dotnet run -- image.png --quick

# Hex dump of a binary file
dotnet run -- data.bin --hexdump

# Analyze a PDF document
dotnet run -- document.pdf --detailed
```

### Sample Output

#### Quick Analysis
```
๐Ÿ“„ File: example.exe (2048 bytes)
๐Ÿ” Type: PE Executable
๐Ÿ“Š Entropy: 6.2341
๐Ÿ” MD5: a1b2c3d4e5f6...
๐Ÿ“ Content: Likely executable
๐Ÿ’ป Disassembly available
๐Ÿ’ก Use --detailed for complete report
```

#### Detailed Analysis
```
=== BINARY ANALYSIS REPORT ===
Size: 2048 bytes
Type: PE Executable
Entropy: 6.2341
MD5: a1b2c3d4e5f6...
SHA256: f1e2d3c4b5a6...

=== HEURISTICS ===
Likely text: NO
Likely executable: YES
Likely compressed: NO

=== PE ANALYSIS ===
Architecture: x64
Sections: .text, .data, .rdata
Entry Point: 0x1400
Imports: kernel32.dll, user32.dll

=== BYTE FREQUENCY (Top 10) ===
0x00: 150 (7.3%)
0xFF: 89 (4.3%)
...
```

## ๐Ÿ—๏ธ Architecture

For detailed architecture documentation with visual diagrams, see [ARCHITECTURE.md](ARCHITECTURE.md).

### Project Structure
```
BinaryAnalyzer/
โ”œโ”€โ”€ Core/ # Core business logic
โ”‚ โ”œโ”€โ”€ BinaryParser.cs # Binary โ†’ format conversion
โ”‚ โ”œโ”€โ”€ FileAnalyzer.cs # File signature detection
โ”‚ โ”œโ”€โ”€ Disassembler.cs # Capstone.NET integration
โ”‚ โ”œโ”€โ”€ PEAnalyzer.cs # PE file analysis
โ”‚ โ””โ”€โ”€ MetadataAnalyzer.cs # Metadata extraction
โ”œโ”€โ”€ Utils/ # Utilities
โ”‚ โ”œโ”€โ”€ Entropy.cs # Shannon entropy calculation
โ”‚ โ””โ”€โ”€ Extensions.cs # Extension methods
โ”œโ”€โ”€ Program.cs # CLI entry point
โ””โ”€โ”€ BinaryAnalyzer.csproj # Project configuration

BinaryAnalyzer.Tests/ # Test suite
โ”œโ”€โ”€ Core/ # Core module tests
โ”œโ”€โ”€ Utils/ # Utility tests
โ””โ”€โ”€ Integration/ # Integration tests
```

### Key Components

#### BinaryParser
Handles binary-to-text conversion, encoding detection, and format transformations.

#### FileAnalyzer
Provides file type detection using magic number signatures and heuristic analysis.

#### Disassembler
Integrates with Capstone.NET for x86/x64 disassembly capabilities.

#### PEAnalyzer
Specialized analysis for Windows PE (Portable Executable) files.

#### MetadataAnalyzer
Extracts and analyzes file metadata and generates comprehensive reports.

## ๐Ÿงช Testing

The project includes comprehensive test coverage with 67 unit and integration tests.

```bash
# Run all tests
dotnet test

# Run specific test category
dotnet test --filter Category=Core
dotnet test --filter Category=Integration
```

### Test Coverage
- โœ… Core modules (BinaryParser, FileAnalyzer, Disassembler, PEAnalyzer, MetadataAnalyzer)
- โœ… Utility functions (Entropy, Extensions)
- โœ… Integration tests (CLI and report generation)
- โœ… Edge cases and error handling

## ๐Ÿ”ง Development

### Adding New File Types
Extend the `MagicNumbers` dictionary in `FileAnalyzer.cs`:
```csharp
{ "NEW_TYPE", new byte[] { 0x???, 0x???, ... } }
```

### Extending Disassembly Features
The `Disassembler.cs` module uses Capstone.NET. Refer to the documentation to add support for other architectures (ARM, MIPS, etc.).

### Recommended Testing
- Files of various sizes (1 KB to 100+ MB)
- Corrupted or partial files
- Highly compressed vs. random data
- Executables with different architectures

## ๐Ÿ› Troubleshooting

### Common Issues

**"File not found"**
- Verify the absolute file path
- Check file permissions

**"Disassembly error"**
- File may not contain valid machine code
- Architecture may not be supported

**Memory exceptions**
- Very large files (>1GB) may cause issues
- Consider processing in chunks for large files

### Current Limitations
- Disassembly limited to first instructions
- No support for exotic file formats
- Basic CLI interface (no GUI)

## ๐Ÿš€ Future Enhancements

### Advanced Features
- **Graphical interface**: WPF or Avalonia UI
- **Malware analysis**: Suspicious pattern detection
- **Report export**: JSON, XML, HTML formats
- **Network analysis**: Packet inspection
- **Database integration**: Store previous analyses

### Integrations
- **VirusTotal API**: Hash verification
- **YARA rules**: Signature detection
- **Hex editor**: Interactive visualization
- **Plugin system**: Modular extensions

## ๐Ÿ“š Dependencies

- **.NET 7.0**: Core framework
- **Capstone.NET**: Disassembly engine (optional)
- **xUnit**: Testing framework
- **System.Security.Cryptography**: Hash calculations

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“ž Support

For questions, bug reports, or feature requests, please open an issue on the repository.

## ๐Ÿ“– Additional Resources

- [Capstone Engine Documentation](http://www.capstone-engine.org/)
- [File Signatures Database](https://www.filesignatures.net/)
- [.NET Binary Data Processing](https://docs.microsoft.com/en-us/dotnet/api/system.io.binaryreader)
- [PE Format Specification](https://docs.microsoft.com/en-us/windows/win32/debug/pe-format)

---

**Last updated:** July 5, 2025

*Built with โค๏ธ using C# and .NET*