← 返回
数据分析 中文

struct-offset-analyzer

Statically analyze C struct member offsets through code reading to calculate memory layouts
静态分析C结构体成员偏移,计算内存布局
littleenough
数据分析 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 2
Stars
📥 663
下载
💾 7
安装
1
版本
#latest

概述

struct-offset-analyzer

Statically analyze the memory offsets of C language struct members without needing to run code.

Use Cases

  • Locating struct members during reverse engineering
  • Confirming memory layouts during debugging
  • Analyzing data structures in security research
  • Understanding struct field positions in binary analysis

Workflow

1. Locate Struct Definition

# Search for struct definition
grep -n "struct xxx_st {" **/*.h
grep -n "typedef struct" **/*.h

2. Collect Type Information

Find definitions for all member types:

  • Nested structs
  • Enum types
  • typedef aliases
  • Constant definitions (e.g., #define EVP_MAX_MD_SIZE 64)

3. Calculate Alignment Rules

| Type | Size (64-bit) | Alignment Requirement |

|------|---------------|----------------------|

| char/unsigned char | 1 | 1 |

| short | 2 | 2 |

| int/uint32_t | 4 | 4 |

| long/size_t/pointer | 8 | 8 |

| unsigned char[N] | N | 1 (no padding needed) |

| enum | usually 4 | 4 |

| struct | depends on members | aligned to largest member |

Key Rules:

  • Member offset must be a multiple of its size
  • unsigned char arrays are 1-byte aligned, no padding required
  • Overall struct size is aligned to the size of its largest member
  • Padding bytes count toward offsets

4. Output Offset Table

Use hexadecimal representation for offsets, format:

| Offset(0x) | Member | Type | Size |
|------------|--------|------|------|
| 0x00 | field1 | int | 4 |
| 0x04 | *(padding)* | - | 4 |
| 0x08 | field2 | void * | 8 |

Common Search Patterns

# Find struct member definition
grep -n "struct xxx_st" **/*.h

# Find type definition
grep -n "typedef.*XXX" **/*.h

# Find constant definition
grep -n "#define.*SIZE" **/*.h

# Find enum definition
grep -n "typedef enum" **/*.h

Example: OpenSSL ssl_st Analysis

Analyzing client_app_traffic_secret member offset:

  1. Locate struct: ssl/ssl_local.h:1068
  2. Find constant: EVP_MAX_MD_SIZE = 64 (include/openssl/evp.h:19)
  3. Calculate layout, note that unsigned char arrays need no padding
  4. Result: offset 0x33c (828 bytes)

Notes

  • Confirm target platform (32-bit vs 64-bit)
  • Note that conditional compilation (#ifdef) may affect struct layout
  • Check for #pragma pack directives that may change alignment
  • Union members share the same offset

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-03-29 18:15 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Data Analysis

ivangdavila
{"answer":"数据分析与可视化。查询数据库、生成报告、自动化电子表格,将原始数据转化为清晰可行的见解。适用于:(1) 您……"}
★ 198 📥 65,120
data-analysis

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 368 📥 140,463
data-analysis

Stock Analysis

udiedrichsen
{"answer":"基于雅虎财经数据,分析股票与加密货币。支持投资组合管理、自选股预警、股息分析、8维评分、热门趋势扫描及传闻/早期信号探测。适用于股票分析、持仓追踪、财报异动、加密监控、热门股追踪或提前发掘非主流传闻。"}
★ 270 📥 56,974