# 2.2 进程 (Process)

* `Process.id`: 进程id，数字。
* `Process.arch`: 架构，字符串：`ia32`, `x64`, `arm`, `arm64`
* `Process.platform`: 系统，字符串：`windows`, `darwin`, `linux`, `qnx`
* `Process.pageSize`: 虚拟内存页大小（单位为字节），数字。这个属性可以帮助你写出移植性更好的脚本。
* `Process.pointerSize`: 指针大小（单位为字节），数字。同样可以提高你脚本的可移植性。
* `Process.codeSigningPolicy`:&#x20;
* `Process.isDebuggerAttached()`: 指明当前是否有调试器调试，布尔值。
* `Process.getCurrentThreadId()`: 后去当前线程的系统级别的ID，数字。
* `Process.enumerateThreads()`: 枚举所有的线程，并返回一个对象数组，数组中每个对象都包含以下几个属性:\
  \* `id`: 数字，系统层级的id\
  \* `state`: 字符串，表示该线程的状态：`running`, `stopped`, `waitting`, `uninterruptible`, `halted`\
  \* `context`: 对象，包含 `pc`， `sp`属性，这两个属性为`NativePointer`对象，用于指明 `EIP`/`RIP`/`PC`和`ESP`/`RSP`/`SP`（分别对应`ia32`/`x64`/`arm`）。其他处理器也适用，比如`eax`, `rax`, `r0`, `x0`, 等等。
* `Process.findModuleByAddress(address)`, `Process.getModuleByAddress(address)`, `Process.findModuleByName(name)`, `Process.getModuleByName(name)`: 返回一个`Module`，该模块的地址/名称匹配搜索串。若没有找到目标模块，find类函数会返回`null`，而get类函数会抛出异常。
* `Process.enumerateModules()`: 枚举当前已加载的模块，返回值为模块对象列表。
* `Process.findRangeByAddress(address)`, `Process.getRangeByAddress(address)`: 返回一个对象，该对象描述了包含目标地址的内存块的详细信息。若没有找到这样的内存范围，前者会返回`null`，而后者会抛出异常。列举的详细信息，详情查看`Process.enumerateRanges()`。
* `Process.enumerateRanges(protection|specifier)`: 枚举内存中满足`protection`条件的内存范围。`protection`参数应当为这样形式的字符串: `rwx`, 而`rw-`表示必须至少可写可读。或者可以传入`specifier`对象，该对象包含`protection`和`coalesce`两个键。`protection`键同上，`coalesce`键表示附件的range是否也是同样的保护机制（默认为`false`，也就是将range分离开）。该函数返回一个对象数组，其中每个对象包含以下属性：\
  \* `base`: `NativePointer`，表示基地址\
  \* `size`: 大小，以字节为单位\
  \* `protection`: 保护属性\
  \* `file`: 对象，文件映射细节，包含以下属性:\
  &#x20; \* `path`: 文件的系统地址\
  &#x20; \* `offset`: 偏移量，单位字节\
  &#x20; \* `size`: 文件大小，单位字节
* `Process.enumerateMallocRanges()`: 和`enumerateRanges()`类似，但是返回系统堆部分的内存。
* `Process.setExceptionHandler(callback)`: 安装一个进程级的异常处理回调。该回调会在原进程处理函数调用前调用。该回调只有一个参数，`details`，该参数为为一个对象，包含以下属性:\
  \* `type`: 字符串: `abort`, `access-violation`, `guard-page`, `illegal-instruction`, `stack-overflow`, `arithmetic`, `breakpoint`, `single-step`, `system`\
  \* `address`: `NativePointer`，发生异常的地址\
  \* `memory`: 包含以下属性的对象:\
  &#x20; \* `operation`: 触发异常的操作，字符串: `read`, `write`, `execute`\
  &#x20; \* `address`: `NativePointer`，异常发生时，存取的内存地址\
  \* `context`: 对象，包含`pc`属性和`sp`属性，分别为指明 `EIP`/`RIP`/`PC` 和 `ESP`/`RSP`/`SP` 的`NativePointer`（对应 `ia32`/`x64`/`arm`）。其他处理器也可以使用，比如`eax`，`rax`，`r0`，`x0`等等。你也可以通过给这些属性赋值来更新寄存器的值。\
  \* `nativeContext`: `NativePointer`，包含操作系统的地址，以及架构特异的CPU上下文结构。这个参数是对`context`参数的补充，防止`context`提供的信息不足；不过我们不推荐使用这个参数，如果出错了也不要给我们提交pr。\
  你的回调函数将会决定如何处理异常。你可以单纯记录，并通过`send`函数和阻塞的`recv`函数来和你的app通信，也可以修改寄存器和内存，以恢复异常。如果你真的处理了该异常，那么该回调应该返回`true`，之后frida会立刻恢复该线程。如果你不返回`true`，frida会将该异常传递给进程的异常处理器，或者让操作系统终止该进程。


---

# 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://frida.ivory.cafe/2.-jin-cheng-xian-cheng-mo-kuai-he-nei-cun/2.2-jin-cheng-process.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.
