понеделник, 5 декември 2016 г.

How to root Xperia X8 trough Linux and export mmssms.db

To backup the sms from my old phone, it turned out I have to first root it. Which I never did for unknown reasons. Anyway, because my ex-phone is with some ridiculously old Android (not even Gingerbread), I had to root it in the konsole adb way. I found this great tutorial how to do it.
1. Download SuperOneClickv2.3.3-ShortFuse.zip and extract it to a folder
2. Cd into SuperOneClickv2.3.3-ShortFuse/
3. Turn on USB Debugging mode (Settings --> Applications --> Development --> USB Debugging)
4. Unmount the SD Card (Settings --> SD Card --> Unmount SD Card)
5. Connect your phone to the computer using the USB lead, when the phone asks chose "Charge Phone".
6. Go to your konsole (BASH):
Execute the following commands:
$adb push Exploits/psneuter /data/local/tmp/psneuter
$adb push Root/su-v2 /data/local/tmp/su                      
$adb push Root/Superuser.apk /data/local/tmp/superuser.apk
$adb shell
$cd /data/local/tmp
$chmod 755 psneuter

$adb shell
$cd /data/local/tmp
$mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
$cat su > /system/bin/su
$cat superuser.apk > /system/app/superuser.apk
$chmod 06777 /system/bin/su
$chmod 777 /system/app/superuser.apk

Then you should have "su" on your phone. You can test this by typing:
$adb shell
If you don't get an error, you're good to go. If you get an error, get to the link above and see possible solutions.

Then on to copying your text messages.
You need the following file: /data/data/com.android.providers.telephony/databases/mmssms.db
 I tried pulling it as it is, but I got permission error.
So what I did is the following:
$adb shell
$chmod 777 /data/data/com.android.providers.telephony/databases/mmssms.db
$cd ~/Downloads
$adb pull /data/data/com.android.providers.telephony/databases/mmssms.db
And the file was in ~/Downloads.
To import this file to your new phone, you need to do:
$adb push mmssms.db /data/data/com.android.providers.telephony/databases/
Obviously, your new phone will have to be rooted, which is somewhat inconvenient if your phone is brand new. But in principle you can.
This is a database file. You can play with it using sqlite. For example: 
$sqlite3 -header mmssms.db 'select address from sms' | sort -n | uniq -c | sort -n
will tell you who is the person you communicated with the most.
$sqlite3 mmssms.db
$ SELECT * FROM sms WHERE read=1;
will show you all the read messages and read=0 will show you the unread messages.
The same funtion without entering sqlite
$ echo 'select address,body from sms;' | sqlite3 -csv mmssms.db
If you want to, you can export them to a file (db.txt) with:
$echo 'select address,body from sms;' | sqlite3 -csv mmssms.db >> dx.txt
Then you can replace all the phones with names and happily read your sms.

петък, 16 септември 2016 г.

How to make dropbox sync

From the Dropbox help:
1.Stop Dropbox on the PC
2. In a termina write: 
  1. sudo chown "$USER" "$HOME"
    sudo chown -R "$USER" ~/Dropbox ~/.dropbox
    sudo chattr -R -i ~/Dropbox
    sudo chmod -R u+rw ~/Dropbox ~/.dropbox

    where Dropbox is the name of your dropbox folder 
3. Restart Dropbox 

вторник, 6 септември 2016 г.

Odd virtual machine error

Just tried to start my virtual machine and got this odd error:
Error starting domain: Failed to connect socket to '/var/run/libvirt/virtlogd-sock': No such file or Directory
I have no idea where it came from, since I haven't used my virtual machine for a month. In any case, the solution was very simple:
$ systemctl start virtlogd.socket
And then restart the virtual machine manager. 
Now it works: 

сряда, 13 юли 2016 г.

Virtual manager freezing

This seems to be universal problem. During the use of the virtual machine (I use qemu), it periodically freezes. The problem is not observed with ssh, so obviously, the problem is not in the virtual machine itself, but as suggested in the video acceleration or something.
The suggestion was to do
$vblank_mode=0 /usr/bin/virt-manager
I tried it, it still freezes.
Second attempt is the solution given here.
IT tells you to do (rc.local should have $chmod a+rx rx.local):
 sudo nano /etc/rc.local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
