Skip to content

magic :: code clean up and documentation - #1524

Open
dev-mlb wants to merge 2 commits into
NationalSecurityAgency:mainfrom
dev-mlb:feature/filemagic
Open

magic :: code clean up and documentation#1524
dev-mlb wants to merge 2 commits into
NationalSecurityAgency:mainfrom
dev-mlb:feature/filemagic

Conversation

@dev-mlb

@dev-mlb dev-mlb commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

This update continues modernizing our magic file processing logic, focusing on code cleanup, immutability, and documentation. Key improvements include:

  • Immutability & Safety: Converted mutable rule objects (MagicNumber) into read-only, parser-built structures.
  • Cleaner Data Types: Replaced legacy magic numbers with the new MagicDataType enum for self-documenting names, sizes, and byte orders.
  • Streamlined Logic: Consolidated comparison logic into a single location and refactored the escape-sequence decoder (replacing a 256-row lookup table with a switch statement and removing 3 unused methods).
  • Bug Fix: Fixed an issue where two UnixFile constructors accidentally loaded rules into a throwaway object, leaving zero detection rules (now properly chained).
  • Documentation: Thoroughly updated Javadocs, comments, and the package-info comparison matrix.

@dev-mlb dev-mlb changed the title magic :: code clean up and documentation [draft] magic :: code clean up and documentation Aug 25, 2026
@dev-mlb dev-mlb changed the title [draft] magic :: code clean up and documentation magic :: code clean up and documentation Aug 25, 2026
@cfkoehler cfkoehler added the enhancement An enhancement or update to an existing feature label Sep 1, 2026
@cfkoehler cfkoehler added this to the v8.50.0 milestone Sep 1, 2026
BELONG("BELONG", 6, 4),

/** A 4-byte big-endian date stamp, skipped by the parser. */
BEDATE("BEDATE", 7, 4),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change BEDATE becomes a supported type right? Just double checking

main:  '0 bedate 0x41424344 FOO' -> ParseException: Unsupported Data Type: bedate
1424:  '0 bedate 0x41424344 FOO' -> OK: 0     BEDATE  =0x41424344     FOO

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this change is just moving some things around and attempting to start code clean up. All behavior should be as before. Follow on changes will actually add support for more types. These types were moved to this enum from MagicNumber.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cfkoehler Instead of this code cleanup pr, maybe I should add more testing first to exercise what's there? That way we can sift thru what's implemented fully and what errors out. This can serve as a follow on pr to that. Thoughts?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will help. Thanks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making note of the protected -> private scope changes. Not sure the impact of that downstream.

Comment thread src/main/java/emissary/util/magic/MagicNumber.java Outdated
Comment thread src/main/java/emissary/util/magic/MagicNumber.java Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or update to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants