Tag: android

Fixing save file corruption in Ridiculous Fishing

Ridiculous Fishing is a game by Vlambeer about fishing. That's if you can call chainsawing fish and blowing them out of the sky with a bazooka "fishing".

I've been playing this game on and off for a while now, but just recently I had a problem where my save file somehow got corrupted, making the app refuse to open.

The problem first manifested as the game freezing for up to 5 seconds when navigating around the UI or buying items in the in-game store. Since I was running the game on a Nexus 5 (not the latest and greatest, but pretty close), it seemed weird. The delay got longer and longer until the game eventually crashed and refused to reopen.

Since I was pretty far into the game (I only needed to catch one more species of fish!), I opted to try to fix it instead of just wiping the app's data and starting again. I initially tried clearing the app's cache and reinstalling the app, but the problem persisted.

The next step was to dump the games's data to my computer so I could do some analysis on it. Some exploration on the device revealed that the settings and data were stored in the folder /data/data/com.vlambeer.RidiculousFishing.humble (I have the Humble Bundle version of the app).

To pull that folder to my current directory, I used ADB:

1
2
adb root #Restart adbd on the device with root permissions
adb pull /data/data/com.vlambeer.RidiculousFishing.humble/

A quick du -h revealed that something was very wrong in the files/Library/Preferences/com.vlambeer.RidiculousFishing.humble.plist file. It should've been just a text document, but was well over 200MB.

After trying out of habit to open the file in Vim and having it hang (oops), I paged through the document with less. About halfway through the file, there was a line containing &amp;lt;message&amp;gt;@eggbirdTBA Take it to the Smartypants Bar (no, that's not a formatting error, in the plist there's XML data stored in a <string> element, requiring the < and > characters to be escaped) followed by about 200MB of garbage.

Apparently there are ways to load huge files in Vim, as well as other text editors that handle them nicely, but since I already knew what line was causing the issue, a simple sed command would do the trick.

1
sed '/Take it to the Smartypants Bar/d' com.vlambeer.RidiculousFishing.humble.plist > temp.plist

Total size of temp.plist: 107.11KB. Much better.

After going though and deleting some lines around the one that was removed (to make the XML valid again), I pushed the file back to the device:

1
adb push temp.plist /data/data/com.vlambeer.RidiculousFishing.humble/files/Library/Preferences/com.vlambeer.RidiculousFishing.humble.plist

Success! The game opened properly, all the freezing issues were gone, and my save data was still there.

Now to find that stupid Mimic Fish...


Reinstalling an Android app without losing data

When an application isn't opening (and clearing the cache doesn't help) it sometimes helps to reinstall it. However, uninstalling then reinstalling the app normally will delete all the data associated with it.

The way around this is to directly call the package manager from the shell and give it the -k argument, which tells it to keep the data and cache directories.

Simply connect the device to a computer with ADB installed and run:

1
adb -d shell "pm uninstall -k com.package.name"

Then just reinstall the app (either from an apk file or the Play Store) and the app will be back with all of its data intact.


Preserving the Xposed Framework through a ROM flash

The Xposed Framework is a neat Android program that enables user-made modules to change the behaviour of the lower-level Android OS. It does this by modifying /system/bin/app_process to add some hooks into it.

The issue is that when flashing a new ROM, the modified app_process is reverted back to the original version, disabling the Xposed Framework until it's restored.

Update

The Xposed Framework installer now includes the option to flash a zip file to install the framework instead of patching app_process directly. The method detailed in this post will still work, but the new way to make sure the framework is installed after flashing a new ROM is to simply flash the Xposed installer zip right after flashing the ROM.

The solution to this is a script that will automatically back up the existing app_process before a flash, then restore it after the flash completes.

The 90-xposed.sh script does exactly that. To enable it, download it to the Android device, move it to /system/addon.d/90-xposed.sh, and give it executable permissions.

This can be done on the device with a few different programs, but it's much easier to do from a computer with adb.

Download the script and push it to the SD card of the Android device with

1
adb push 90-xposed.sh /sdcard/

Once the file is on the device, log into it (using adb shell) and run the following commands:

1
2
3
su  # Get root permissions
cp /sdcard/90-xposed.sh /system/addon.d/  # Copy the file to the correct folder
chmod 755 /system/addon.d/90-xposed.sh  # Make the file executable

After logging out of the device, the Xposed framework will stay installed and active even after flashing a new ROM. Note that this should only really be used in situations where the ROM isn't changing too much (like flashing a new nightly ROM).

In situations where app_process would actually be changed by the flash, this script could cause issues as it would restore an incorrect version of the file. If this happens, delete app_process and app_process.orig in the /system/bin/ directory, then reflash. The script won't interfere, allowing the flash to update app_process to the correct version. After rebooting, install the Xposed Framework again.

© Carey Metcalfe. Built using Pelican. Theme is subtle by Carey Metcalfe. Based on svbhack by Giulio Fidente.