exit 0

The problem is that my system is using systemd so the rc.local is not even being read.
So to enable it I've found this:
Create a file /etc/systemd/system/rc-local.service with the following contents:
#  This file is part of systemd.
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.

Description=/etc/rc.local Compatibility

ExecStart=/etc/rc.local start
Then, just run systemctl enable rc-local.service as root to enable it.
You can also test it/run it now by running systemctl start rc-local.service

I still don't know if it works, because I have to test the virtual machine and systemctl enable gives an error: "sudo systemctl enable rc-local.service
The unit files have no [Install] section. They are not meant to be enabled
using systemctl."
Ok, after revising rc-local.service to contain the [Install] section, everything works like a charm.
And guess what, my virtual machine is finally not freezing. I've been using it for hours now and it seems to work flawlessly. Yay!

сряда, 6 юли 2016 г.

Primusrun not working on Sabayon (Gentoo)

Recently I got this odd error when trying to start primusrun:
"primus: fatal: failed to load any of the libraries: /usr/lib64/opengl/nvidia/lib/libGL.so.1:/usr/lib32/opengl/nvidia/lib/libGL.so.1:/usr/lib/opengl/nvidia/lib/libGL.so.1
/usr/lib64/opengl/nvidia/lib/libGL.so.1: wrong ELF class: ELFCLASS64
libGLX.so.0: cannot open shared object file: No such file or directory
/usr/lib/opengl/nvidia/lib/libGL.so.1: wrong ELF class: ELFCLASS64"

Obviously, this is not a critical error, but it prevented me from using my beloved nvidia card so I had to fix it. It turned out, it might be a problem of the nvidia driver in Sabayon being compiled without a -compat flag. I'm not that sure if that's the case, but anyway, Steam wasn't working and that was a pain.
I still don't know how to fix this, but I found a work around it. It is to run:
$ vblank_mode=0 optirun -b primus steam
Oddly enough, I discovered that this make a damaric change in the performance.
For example:
Polygons in scene: 62464 (61 spheres * 1024 polys/spheres)
Visual ID of window: 0xb4
Context is Direct
OpenGL Renderer: Mesa DRI Intel(R) Haswell Mobile
60.719441 frames/sec - 67.762896 Mpixels/sec

$optirun glxspheres
Polygons in scene: 62464 (61 spheres * 1024 polys/spheres)
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: GeForce GT 750M/PCIe/SSE2
270.979545 frames/sec - 302.413172 Mpixels/sec

$ vblank_mode=0 optirun -b primus glxspheres
Polygons in scene: 62464 (61 spheres * 1024 polys/spheres)
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
Visual ID of window: 0xb4
Context is Direct
OpenGL Renderer: GeForce GT 750M/PCIe/SSE2
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
317.778206 frames/sec - 354.640478 Mpixels/sec

Surprising, huh? I didn't realize the nvidia makes that much difference. Nice.

P.S. Btw, the packages which I reinstalled were:
bumblebee bumblebee-nvidia virtualgl linux-headers libglw primus
And yeah, another thing, how to restart bumblebee:
systemctl enable bumblebeed.service
systemctl start bumblebeed.service

четвъртък, 30 юни 2016 г.

How to resize partition in virtual machine

First, find the directory where your  *.qcow2 file resides.
$ ls -la *.qcow2
should show the file you're looking for
Then use qemu to resize the file.
$sudo qemu-img resize X*.qcow2 +10GB
will add 10GB to your file. Make sure not to add more GBs than you'd like the file to have, because then you cannot shrink it back to less. I found it out the hard way :)
All this is done with the virtual machine turned off.
Then comes the complicated part.
You need to convince you're virtual OS that it has more space. So this is what I did (following source):
So start your virtual machine, start a terminal and work there.
 First, check your current partition table:
