Obviously Mathematica is able to remove this attribute; it's just not letting me. Does anyone know of any hacks to force Mathematica to do what I say?
-
"`Locked` is an attribute that, once assigned, prevents modification of any attributes of a symbol" I don't know why you say it is "obviously able to remove this attribute". Perhaps you want to remove `ReadProtected` instead? Just explain what you want to do. – Szabolcs Mar 19 '12 at 06:36
-
@Szabolcs I assume he is trying to circumvent *Mathematica's* security measures. – Mr.Wizard Mar 19 '12 at 15:35
-
Why? What are you trying to accomplish by doing this? – rcollyer Mar 19 '12 at 15:44
-
6Because it's my computer, not Wolfram's. I just want to know I'll be able to if I ever need to. – flarn2006 Mar 20 '12 at 00:03
1 Answers
This is not a positive answer.
One particular use case that might require removing the Locked
attribute would be the local modification of a symbol with e.g. Internal`InheritedBlock
. Often this scoping construct is used to change/remove attributes locally of system symbols, to yield a different behaviour for the scope of the block (see for example this answer).
However, according to my research, out of the 38 Locked
symbols (out of all contexts and packages loaded with Quiet[Needs /@ Contexts[]]
!) none have any other functional attributes that, if changed, would result in modified behaviour (e.g. no Flat
, Orderless
, Hold***
, etc.) and none of them have any Options
that could be changed. Usually these symbols are very basic ones, almost all from the System`
context e.g. I
, List
or True
. The only 3 exceptions having either functional attributes or options are:
(* Symbol *) (* Attributes *) (* Options *)
Remove {HoldAll, Locked, Protected} {}
$ProductInformation {Locked, Protected} {"ProductIDName" -> "Mathematica", "ProductKernelName" -> "Mathematica 9 Kernel", "ProductVersion" -> "9.0 for Microsoft Windows (64-bit) (January 25, 2013)", "ProductVersionNumber" -> 9.}
Developer`StartProtectedMode {Locked, Protected} {"Allow" -> Null, "Deny" -> Null, "Execute" -> {}, "Read" -> {}, "ReadWrite" -> {}, "Write" -> {}}
So apart from modifying these remotely used functions, the only reason one would want to remove Locked
is to directly modify some symbol's definitions. But this could only be performed if symbol also is ReadProtected
, otherwise the code is written in lower-than-Mathematica-level that is completely hidden from the user (except perhaps high-level wrappers). There are only three such symbols (again, out of all standard contexts and packages):
I (* with {Locked, Protected, ReadProtected} *)
$InputStreamMethods (* with {Locked, Protected, ReadProtected} *)
$OutputStreamMethods (* with {Locked, Protected, ReadProtected} *)
As a conclusion, I would say removing Locked
wouldn't really give any advantage on exploring/modifying function internals for a great many functions, and also changing behaviour of such fundamental functions as I
or $Input
seems to be a very bad idea, so no one is likely to invest too much time in figuring out a hack.
Furthermore, since Locked
itself has the attribute Locked
(since v9, in v8 it was only Protected
), it cannot be redefined to e.g. Locked = Sequence[]
before loading a package to bypass security even for encrypted stuff. One could redefine Attributes
and SetAttributes
before loading packages, but god knows what could go wrong if done so.
Of course if the function is a packaged one and the package files are available and not encoded, one can remove attributes manually by editing the files directly. But according to my experience, the common tradition is that functions that are freely explorable in packages are not Locked
.

- 1
- 1

- 1,343
- 2
- 13
- 31
-
1Wow, I didn't think there'd actually ever be a decent answer posted here. In the mean time, I posted on my blog (http://flarn2006.blogspot.com/2013/02/disabling-mathematicas-locked-attribute.html) about this, including that `Sequence[]` suggestion you made. For Mathematica 9, you can still manually rename the Locked attribute in `mathdll.dll`, so it would just be treated as an invalid attribute. – flarn2006 Oct 10 '13 at 06:51
-
Ahh, sorry, I did not realize it was your blog: I have found it, even included it in the answer and then removed due to a [chat discussion](http://chat.stackexchange.com/transcript/message/11536692#11536692) over *Mathematica*.SE not to raise tensions. – István Zachar Oct 10 '13 at 06:59
-
@flarn2006 I think its very questionable to share such information in public since it is security relevant. If one does not want you to see his code, because its his own intellectual property, you should respect this. Your question seems to aim at reading out definitions of encoded packages, rather than learning something about build in functions or any legal use of it. I can understand your hacking attitudes, but please dont share this in public. – sacratus Apr 09 '15 at 04:08
-
4@sacratus Thanks for your feedback, but I don't share your opinion on the matter, and I do not intend to stop sharing this type of information. If my computer has access to something, I believe I should be able to see it as well. My opinion is that the wishes of the device owner take precedence over those of the software developer. (And yes, I think the same if it's my code running on someone else's computer.) Sorry if that disappoints you! – flarn2006 Apr 10 '15 at 05:26
-
Any way to remove Locked from newer versions of Mathematica? I want to test some non-strict evaluation strategies which would require adding the `HoldAll` attribute to `List`. – user3257842 Oct 07 '22 at 13:17