# Khái quát

Trình gỡ lỗi gồm 3 phần:

* **DBG** là phần gỡ lỗi của trình gỡ lỗi. Nó xử lý việc gỡ lỗi và sẽ cung cấp data cho GUI.
* **GUI** là phần đồ họa của trình gỡ lỗi. (nó giúp tương tác với user)
* Bridge là thư viện truyền thông cho phần DBG và GUI. Nó có thể được sử dụng để hoạt động trên các tính năng mới mà không phải cập nhật mã của các bộ phận khác.

## Glossary (Thuật ngữ)

* **Breakpoint** là một điểm dừng xác định một điều kiện khi người gỡ lỗi nên được tạm dừng. Có 5 loại breakpoint: software breakpoint, hardware breakpoint, memory breakpoint, DLL breakpoint and exception breakpoint.
* **Conditional Breakpoint** là một điểm dừng có điều kiều cho phép bạn xác định một số hoạt động đơn giản thực hiện tự động khi điểm dừng được hit và sau đó tiếp tục thực hiện chương trình.
* **Conditional Tracing** là theo dõi có điều kiện cho phép bạn thực hiện step-by-step the program và pause khi điều kiện được chỉ định được đáp ứng.
* **DLL Breakpoint** là một điểm dừng DLL chỉ định (specifies) the name of a DLL. When the DLL is loaded or unloaded, the debugger will be paused.
* **Trace recording** là nhật ký (log) of all traced các hướng dẫn (instructions) thường (typically) được hiển thị (displayed) in the Trace View.
* Trace coverage là theo dõi phạm vi (vùng) records nếu và bao nhiêu lần an instruction has been executed (thực hiện). An instruction đã được che trước đó sẽ được hiện thị bằng một màu nền khác (by default green). Tương tự như để lại dâu chân khi khám phá một mê cung.

## Input

### Commands

```shell
command arg1, arg2, argN
```

### Variables

Các biến tùy chọn bắt đầu bằng $ và chỉ có thể lưu trữ one DWORD (QWORD on x64)

### Registers

Tất cả các thanh ghi thuộc tất cả các kích thước, ngoại trừ floating-point registers có thể được sử dụng làm variables.

Floating-point registers like XMM0, YMM0 or ST(0) có thể không được sử dụng làm biến. Nhưng chúng có thể được ghi lại (log) thông qua kiểu String Formatting floating-point. AVX-512 registers hiện không được hỗ trợ (not supported).

> Ngoài các thanh ghi trong kiến trúc, x64dbg provides registers: `CAX` , `CBX` , `CCX` , `CDX` , `CSP` , `CBP` , `CSI` , `CDI` , `CIP`
>
> Các thanh ghi này được ánh xạ tới các thanh ghi 32 bit trên nền tảng 32-bit và đến các thanh ghi 64-bit trên nền tảng 64bit. Ví dụ `CIP` là `EIP` on 32-bit platform, and is `RIP` on 64-bit flatform.
>
> Tính năng này nhằm hỗ trợ mã độc lập với kiến trúc.

### Memory locations

Bạn có thể đọc hoặc ghi từ hoặc đến vị trí bộ nhớ bằng cách sử dụng một số biểu thức sau:

* `[addr]` read a DWORD/QWORD from `addr`.
* `n:[addr]` read n bytes from `addr`.
* `seg:[addr]` read a DWORD/QWORD from a segment at `addr`.
* `byte:[addr]` read a BYTE from `addr`.
* `word:[addr]` read a WORD from `addr`.
* `dword:[addr]` read a DWORD from `addr`.
* `qword:[addr]` read a QWORD from `addr` (x64 only).

> n là lượng bytes để đọc, có thể nhỏ hơn 4 trên x32 và nhỏ hơn 8 trên x64 khi được chỉ định, nếu không sẽ có lỗi.
>
> `seg` can be `gs`, `es`, `cs`, `fs`, `ds`, `ss`. Only `fs` and `gs` have an effect

### Flags

Cờ gỡ lỗi có thể được sử dụng làm input. Cờ được cấu thành từ tiền tố `_` theo sau là tên cờ.

Các cờ hợp lệ: `_cf`, `_pf`, `_af`, `_zf`, `_sf`, `_tf`, `_if`, `_df`, `_of`, `_rf`, `_vm`, `_ac`, `_vif`, `_vip` and `_id`

### Numbers

All numbers được hiểu là **`HEX`** là mặc định.