$df -h
and make sure you're working on the correct partition. In my case, I had to work on /dev/sda.
Then delete the last partition on /dev/sda
$fdisk /dev/sda
to print the current partition table.
I had
/dev/sda1 -> primary, root partition
/dev/sda2 -> extended
/dev/sda5 -> SWAP.
Obviously different situation from the instructions, so I decided to delete /dev/sda2 and work from there.
So to delete /dev/sda2
This finalizes the destruction.
Then I had the space in the end of my virtual hard empty. I created a new partition
$fdisk /dev/sda
all else was the default ones, just make sure the final cylinder is indeed the final of the "disk", because for me, the first time, it wasn't.
After that you finish with $w and exit.
Then you need to reboot to finalize.
$sudo reboot
In the better case, you could use
$resize2fs /dev/sda1

to expand your root hard. It didn't work for me, so I started gparted
$sudo gparted
and deleted the new partition, because resize2fs gave me some error with cylinders.
After deleting, I created a new ext4 partition and I hit "Apply". The idea was to fix the error I got previously.
Then when it was ready, I deleted the new partition, clicked on /dev/sda1 and told it to resize to the end (or almost) of the now unformatted region. I left little space in the end which I formatted as swap, just so that I have some. Then I clicked Apply and gparted did the magic.
Now I have 20GB bigger virtual hard, which is 10GB more than I planned for, but still, it all seems to work fine.

вторник, 24 май 2016 г.

lmutil not working

lmutil is a licensing utility . I needed it and it didn't work, because my lan interface wasn't called eth0 and I got this message:
$ lmutil hostid
lmutil - Copyright (c) 1989-2009 Acresso Software Inc. All Rights Reserved.
The FLEXnet host ID of this machine is "000000000000"
Obviously, not very helpful if you need a license file generated for this host ID.

The solution was quite simple.
  1. Edit /etc/default/grub
  2. At the end of the GRUB_CMDLINE_LINUX line append the text:
    net.ifnames=0 biosdevname=0
  3. Save the file.
  4. Execute the following commands:
    grub2-mkconfig -o /boot/grub/grub.cfg

вторник, 17 май 2016 г.

wallet files not opening

So, after my fresh installation, I wanted to port my wallet files. But for some very strange reason, it kept on telling me my password is incorrect. Which is simply not true. So anyway, I found this howto and it worked as a charm.
Basically, you need to disable your wallet from System, then paste the old .kwl and .salt files into the appropriate folders:
 and then to enable the wallet from System Settings. This time, my wallet worked.
So wallet panic is happily over and problem is solved.

сряда, 11 май 2016 г.

juniper (pulse secure) under gentoo. Finally!

Woah, that was one of the craziest thing I needed to do. It took me forever to find how to convince the company's server that I'm connecting with Pulse Secure. But after days of me wanting to rip my head off, I finally made it.
The problem is that the app which Pulse Secure provides is not a native 64x library and it's not a native Gentoo app, which makes it a nightmare to install it. In the end you can extract the deb package and put it where it belongs (/usr/local/pulse), you can connect /bin/ifconfig with /usr/sbin/ifconfig), but that won't help much since the whole thing is totally messed up and pulsesvc is a compiled file so you can't change PATHs and what's worst, you don't know the PATHs inside and so you don't get an error, you don't get anything to work with.

 After days of trying everything, here is what worked for me.
