Skip to content

Improve value argument to accept hex, binary, and octal literals (#4)#5

Open
p0dalirius wants to merge 1 commit intomainfrom
enhancement-hex-binary-input
Open

Improve value argument to accept hex, binary, and octal literals (#4)#5
p0dalirius wants to merge 1 commit intomainfrom
enhancement-hex-binary-input

Conversation

@p0dalirius
Copy link
Copy Markdown
Owner

Linked Issue

Closes #4

Motivation

userAccountControl and sAMAccountType are almost always displayed in hexadecimal in Windows/AD tooling and Microsoft documentation (e.g. 0x200, 0x30000001). The decoder previously accepted decimal only, forcing users to convert before running it. This change removes that friction by letting the CLI consume any standard Python integer literal.

What Changed

  • Replaced int(options.value) with int(options.value, 0) and centralised the parse in a single try/except at the top of the __main__ block. int(x, 0) auto-detects the base from the 0x / 0b / 0o / no-prefix form.
  • Removed the two per-branch options.value = int(options.value) lines that are now redundant.
  • On parse failure, prints [!] Invalid value <repr>: expected an integer (decimal, 0x… hex, 0b… binary, or 0o… octal) and exits with status code 1, instead of crashing with a ValueError traceback.
  • Added a short line to README.md documenting that hex/binary/octal values are accepted.

Design Notes

int(x, 0) is a superset of int(x) for every previously accepted value — plain decimal digits still parse the same way. No change to the decoding logic itself was required. The friendly error path also covers the crash seen in #2; this PR and the PR against #2 touch the same region, so whichever lands first will make the other a trivial rebase.

Acceptance Criteria Check

  • ./msFlagsDecoder.py userAccountControl 0x200 matches ./msFlagsDecoder.py userAccountControl 512 — verified below.
  • ./msFlagsDecoder.py sAMAccountType 0x30000000 matches ./msFlagsDecoder.py sAMAccountType 805306368 — verified below.
  • ./msFlagsDecoder.py userAccountControl 0b1000000000 matches ./msFlagsDecoder.py userAccountControl 512 — verified below.
  • abc / 0xZZ produce a concise error message and non-zero exit status — verified below.
  • README mentions hex/binary values are accepted — see diff in README.md.

How Verified

Runtime:

$ ./msFlagsDecoder.py userAccountControl 0x200
[>] userAccountControl value       : 0x200
  | NORMAL_ACCOUNT                 : It's a default account type that represents a typical user.

$ ./msFlagsDecoder.py userAccountControl 512
[>] userAccountControl value       : 0x200
  | NORMAL_ACCOUNT                 : It's a default account type that represents a typical user.

$ ./msFlagsDecoder.py userAccountControl 0b1000000000
[>] userAccountControl value       : 0x200
  | NORMAL_ACCOUNT                 : It's a default account type that represents a typical user.

$ ./msFlagsDecoder.py sAMAccountType 0x30000000
[>] sAMAccountType value      : 0x30000000
  | SAM_USER_OBJECT           : Represents a user object.

$ ./msFlagsDecoder.py userAccountControl abc
[!] Invalid value 'abc': expected an integer (decimal, 0x… hex, 0b… binary, or 0o… octal)
$ echo $?
1

$ ./msFlagsDecoder.py userAccountControl 0xZZ
[!] Invalid value '0xZZ': expected an integer (decimal, 0x… hex, 0b… binary, or 0o… octal)
$ echo $?
1

Test Coverage

None: repository has no automated test suite; behaviour is verified via the runtime checks above. Adding a test harness is out of scope for this enhancement.

Scope of Change

  • Files changed: msFlagsDecoder.py, README.md
  • Submodule pointer updated: no
  • Public API changes: additive — the CLI now accepts a strictly larger set of value strings; all previously valid inputs still produce identical output.
  • Behavioral changes outside the stated enhancement: none

Risk and Rollout

Local change limited to the CLI entry point and the usage note in the README. No existing input regresses. Safe to merge without staged rollout.

Notes

Overlaps with issue #2 / PR #3: both sit on the same three lines. Merging either one first makes the other a trivial rebase.

@p0dalirius p0dalirius self-assigned this Apr 18, 2026
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.

Accept hexadecimal, binary, and octal notation for the value argument

1 participant