1# Disassembler 2 3## Introduction 4 5Disassembler is an ArkTS disassembly tool. If you need to analyze issues related to Ark bytecode files (\*.abc), you can use Disassembler to disassemble byte data into readable assembly instructions. 6 7The tool is released with the DevEco Studio SDK. Take the Windows platform as an example. The Disassembler tool is stored in [DevEco Studio installation directory]\sdk\[SDK version]\openharmony\toolchains\ark_disasm.exe. 8 9## Commands 10 11Disassembly command: 12 13``` 14ark_disasm.exe [options] input_file output_file 15``` 16 17Parameter description 18 19| Option| Left Unspecified Allowed| Description| 20| -------- | -------- | -------- | 21| [options] | This parameter can be left unspecified.| Command option. For details, see the following description of options.| 22| input_file | No| Path of the ARK bytecode file to be disassembled.| 23| output_file | No| Output file path of the disassembled content.| 24 25Description of options 26 27| Option| Left Unspecified Allowed| Argument Carried| Description| 28| -------- | -------- | -------- | -------- | 29| --debug | This parameter can be left unspecified.| No| Enables the function of outputting debugging information. By default, debugging information is output to the screen.| 30| --debug-file | This parameter can be left unspecified.| Yes| Specifies the output file of debugging information if --debug is enabled.| 31| --help | This parameter can be left unspecified.| No| Prints help information.| 32| --skip-string-literals | This parameter can be left unspecified.| No| Skips disassembly of string literals.| 33| --quiet | This parameter can be left unspecified.| No| Enables all options starting with '--skip-'.| 34| --verbose | This parameter can be left unspecified.| No| Enables the output of additional information (byte position, ARK bytecode format, and operation code).| 35| --version | This parameter can be left unspecified.| No| Displays the version number of the Ark bytecode file and the earliest supported Ark bytecode file version.| 36 37## Samples 38 39Assume that the Ark bytecode file test.abc exists. The source code is as follows: 40 41``` 42let i = 99; 43function show(){return i;} 44show(); 45``` 46 47 48Run the following command to generate the disassembly file test.txt: The generated disassembly file contains information such as the operation code and format. 49 50``` 51ark_disasm.exe test.abc test.txt 52``` 53 54View the content of the disassembly file. 55 56 57``` 58cat test.txt 59``` 60 61Modify the file 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 79The data starts with .record _ESConcurrentModuleRequestsAnnotation { // _ and is fixed module data. 80} 81 82.record test { // One JS file corresponds to one module data, including the module information (location in the ARK bytecode file, 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 } 93The show method in the source code of the .function any test.#*#show(any a0, any a1, any a2) <static> { // method belongs to the test module. 94 ldlexvar 0x0, 0x0 95 ...... 96} 97 98L_ESSlotNumberAnnotation: 99 u32 slotNumberIdx { 0x3 } 100The .function any test.func_main_0(any a0, any a1, any a2) <static> { // method is automatically generated. The entire JS file can be regarded as a method. The method name is 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 118Some examples are listed here. 119 120``` 121.record _ESSlotNumberAnnotation { # offset: 0x00cd, size: 0x0026 (38) //: Prints the specific position and size of the module in the ARK bytecode file. 122} 123 124.record test {# offset: 0x00f3, size: 0x0098 (152) // The specific position of the module in the ARK bytecode file is displayed. 125 u32 moduleRecordIdx = 0x203 # offset: 0x0144 // Location where the module information is printed 126} 127...... 128.function any test.#*#show(any a0, any a1, any a2) <static> { # offset: 0x0153, code offset: 0x0245 //: indicates the specific location of the method information and the specific location of the instruction in the method. 129# CODE: 130 ldlexvar 0x0, 0x0 # offset: 0x0249, [IMM4_IMM4].........[0x3c 0x00] //: indicates the location of each command. 131 ...... 132} 133``` 134