I followed this guide (for a while at least).
0. You need to start the "tun" module. 
$ sudo modprobe tun
$ sudo echo "tun" > /etc/modules-load.d/VPN.conf  - this one turned out not to be necessary
If you get an error on modprobe tun try $sudo modprobe --force tun
it worked for me. But this step is key, otherwise, openconnect cannot set up the connection.
1. Get you certificate  (from here):
Log into your vpn trough Firefox. Go to Tools->Page Info -> Security->View Certificate -> Details -> Export
Save the file as .DER (for Juniper's client) or .PEM (for OpenConnect)
2. Download stuff:
sudo equo install vpnc
sudo chmod a+x+r -R /etc/vpnc
sudo equo install libxml2 libxml2-dev gettext make libssl-dev pkg-config libtool autoconf git pip net-tools libgnutls-dev 
Most of those don't exist in Gentoo but still I post them here becaues maybe something helped :)
sudo equo install openconnect
sudo pip install mechanize
git clone https://github.com/russdill/juniper-vpn-py
cd juniper-vpn-py
/if it doesn't exist,first $mkdir juniper-vpn-py/
sed -i '/ssl._create_default_https_context = ssl._create_unverified_context/d' ./juniper-vpn.py
sed -i '/ssl._create_default_https_context = ssl._create_unverified_context/d' ./tncc.py
sudo mkdir -p /run/resolvconf/interface
sudo cp /etc/resolv.conf /run/resolvconf/resolv.conf
sudo mv /etc/resolv.conf /run/resolvconf/interface/mlan0
sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
sudo resolvconf --enable-updates
/that gives me errors so probably wasn't very important/
4. Finally, I created this file:
$nano tun.sh
with the content:

if (ip tuntap add dev tun0 mode tun)
  echo "New tun Created Successfully"
  sleep 4
  echo "Old tun Exists, Need to Cleanup"
  ifconfig tun0 down
  ip tuntap del dev tun0 mode tun
  sleep 4
  ip tuntap add dev tun0 mode tun
  sleep 4

if(ifconfig tun0 up)
  echo "Interface tun0 is up"
  echo "Something went wrong, exiting..."

export LD_LIBRARY_PATH="/usr/local/lib"

5. $sudo sh tun.sh
This will set up the tun interface and make sure it is fresh and ok. You may add to the script
 $modprobe tun
6. For me the python script didn't work for some unknown reason which I don't have time to research right now. So to connect I did:
$ sudo openconnect --cafile ~/cert_file.pem --juniper VPN_host -u USER_name
 where cert_file is the name you gave to your certificate, VPN_host is the name of your host's VPN, USER_name is your login username for the VPN.
When it connects, it will also ask you for the password.

Then when it says "ESP session established with server"  you're good to go and do whatever you need to do with your vpn, in my case, use perforce.

7. You stop the connection with CTRL+C and $sudo ifconfig tun0 down

I'm soooo happy I managed to do that. It seems simple once it's done, but it took me days to find the howto that works for me and also, I tried to install the Pulse Secure app on Sabayon, Ubuntu x64, Fedora x32 and LUbuntu x32. It didn't work anywhere! So this is really a success.

Btw, if you don't feel like filling in the password each time, you can make a simple script:
echo "$password" |  sudo openconnect --cafile $cert --juniper $url -u $username --passwd-on-stdin

And then to run it like sh script.sh
This way, you'll have to fill only your sudo password :)

Some links where you can find many howtos, maybe they will woro for you, they didn't for me.
ArchLinux, Short VPN guide, AnotherOneDownloadPage, GentooHowto,

Explanation how to install in Ubuntu x64. I couldn't make it work. Some more explanations + download links for Mac, Win and Linux.

This should tell you if you have TUN:
$ grep CONFIG_TUN /usr/src/linux/.config

From Sabayon wiki:
$ cd /sbin
$ sudo ln -s /bin/ifconfig ifconfig
$ sudo ln -s /bin/route route
I don't know how much the last step helped. 

неделя, 17 април 2016 г.

How to restart touchpad without reboot

I'm so happy with this one.
When my laptop is very VERY loaded, sometimes (though not often), the touchpad decides it doesn't exit. No idea why, the mouse pointer just freezes on the screen and that's it. So today I found out how I can fix this without rebooting, which probably saved me 40 cpu/hours of calculations. Yay!
So here is what I did (following this). In the konsole:
$equo install xinput
$ xinput --list
You see the id of the touchpad - mine is Elantech touchpad and was #13
$xinput disable 13
$xinput enable 13
And voila, I have touchpad again! And that's fantastic, because in my case even when I plugged the USB mouse, it didn't work, so it was a life-saviour. I love linux :)
P.S. Btw, while trying to figure out how to restart the touchpad I found this great site for kde shortcuts. I didn't know you could change the virtual desktop with ctrl+f1, ctrl+f2. Awesome...

