Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If I have a variable, how do I turn it into a list of bytes or a string containing its value as it's stored internally? To better illustrate what I mean, what I want to do could be done in C with (char*)&variable, and then indexing the resulting pointer as an array. In case I wasn't clear enough before, what I want is the value in its internal form as Mathematica stores it.

For anyone asking why I need this, say there's a package I have that was encoded using the Encode function. I want to view the code for a function in the package, but that function's attributes are {ReadProtected, Locked}. If I knew the way that list was stored internally however, I could search for that data in the kernel's memory and replace it with an empty list, allowing me to view the code. In case anyone's wondering, I don't actually have a package I need to view the code of right now, but I'd like to know I can do it if I want to.

share|improve this question
7  
Since the internal structure of Mathematica expressions is not documented, it's not clear to me how this could be useful, and moreover, it's by no means guaranteed that a given expression will be contiguous in memory as you apparently expect. Indeed, most complicated expressions probably will not be, and chasing the pointers will most likely prove difficult since you won't know which values are pointers or what structures they point to. With that said, I think you might be able to do this in C via LibraryLink, but I'm not sure how this might work in practice as I haven't tried it myself. – Oleksandr R. Jan 6 at 4:40
What goal are you trying to achieve by this method of access? – image_doctor Jan 6 at 9:10
If the variable is in a CompiledFunction which is compiled on the Wolfram Virtual Machine, then there are some informations on the register level can be get by analyzing the CompiledFunction. See documentation of CompilePrint for more details. – Silvia Jan 6 at 11:39
1  
Due to your stated motivation you probably will not receive an answer, and as you can see the question has already attracted close votes. We discussed this issue in the past, and reached a consensus that it would be harmful to the Mathematica community if any of us would disclose methods to break Encode. Not only is it likely to raise WRI's ire, but also this is the only practical method available to third party package developers to protect their code. As such, to answer would both risk losing WRI's support for our efforts here and actively discourage third party package development. – Oleksandr R. Jan 8 at 10:26
"[...] this is the only practical method available to third party package developers to protect their code." That's their problem, not mine. (It is my computer, after all...) – flarn2006 Feb 3 at 6:35
show 1 more comment

closed as not constructive by belisarius, nikie, Oleksandr R., Simon Woods, Sjoerd C. de Vries Jan 9 at 19:09

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

Browse other questions tagged or ask your own question.