Skip to content

Commit 712f537

Browse files
committed
update docs
1 parent 420378e commit 712f537

File tree

7 files changed

+413
-0
lines changed

7 files changed

+413
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# core.base.binutils
2+
3+
Binary file processing utility module.
4+
5+
## binutils.bin2c
6+
7+
Generate C/C++ code from binary file.
8+
9+
### Function Prototype
10+
11+
::: tip API
12+
```lua
13+
binutils.bin2c(binaryfile: <string>, outputfile: <string>, opt: <table>)
14+
```
15+
:::
16+
17+
### Parameter Description
18+
19+
| Parameter | Description |
20+
|-----------|-------------|
21+
| binaryfile | Required. Input binary file path |
22+
| outputfile | Required. Output C/C++ source file path |
23+
| opt | Optional. Options: <br>- `linewidth`: line width (default: 32) <br>- `nozeroend`: do not append null terminator (default: false) |
24+
25+
## binutils.bin2obj
26+
27+
Generate object file from binary file.
28+
29+
### Function Prototype
30+
31+
::: tip API
32+
```lua
33+
binutils.bin2obj(binaryfile: <string>, outputfile: <string>, opt: <table>)
34+
```
35+
:::
36+
37+
### Parameter Description
38+
39+
| Parameter | Description |
40+
|-----------|-------------|
41+
| binaryfile | Required. Input binary file path |
42+
| outputfile | Required. Output object file path |
43+
| opt | Optional. Options: <br>- `format`: object format (coff, elf, macho) <br>- `symbol_prefix`: symbol prefix (default: `_binary_`) <br>- `arch`: architecture (default: x86_64) <br>- `plat`: platform (default: macosx, only for macho) <br>- `basename`: base name for symbols <br>- `target_minver`: target minimum version (only for macho) <br>- `xcode_sdkver`: Xcode SDK version (only for macho) <br>- `zeroend`: append null terminator (default: false) |
44+
45+
## binutils.readsyms
46+
47+
Read symbols from object file (auto-detect format: COFF, ELF, or Mach-O).
48+
49+
### Function Prototype
50+
51+
::: tip API
52+
```lua
53+
binutils.readsyms(binaryfile: <string>)
54+
```
55+
:::
56+
57+
### Parameter Description
58+
59+
| Parameter | Description |
60+
|-----------|-------------|
61+
| binaryfile | Required. Input object file path |
62+
63+
### Return Value
64+
65+
| Return Value | Description |
66+
|--------------|-------------|
67+
| <table> | Symbols list |
68+
69+
## binutils.deplibs
70+
71+
Get dependent libraries.
72+
73+
### Function Prototype
74+
75+
::: tip API
76+
```lua
77+
binutils.deplibs(binaryfile: <string>)
78+
```
79+
:::
80+
81+
### Parameter Description
82+
83+
| Parameter | Description |
84+
|-----------|-------------|
85+
| binaryfile | Required. Input binary file path |
86+
87+
### Return Value
88+
89+
| Return Value | Description |
90+
|--------------|-------------|
91+
| <table> | Dependent libraries list |
92+
93+
## binutils.extractlib
94+
95+
Extract static library to directory.
96+
97+
### Function Prototype
98+
99+
::: tip API
100+
```lua
101+
binutils.extractlib(libraryfile: <string>, outputdir: <string>, opt: <table>)
102+
```
103+
:::
104+
105+
### Parameter Description
106+
107+
| Parameter | Description |
108+
|-----------|-------------|
109+
| libraryfile | Required. Input static library file path |
110+
| outputdir | Required. Output directory path |
111+
| opt | Optional. Options (reserved) |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# utils.binary
2+
3+
Binary utility modules.
4+
5+
## utils.binary.deplibs
6+
7+
Get dependent libraries.
8+
9+
### Function Prototype
10+
11+
::: tip API
12+
```lua
13+
local deps = deplibs(binaryfile: <string>, opt: <table>)
14+
```
15+
:::
16+
17+
### Parameter Description
18+
19+
| Parameter | Description |
20+
|-----------|-------------|
21+
| binaryfile | Required. Input binary file path |
22+
| opt | Optional. Options: <br>- `plat`: Platform <br>- `arch`: Architecture <br>- `recursive`: Recursively get all sub-dependencies (default: false) <br>- `resolve_path`: Try to resolve the file full path (default: false) <br>- `resolve_hint_paths`: Resolve paths from hints <br>- `resolve_search_paths`: Search library paths (e.g. LD_LIBRARY_PATH) <br>- `check_cycle`: Check for circular dependencies |
23+
24+
### Return Value
25+
26+
| Return Value | Description |
27+
|--------------|-------------|
28+
| <table> | Dependent libraries list |
29+
30+
## utils.binary.readsyms
31+
32+
Read symbols from object file.
33+
34+
### Function Prototype
35+
36+
::: tip API
37+
```lua
38+
local syms = readsyms(binaryfile: <string>)
39+
```
40+
:::
41+
42+
### Parameter Description
43+
44+
| Parameter | Description |
45+
|-----------|-------------|
46+
| binaryfile | Required. Input object file path |
47+
48+
### Return Value
49+
50+
| Return Value | Description |
51+
|--------------|-------------|
52+
| <table> | Symbols list |
53+
54+
## utils.binary.extractlib
55+
56+
Extract static library to directory.
57+
58+
### Function Prototype
59+
60+
::: tip API
61+
```lua
62+
extractlib(libraryfile: <string>, outputdir: <string>, opt: <table>)
63+
```
64+
:::
65+
66+
### Parameter Description
67+
68+
| Parameter | Description |
69+
|-----------|-------------|
70+
| libraryfile | Required. Input static library file path |
71+
| outputdir | Required. Output directory path |
72+
| opt | Optional. Options |