понеделник, 11 април 2016 г.

My fight with qemu, part 2: ssh from host to guest

Ok, my next step is to install the planned guest OS and to run ssh on it. So this is my log of it.

1. Find an .iso.
For some reasons, the network install wasn't that glorious, though I tried only once.
So let's do it with the iso.
Note to self: don't xkill qemu while trying to install new OS, because it falls asleep, gets in d state and needs a restart to fix.
Second note to self: Don't install new guest OS from ISO while doing calculations on the PC which will prevent you to restart. Facepalm and go to sleep.
The iso I chose:
the x64 desktop version. I need something light and stable for the perversions I planned. So we start with XUBUNTU.
2. Install it on the virtual machine.
I made a new virtual machine with a 20GB raw partition and then mounted the iso as a cdrom from Machine->Details->Cdrom.
After that I started the machine and installed Xubuntu. Not much surprise there.
3. Try not to ruin your new install in the first 5 minutes.
A little surprise was that a software update crashed and I had to do:
$sudo dpkg --configure -a
once or twice and to restart to fix it.
4. Install ssh
To install ssh I followed this ubuntu tutorial.
Basically I did:
$sudo asudo apt-get install openssh-server 
$sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults
$sudo chmod a-w /etc/ssh/sshd_config.factory-defaults
$sudo gedit /etc/ssh/sshd_config
 where I didn't change much, maybe just disabled password-less authentication and allowd X-forwarding (as stupid as it sounds for a virtual machine). 
$sudo restart ssh
to apply the changes. 
5. Connect to your ssh-server :) 
From your host machine do
$ssh user@home-ip
and from my host machine I could ssh to the virtual machine.
Now that's awesome! And quite easy! Still can't get ssh-server to work on my Sabayon. Oh, well, that's why I chose Ubuntu for the virtual machine.


неделя, 10 април 2016 г.

My fight with qemu, part 1: bridge wifi to guest machine

The situation - I need a virtual machine on one of bigger hards say /hda1. Ideally, it would be a light linux box for experiments, which should communicate with the host with "ssh".

I had this windows virtual machine I set up some time ago,so I decided to use it for a test. So starting qemu, the first thing I see is that I don't have access to my virtual machine - permission denied. Because it resided on /run/media/user/hd1 and of course, the qemu user didn't have permission to mess with /run/media.

To fix this, you need to edit the following file and to change the user to either your user or root. Both work. 
$nano /etc/libvirt/qemu.conf 
# The user for QEMU processes run by the system instance. It can be
# specified as a user name or as a user id. The qemu driver will try to
# parse this value first as a name and then, if the name doesn't exist,
# as a user id.
# Since a sequence of digits is a valid user name, a leading plus sign
# can be used to ensure that a user id will not be interpreted as a user
# name.
# Some examples of valid values are:
#       user = "qemu"   # A user named "qemu"
#       user = "+0"     # Super user (uid=0)
#       user = "100"    # A user named "100" or a user with uid=100
user = "root"

# The group for QEMU processes run by the system instance. It can be
# specified in a similar way to user.
group = "root"

# Whether libvirt should dynamically change file ownership
# to match the configured user/group above. Defaults to 1.
# Set to 0 to disable file ownership changes.
#dynamic_ownership = 1 
Then you need to restart libvertd. 
On older systems with: 
# [root@dev1 ~]# service libvirtd restart
On mine:
$systemctl restart libvirtd.
And that did the trick for the permissions. Now I can access my virt. machine! YAY

New problem - the virt. machine doesn't have internet. And trying to get it connected ruins the host internet connection. It turns out this is a major problem stemming from the fact you cannot bridge wifi connection with virtual network. At least not very easily. Well, luckily, it turned out it's not that impossible as it seemed in the beginning.Note: in all thing below: when I say "guest" I refer to the virtual machine OS, when I say "host" I mean the host OS as in your laptop's OS.

