12 January 2017

Extracting files from water damaged phone using chip-off method

I managed to drop my phone in saltwater which completely broke it. After soaking in isopropyl, careful cleaning of rust and drying out for weeks, the phone did not even react to plugging in the charger. The files, and most importantly photos that had not synced to the cloud yet, were all trapped inside the dead phone.

I tried to find a service that could recover the data, but the service providers i found were either non-responsive or costed ridiculous amount of money for them to even try recovering files. I ended up buying a eMMC reader myself and desoldered the memory chip from the phone and recovered the files. Fortunately i had not encrypted the storage on my phone, otherwise it would have been much harder to get the images out of the encrypted chip.

It turns out that the android phone i had (Sony Xperia Z5 compact, not so waterproof as they let you think in the commercial..) stores all the files in the phone on a 11.5x13mm eMMC chip which looks like this:

Apparently the eMMC cards use the same standard as ordinary SD cards, so it is possible to build a eMMC-SD adaptor and just read the SD card in your normal SD card reader. The just requires you to attach the SD card contacts to the correct connectors on the eMMC chip. The connectors on the underside of the chip are way too small for me to be able to solder wires to them:




I decided to buy an adapter and found various places to buy them. Often they would cost $200-$300, but i found a store that sold them for only $99 (https://kzt-socket.aliexpress.com) and i took a chance and ordered it.


At first i must have done something wrong, i could not get the computer to recognize the reader. I had bought a couple of new eMMC chips to try things out with. Being a little sad that the expensive reader i had bought did not work, i let the project rest for almost a year before taking it up again. When i took it up again i got it to work on the first try, so i have no idea why it did not work the first time.. 

After establishing that the reader worked, i took out an old phone i had (LG G3) which turned out to have the same type of eMMC chip, and i made my first attempt to desolder the chip and read it. The first try failed, i could not read the chip in the reader. I think i heated it up too much and simply broke it. The next try (an broken Nexus 5) i did a bit more research on. This chip worked after desoldering it, so i felt confident enough (and fresh out of phones) to try it on the phone where my photos were.


I finally had a reason to buy a heat gun :)


I found where the eMMC chip is located.


Set the heat gun to 200C and let it heat up.


Then aim it straight at the eMMC chip and let it heat it for 60 seconds. This will make sure the chip is heated all the way through to the solder points below it before you turn up the heat even more. If you don't want to damage the other components, it's recommended to heat up the whole board evenly, but i was only interested in removing the eMMC chip.


 When 60 seconds of 200C have passed, increase the temperature to 400C and heat the chip for 30 seconds with it. This will melt the solder and the chip will be free.


Almost at least, there is also some glue underneath the chip that will require some prying to get loose. It's not too hard attached though, so a small flat screwdriver did the job without damaging the chip.


Tada, the chip is now off!


It was not the prettiest chip right after removing it. There were still some solder left that shorted some of the pins, the there were glue residue everywhere.


I took out my soldering iron and put on the flat solder head.


Heated it up to ~350C and started cleaning the chip.


First i applied some solder flux.


Then i just scraped the surface, not super hard, of the chip and removed all old solder points and glue residue until the surface was smooth enough to not interfere with the eMMC reader.


When the chip was clean i could just pop it into the reader and connect it to the computer and it showed up as a SD card in my file browser. After that it was just a matter of copying the photos to the computer.


08 September 2016

Making remote content accessible on a web server using reverse ssh tunneling

So, i had a flask server running on my laptop and i wanted to show the results online. I did not want to bother copying the project to the web server computer, installing all the dependencies and configuring nginx to run a flask project.

I ended up configuring a subdomain in nginx to always proxy from another empty port of the web server (1234 in my case but could be anything really). Usually there is nothing running there, so if i open that subdomain in a web browser it should usually show 502 Bad Gateway. Then i connect to the web server from my laptop and do a reverse ssh tunnel over the connecting, mapping my flask servers port (5000) to port 1234 on the web server.  When the connection is established, all incoming web traffic on the subdomain will proxy the request to the reverse ssh tunnel which will serve the flask content from the laptop.

This works even if the laptop is behind a firewall, dynamic ip, or any other problem that might be in the way of the laptop being visible online.

So, here is the nginx config (/etc/nginx/sites-enabled/ext_proxy):

server {
    listen 80;
    server_name ext.domain.com;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:1234;
    }
}



and the ssh command i run on the laptop:

ssh -R 1234:localhost:5000 user@domain.com


For simplicity i defined it as a function where you can specify which port on the laptop should be exposed through the subdomain:

extproxy () 
    ssh -R 1234:localhost:$1 user@domain.com
}

that i run as follows:

extproxy 5000

which will expose port 5000 on my laptop on ext.domain.com

07 July 2014

