Skip to content

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

@p0dalirius

Description

@p0dalirius

Summary

Allow the value positional argument to be provided in any of the standard Python integer literal bases (decimal, hexadecimal 0x…, binary 0b…, octal 0o…) rather than decimal only.

Motivation

Windows tooling and documentation display both userAccountControl and sAMAccountType values in hexadecimal almost exclusively (e.g. 0x200, 0x30000001). Today the decoder only accepts base-10 integers, so analysts have to mentally or manually convert hex values they pulled from AD, from LDAP queries, or from Microsoft docs before they can feed them to the tool. Binary input is likewise natural for bit-masking work. Supporting Python's usual 0x/0b/0o prefixes removes that friction and matches how these values are actually written in the wild.

Proposed Change

Parse the value argument with automatic base detection so that any prefixed literal is accepted. Plain decimal continues to work unchanged. The existing friendly error path on unparsable input remains the same.

Scope

  • File(s) / package(s) expected to change: msFlagsDecoder.py
  • Public API surface affected: yes — the CLI accepts a strictly larger set of value strings; all previously accepted inputs still work identically.

Category

ergonomics

Priority

medium

Acceptance Criteria

  • ./msFlagsDecoder.py userAccountControl 0x200 prints the same decoded output as ./msFlagsDecoder.py userAccountControl 512.
  • ./msFlagsDecoder.py sAMAccountType 0x30000000 prints the same decoded output as ./msFlagsDecoder.py sAMAccountType 805306368.
  • ./msFlagsDecoder.py userAccountControl 0b1000000000 prints the same decoded output as ./msFlagsDecoder.py userAccountControl 512.
  • Invalid strings (e.g. abc, 0xZZ) still produce a concise error message and a non-zero exit code rather than a traceback.
  • README usage section mentions that hex/binary values are accepted.

Alternatives Considered

  • Adding an explicit --hex flag. Rejected: increases CLI surface area and still forces the user to think about base up front. int(x, 0) covers all three common bases transparently.

Notes

Implementation sketch: replace int(options.value) with int(options.value, 0) at the top of the __main__ block. No change to the decoding logic is required.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions