Warning: State is stored in XML, chrs can change!

Monkey Targets Forums/Android/Warning: State is stored in XML, chrs can change!

Nobuyuki(Posted 2013) [#1]
This is a warning for you guys who want to encrypt their state data. If you are using a cycling XOR key type cipher, be sure to encode your output with base64 before saving it to the state file, because character conversion can occur when escaping certain reserved characters. Newline characters may also be escaped or converted, I haven't tested this for sure!

What this means is that saving an encrypted state without base64 encoding can (and will) eventually cause corruption of your state file. Don't risk it!


Soap(Posted 2013) [#2]
I wouldn't recommend using this. Would probably be better to Base64 the state in pure Monkey.

androidgame.java



Without modifying the target:


game.monkey



base64saveloadstate.monkey




native/base64saveloadstate.java




skid(Posted 2013) [#3]
I'm confused, if LoadState returns a String that is different from the one passed to SaveState shouldn't that be considered a bug in Monkey and some effort be made to post a bug report?


Soap(Posted 2013) [#4]
If I'm not mistaken any sort of data saved in monkeystate for Android, which XML would normally not like, must be modified into something safe, because the methods SharedPreferences uses will escape your data to be safe for saving into the XML file which may possibly lead to binary data corruption. It may only happen in special cases.

Anyone who doesn't save binary data into the state won't have the same problem with the Android target's monkeystate.


skid(Posted 2013) [#5]
I doubt the state commands have anything to do with it.

However the Android string constructor

  public String (int[] codePoints, int offset, int count) 


will throw an exception if you try and store illegal code points and Monkey should pass that exception on.

So no amount of mime64 encoding will fix a string that hasn't stored your int[] array to begin with if you see what I am getting at.

That and the API documentation for Android's SharedPreferences.Editor that Monkey uses in no way suggests it's inability to store and retrieve Strings in a lossless manner.


Soap(Posted 2013) [#6]
I will have to look more. Tested with Base64 as shown above and it did at least allow what was failing previous to work - SharedPreferences escaped a modified state and then failed to unescape it properly after loading it back, leading to corruption. Maybe an oversight. With Base64 inbetween it at least works.


skid(Posted 2013) [#7]
If that's the case I'll do some more looking too.


Soap(Posted 2013) [#8]
Unpatched androidgame.java doesn't work as expected and gives these warnings when attempting to load a saved modified state:



Patched works as desired and gives no warnings. Still looking more.

This is what I was testing with + random JSON data: http://www.monkeycoder.co.nz/Community/posts.php?topic=5061


Soap(Posted 2013) [#9]
(This forum software makes double posting too easy.)


dragon(Posted 2013) [#10]
state is saved in xml?


Soap(Posted 2013) [#11]
For Android target, yes. You don't actually have to worry about the XML part. That's just the container.

/data/data/com.monkey/shared_prefs/com.monkey_preferences.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name=".monkeystate">state goes here</string>
</map>