• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Disassembler
2
3## Overview
4
5Disassembler is a utility in the ArkTS toolchain designed to convert Ark bytecode files (*.abc) into human-readable assembly instructions. It is particularly useful when you want to analyze or debug issues related to Ark bytecode files.
6
7Disassembler is released with the DevEco Studio SDK. For instance, on Windows, the tool can be found at: DevEco Studio/sdk/default/openharmony/toolchains/ark_disasm.exe.
8
9## Command-Line Instructions
10
11To use Disassembler, run the following command:
12
13```
14ark_disasm.exe [options] input_file output_file
15```
16
17Parameters
18
19| Parameter| Optional| Description|
20| -------- | -------- | -------- |
21| [options] | Yes| Command options. For details, see **Description of options** below.|
22| input_file | No| Path of the Ark bytecode file to be disassembled.|
23| output_file | No| Path where the disassembled file will be saved.|
24
25Description of **options**
26
27| Option| Mandatory| Argument Carried| Description|
28| -------- | -------- | -------- | -------- |
29| --debug | No | No | Enables the function of outputting debugging information. By default, debugging information is output to the screen.|
30| --debug-file | No| Yes| Specifies the output file of debugging information if **--debug** is enabled.|
31| --help | No| No| Displays help information.|
32| --skip-string-literals | No| No| Skips disassembly of string literals.|
33| --quiet | No| No| Enables all options prefixed with **--skip-**.|
34| --verbose | No| No| Enables the output of additional information (byte position, ARK bytecode format, and operation code).|
35| --version | No| No| Displays the version of the Ark bytecode file and the minimum supported version.|
36
37## Usage Example
38
39Assume that the Ark bytecode file **test.abc** exists, with the following source code:
40
41```
42let i = 99;
43function show(){return i;}
44show();
45```
46
47
48Run the following command to generate a disassembled file named **test.txt**, which contains information such as the operation code and format:
49
50```
51ark_disasm.exe test.abc test.txt
52```
53
54Run the following command to view the content of the disassembled file:
55
56
57```
58cat test.txt
59```
60
61The file content is as follows:
62
63```
64# source binary: test.abc                                                    // Disassembled Ark bytecode file.
65
66.language ECMAScript
67
68# ====================
69# LITERALS                                                                   // Literal data.
70
710 0x203 { 0 [
72	MODULE_REQUEST_ARRAY: {
73	};
74]}
75
76# ====================
77# RECORDS                                                                    // Module definition data.
78
79.record _ESConcurrentModuleRequestsAnnotation {                              // Data prefixed with _ is fixed module data.
80}
81
82.record test {                                                               // One JS file corresponds to one module. It contains the module information, for example, location in the ARK bytecode file and whether it is CommonJS.
83	u8 isCommonjs = 0x0
84	u32 moduleRecordIdx = 0x203
85	......
86}
87
88# ====================
89# METHODS                                                                    // Method definition data.
90
91L_ESSlotNumberAnnotation:
92	u32 slotNumberIdx { 0x0 }
93.function any test.#*#show(any a0, any a1, any a2) <static> {                // The show method in the source code. It belongs to the test module.
94	ldlexvar 0x0, 0x0
95	......
96}
97
98L_ESSlotNumberAnnotation:
99	u32 slotNumberIdx { 0x3 }
100.function any test.func_main_0(any a0, any a1, any a2) <static> {            // The method is automatically generated. The entire JS file can be regarded as a method named func_main_0.
101	newlexenv 0x1
102	......
103}
104
105# ====================
106# STRING                                                                     // Symbol table information
107
108[offset:0x88, name_value:i]
109```
110
111Use the **--verbose** parameter to print more details such as the offset.
112
113
114```
115ark_disasm.exe --verbose test.abc test.txt
116```
117
118Here are some examples of the output with **--verbose**:
119
120```
121.record _ESSlotNumberAnnotation { # offset: 0x00cd, size: 0x0026 (38)                                  // This prints the location and size of the module within the ARK bytecode file.
122}
123
124.record test { # offset: 0x00f3, size: 0x0098 (152)                                                    // This prints the location of the module within the ARK bytecode file.
125	u32 moduleRecordIdx = 0x203 # offset: 0x0144                                                   // This prints the location of the module information.
126}
127......
128.function any test.#*#show(any a0, any a1, any a2) <static> { # offset: 0x0153, code offset: 0x0245    // This prints the location of the method information and the location of the instruction in the method.
129#   CODE:
130	ldlexvar 0x0, 0x0 # offset: 0x0249, [IMM4_IMM4].........[0x3c 0x00]                            // This prints the location of each command.
131	......
132}
133```
134