Skip to content

feat: make bufflength optional on write and search methods#42

Merged
JeanExtreme002 merged 1 commit into
mainfrom
jeanextreme002/optional-bufflength
Jun 4, 2026
Merged

feat: make bufflength optional on write and search methods#42
JeanExtreme002 merged 1 commit into
mainfrom
jeanextreme002/optional-bufflength

Conversation

@JeanExtreme002
Copy link
Copy Markdown
Owner

Summary

bufflength is now optional (defaults to None) on write_process_memory, search_by_value, search_by_value_between and search_by_addresses. Previously it was a required positional parameter sitting before the value, forcing calls like write_process_memory(addr, str, None, "hi"). Now you can simply write:

process.write_process_memory(addr, str, value="hi")
process.search_by_value(int, value=100)
process.search_by_value_between(int, start=10, end=20)
process.search_by_addresses(int, addresses=[0x1000, 0x1004])

Behavior

  • Numeric types (int/float/bool) fall back to their default width (4/8/1) when bufflength is omitted.
  • str/bytes on search_by_value / search_by_value_between infer the width from the value being searched (UTF-8 for str; the longer endpoint for a range search).
  • search_by_addresses still requires an explicit size for str/bytes — there is no value to infer the width from, only addresses to read (same as read_process_memory).
  • A new UNSET sentinel keeps value / start / end / addresses required while bufflength carries a default; omitting them raises a clear TypeError.
  • Positional calls keep working unchangedwrite_process_memory(addr, int, 4, 99) and search_by_value(int, 4, 100) are fully backward compatible.

Changes

  • util/convert.py: UNSET sentinel and resolve_bufflength_for_value helper; prepare_write validates a missing value.
  • process/abstract.py + win32/linux/macos backends: optional bufflength, sentinel-defaulted required args, updated docstrings.
  • Docs (read-write, searching, openprocess, index) updated; no more positional-None examples.
  • Tests added covering keyword calls, str/bytes inference, positional backward compatibility, and the missing-argument errors.

Verification

  • make type-check (mypy): clean.
  • Relevant test suite: 93 passed, 4 skipped (platform-specific).

bufflength now defaults to None on write_process_memory, search_by_value,
search_by_value_between and search_by_addresses, so the value/addresses can
be passed by keyword without a placeholder None.

- numeric types fall back to their default width (int->4, float->8, bool->1)
- str/bytes infer the width from the value on search_by_value/_between
  (search_by_addresses still needs an explicit size: no value to measure)
- a new UNSET sentinel keeps value/start/end/addresses required while
  bufflength has a default; a clear error is raised when they are omitted
- positional calls keep working unchanged

Docs and tests updated accordingly.
@JeanExtreme002 JeanExtreme002 merged commit adc9e79 into main Jun 4, 2026
12 checks passed
@github-actions github-actions Bot deleted the jeanextreme002/optional-bufflength branch June 4, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant