peekmem 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ /target
2
+ **/*.rs.bk
3
+ *.pdb
4
+
5
+ # Python
6
+ __pycache__/
7
+ *.py[cod]
8
+ *.so
9
+ *.pyd
10
+ *.egg-info/
11
+ .venv/
12
+ venv/
13
+ dist/
14
+ build/
15
+
16
+ # maturin
17
+ /target/wheels/
18
+
19
+ # IDE
20
+ .idea/
21
+ .vscode/
@@ -0,0 +1,159 @@
1
+ # Comece aqui — retomando o peekmem no VS Code
2
+
3
+ Documento de retomada. Leia este primeiro; o detalhamento técnico está em
4
+ `peekmem-plano.md`.
5
+
6
+ ---
7
+
8
+ ## Onde paramos (02/12/2026)
9
+
10
+ **Estado:** núcleo completo e **validado ponta a ponta no Linux e no Windows** —
11
+ 46/46 testes funcionais passando contra um processo vivo nos dois. Números de
12
+ performance no Linux (os de batch, no Windows, estão na seção 5.2): leitura a ~2,5 M ops/s, scan a ~1,33 GB/s.
13
+
14
+ **Windows (02/12/2026):** rustc 1.99.1 MSVC, Python 3.12.10, maturin 1.16.0. O
15
+ FFI compilou sem alteração; 5/5 testes Rust também passam.
16
+
17
+ **Batch de leitura: feito** (`read_batch`, `read_batch_f32`).
18
+
19
+ **Enumeração de regiões: feita** (`regions`, `aob_scan_module`).
20
+
21
+ **O que falta agora:** overlay com `raylib-rs` (seção 5.4 do plano).
22
+
23
+ **Decisões já fechadas** (não precisa reabrir): nome `peekmem`/`pk`, API em
24
+ inglês com `read_`/`write_` + sufixo de tipo (`read_f32`), scan como
25
+ `aob_scan`. Detalhes e racional na seção 2 do `peekmem-plano.md`.
26
+
27
+ ---
28
+
29
+ ## Compilar e testar no Windows (feito, para referência)
30
+
31
+ ### 1. Pré-requisitos no Windows (uma vez só)
32
+
33
+ | O que | Como |
34
+ |---|---|
35
+ | Rust | https://rustup.rs — instala o toolchain MSVC |
36
+ | MSVC Build Tools | Visual Studio Installer → "Desktop development with C++" (o linker vem daí; sem isso o build falha) |
37
+ | Python 3.8+ | já tem, se usa PyCharm/VS Code |
38
+ | maturin | `pip install maturin` |
39
+
40
+ Confere com:
41
+ ```powershell
42
+ rustc --version
43
+ cargo --version
44
+ maturin --version
45
+ ```
46
+
47
+ ### 2. Compilar e testar
48
+
49
+ ```powershell
50
+ cd caminho/do/peekmem
51
+
52
+ maturin build --release
53
+ pip install --force-reinstall --find-links target/wheels peekmem
54
+
55
+ python tests/run_test.py
56
+ ```
57
+
58
+ O teste é o mesmo nos dois sistemas: ele escolhe o módulo do alvo
59
+ (`python.exe` ou `libc.so.6`) e os caminhos sozinho.
60
+
61
+ Resultado esperado: `RESULTADO: 46 passaram, 0 falharam`.
62
+
63
+ ### 3. Se der erro
64
+
65
+ - **Erro de compilação no FFI** (tipos, `HANDLE`, nomes de função): é o risco
66
+ conhecido. Guarda a saída do `cargo build` — é o que precisa pra corrigir.
67
+ - **Erro de linker** (`link.exe not found`): faltam os MSVC Build Tools.
68
+ - **`OpenProcess failed ... (Access is denied)`**: roda o terminal como
69
+ Administrador, ou escolhe um processo alvo mais permissivo.
70
+
71
+ ---
72
+
73
+ ## Próximos passos
74
+
75
+ Prioridade clara, pelo que o benchmark mostrou:
76
+
77
+ 1. **Overlay com `raylib-rs`**. Seção 5.4.
78
+
79
+ ---
80
+
81
+ ## Trabalhando no VS Code
82
+
83
+ ### Extensões
84
+ - **rust-analyzer** — essencial
85
+ - **Even Better TOML** — para `Cargo.toml`/`pyproject.toml`
86
+ - **Python** (Microsoft) — usa o `peekmem.pyi` para autocomplete
87
+
88
+ Já existe `.vscode/settings.json` no projeto com a configuração necessária.
89
+
90
+ ### Armadilha importante dos testes Rust
91
+
92
+ `cargo test` **sozinho falha no linker**, e não é bug do seu código: a feature
93
+ `extension-module` faz os símbolos do CPython serem resolvidos só quando o
94
+ Python carrega o módulo, então o binário de teste não acha. Use sempre:
95
+
96
+ ```powershell
97
+ cargo test --no-default-features
98
+ ```
99
+
100
+ É por isso que `extension-module` é feature opcional no `Cargo.toml` (o maturin
101
+ liga, o teste desliga).
102
+
103
+ ### Comandos do dia a dia
104
+
105
+ ```powershell
106
+ cargo check # feedback rápido de compilação
107
+ cargo clippy # lint
108
+ cargo test --no-default-features # testes Rust (parser do scan)
109
+ maturin develop --release # compila e instala no venv ativo
110
+ python tests/run_test.py # teste funcional ponta a ponta
111
+ ```
112
+
113
+ `maturin develop` precisa de um venv ativo. `maturin build` não, e gera a wheel
114
+ em `target/wheels/`.
115
+
116
+ ---
117
+
118
+ ## Mapa dos arquivos
119
+
120
+ ```
121
+ peekmem/
122
+ ├── COMECE-AQUI.md <- este arquivo
123
+ ├── peekmem-plano.md <- plano completo, decisões, roadmap detalhado
124
+ ├── README.md <- apresentação do projeto (vira o README do GitHub)
125
+ ├── Cargo.toml <- deps + perfil release agressivo (LTO fat)
126
+ ├── pyproject.toml <- build via maturin
127
+ ├── peekmem.pyi <- type stubs (autocomplete no editor)
128
+ ├── .vscode/settings.json
129
+ ├── src/
130
+ │ ├── lib.rs <- #[pymodule], funções de módulo
131
+ │ ├── raw.rs <- FFI: Windows (windows-sys) + Linux (libc)
132
+ │ ├── process.rs <- #[pyclass] Process + métodos tipados
133
+ │ ├── scan.rs <- AOB scan com SIMD + testes unitários
134
+ │ └── error.rs <- peekmem.MemoryError
135
+ └── tests/
136
+ ├── run_test.py <- teste funcional (46 casos)
137
+ ├── target_proc.py <- processo-alvo com valores conhecidos
138
+ └── README.md
139
+ ```
140
+
141
+ **Onde mexer pra cada coisa:**
142
+ - novo tipo de leitura → `process.rs` (wrapper de 1 linha sobre `read_pod`)
143
+ - nova syscall/API de SO → `raw.rs`, nos **dois** módulos (`win` e `unix`)
144
+ - lógica de scan → `scan.rs`
145
+ - nova mensagem de erro → `error.rs`
146
+ - qualquer método novo → espelhar em `peekmem.pyi`
147
+
148
+ ---
149
+
150
+ ## Publicar
151
+
152
+ Wheel abi3 (uma só para Python 3.8+). O `RUSTFLAGS` tira do binário os caminhos
153
+ da máquina que compila.
154
+
155
+ ```powershell
156
+ $env:RUSTFLAGS = "--remap-path-prefix=$env:USERPROFILE=~"
157
+ maturin build --release --sdist --out dist
158
+ maturin upload dist/peekmem-0.1.0-cp38-abi3-win_amd64.whl dist/peekmem-0.1.0.tar.gz # pede o token
159
+ ```
@@ -0,0 +1,262 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
10
+
11
+ [[package]]
12
+ name = "cfg-if"
13
+ version = "1.0.5"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
16
+
17
+ [[package]]
18
+ name = "heck"
19
+ version = "0.5.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
22
+
23
+ [[package]]
24
+ name = "indoc"
25
+ version = "2.0.8"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "a37b2691796cffeb8a8cd305ac66e65841559f147f4e63231d0eafa4db5384d1"
28
+ dependencies = [
29
+ "rustversion",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "libc"
34
+ version = "0.2.191"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
37
+
38
+ [[package]]
39
+ name = "memchr"
40
+ version = "2.8.3"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
43
+
44
+ [[package]]
45
+ name = "memoffset"
46
+ version = "0.9.1"
47
+ source = "registry+https://github.com/rust-lang/crates.io-index"
48
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
49
+ dependencies = [
50
+ "autocfg",
51
+ ]
52
+
53
+ [[package]]
54
+ name = "once_cell"
55
+ version = "1.21.4"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
58
+
59
+ [[package]]
60
+ name = "peekmem"
61
+ version = "0.1.0"
62
+ dependencies = [
63
+ "libc",
64
+ "memchr",
65
+ "pyo3",
66
+ "windows-sys",
67
+ ]
68
+
69
+ [[package]]
70
+ name = "portable-atomic"
71
+ version = "1.15.0"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
74
+
75
+ [[package]]
76
+ name = "proc-macro2"
77
+ version = "1.0.107"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
80
+ dependencies = [
81
+ "unicode-ident",
82
+ ]
83
+
84
+ [[package]]
85
+ name = "pyo3"
86
+ version = "0.22.6"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
89
+ dependencies = [
90
+ "cfg-if",
91
+ "indoc",
92
+ "libc",
93
+ "memoffset",
94
+ "once_cell",
95
+ "portable-atomic",
96
+ "pyo3-build-config",
97
+ "pyo3-ffi",
98
+ "pyo3-macros",
99
+ "unindent",
100
+ ]
101
+
102
+ [[package]]
103
+ name = "pyo3-build-config"
104
+ version = "0.22.6"
105
+ source = "registry+https://github.com/rust-lang/crates.io-index"
106
+ checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
107
+ dependencies = [
108
+ "once_cell",
109
+ "target-lexicon",
110
+ ]
111
+
112
+ [[package]]
113
+ name = "pyo3-ffi"
114
+ version = "0.22.6"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
117
+ dependencies = [
118
+ "libc",
119
+ "pyo3-build-config",
120
+ ]
121
+
122
+ [[package]]
123
+ name = "pyo3-macros"
124
+ version = "0.22.6"
125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
126
+ checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
127
+ dependencies = [
128
+ "proc-macro2",
129
+ "pyo3-macros-backend",
130
+ "quote",
131
+ "syn",
132
+ ]
133
+
134
+ [[package]]
135
+ name = "pyo3-macros-backend"
136
+ version = "0.22.6"
137
+ source = "registry+https://github.com/rust-lang/crates.io-index"
138
+ checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
139
+ dependencies = [
140
+ "heck",
141
+ "proc-macro2",
142
+ "pyo3-build-config",
143
+ "quote",
144
+ "syn",
145
+ ]
146
+
147
+ [[package]]
148
+ name = "quote"
149
+ version = "1.0.47"
150
+ source = "registry+https://github.com/rust-lang/crates.io-index"
151
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
152
+ dependencies = [
153
+ "proc-macro2",
154
+ ]
155
+
156
+ [[package]]
157
+ name = "rustversion"
158
+ version = "1.0.23"
159
+ source = "registry+https://github.com/rust-lang/crates.io-index"
160
+ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
161
+
162
+ [[package]]
163
+ name = "syn"
164
+ version = "2.0.119"
165
+ source = "registry+https://github.com/rust-lang/crates.io-index"
166
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
167
+ dependencies = [
168
+ "proc-macro2",
169
+ "quote",
170
+ "unicode-ident",
171
+ ]
172
+
173
+ [[package]]
174
+ name = "target-lexicon"
175
+ version = "0.12.16"
176
+ source = "registry+https://github.com/rust-lang/crates.io-index"
177
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
178
+
179
+ [[package]]
180
+ name = "unicode-ident"
181
+ version = "1.0.27"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
184
+
185
+ [[package]]
186
+ name = "unindent"
187
+ version = "0.2.4"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
190
+
191
+ [[package]]
192
+ name = "windows-sys"
193
+ version = "0.59.0"
194
+ source = "registry+https://github.com/rust-lang/crates.io-index"
195
+ checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
196
+ dependencies = [
197
+ "windows-targets",
198
+ ]
199
+
200
+ [[package]]
201
+ name = "windows-targets"
202
+ version = "0.52.6"
203
+ source = "registry+https://github.com/rust-lang/crates.io-index"
204
+ checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
205
+ dependencies = [
206
+ "windows_aarch64_gnullvm",
207
+ "windows_aarch64_msvc",
208
+ "windows_i686_gnu",
209
+ "windows_i686_gnullvm",
210
+ "windows_i686_msvc",
211
+ "windows_x86_64_gnu",
212
+ "windows_x86_64_gnullvm",
213
+ "windows_x86_64_msvc",
214
+ ]
215
+
216
+ [[package]]
217
+ name = "windows_aarch64_gnullvm"
218
+ version = "0.52.6"
219
+ source = "registry+https://github.com/rust-lang/crates.io-index"
220
+ checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
221
+
222
+ [[package]]
223
+ name = "windows_aarch64_msvc"
224
+ version = "0.52.6"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
227
+
228
+ [[package]]
229
+ name = "windows_i686_gnu"
230
+ version = "0.52.6"
231
+ source = "registry+https://github.com/rust-lang/crates.io-index"
232
+ checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
233
+
234
+ [[package]]
235
+ name = "windows_i686_gnullvm"
236
+ version = "0.52.6"
237
+ source = "registry+https://github.com/rust-lang/crates.io-index"
238
+ checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
239
+
240
+ [[package]]
241
+ name = "windows_i686_msvc"
242
+ version = "0.52.6"
243
+ source = "registry+https://github.com/rust-lang/crates.io-index"
244
+ checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
245
+
246
+ [[package]]
247
+ name = "windows_x86_64_gnu"
248
+ version = "0.52.6"
249
+ source = "registry+https://github.com/rust-lang/crates.io-index"
250
+ checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
251
+
252
+ [[package]]
253
+ name = "windows_x86_64_gnullvm"
254
+ version = "0.52.6"
255
+ source = "registry+https://github.com/rust-lang/crates.io-index"
256
+ checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
257
+
258
+ [[package]]
259
+ name = "windows_x86_64_msvc"
260
+ version = "0.52.6"
261
+ source = "registry+https://github.com/rust-lang/crates.io-index"
262
+ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
@@ -0,0 +1,45 @@
1
+ [package]
2
+ name = "peekmem"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "Fast external process memory library for Python, written in Rust"
6
+ license = "MIT"
7
+ repository = "https://github.com/alexsandrejr/peekmem"
8
+ readme = "README.md"
9
+
10
+ [lib]
11
+ name = "peekmem"
12
+ crate-type = ["cdylib"]
13
+
14
+ [dependencies]
15
+ pyo3 = "0.22"
16
+ # busca de byte-ancora acelerada por SIMD, usada no AOB scan
17
+ memchr = "2"
18
+
19
+ # `extension-module` fica opcional de proposito:
20
+ # - maturin liga essa feature (ver pyproject.toml) pro build real
21
+ # - `cargo test --no-default-features` desliga, senao o binario de teste
22
+ # nao acha os simbolos do CPython e falha no linker
23
+ [features]
24
+ default = ["extension-module"]
25
+ extension-module = ["pyo3/extension-module"]
26
+
27
+ [target.'cfg(windows)'.dependencies]
28
+ windows-sys = { version = "0.59", features = [
29
+ "Win32_Foundation",
30
+ "Win32_System_Memory",
31
+ "Win32_System_Threading",
32
+ "Win32_System_Diagnostics_Debug",
33
+ "Win32_System_Diagnostics_ToolHelp",
34
+ ] }
35
+
36
+ [target.'cfg(unix)'.dependencies]
37
+ libc = "0.2"
38
+
39
+ # Perfil de release agressivo: a lib existe pra ser rapida.
40
+ [profile.release]
41
+ opt-level = 3
42
+ lto = "fat" # otimizacao entre crates
43
+ codegen-units = 1 # menos paralelismo no build, binario mais rapido
44
+ panic = "abort"
45
+ strip = true
peekmem-0.1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 alexsandrejr
4
+ Copyright (c) 2020 Meowz
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
peekmem-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: peekmem
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Operating System :: Microsoft :: Windows
7
+ Classifier: Operating System :: POSIX :: Linux
8
+ Classifier: Topic :: Software Development :: Debuggers
9
+ License-File: LICENSE
10
+ Summary: Fast external process memory library, written in Rust
11
+ License: MIT
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
14
+ Project-URL: Repository, https://github.com/alexsandrejr/peekmem
15
+
16
+ # peekmem
17
+
18
+ Leitura e escrita de memória de processo externo para Python, escrita em Rust.
19
+ Port parcial e modernizado do [pyMeow](https://github.com/qb-0/pyMeow) (Nim),
20
+ focado no módulo de memória — a parte de overlay fica com `raylib-rs`.
21
+
22
+ > Uso previsto: engenharia reversa, debugging, trainers de single-player e
23
+ > estudo de sistemas. Em jogos multiplayer online isso viola ToS e dá ban.
24
+
25
+ ```python
26
+ import peekmem as pk
27
+
28
+ proc = pk.Process.from_name("game.exe")
29
+ base = proc.module_base("client.dll")
30
+
31
+ hp = proc.read_f32(base + 0x10)
32
+ proc.write_f32(base + 0x10, 100.0)
33
+
34
+ pos = proc.read_vec3(base + 0x20) # 1 syscall para os 3 floats
35
+ hps = proc.read_batch_f32([base + 0x10, base + 0x90]) # agrupa syscalls
36
+ addr = proc.read_ptr_chain(base, [0x18, 0x40, 0x8])
37
+
38
+ hit = proc.aob_scan("48 8B 05 ?? ?? ?? ??", base, 0x100000)
39
+ hit = proc.aob_scan_module("client.dll", "48 8B 05 ?? ?? ?? ??") # modulo inteiro
40
+ ```
41
+
42
+ ## Decisões de performance
43
+
44
+ | Decisão | Por quê |
45
+ |---|---|
46
+ | `read_pod<T>` genérico com buffer na stack | zero alocação no heap por leitura |
47
+ | `PyBytes::new_bound_with` | escreve direto no buffer do objeto Python, sem cópia intermediária |
48
+ | `read_vec3` / `read_mat4` em uma leitura | 1 syscall em vez de 3 ou 16 |
49
+ | AOB scan: lê a região inteira de uma vez | 1 syscall em vez de N |
50
+ | AOB scan: âncora via `memchr` (SIMD) | pula a maior parte do buffer sem comparar |
51
+ | AOB scan dentro de `py.allow_threads` | libera o GIL durante trabalho CPU-bound |
52
+ | Cache de `module_base` | evita reenumerar módulos a cada chamada |
53
+ | `lto = "fat"`, `codegen-units = 1` | otimização entre crates no release |
54
+
55
+ Erros nunca são silenciosos: toda leitura/escrita parcial ou inválida levanta
56
+ `peekmem.MemoryError` com o endereço em hex e o erro do SO.
57
+
58
+ > Retomando o projeto? Leia **`COMECE-AQUI.md`** primeiro.
59
+
60
+ ## Estrutura
61
+
62
+ ```
63
+ peekmem/
64
+ ├── Cargo.toml # crate cdylib + perfil release agressivo
65
+ ├── pyproject.toml # build via maturin
66
+ ├── peekmem.pyi # type stubs (autocomplete no PyCharm)
67
+ ├── README.md
68
+ ├── COMECE-AQUI.md # estado atual e como continuar
69
+ ├── peekmem-plano.md # plano, decisões e roadmap detalhado
70
+ ├── tests/ # teste funcional ponta a ponta (46 casos)
71
+ └── src/
72
+ ├── lib.rs # #[pymodule], funções de nível de módulo
73
+ ├── raw.rs # FFI: Windows (windows-sys) e Linux (libc)
74
+ ├── process.rs # #[pyclass] Process + métodos tipados
75
+ ├── scan.rs # AOB / pattern scan com SIMD
76
+ └── error.rs # exceção peekmem.MemoryError
77
+ ```
78
+
79
+ ## Instalação
80
+
81
+ ```bash
82
+ pip install peekmem
83
+ ```
84
+
85
+ Wheel pronta para Windows x64 (Python 3.8+). No Linux o pip compila do fonte e
86
+ precisa de Rust; no Python 3.14+, use `PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1`.
87
+
88
+ ## Build
89
+
90
+ ```bash
91
+ pip install maturin
92
+ maturin develop # compila e instala no venv atual
93
+ maturin develop --release # com otimizações (use esse para medir perf)
94
+ cargo test --no-default-features # testes do parser/scan de padrão
95
+ ```
96
+
97
+ Para publicar:
98
+
99
+ ```bash
100
+ maturin build --release # gera a wheel em target/wheels/
101
+ ```
102
+
103
+ ## Plataformas
104
+
105
+ | | API usada |
106
+ |---|---|
107
+ | Windows | `OpenProcess`, `ReadProcessMemory`, `WriteProcessMemory`, `VirtualQueryEx`, ToolHelp32 |
108
+ | Linux | `process_vm_readv`, `process_vm_writev`, `/proc/<pid>/maps` |
109
+
110
+ No Linux pode ser necessário `sudo` ou ajustar `ptrace_scope`:
111
+
112
+ ```bash
113
+ sudo sysctl -w kernel.yama.ptrace_scope=0
114
+ ```
115
+
116
+ ## Status
117
+
118
+ Núcleo validado ponta a ponta no Linux: **46/46 testes funcionais passando**
119
+ contra um processo vivo (`tests/`), com leitura ~2,5 M ops/s e scan ~1,33 GB/s.
120
+ O caminho de Windows foi compilado e testado numa máquina Windows: 46/46 testes
121
+ funcionais passando (Python 3.12, MSVC).
122
+
123
+ Pendências no roadmap (`peekmem-plano.md`):
124
+
125
+ - [x] ~~validação funcional ponta a ponta~~ (Linux)
126
+ - [x] compilar e rodar os testes no Windows
127
+ - [x] batch de leitura (multi-iovec no Linux, agrupar contíguos no Windows)
128
+ - [x] enumeração de regiões para scan em módulo inteiro
129
+ - [ ] integração opcional com `raylib-rs` para overlay
130
+