Mint 17 Cinnamon: Wallpaper slideshow using crontab

I wanted to have a folder containing lots of pictures that would be used to change my desktop wallpaper every once in a while. If I added more pictures to the folder, they should be included automatically.

Before Mint 17 it was easy to use gsettings in your crontab to do this, but something had changed when they switched to Ubuntu 14.04 instead. I found a nice thread on AskUbuntu (http://askubuntu.com/questions/457016/how-to-change-gsettings-via-remote-shell) which solved a similar problem. I then adapted that solution to my own problem.

It turned out that if you try to run gsettings in crontab, it is missing an environment variable, which can be found using the script below.

1. Save this script file: pastebin link
I put mine in /home/dahlo/tools/wallpaper-change_cinnamon.bash


#!/bin/bash

# Search these processes for the session variable 
# (they are run as the current user and have the DBUS session variable set)
compatiblePrograms=( nemo pulseaudio trackerd nautilus )

# Attempt to get a program pid
for index in ${compatiblePrograms[@]}; do
    PID=$(pidof -s ${index})
    if [[ "${PID}" != "" ]]; then
        break
    fi
done
if [[ "${PID}" == "" ]]; then
    echo "Could not detect active login session"
fi

QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "${QUERY_ENVIRON}" != "" ]]; then

    export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
    # echo "Connected to session:"
    # echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"

    # Script to randomly set Background from files in a directory

    # Directory Containing Pictures is given via command-line, could be hardcoded in there as well
    DIR=$1

    #DIR="/home/user/Picture"
    #DIR="/home/user/Documents/cultural-festivities/"

    # Command to Select a random jpg file from directory
    # Delete the *.jpg to select any file but it may return a folder
    PIC=$(find $DIR -type f -exec file {} \; | grep -o -P '^.+: \w+ image' | cut -d ':' -f 1 | shuf -n1)

    # Command to set Background Image
    gsettings set org.cinnamon.desktop.background picture-uri "file:///$PIC"



else
    echo "Could not find dbus session ID in user environment."
fi

2. Add it to your crontab and supply the path to the picture folder (/home/dahlo/tools/Wallpapers) as an argument.


# change wallpaper every 5 minutes
*/5 * * * * bash /home/dahlo/tools/wallpaper-change_cinnamon.bash /home/dahlo/tools/Wallpapers 


This will randomly select one of the image files in the folder you specify and use it as your desktop wallpaper.

13 March 2013

How to persistently change primary monitor in Linux Mint 14

I have 2 monitors connected, and of course the one i want to have as primary is not used as primary by the computer.

I read around on forums and the only suggestion i found was to use xrand to change primary monitor in a startup script. The problem was that my panels got all messed up by doing this, since the panels got initialized on the smaller screen first, and then changed to the larger screen once my script ran.

The soulution was very simple it turned out. Instead of using xrand, just change which monitor to use as primary in


  • ~/.config/monitors.xml


Find the screen you want to use as primary and change the


  • <primary>no</primary>


to


  • <primary>yes</primary>


No more startup scripts or any other messy things!


Thanks to AlbertP on the Linux Mint forums: http://forums.linuxmint.com/viewtopic.php?f=206&t=104497

01 September 2012

How to install Compiz in MATE in Linux Mint 13

It bugged my quite a lot that i could not blur the background in my transparent terminal in Linux Mint 13 Mate. Not only that, i missed many of the other Compiz features, like zoom, grid and other nice things. So i decided i had to install compiz :)

I googled around and found a couple of good guides, so i thought "Hey, there can always be one more guide!". So here we go:


TL;DR: the short version

$ sudo apt-get install compizconfig-settings-manager
$ compiz --replace

