2

I need a function to deserialize the contents of an MX source file for reading. We can’t simply use Get because I don’t want to load or run the code, but rather to read whatever in the file? Is there such a function in existence, if not how could we write this UnscrambleSourceMXFile[], if this is even possible?

user5601
  • 3,573
  • 2
  • 24
  • 56
  • 8
    I mean, in general no. That’s part of why one would put the source in an MX file. And if it’s Locked and ReadProtected there’s absolutely no way. On the other hand, if you know what symbols are declared in the MX file you can use GeneralUtilities`PrintDefinitionsLocal to see the definitions of those. – b3m2a1 Dec 13 '19 at 17:32
  • 2
    I am not sure about this, but I always suspected that this is not possible with MX files as they directly encode in-memory definitions. In fact, MX files cannot even contain a plain expression. All they can contain is assigned definitions. When you Export a plain expression to MX, it will first be assigned to special internal symbol, then this symbol is DumpSaved. Import will Get the file, then check the definition of that symbol. – Szabolcs Dec 13 '19 at 21:00
  • 2
    This is very different from other serializations such as an .m file, Compress or sending through MathLink. All those encode a plain expression. If that expression is evaluated, that can in turn create definitions. I think MX is the opposite: it just saves the kernel state associated with some symbols. – Szabolcs Dec 13 '19 at 21:02

0 Answers0