🐍 Meet the new file identification package for Python!

Say hello to pure-magic-rs, the brand-new Python package that’s changing the game for file type detection!

✨ Safe – A reliable, pure Rust implementation of libmagic, ensuring high compatibility with existing magic rules.
🌍 Cross-Platform – No more headaches! Works seamlessly across all platforms without needing external dependencies or compiling C code.
📦 Self-Contained – Forget about managing external magic database files—it embeds its own, making setup a breeze.

Whether you're parsing unknown files, validating uploads, or building security tools, pure-magic-rs simplifies the process with safety, speed and accuracy.

Check it out and supercharge your file handling today: https://pypi.org/project/pure-magic-rs/

#Python #Rust #LibMagic #OpenSource

Client Challenge

📦 "New Crates Roll Into Town!"

Meet magic-rs—the safe, Rust-powered file detective with 99% libmagic superpowers! No unsafe, no excuses—just pure, speedy file type detection!

Five reasons to use it:
✨ 99 percent compatible with libmagic rules
💯 percent memory-safe
⚡ fast
🚚 embed rules (compile them INTO your binary)
🔧 extend it easily

The Squad:
- magic-rs – The brain: https://crates.io/crates/magic-rs
- magic-embed – The macro magician (embed rules at compile time): https://crates.io/crates/magic-embed
- magic-db – Pre-compiled rules: https://crates.io/crates/magic-db

Test Drive with wiza, the file command replacement using magic-rs: https://crates.io/crates/wiza

📣 Shoutouts:
@adulau my colleagues at @circl and the OG file/libmagic project

Check it out: https://github.com/qjerome/magic-rs

#rust #libmagic #opensource #programming

crates.io: Rust Package Registry

New secure re-implementation of libmagic by @0xrawsec is presented as a lighting talk at hack.lu.

  https://github.com/qjerome/magic-rs/tree/dev (currently in the dev branch)

#rust #libmagic #opensource #cybersecurity

GitHub - qjerome/magic-rs at dev

Pure Rust implementation of libmagic. Contribute to qjerome/magic-rs development by creating an account on GitHub.

GitHub

🚀 Porting libmagic to Rust: Safer File Identification 🚀

A little while ago (maybe a month or two), I started porting a great project to Rust: libmagic, the library behind the `file` command utility.

🤔 Why did I do that?
For years, I've faced the same issue with file identification: embedding a C library that does intensive parsing into my memory-safe code (Rust, Go, Python, etc.). While I trust the file/libmagic developer community's code quality, I know there are skilled people capable of finding and exploiting bugs—especially in C/C++ parsers. So I've always been reluctant to run libmagic on untrusted input, which creates a tricky situation that kind of defeats its original purpose: categorizing files you know nothing about.

🦀 Why Rust?
Rust is the perfect fit for this port. It provides strong safety guarantees while maintaining high performance and easy bindings to other languages (C/C++, Python, Go, Elixir, etc.). Bonus: the library and tool will be portable to all Rust-supported targets.

💻 Show me the code!
Here it is: https://github.com/qjerome/magic-rs/pull/1
⚠️ Note: This isn't a full implementation yet—it's still a work in progress and needs more work for a usable, clean version (see PR description). That said, if you're feeling adventurous, you can test it out. It already successfully identifies several file types: MS-DOS executables, ELF binaries, scripts, and more.

🔄 Compatibility with C libmagic file format?
This project aims for 99% compatibility with libmagic's rule file format. A few rules (such as those using ternary notations in messages) may need adjustments, but the goal is to stay true to the existing specification.

📌 What's next?
- Finalize the library implementation and publish a Rust crate
- Complete the CLI tool (a `file`-equivalent implementation)
- Create bindings for other languages

If you're interested in this work, don't hesitate to follow along or reach out!

Special thanks to @adulau and @circl for supporting this work! 🙏

#Rust #Libmagic #Security #OpenSource #Programming #SoftwareDevelopment

add: very first implementation by qjerome · Pull Request #1 · qjerome/magic-rs

This is early development branch so the code: may contain garbage may contain inconsistencies is lacking documentation does not contain all tests is lacking features / implementations is likely no...

GitHub

magika by google clearly outperform legacy file-matching libraries like libmagic and file utility but requires a python dependency. man at this point i hate doing pip for nuts, i am going no-dependency rule, but magic is 474443 bytes, libmagic.a is 38588 bytes. i should roll out my own for C

#libmagic #unix

Anyone out there wanting to use #libmagic on #Windows, and finding the situation quite unworkable, this seems like a decent parallel, I'll be taking it for a spin soon. https://github.com/cdgriffith/puremagic (and it's 100% #python !) I also like that you can kinda find polyglots by getting back all the ways a file could match, in confidence order.
GitHub - cdgriffith/puremagic: Pure python implementation of identifying files based off their magic numbers

Pure python implementation of identifying files based off their magic numbers - cdgriffith/puremagic

GitHub

Last for today, but certainly not least: Ange Albertini presenting "Understanding file type identifiers"
@Ange
Warning: contains raw bytes

#Magika

https://github.com/google/magika

#hacklu2024 @hack_lu #Yara
#LibMagic #TrID #Yara #Magika #PeID #Pronom #FDD #ShareMime #DiE

GitHub - google/magika: Fast and accurate AI powered file content types detection

Fast and accurate AI powered file content types detection - GitHub - google/magika: Fast and accurate AI powered file content types detection

GitHub
#Linux people, how often is the file / #libmagic database updated?