Adding Bytes Using a Hex Editor
-
30-04-2021 - |
質問
Due to incompatibility of root account and sandbox, I need to manually disable sandboxing of MS Office applications (so that it can be activated) by changing the value of com.apple.security.app-sandbox
within the application binary (/Applications/Microsoft Word.app/Contents/MacOS/Microsoft Word
) from <true/>
to <false/>
.
However, this change would lead the addition of a byte, and I can't find any documentation on how to insert a byte. I'm using hexedit
, installed with brew (brew install hexedit
).
Also, if someone can provide a script to automatically detect and edit that flag, that will be great. Here is an excerpt:
解決
You don't need additional software for this, the standard vi
installed by macOS can edit binary files.
cd /Applications/Microsoft\ Word.app/Contents/MacOS/
cp Microsoft\ Word Microsoft\ Word.orig
vi -b Microsoft\ Word
Now, assuming you are not used to vi
:
- Type
/app-sandbox
followed by Return to jump to the definition you want to change
- Press Return again to move the cursor to the next line
- Type
ct/<false
followed by ESC
- Type
ZZ
to save and quit
PS: If you get stuck within vi
, press ESC twice and then type :q!
to quit without saving.
If you want to script this, use (at our own risk)
vi -b Microsoft\ Word '+/app-sandbox/+1s/true/false/' '+wq'
which basically does the same thing as the interactive sequence above in one go.
/app-sandbox/+1
makes the following command (the substitution) only apply on the line after the one containing theapp-sandbox
strings/true/false/
is the substitution and replacestrue
byfalse
wq
writes the modified file back to disk and quits