Skip to content

Added $mem for converting MB to lhex and vise-versa#160

Open
chrisdodgers wants to merge 2 commits into
corpnewt:rewritefrom
chrisdodgers:rewrite
Open

Added $mem for converting MB to lhex and vise-versa#160
chrisdodgers wants to merge 2 commits into
corpnewt:rewritefrom
chrisdodgers:rewrite

Conversation

@chrisdodgers

Copy link
Copy Markdown

Can also be used with the following aliases: $fbmem, $stolenmem, $unifiedmem, and $cursormem.

Usage example:
$stolenmem 26m

$fbmem 00009000

$mem 0x00000006

$cursormem 1MB

Screenshot 2026-03-23 at 12 29 17 AM Screenshot 2026-03-23 at 12 33 42 AM

Aliases also include $fbmem, $stolenmem, $unifiedmem, $cursormem

Usage example:
$stolenmem 26m
$fbmem 00009000
- Removed `mib = [“mib”, “mb”, “m”]` as it is unnecessarily redundant. Just checking for if `”m”` exists in the input value serves the same expected results determining if dealing with MiB input .

- Removed `is_lhex`. Kind of pointless as if the input value doesn’t fall under `is_mib`, just assume its lhex. Any bad input values resulting in an error would just be caught in the try/except.

- Removed the unnecessary string comparisons of `from_type` and `to_type`. Conversion logic for MiB -> lhex happens now in `if is_mib`, and `else` we do lhex -> MiB.

- Removed the regex handling in `num` to strip `mib` from the input value. Instead, just simply only storing `0-9` and `.` in the float and ignoring any other character that may be in the input value.

- Cleaned up the calculation for `bytes_val` by using `num * 1024 ** 2` instead of `num * 1024 *1024`. (And cleaned this up likewise in `mib_val`).

- Removed `hex_val` and instead directly feeding `bytes_val` to `_convert_value` using `decimal` to `lhex32`. Using `lhex32` instead of originally `lhex` replaces the previous need of pre-formatting to get proper padding.

- Removed the use of Nullify. The output of `_convert_value()` is already sanitized and can be fed directly to the ctx. Also it is not needed in the particular response in `except Exception`.

Huge credit and thanks to @corpnewt for these clean up suggestions and points I originally overlooked.
@chrisdodgers

chrisdodgers commented Mar 25, 2026

Copy link
Copy Markdown
Author
  • Removed mib = [“mib”, “mb”, “m”] as it is unnecessarily redundant. Just checking for if ”m” exists in the input value serves the same expected results determining if dealing with MiB input .
  • Removed is_lhex. Kind of pointless as if the input value doesn’t fall under is_mib, just assume its lhex. Any bad input values resulting in an error would just be caught in the try/except.
  • Removed the unnecessary string comparisons of from_type and to_type. Conversion logic for MiB -> lhex happens now in if is_mib, and else we do lhex -> MiB.
  • Removed the regex handling in num to strip mib from the input value. Instead, just simply only storing 0-9 and . in the float and ignoring any other character that may be in the input value.
  • Cleaned up the calculation for bytes_val by using num * 1024 ** 2 instead of num * 1024 *1024. (And cleaned this up likewise in mib_val).
  • Removed hex_val and instead directly feeding bytes_val to _convert_value using decimal to lhex32. Using lhex32 instead of originally lhex replaces the previous need of pre-formatting to get proper padding.
  • Removed the use of Nullify. The output of _convert_value() is already sanitized and can be fed directly to the ctx. Also it is not needed in the particular response in except Exception.

Huge credit and thanks to @corpnewt for these clean up suggestions and for pointing out things I originally overlooked.

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