docs/posts/xmake-update-v3.0.6.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ It is incompatible with LTCG/PGO/OPT-ICF.
175175
set_policy("build.c++.dynamic_debugging", true)
176176
```
177177

178+
### Binary Utilities
179+
180+
We added the `core.base.binutils` module and the `utils.binary` extension module for processing binary files.
181+
182+
They provide functions such as `bin2c`, `bin2obj`, `readsyms`, `deplibs`, and `extractlib`, which can be used to generate code from binary files, read symbols, obtain dependent libraries, and extract static libraries.
183+
184+
```lua
185+
import("utils.binary.deplibs")
186+
import("utils.binary.readsyms")
187+
import("utils.binary.extractlib")
188+
189+
-- Get dependent libraries
190+
local deps = deplibs("/path/to/bin")
191+
192+
-- Read symbols
193+
local syms = readsyms("/path/to/obj")
194+
195+
-- Extract static library
196+
extractlib("/path/to/lib.a", "/path/to/outputdir")
197+
```
198+
199+
In addition, we have improved dependent library resolution, support for extracting objects used in static library merging, and symbol dumping.
200+
178201
---
179202

180203
## Changelog

docs/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ function utilsModulesApiSidebar(): DefaultTheme.SidebarItem {
252252
collapsed: true,
253253
items: [
254254
{ text: 'archive', link: 'extension-modules/utils/archive' },
255+
{ text: 'binary', link: 'extension-modules/utils/binary' },
255256
{ text: 'platform', link: 'extension-modules/utils/platform' },
256257
]
257258
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# core.base.binutils
2+
3+
二进制文件处理工具模块。
4+
5+
## binutils.bin2c
6+
7+
从二进制文件生成 C/C++ 代码。
8+
9+
### 函数原型
10+
11+
::: tip API
12+
```lua
13+
binutils.bin2c(binaryfile: <string>, outputfile: <string>, opt: <table>)
14+
```
15+
:::
16+
17+
### 参数说明
18+
19+
| 参数 | 描述 |
20+
|------|------|
21+
| binaryfile | 必需。输入二进制文件路径 |
22+
| outputfile | 必需。输出 C/C++ 源文件路径 |
23+
| opt | 可选。选项:<br>- `linewidth`: 行宽 (默认: 32) <br>- `nozeroend`: 不追加空终止符 (默认: false) |
24+
25+
## binutils.bin2obj
26+
27+
从二进制文件生成对象文件。
28+
29+
### 函数原型
30+
31+
::: tip API
32+
```lua
33+
binutils.bin2obj(binaryfile: <string>, outputfile: <string>, opt: <table>)
34+
```
35+
:::
36+
37+
### 参数说明
38+
39+
| 参数 | 描述 |
40+
|------|------|
41+
| binaryfile | 必需。输入二进制文件路径 |
42+
| outputfile | 必需。输出对象文件路径 |
43+
| opt | 可选。选项:<br>- `format`: 对象格式 (coff, elf, macho) <br>- `symbol_prefix`: 符号前缀 (默认: `_binary_`) <br>- `arch`: 架构 (默认: x86_64) <br>- `plat`: 平台 (默认: macosx, 仅限 macho) <br>- `basename`: 符号基名 <br>- `target_minver`: 目标最小版本 (仅限 macho) <br>- `xcode_sdkver`: Xcode SDK 版本 (仅限 macho) <br>- `zeroend`: 追加空终止符 (默认: false) |
44+
45+
## binutils.readsyms
46+
47+
读取对象文件符号(自动检测格式:COFF, ELF, 或 Mach-O)。
48+
49+
### 函数原型
50+
51+
::: tip API
52+
```lua
53+
binutils.readsyms(binaryfile: <string>)
54+
```
55+
:::
56+
57+
### 参数说明
58+
59+
| 参数 | 描述 |
60+
|------|------|
61+
| binaryfile | 必需。输入对象文件路径 |
62+
63+
### 返回值说明
64+
65+
| 返回值 | 描述 |
66+
|--------|------|
67+
| <table> | 符号列表 |
68+
69+
## binutils.deplibs
70+
71+
获取依赖库列表。
72+
73+
### 函数原型
74+
75+
::: tip API
76+
```lua
77+
binutils.deplibs(binaryfile: <string>)
78+
```
79+
:::
80+
81+
### 参数说明
82+
83+
| 参数 | 描述 |
84+
|------|------|
85+
| binaryfile | 必需。输入二进制文件路径 |
86+
87+
### 返回值说明
88+
89+
| 返回值 | 描述 |
90+
|--------|------|
91+
| <table> | 依赖库列表 |
92+
93+
## binutils.extractlib
94+
95+
解压静态库到目录。
96+
97+
### 函数原型
98+
99+
::: tip API
100+
```lua
101+
binutils.extractlib(libraryfile: <string>, outputdir: <string>, opt: <table>)
102+
```
103+
:::
104+
105+
### 参数说明
106+
107+
| 参数 | 描述 |
108+
|------|------|
109+
| libraryfile | 必需。输入静态库文件路径 |
110+
| outputdir | 必需。输出目录路径 |
111+
| opt | 可选。选项(保留) |

0 commit comments

Comments
 (0)