Wei-Guo Zhang

12 papers Journal 12
YearRankTypeTitle / Venue / Authors
2025 J jnl
Int. J. Found. Comput. Sci.
Yan-Ping Wang, Wei-Guo Zhang
2019 J jnl
Inf. Process. Lett.
Enes Pasalic, Sugata Gangopadhyay, Wei-Guo Zhang, Samed Bajric
2018 J jnl
CoRR
Samir Hodzic, Enes Pasalic, Wei-Guo Zhang
2016 J jnl
IACR Cryptol. ePrint Arch.
Wei-Guo Zhang, Luyang Li, Enes Pasalic
2016 J jnl
Sci. China Inf. Sci.
Luyang Li, Wei-Guo Zhang
2015 J jnl
Secur. Commun. Networks
Luyang Li, Wei-Guo Zhang
2014 J jnl
IEEE Trans. Inf. Theory
Wei-Guo Zhang, Enes Pasalic
2014 J jnl
IEEE Trans. Inf. Theory
Wei-Guo Zhang, Enes Pasalic
2014 J jnl
IEEE Trans. Inf. Theory
Wei-Guo Zhang, Enes Pasalic
2012 J jnl
Inf. Process. Lett.
Enes Pasalic, Wei-Guo Zhang
2011 J jnl
J. Comput. Sci. Technol.
Sen-Shan Pan, Xiao-Tong Fu, Wei-Guo Zhang
2010 J jnl
IACR Cryptol. ePrint Arch.
Sen-Shan Pan, Xiao-Tong Fu, Wei-Guo Zhang
docs/macho_extractors_README.md
← Index docs/macho_extractors_README.md markdown
# MachO Extractors for RedB

This document describes the MachO extractors implementation for the RedB binary analysis framework.

## Overview

The MachO extractors provide comprehensive analysis capabilities for Mach-O binaries (macOS, iOS, watchOS, tvOS executables) following the same pattern as the existing PE extractors. The implementation uses the `machofile` library located in the `docs/` folder.

## Architecture

### Main Components

1. **MachOExtractor** (`redb/extractors/macho_extractor.py`)
   - Abstract base class for all MachO extractors
   - Handles MachO file parsing and common functionality
   - Supports both single-architecture and Universal/FAT binaries

2. **Individual Extractors** (`redb/extractors/macho_extractors/`)
   - `macho_features.py` - Basic MachO header and metadata
   - `macho_segments.py` - Segment information and analysis
   - `macho_imports.py` - Imported functions and libraries
   - `macho_exports.py` - Exported symbols
   - `macho_dylibs.py` - Dynamic library dependencies
   - `macho_signature.py` - Code signing information

3. **Data Models** (`redb/models/dataclasses.py`)
   - MachO-specific dataclasses for structured data storage
   - Compatible with Elasticsearch and ClickHouse exporters

## Features

### Supported Binary Types
- Single-architecture Mach-O binaries (32-bit and 64-bit)
- Universal/FAT binaries with multiple architectures
- All major CPU architectures (x86, x86_64, ARM, ARM64)

### Extracted Information

#### MachO Features
- Header information (magic, CPU type, file type, flags)
- Architecture detection
- Entry point information
- UUID
- Version information
- Signing status
- Encryption status
- Counts (segments, dylibs, imports, exports)

#### Segments
- Segment names and properties
- Virtual addresses and sizes
- File offsets and sizes
- Protection flags
- Entropy calculation
- Segment hashes (MD5, SHA256)

#### Imports
- Imported function names
- Library dependencies
- Import counts and statistics

#### Exports
- Exported symbol names
- Export counts and statistics

#### Dynamic Libraries
- Dylib names and paths
- Version information
- Timestamps
- Load command types

#### Code Signing
- Signing status
- Certificate information
- Entitlements
- Code directory details

## Usage

### Basic Usage

```python
from redb.extractors.macho_extractors import MachOFeaturesExtractor

# Create extractor
extractor = MachOFeaturesExtractor(
    filepath="/path/to/macho/binary",
    log=logger
)

# Extract data
features = extractor.extract()

# Export to databases
extractor.export_data()
```

### Testing

Use the provided test script to verify functionality:

```bash
python test_macho_extractors.py /path/to/macho/binary
```

## Implementation Details

### Universal Binary Support

The extractors handle Universal/FAT binaries by:
1. Detecting FAT binary format
2. Extracting individual architectures
3. Providing unified interface for both single and multi-arch binaries
4. Supporting architecture-specific extraction

### Error Handling

- Graceful handling of malformed binaries
- Comprehensive logging for debugging
- Fallback mechanisms for missing data
- Exception handling for corrupted files

### Performance Considerations

- Lazy parsing of MachO structures
- Efficient memory usage for large binaries
- Cached property access for repeated queries
- Optimized data extraction patterns

## Integration

### Database Exporters

The extractors support both Elasticsearch and ClickHouse exporters:

- **Elasticsearch**: JSON document storage with full-text search
- **ClickHouse**: Columnar storage for analytical queries

### Schema Compatibility

All extractors follow the established schema patterns:
- Consistent field naming
- Proper data types
- Timestamp handling
- Hash field inclusion

## Future Enhancements

Potential areas for improvement:

1. **Additional Extractors**
   - MachO resources extraction
   - Symbol table analysis
   - Relocation information
   - Thread state analysis

2. **Enhanced Analysis**
   - Malware detection patterns
   - Behavioral analysis
   - Similarity hashing
   - YARA rule integration

3. **Performance Optimizations**
   - Parallel processing for multi-arch binaries
   - Streaming data processing
   - Memory-mapped file access

## Dependencies

- `machofile` library (included in `docs/`)
- Standard Python libraries (hashlib, datetime, etc.)
- RedB framework components

## Contributing

When adding new MachO extractors:

1. Follow the established pattern in existing extractors
2. Add appropriate dataclasses to `dataclasses.py`
3. Update the enum tags in `enum.py`
4. Include comprehensive error handling
5. Add tests for new functionality
6. Update this documentation

## Troubleshooting

### Common Issues

1. **Import Errors**: Ensure `machofile` library is accessible
2. **Memory Issues**: Large Universal binaries may require significant memory
3. **Corrupted Files**: Malformed MachO files may cause parsing errors
4. **Architecture Mismatch**: Some features may not be available for all architectures

### Debugging

Enable debug logging to see detailed extraction process:

```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

## License

This implementation follows the same license as the main RedB project.