Nếu muốn chắc chắn bạn có thể thêm tiền tố `x` hoặc `0x` trước numbers. Số thập phân có thể sử dụng bằng tiền tố số có dấu chấm `.123=7B`.

### Module Data

#### DLL exports

Type `GetProcAddress` và nó sẽ tự động đưuocj giải quyết đến địa chỉ thực tế của hàm.

Để xác định rõ ràng module to load the API, use: `[module].dll:[api]` or `[module]:[api]`.

In a similar way you can resolve ordinals, try `[module]:[ordinal]`. Another macro allows you to get the loaded base of a module.

When `[module]` is an empty string `:GetProcAddress` for example, the module that is currently selected in the CPU will be used.

#### Loaded module bases

Nếu bạn muốn truy cập các mô đun cơ sở đã được load, you can write: `[module]:0`, `[module]:base`, `[module]:imagebase` or `[module]:header`.

#### RVA/File offset

If you want to access a module RVA you can either write `[module]:0+[rva]` or you can write `[module]:$[rva]`.

If you want to convert a file offset to a VA you can use `[module]:#[offset]`.

When `[module]` is an empty string `:0` for example, the module that is currently selected in the CPU will be used.

#### Module entry points

To access a module entry point you can write `[module]:entry`, `[module]:oep` or `[module]:ep`.

Notice that when there are exports with the names `entry`, `oep` or `ep` the address of these will be returned instead (thay thế, đại diện).

## Expressions (Biểu thức)

Trình gỡ lỗi cho phép sử dụng các biểu thức cơ bản.

1. *parentheses/brackets*: `(1+2)`, `[1+6]` have priority over other operations.
2. *unary minus/binary not/logical not*: `-1` (negative 1), `~1` (binary not of 1), `!0` (logical not of 0).
3. *multiplication/division*: `2*3` (regular multiplication), ``2`3`` (gets high part of the multiplication), `6/3` (regular division), `5%3` (modulo/remainder of the division).
4. *addition/subtraction*: `1+3` (addition), `5-2` (subtraction).
5. *left/right shift/rotate*: `1<<2` (shift left, shl for unsigned, sal for signed), `10>>1` (shift right, shl for unsigned, sal for signed), `1<<<2` (rotate left), `1>>>2` (rotate right).
6. *smaller (equal)/bigger (equal)*: `4<10`, `3>6`, `1<=2`, `6>=7` (resolves to 1 if true, 0 if false).
7. *equal/not equal*: `1==1`, `2!=6` (resolves to 1 if true, 0 if false).
8. *binary and*: `12&2` (regular binary and).
9. *binary xor*: `2^1` (regular binary xor).
10. *binary or*: `2|8` (regular binary or).
11. *logical and*: `0&&3` (resolves to 1 if true, 0 if false).
12. *logical or*: `0||3` (resolves to 1 if true, 0 if false).
13. *logical implication*: `0->1` (resolved to 1 if true, 0 if false).

Thay đổi bộ nhớ, một biến, thanh ghi hoặc cờ có thể dễ dàng thực hiện bằng cú pháp giống C:

* `a?=b` where `?` can be any non-logical operator. `a` can be any register, flag, variable or memory location. `b` can be anything that is recognized as an expression.
* `a++/a--` where `a` can be any register, flag, variable or memory location.

## Expresstion Functions

### Strings

* `utf8(addr)` : Reads a UTF-8 string from `addr` and returns the string value.
* `utf16(addr)` : Reads a UTF-16 string from `addr` and returns the string value.
* `strstr(str1, str2)` : Find a substring. Example: `strstr(utf8(addr), "abc")`.
* `streq(str1, str2)` : Compare two strings. Example: `streq(utf8(addr), "abc")`.
* `strlen(str)` : Calculates the length of a string.

Các hàm `utf8` và `utf16` có thể được sử dụng làm input cho các functions khác có đối số `str`.

The expresion `utf8(rax)` does not return a number.

### GUI Interaction (tương tác GUI)

* `disasm.sel()`/`dis.sel()` : Get the selected address in the disassembly view.
* `dump.sel()` : Get the selected address in the dump view.
* `stack.sel()` : Get the selected address in the stack view.

### Source

* `src.disp(addr)` : Get displacement of `addr` relative to last source line.
* `src.line(addr)` : Get the source line number of `addr`

> Nguồn tham khảo:
>
> <https://help.x64dbg.com/en/latest/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viettaliii.gitbook.io/home/education/tools/x32-x64dbg/khai-quat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