So this is how I did it. For the moment I have tested it only on one virtual machine, it worked, but clearly you'll have to do the arp line after each restart of the computer.
1. Start virt-manager
2. Connection details->Virtual Networks -> New (sub)network
The new network can have any name, but the network ip should be part of your network but not the same as you host network:
so if your host ip is: and your router is at (this is the gateway).
then the new subnetwork can be:
you need to know your guest ip for the last step so what I did for the DHCP is :
this will give you only 2 ips, but this way, you'll know that your host ip is either 150 or 151. If you plan to use only 1 virtual machine, even better, give it just 1 ip.
Also notice that when changing the ips, the gateway written in the text between the "network" field and the DHCP fields change. So when playing with the numbers, make sure the gateway is still the correct one and not something random (it happened to me like 3 times to get weird gateways). 
After setting up that, you click next, and next and in the final window, you choose from the falling menu
"Physical device: Wlan0" and from the second "Route".
Then you just click finish.
If you get an error: "Wlan0 already in use" the change the /25 to something different like /27 etc. IF you get some other random error, you either need to change the use in qemu.conf  to "root" or just google it and be persistent :)

After you click "Finish" and you get the message your subnetwork is ready, you need to test your host network, because if you get things wrong it will screw it. So try loading Google in host's browser or pinging it. If it works, rejoice!
If it doesn't work, stop that network from the virt-manager gui (the button is "-", or directly the "trash").
Then make a new one and try with different ips - the previous ones may be have been taken already.

If you do:
you'll see info on your networks.‘virbr1’ and ‘wlan0’ shouldn’t have the same Destination. If they do, you'll need to remove virbr1 from the virt-manager gui and create a new subnetwork. Btw , if you like me get it to work from try number N, "vibr1" might be "vibr2" or more, just check the Connection details->Virtual Networks for the actual name.

Final step:
$sudo  arp -i wlan0 -Ds wlan0 pub
where the ip you see is your GUEST ip! So in my case, I had two ips *.150 and *.151 and I did it twice.
$ sudo arp -i wlan0 -Ds wlan0 pub
$sudo  arp -i wlan0 -Ds wlan0 pub

After that, you are ready to give network to your virtual machine. You go to virt-manager, you click on the details of your virt. machine and from the NIC section you choose "VIRBR1" and for the device name - the hypervisor defaul. Click "Ok" (or whatever) and start your machine.With some luck, it will be finally connected!

If it is not, start over.  For better description, see the post where I found the solution + one similar which also helped.

I got it working after like 7 hours of googling and trying out solutions. But to my defence, I had no idea what all those options like "bridge, vepa, and passtrough" mean. So it could be just me, but if it's not working for you, just keep trying. The solution does work, even if it's messy and ugly.

Some resources which helped me figure out the situation:
qemu networking explained (source1, source2, source3 !!!, same as source3 but on ubuntu)

if you want to start the qemu from konsole, this link might come handy.
For eth0 bridging, I suspect things will be piece of cake, but I haven't tried them, so this link seems important.
There is aslo a script for routing from Wifi to qemu, but I couldn't make it work, probably because at the time I didn't know my guest ip. 

P.S. If after restart you don't have internet on your virtual machine you may want to 1) delete all the unnecessary connections in  Connection details->Virtual Networks and 2) run
$ sudo arp -i wlan0 -Ds wlan0 pub before starting virt-machine, then do 
$systemctl restart libvirtd.
and then start your machine.
And or disconnect and reconnect it couple of times from inside the guest machine. At some point it starts working.

неделя, 3 януари 2016 г.

How to export latex figure to eps

It turned out quite easily (see here).
You need to use the tikz package and then add:
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
-interaction=batchmode -jobname "\image" "\texsource";
dvips -o "\image".ps "\image".dvi;
ps2eps "\image.ps"}}

Then you have to run in the konsole
$latex --shell-escape document.tex
and you have your eps. Oddly enough I couldn't make Kile do that or use the pdftex option, but anyway, at leat the eps export works like this.