2016-07-31

Network is gone on a server: "r8169 0000:03:00.0: eth0: link up"

I got this one lately a few times (after putting millions of connections/queries to a MySQL server):

Jul 31 12:01:25 mysql-data-node1 kernel: [76159.918858] r8169 0000:03:00.0: eth0: link up
Jul 31 12:01:25 mysql-data-node1 kernel: [76159.990707] r8169 0000:03:00.0: eth0: link up
Jul 31 12:01:56 mysql-data-node1 kernel: [76190.838088] r8169 0000:03:00.0: eth0: link up

Found the answer here.

Copy/Paste for posterity: [I also added the download here, in case it gets removed]

cd /usr/src
wget http://djlab.com/stuff/r8168-8.032.00.tar.bz2
tar jxvf r8168-8.032.00.tar.bz2
cd r8168-8.032.00
make clean modules
make install
depmod -a
echo "blacklist r8169" >> /etc/modprobe.d/blacklist-network.conf
update-initramfs -u
apt-get install dkms gcc

cat < /usr/src/r8168-8.032.00/dkms.conf
PACKAGE_NAME=r8168
PACKAGE_VERSION=8.032.00
MAKE[0]="'make'"
BUILT_MODULE_NAME[0]=r8168
BUILT_MODULE_LOCATION[0]="src/"
DEST_MODULE_LOCATION[0]="/kernel/updates/dkms"
AUTOINSTALL="YES"
EOF
dkms add -m r8168 -v 8.032.00
dkms build -m r8168 -v 8.032.00
dkms install -m r8168 -v 8.032.00 --force

Then, reboot the box and check which driver you’re using with ‘ethtool -i eth0’. It should now be r8168 instead of r8169:
driver: r8168
version: 8.032.00-NAPI
firmware-version:
bus-info: 0000:01:00.0



2016-06-28

How to change an asset (not a classes.dex file) in an Android APK

- You will need to have root on your phone (this is easy to find online).
- Don't expect me to tell you how to modify the classes.dex file. That's also easy to find.
- You'll need the Java JDK (not JRE)!

1. Extract the APK [Tools: WinRAR].
2. Change/Add the asset you want. In my case it was a .NET dll which I 'adjusted' to give unlimited search tool & energy [Tools: Reflector + Reflexil]
3. Open the original APK, and change the asset.
4. Go to META-INF in the APK file, and delete all *.RSA, *.SF files (1 file left: manifest.mf).
5. Get a key:
"C:\Program Files (x86)\Java\jdk1.8.0_91\bin\keytool" -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

6. Sign the APK:
"C:\Program Files\Java\jdk1.8.0_91\bin\jarsigner" -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore com.wooga.pearlsperil-1.apk alias_name

7. Upload it to your phone somehow
8. Log in via SSH (find out online how to do that)
9. su - [to really get root]
10. pm install


Tadaaa :-).

2016-01-22

Debugging an Android app with IDA Pro

I decided to write about this as I had to piece this together from countless online sources, help from IDA support and a few friends.

So here it goes.


Steps (I can forget something here, so please use the comments if you miss something)

* A rooted Android phone (check for example http://www.androidcentral.com/root -- use a slightly older model to be certain).
* Once rooted, install SSH server on it (I used https://play.google.com/store/apps/details?id=com.icecoldapps.sshserver&hl=en). Inside this app, create an SSH server with an as long as possible timeout value.
* Log into your SSH server (normal log information is root/admin), and go to /data/app, and copy your apk file to /mnt/sdcard. [ you probably need to do "su -" to fully gain root ]
* Download it on your Windows PC. (I use WinSCP)
* Next thing you need is apktool (https://ibotpeaches.github.io/Apktool/)
     apktool -d
* re-package with debugging enabled:
     apktool -b -d
* sign the apk (I don't know if this step is necessary, but I did it, and the final result worked, so :)). [https://github.com/appium/sign - I found a download at: http://www.learn2crack.com/2014/02/sign-android-apk-zip.html]
   java -jar signapk.jar testkey.x509.pem testkey.pk8
* install Android SDK (you will only need the SDK tools: http://developer.android.com/sdk/index.html#Other)
* See that adb.exe can be found in your PATH environment variable!
* adb devices -l
* adb install [ I made sure that the official app was first uninstalled ]
* enable USB debugging (https://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm)
 --> I also set to keep awake while charging
 --> + set the debug application to the one you just installed (your own debuggable version)
* Copy/Start android server into the Android device (for me it was in C:\Program Files (x86)\IDA 6.9\dbgsrv\android_server).
[ from: https://www.trustwave.com/Resources/SpiderLabs-Blog/Debugging-Android-Libraries-using-IDA/]
adb remount
adb push android_server /system/
adb shell
su (probably not needed for the emulator but is necessary if doing this on a rooted device)
cd /system
chmod 755 android_server
./android_server



now fire up 2 IDA's

IDA 1: load the signed APK file & point to the classes.dex
- Debugger > Debugger Options > Set Specific Options:
  * emulator (got that from adb devices)
  * click "fill" button
  * adb.exe should be auto-found.
- put your breakpoints
- change the default port in “Debugger/Process options” to any other value.
- start the Dalvik debugger and wait until breakpoint is hit.

IDA 2: load the signed APK file & point to the JNI file (generally under /lib/armeabi*/*.so
- put your breakpoints
- select "remote arm linux/android debugger"
  * Debugger > Process Options: set everything OK here (no need to concern with the paths, just ip & port). I left the local file in there, and it asked me if this was the same (it was). So all ok there.
- debugger > attach to process (select the process)
- it will break on entry. So just say "run (F9)".

IDA 1: F8 to call the native function

IDA 2: here your breakpoint should have triggered.



That's all :-).


Other sources:
https://www.trustwave.com/Resources/SpiderLabs-Blog/Debugging-Android-Libraries-using-IDA/
http://www.hexblog.com/?p=809
http://bbs.pediy.com/showthread.php?t=138472
http://www.asciitable.com/

2014-01-12

Tap Paradise Cove: the internals

First, let me give thanks for this: GirlPlaysGame.
Read the site before continuing here. You'll get an idea of what is possible.


At least it got me started. And no, still no JailBreak is needed to do this.


Tap Paradise Cove is an enjoyable game, but it is WAY too greedy!! I mean, you need to spend at least €100 a month to be able to play comfortably... In my opinion: way too much. Plus you can't achieve everything with a lot of patience... Also a bad no no. Ok, make it difficult, but not impossible you know.

Lucky for us most of the information is stored on the iPad (well, their systems would overload I think if everyone logging on needed to download/upload a 1 mega database all the time :)).

Necessary utils: iFunBox, some kind SQLite database utility, PHP or something alike.

This is not a step-by-step guide. Just a brain dump of what I found out and what is working with the most current version as of January 2014.

What did I discover?
- A lot of interesting files are present in \Library\Application Support\resources
- If you want to add something, watch out for the metadata table. See that the Z_PK value of the table you changed (this will likely be zgameobject) match the Z_PRIMARYKEY table. This should contain the maximum value.
- in most tables you'll have a ZWORLD parameter. 0 = main world, 1 = atlantis, 2 = asgard. Watch out. Sometimes it's something like "0;1;2" or with a comma. Just watch out by using an update there.
- Always create a backup of your survivor.sqlite file before you start messing things up! (I generally do copy/paste in the same dir & remove them after a while).

- Pirates can be reset (when defeated) by setting ZCURRENTHEALTHPERCENTAGE=1.0, ZTIMEOFLASTDAMAGE=0. If you want to go fast in a quest to defeat someone till level xxx. Just set the ZCURRENTLEVEL to 1 level lower (for example if the quest is to defeat him at level 5, set it at 4, defeat him & you've completed the quest). [Check Fleets.csv for the ZFLEETIDENTIFIER/ZPIRATEIDENTIFIER]
update ZPIRATE
set ZCURRENTHEALTHPERCENTAGE=1.0, ZTIMEOFLASTDAMAGE=0
WHERE ZCURRENTHEALTHPERCENTAGE != 1.0 and zfleetidentifier=299;

- There are some special ruby decorations. Well, if you don't want to pay for them (199 rubies)... Why you don't just make them (well, you don't need them anyhow as I will show you later on)?
Find a good x/y coordinates on the map and place them (my personal favorite is 'sugarplum', it's small and nets 4 rubies in 4 days). [Check Decorations.csv for others, check for 'rubies' - keep in mind the size!]
To fasten ruby generation:
update zgameobject
set ZTIMEATWHICHOBJECTWILLBECOMEHARVESTABLENUM=strftime('%s', 'now')
where z_ent=21 and zcanpayoutnum=1;

- You feel powerless? Like can't beat any pirate? Why don't you just upgrade your ships? Or downgrade them for whatever reason necessary? zupgradecount1 45 means fully upgraded for a ship. For a shop that is zupgradecount (mind the missing 1) 25.
update zgameobject
set zupgradecount1=45
where z_ent=27;
- You've been beaten by a pirate, and just want to repair all your ships? No stress :-)
update zgameobject
set ZREPAIRENDTIMENUM=0, ZISCURRENTLYREPAIREDATDOCKNUM=0,ZCURRENTHEALTHPERCENTAGE=1.0
where z_ent=27;

- Expanding land? Tired of waiting 4 hours, and don't want to waste any rubies?
update ZBUILDABLEAREA
set ZEXPANSIONCOMPLETETIMESTAMP=strftime('%s', 'now')
where ZEXPANSIONSTATE=2;

- Or you just want to expand all the available land at once? Remember, you still got to chop trees/seaweed!
ZEXPANSIONSTATE = 2 means you still got to click yourself to 'finish' the expansion. This is sometimes needed as a trigger for quests. ZEXPANSIONSTATE = 3 means expanded, and 1 means dark/in need of expansion.
  $s = new SQLite3('survivor.sqlite');
  # 0 = main
  # 1 = Atlantis
  # 2 = Asgard
  $zworld = '2';

  $last_expansion = min(time(), $s->querySingle("select max(ZEXPANSIONCOMPLETETIMESTAMP) from ZBUILDABLEAREA where zworld=$zworld"));
  if ( $last_expansion <= 0 ) {
    $last_expansion = time();
  }
  $last_number    = $s->querySingle("select max(ZEXPANSIONPURCHASENUMBER) from ZBUILDABLEAREA where zworld=$zworld");
  $s->query('begin transaction');
  while ( true ) {
    $z_pk = $s->querySingle("SELECT z_pk FROM ZBUILDABLEAREA where zworld=$zworld and ZEXPANSIONCOMPLETETIMESTAMP=0 AND ZEXPANSIONSTATE=1");
    if ( !$z_pk ) {
      break;
    }
    echo $z_pk . "\n";
    $last_expansion++;
    $last_number++;
    $s->query("UPDATE ZBUILDABLEAREA set ZEXPANSIONCOMPLETETIMESTAMP=$last_expansion, ZEXPANSIONPURCHASENUMBER=$last_number, ZEXPANSIONSTATE=2 Where z_pk=$z_pk");
  }
  $s->query('commit');
- Tired of waiting to build your buildings, and don't want to spend rubies? Well... Why not...Watch out here, because the atlantis merchants and the asgard one are a little special. Hence the additional restrictions (or you won't be able to finish that quest).
update zgameobject
set ZCURRENTHEALTHPERCENTAGE=1.0, ZTIMEATWHICHOBJECTWILLFINISHCONSTRUCTIONNUM=strftime('%s', 'now'), zupgradecount=25
where zstatenum=2 and (ZCURRENTHEALTHPERCENTAGE is null or ziscraftingnum=1);
- Want to send ALL your ships on a long voyage to get back a lot of stuff? And without spending coins to do that? This query just enables the voyage, it doesn't finish it necessarily. The additional restrictions is because sometimes you need to go on short/medium voyages, so these will not get erased by the query. Read more below how to finish the voyages immediately.
update zgameobject
set zonvoyagenum=1, zcurrentvoyageindex=2
where (zonvoyagenum != 1 or zonvoyagenum is null) and z_ent=27;
- Next step: finish the voyages instantaneously:
update zgameobject
set zendofvoyagetime=strftime('%s', 'now')
where zonvoyagenum = 1 and z_ent=27 and zendofvoyagetime > strftime('%s', 'now');
- Well, I do have a workshop and I want to build something (I used this hack in fact for Eric. I just couldn't get any map fragments, so I just set the workshop to build me a compass anyhow, without using any resources :-)). This query will not clear out if you already are building something. More information on things you can craft in CraftingRecipes.csv (check for workshop/armorsmith in there).
update zgameobject
set ZRECIPEIDINPROGRESS='Upgrade_Chest'
where zname = 'workshop' and (ZRECIPEIDINPROGRESS is null or ZRECIPEIDINPROGRESS = '');
- Same thing for the armorsmith:
update zgameobject
set ZRECIPEIDINPROGRESS=114
where zname = 'armorsmith' and (ZRECIPEIDINPROGRESS is null or ZRECIPEIDINPROGRESS = '');
- And now to finish these craftings immediately:
update zgameobject
set ZTIMEATWHICHOBJECTWILLBECOMEHARVESTABLENUM1=strftime('%s', 'now')
where zname IN ('workshop', 'armorsmith') and (ZRECIPEIDINPROGRESS is not null or ZRECIPEIDINPROGRESS != '');
- Fasten coin collection from buildings (I generally do this only on 'reward' buildings so I can get more ropes/canvasses etc etc). Just remove the ZNAMEDREWARD restriction if you want everything.
update zgameobject
set ZTIMEATWHICHOBJECTWILLBECOMEHARVESTABLENUM=strftime('%s', 'now'), zupgradecount=25
where ZTIMEATWHICHOBJECTWILLBECOMEHARVESTABLENUM != 0 and z_ent=23 and (ZNAMEDREWARD is not null);
- Fasten coin collection from ruby buildings:
update zgameobject
set ZTIMEATWHICHOBJECTWILLBECOMEHARVESTABLENUM=strftime('%s', 'now')
where ZTIMEATWHICHOBJECTWILLBECOMEHARVESTABLENUM != 0 and z_ent=22 and (ZNAMEDREWARD is not null);
- Another interesting stuff is quests. That can go wrong a lot of times, but just check out the URL on top of this article. You can just skip stuff, or add achievements and so on.

- How to get new ships? Like to top10-pvp Ships? :-). Easy Peasy... What I generally do is export my database. Get in the game & move a few ships. Export the database again & see what coordinates they were BEFORE (watch out, you need to modify 2x the coordinates in the same insert statement!).
Then set Z_PK to null (it will autoincrement that way). Change the ship you want (like pvpShip3 for the midnight ship which is running now). Check that the gameobject identifier in Z_PRIMARYKEY is still ok & you have a freaking new ship :-). For safety reasons I set ZCREWONEFBID/ZCREWTHREEFBID/ZCREWTWOFBID to null and ZEQUIPMENTSDATA=null. But I think the ZEQUIPMENTSDATA can be left as-is, and I believe it will duplicate the equipment into your new ship as well. But didn't bother trying that. It's faster to just re-assign new equipments anyhow than starting the game anew.

- Now what you've all been waiting for... How the **** can I get free rubies/coins? In fact it's fairly simple :-).
Adjust the ZMONEY (anything from cannons to hulls to boosts and ropes etc etc) or the ZUSERMODEL (wood, xp, coins, rubies) table. Well, 1 caveat... The ZROWHASH... Here's how to calculate it:

(PHP code follows)
  $openUDID = '';
  $currency = '';
  $amount = '';
  $wood = '';
  $xp = '';
  $coins = '';
  $gems = '';
  $energy = '';
  # For currency:
  $hash = base64_encode( sha1("$currency,$amount,$openUDID", true) );
  echo "$currency: '$hash'\n";
  # For usermodel:
  $hash = base64_encode( sha1("$wood,$xp,$coins,$gems,$energy,$openUDID", true) );
  echo "user: '$hash'\n";
Or simpler: http://www.salvania.be/calculate.ZROWHASH.php
Where to find the openUDID? Also simple... Once you know it of course :). It's in Library\Preferences\com.pocketgems.paradisecove.plist. It's just an XML file. Just search for OpenUDID, and you'll see something 40 characters long consisting of 0-9a-z. That's the OpenUDID! Now you can update this ZROWHASH whenever and however you want...
Unlimited midnight cannons (+520 attack)? You got it... Unlimited rubies? Sand dollars (atlantis money), silver rings (asgard money)? You got it :-).


And no, I don't feel bad one single bit... Greedy games should be hacked.



Still figuring out how to cheat at the pvp competitions, but I think it's not that difficult :-).

As Finch says in PoI: "If they don't want you to get inside, they ought to build it better."


Update @ 2014-03-20:
What is the name of that ship again? Or that nifty cannon? Don't know it? Well, quite easy to get it...
Go to Library\Application Support\resources. You'll see a lot of CSV files.
* Shipnames are in ... Ships.csv (duh ;)). The first entry is the name in the database, the second the name in the game. Easy.
* Cannons and stuff is in ... Money.csv (remember the database table is ZMONEY?) Again, the first entry is the name in the database, the second the name in the game...


Have fun!

2009-02-09

Decibel list

Here is a list of dbs and what they compare to
Jet engine at 3m 140
Threshold of pain 130
Rock concert 120
Accelerating motorcycle at 5m 110
Pneumatic hammer at 2m 100
Noisy factory 90
Vacuum cleaner 80
Busy traffic 70
Quiet restaurant 50
Residential area at night 40
Empty movie house 30
Rustling of leaves 20
Human breathing (at 3m) 10
Threshold of hearing (good ears) 0

2008-12-21

"Repair with keycache": how to avoid?

Set:
myisam_max_sort_file_size


To:
# of rows
*
1 row length
(if UTF-8): * 3

Generally I set it to something huge which still fits into the "/tmp" filesystem

2008-12-05

Mac Tip: Run Software Update from the command line

I like running softwareupdate in the Terminal so I don't get a popup that won't go away reminding me I need to reboot or shut down. Running in the terminal lets me continue to work and reboot on my own terms. The command is:

sudo softwareupdate -i -a

and will install all available updates.