(Keep the terminal open until you are done. You will want Compiz to start automatically,  Control Center -> Startup Applications, and add a new post "Compiz" with the command "compiz --replace", without the "".

$ mateconf-editor
# Go to /desktop/mate/session/required_components/windowmanager and
replace "marco" with "compiz".

# Download and import this compiz profile in CompizConfig Settings Manager - Preferences - Profile & Backend - Import: http://pastebin.com/7d5h5vyq

$ sudo apt-get install gconf-editor
$ gconf-editor

# Enter themes name in /apps/metacity/general/theme (I settled for Mint-X)
# List of available themes in /usr/share/themes/ (no way to preview? :/ )

Log out and then back in again, and everything should be finished.


From this guide to start using compiz: http://community.linuxmint.com/tutorial/view/919

Copy of the content:

There is some things you have to do to get Compiz work.

Install the packet "compizconfig-settings-manager".

 In a terminal window write "compiz --replace"     (When you want
Compiz start automatic you can open Control Center -> Startup
Applications, and add a new post "Compiz" keeping the same command
"compiz --replace".

The CPU usage now raises a lot.  That is because there is two
competing window-managers running.
To stop that high CPU usage in MATE when running Compiz:

In a terminal type “mateconf-editor”

When the editor opens:
Go to /desktop/mate/session/required_components/windowmanager and
replace "marco" with "compiz".
Not much happens now,

Thats because nothing is checked in "Compiz Configuration Settings Manager".

Open the Compiz Configuration Settings Manager.

Check what compiz-functions you want to activate.

One you sure need, the "Window Decoration".

Then you can choose "Move Window" and things you find good for you.


I took a copy of my compiz config-file and put it on pastebin: http://pastebin.com/7d5h5vyq

Save the config as a file and import it in Compiz Configuration Settings Manager (Preferences - Profile & Backend - Import)


Now, the window decorations will look like crap (imho), so that has to change.

To change window decoration theme, install gconf-editor and follow the
2nd answer in this thread:
http://askubuntu.com/questions/98243/how-to-customise-window-decoration-whilst-using-compiz-on-xubuntu

installing gnome-tweak-tool would pull almost the entire Gnome as
dependencies. I had the same problem today and I didn't want to
install such a lot of unneeded stuff only to change one little setting
and spent some time researching how these things are related and it
seems it is indeed possible with gconf-editor (or gconftool-2) alone.

The key in gconf-editor is /apps/metacity/general/theme.

Type the name of an existing metacity theme into the text field (such
as greybird and note that greybird is starting with a LOWERcase letter
while most other themes are not!), hit enter and it should immediately
change.

You can also change the arrangement of window buttons in
/apps/metacity/general/button_layout (for example to move the window
buttons to the right side where they traditionally belong use this:
menu:minimize,maximize,close). Most other options in this section
describe window behavior rather than style and don't have any effect
on compiz, they would only be used by metacity.

I.e.  install gconf-editor and run it, and type the name of the theme you want in /apps/metacity/general/theme

I used Mint-X and was happy with it. The list of available themes:
$ ls -l /usr/share/themes/ 

(no way to preview? :/ )



And that should do it. I now have Linux Mint 13 Mate with Compiz :)

06 September 2010

Remap mouse buttons in Ubuntu 10.04, to have middle button as 'back' in browser

Ok, so i tried a bunch of programs, like btnx and imwheel, but nothing worked. Btnx worked, but had some weird side effects, such as holding down the alt key every time i pressed the mouse button, so i had to physically press the alt button on the keyboard to stop the 'alt signal'.

The solution was simple:

First, get the name for your mouse


$ xinput list

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ PS/2 Generic Mouse id=11 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)]
⎜ ↳ Macintosh mouse button emulation id=13 [slave pointer (2)]
⎜ ↳ Logitech Trackball id=16 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ HP Webcam [2 MP Macro] id=9 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]



Find the mouse. My mouse has the name "Logitech Trackball".

A fancier mouse with more buttons will have a button for 'back' in the browser, so i wanted to set my middle mouse button to that signal.

First, just for fun, look at your current mouse map

$ xinput get-button-map "Logitech Trackball"
1 2 3 4 5 6 7


This is the standard map. The order of the numbers are 1 = left mb, 2 = middle mb, 3 = right mb, 4 = mwheel up, 5 = mwheel down

So what is 6 and 7? I have no idea :) But i know for a fact that 8 = Back on my mouse :)

I just tried mapping different numbers to my middle mouse button until it worked.

Like this:

$ xinput set-button-map "Logitech Trackball" 1 7 3 4 5 6 7

Tried it, and it did not work. So i increased it once more:

$ xinput set-button-map "Logitech Trackball" 1 8 3 4 5 6 7

And it worked! I did not even had to restart X or anything, it updated instantly.

To make the change permanent, you have to add this to some startup script. I added it to the startup applications thingy in Preferences >> Startup Applications. Simply write xinput set-button-map "Logitech Trackball" 1 8 3 4 5 6 7 in the command field.

27 August 2010

Creating a multi-partition usb drive with dual booting persistent Linux Mint and Puppy Linux

Wow, that title is really a mouth full :)

First off, i used other guides while doing this, and i would not have made it without them.
* http://tazbuntu.blogspot.com/2009/05/multibootin-with-unetbootin.html For getting the multibooting to work

So, i wanted a bootable usb-stick. I wanted Linux Mint, for obvious reasons, and also Puppy Linux, if i ever were to come across a old and crappy computer. To be extra picky, i also wanted the OS to be on a separate partition, since it looks messy with loads of weird linux-files in the root. I also wanted to be able to use the data-part of the stick in both windows and linux.

So, to put in in a list form:

* Boot Mint and Puppy
* Separate OS and data partitions
* Work in both Windows and Linux

Ok, so the first thing i discovered was that Windows for some weird reason will only read the first partition on a usb-stick..

1. Start Linux. I used Linux Mint 9. Whether you have it installed by default or use a live-cd doesnt matter.

2. Install programs needed. Gparted for partitioning, unetbootin for the puppy part.
sudo apt-get install gparted unetbootin

3. Partition your usb-stick.

- Start gparted.

- Remove all partitions on your usb-stick (this WILL delete everything you the usb-stick, so take care while doing it, and make sure it is your usb-stick you are deleting)

- Create the data partition that will work in both linux and windows. I used 12gb for this on my 16gb stick. Make the file system NTFS so that windows can read it. It is IMPORTANT to create this first in the beginning of the usb-stick, since windows only reads the first partition.

- Create the OS partition that will host your linux installs. Make this FAT32. (maybe ext will work?)

- Perform the changes with gparted if you have not already done so.

4. Download the latest Linux Mint and Puppy Linux isos. (just google it)

5. Use unetbootin to install Puppy Linux on the OS partition you just created.

6. Copy the entire OS partition to a folder called /puppy on the data-partition. This is just for storing it until later.

7. Format the OS partition to clear away puppy linux. Make sure it is still FAT32.

8. Use the "Startup Disc Creator" that is included in all later Ubuntu editions. It is for sure included in Linux Mint 9. Use it to install the linux mint iso you downloaded in step 4 onto the newly formated OS partition. Select a nice size for the "reserved extra space". I used 1 gb for this. This is where the persistence comes in. All changes you make will be saved in this space, so dont be cheap ;)

Ok, so now there is a data partition that works in windows, a persistent linux mint on it, and soon there will be puppy as well!

9. Copy the files from the /puppy folder from the data partition and place it in /puppy on the OS partition.

10. Edit /syslinux/syslinux.cfg on the OS partition. This is the grub menu that is displayed during boot. Puppy linux has to be inserted here to be able to choose it.

My file looked like this:

default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Linux Mint 9 Isadora
menu color border 0 #00eeeeee #00000000
menu color sel 7 #ffffffff #33eeeeee
menu color title 0 #ffeeeeee #00000000
menu color tabmsg 0 #ffeeeeee #00000000
menu color unsel 0 #ffeeeeee #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 6
label live
menu label Start Linux Mint
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
menu default
label xforcevesa
menu label Start Linux Mint (compatibility mode)
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper xforcevesa initrd=/casper/initrd.lz ramdisk_size=1048576 root=/dev/ram rw noapic noapci nosplash irqpoll --
label memtest
menu label Memory Test
kernel memtest
label local
menu label Boot from local drive
localboot 0x80


Almost unreadable, so lets add some blank lines


default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Linux Mint 9 Isadora
menu color border 0 #00eeeeee #00000000
menu color sel 7 #ffffffff #33eeeeee
menu color title 0 #ffeeeeee #00000000
menu color tabmsg 0 #ffeeeeee #00000000
menu color unsel 0 #ffeeeeee #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 6

label live
menu label Start Linux Mint
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
menu default

label xforcevesa
menu label Start Linux Mint (compatibility mode)
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper xforcevesa initrd=/casper/initrd.lz ramdisk_size=1048576 root=/dev/ram rw noapic noapci nosplash irqpoll --

label memtest
menu label Memory Test
kernel memtest
label local

menu label Boot from local drive
localboot 0x80


Ahh, much better!

Ok, so we have to add Puppy to the list

label puppy
menu label Puppy Linux 5.1.0
kernel /puppy/vmlinuz
append initrd=/puppy/initrd.gz pmedia=cd

should do the trick. And the final result should look like this:


default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Linux Mint 9 Isadora
menu color border 0 #00eeeeee #00000000
menu color sel 7 #ffffffff #33eeeeee
menu color title 0 #ffeeeeee #00000000
menu color tabmsg 0 #ffeeeeee #00000000
menu color unsel 0 #ffeeeeee #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 6

label live
menu label Start Linux Mint
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
menu default

label xforcevesa
menu label Start Linux Mint (compatibility mode)
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper xforcevesa initrd=/casper/initrd.lz ramdisk_size=1048576 root=/dev/ram rw noapic noapci nosplash irqpoll --

label puppy
menu label Puppy Linux 5.1.0
kernel /puppy/vmlinuz
append initrd=/puppy/initrd.gz pmedia=cd

label memtest
menu label Memory Test
kernel memtest
label local

menu label Boot from local drive
localboot 0x80


Ok, now everything should be working. Reboot your computer and start from the usb-stick, and you should be greeted by grub!

A recommendation is to install PortableApps on the data partition from windows. After that, you will have a very functional usb-stick that has all the programs you need (PortableApps) and can even boot it's own OS if needed (Mint or Puppy).