piątek, 27 września 2013

mount remount android filesystem

1. adb shell
2. su -
3. mount | grep system

shell@android:/ $ mount | grep system
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,relatime,data=ordered 0 0

4. mount -o rw,remount /dev/block/platform/msm_sdcc.1/by-name/system /system


sobota, 21 września 2013

bash shortcut

$ cd /home/user/foo

cd: /home/user/foo: No such file or directory

$ mkdir !*

mkdir /home/user/foo

alternative for bash --> key[alt]+.[key]

sed basics

sed 's/^/# /' test
sed 's/^/> /' test

insert # sing and ">" to file name's test :)

to save change permanent use -i param


sobota, 14 września 2013

how to start wifi from adb site

adb shell svc wifi enable/disable

scapy python

a=sniff(iface="wlan0", prn=lambda x: x.show()) - qool "part" of the Python family - SCAPY:

example output bellow.


###[ Raw ]###
           load= 'HTTP/1.1 204 No Content\r\nPragma: no-cache\r\nCache-Control: private, no-cache\r\nExpires: Wed, 17 Sep 1975 21:32:10 GMT\r\nAccess-Control-Allow-Origin: *\r\nLast-Modified: Wed, 21 Jan 2004 19:51:30 GMT\r\nContent-Type: image/gif\r\nDate: Sat, 14 Sep 2013 22:20:03 GMT\r\nServer: Golfe2\r\nContent-Length: 0\r\nAlternate-Protocol: 80:quic\r\n\r\n'
###[ Ethernet ]###
  dst= 00:b0:0c:47:f8:00
  src= 24:77:03:49:b5:cc
  type= 0x800
###[ IP ]###
     version= 4L
     ihl= 5L
     tos= 0x0
     len= 52
     id= 9305
     flags= DF
     frag= 0L
     ttl= 64
     proto= tcp
     chksum= 0x2672
     src= 192.168.0.100
     dst= 74.125.228.111
     \options\
###[ TCP ]###
        sport= 45577
        dport= http
        seq= 3167215318
        ack= 215831554
        dataofs= 8L
        reserved= 0L
        flags= A
        window= 207
        chksum= 0xf01f
        urgptr= 0
        options= [('NOP', None), ('NOP', None), ('Timestamp', (5630168, 1289009574))]

2. sniff(prn=lambda x:x.sprintf("{IP:%IP.src% -->%IP.dst%\n}{Raw:%Raw. load%\n}"))
sample output:
192.168.0.1 -->239.255.255.250
??

192.168.0.1 -->239.255.255.250
??

192.168.0.1 -->239.255.255.250
??

192.168.0.1 -->239.255.255.25

apk package menagement

how to install apk app.
1. adb install app.apk
2. we can list installed app by:
adb pm list packages
3. we can uninstall this app by:
adb uninstall app.apk


http://forum.xda-developers.com/showthread.php?t=2300873

tip to eliminate wifi problem in nexus 4

adb push Nexus4_wifi_solution_by_kalo86.zip 

install from recovery mode.

Till now no problemy with wifi

how to: python rights permission check

   #!/usr/bin/python                                                               
                                                                                   
   import os                                                                       
   import sys                                                                      
                                                                                   
   if not os.geteuid() == 0:                                                       
       sys.exit('script must be run as root')                                      
   else:                                                                           
       print 'root part'                                                           

piątek, 13 września 2013

when you have problem with mysql The partition with /var/lib/mysql is too full!

* Stopping MySQL database server mysqld [ OK ]
* /etc/init.d/mysql: ERROR: The partition with /var/lib/mysql is too full!


try to restart myql with sudo permissions and flush db logs
mysqladmin -u root -p flush-logs

of flush something more:

  flush-all-statistics    Flush all statistics tables
  flush-all-status        Flush status and statistics
  flush-client-statistics Flush client statistics
  flush-hosts             Flush all cached hosts
  flush-index-statistics  Flush index statistics
  flush-logs              Flush all logs
  flush-privileges        Reload grant tables (same as reload)
  flush-slow-log          Flush slow query log
  flush-status  Clear status variables
  flush-table-statistics  Clear table statistics
  flush-tables            Flush all tables
  flush-threads           Flush the thread cache
  flush-user-statistics   Flush user statistics
  kill id,id,... Kill mysql threads

czwartek, 12 września 2013

servier client python code

client.py
#!/usr/bin/python
import socket
host = 'localhost'
port = 8081

try:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #s.connect(('localhost', 8081))
    s.connect((host, port))
    s.send('Marek Borkowski')
    data = s.recv(1024)
    s.close()
    print 'received: '
    print data
except Exception, e:
    print 'Uupss, something goes wrong, check network connection'


server.py

#!/usr/bin/python
import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

server_address=("localhost", 8081)
print 'starting up on %s port %s' %server_address
server.bind(server_address)

server.listen(5)

connection,client_address = server.accept()
print 'connection from: ', connection.getpeername()

data = connection.recv(4096)
if data:
    print "Received: ", repr(data)

    data = data.rstrip()
    connection.send("%s\n%s\n%s\n" % ('-'*80, data.center(80), '-'*80))
    print "send reponse"


connection.shutdown(socket.SHUT_RD | socket.SHUT_WR)
connection.close()
print "connection closed."
server.close()

wtorek, 10 września 2013

count request per minut access apache log

grep "10/Sep/2013" access.log| cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'

poniedziałek, 9 września 2013

adb logcat - sms has been received.

I/ActivityManager(  543): Start proc com.android.mms for broadcast com.android.mms/.transaction.PrivilegedSmsReceiver: pid=14617 uid=10030 gids={50030, 3003, 1015, 1028}
V/MmsConfig(14617): mnc/mcc: 26006
V/MmsConfig(14617): tag: bool value: enabledMMS - true
V/MmsConfig(14617): tag: int value: maxMessageSize - 307200
V/MmsConfig(14617): tag: int value: maxImageHeight - 480
V/MmsConfig(14617): tag: int value: maxImageWidth - 640
V/MmsConfig(14617): tag: int value: defaultSMSMessagesPerThread - 500
V/MmsConfig(14617): tag: int value: defaultMMSMessagesPerThread - 50
V/MmsConfig(14617): tag: int value: minMessageCountPerThread - 10
V/MmsConfig(14617): tag: int value: maxMessageCountPerThread - 5000
V/MmsConfig(14617): tag: string value: uaProfUrl - http://www.google.com/oha/rdf/ua-profile-kila.xml
V/MmsConfig(14617): tag: int value: recipientLimit - -1
V/MmsConfig(14617): tag: bool value: enableSlideDuration - true
V/MmsConfig(14617): tag: int value: maxMessageTextSize - -1
V/MmsConfig(14617): tag: string value: userAgent - Nexus4
V/SmsReceiverService(14617): onStart: #1 mResultCode: -1 = Activity.RESULT_OK
D/dalvikvm(  543): GC_CONCURRENT freed 1974K, 24% free 21699K/28452K, paused 13ms+28ms, total 284ms
D/MmsSmsProvider(  865): getThreadId: create new thread_id for recipients xxxxxxxx
D/MmsSmsProvider(  865): insertThread: created new thread_id 5 for recipientIds xxxxxxx
D/SmsReceiverService(14617): handleSmsReceived messageUri: content://sms/2 threadId: 5
D/MediaPlayer(  720): Couldn't open file on client side, trying server side
E/MediaPlayerService(  165): Couldn't open fd for content://settings/system/notification_sound
E/MediaPlayer(  720): Unable to to create media player
W/RingtonePlayer(  720): error loading sound for content://settings/system/notification_sound
W/RingtonePlayer(  720): java.io.IOException: setDataSource failed.: status=0x80000000
W/RingtonePlayer(  720): at android.media.MediaPlayer._setDataSource(Native Method)
W/RingtonePlayer(  720): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:958)
W/RingtonePlayer(  720): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:946)
W/RingtonePlayer(  720): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:899)
W/RingtonePlayer(  720): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:854)
W/RingtonePlayer(  720): at com.android.systemui.media.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:88)
D/dalvikvm(  720): GC_CONCURRENT freed 1625K, 60% free 12287K/30052K, paused 18ms+15ms, total 181ms
D/dalvikvm(  720): WAIT_FOR_CONCURRENT_GC blocked 59ms
W/MediaPlayer-JNI(  720): MediaPlayer finalized without being released

but now soud has been asign to this action.


dumsys service list

marek::lati { ~ }-> adb shell dumpsys | grep -i "dump of service"
DUMP OF SERVICE SurfaceFlinger:
DUMP OF SERVICE accessibility:
DUMP OF SERVICE account:
DUMP OF SERVICE activity:
DUMP OF SERVICE alarm:
DUMP OF SERVICE appwidget:
DUMP OF SERVICE assetredirection:
DUMP OF SERVICE audio:
DUMP OF SERVICE backup:
DUMP OF SERVICE battery:
DUMP OF SERVICE batteryinfo:
DUMP OF SERVICE bluetooth_manager:
DUMP OF SERVICE clipboard:
DUMP OF SERVICE commontime_management:
DUMP OF SERVICE connectivity:
DUMP OF SERVICE content:
DUMP OF SERVICE country_detector:
DUMP OF SERVICE cpuinfo:
DUMP OF SERVICE dbinfo:
DUMP OF SERVICE device_policy:
DUMP OF SERVICE devicestoragemonitor:
DUMP OF SERVICE diskstats:
DUMP OF SERVICE display:
DUMP OF SERVICE display.qservice:
DUMP OF SERVICE dreams:
DUMP OF SERVICE drm.drmManager:
DUMP OF SERVICE dropbox:
DUMP OF SERVICE entropy:
DUMP OF SERVICE fm_receiver:
DUMP OF SERVICE fm_transmitter:
DUMP OF SERVICE gfxinfo:
DUMP OF SERVICE hardware:
DUMP OF SERVICE input:
DUMP OF SERVICE input_method:
DUMP OF SERVICE iphonesubinfo:
DUMP OF SERVICE isms:
DUMP OF SERVICE location:
DUMP OF SERVICE lock_settings:
DUMP OF SERVICE media.audio_flinger:
DUMP OF SERVICE media.audio_policy:
DUMP OF SERVICE media.camera:
DUMP OF SERVICE media.player:
DUMP OF SERVICE meminfo:
DUMP OF SERVICE mount:
DUMP OF SERVICE netpolicy:
DUMP OF SERVICE netstats:
DUMP OF SERVICE network_management:
DUMP OF SERVICE nfc:
DUMP OF SERVICE notification:
DUMP OF SERVICE package:
DUMP OF SERVICE permission:
DUMP OF SERVICE phone:
DUMP OF SERVICE pieservice:
DUMP OF SERVICE power:
DUMP OF SERVICE profile:
DUMP OF SERVICE samplingprofiler:
DUMP OF SERVICE scheduling_policy:
DUMP OF SERVICE search:
DUMP OF SERVICE sensorservice:
DUMP OF SERVICE serial:
DUMP OF SERVICE servicediscovery:
DUMP OF SERVICE simphonebook:
DUMP OF SERVICE sip:
DUMP OF SERVICE statusbar:
DUMP OF SERVICE telephony.registry:
DUMP OF SERVICE textservices:
DUMP OF SERVICE throttle:
DUMP OF SERVICE uimode:
DUMP OF SERVICE updatelock:
DUMP OF SERVICE usagestats:
DUMP OF SERVICE usb:
DUMP OF SERVICE user:
DUMP OF SERVICE vibrator:
DUMP OF SERVICE wallpaper:
DUMP OF SERVICE wifi:
DUMP OF SERVICE wifip2p:
DUMP OF SERVICE window:

complex information about battery usage android adb

marek::lati { ~ }-> adb shell dumpsys batteryinfo| more
Battery History:
       -2h27m24s342ms 100 04120041 status=discharging health=good plug=none temp=280 volt=4267 +sc
reen +wifi +wifi_running brightness=dim signal_strength=great
       -2h27m15s233ms 100 44120031 +wake_lock signal_strength=good
       -2h27m15s065ms 100 04120031 -wake_lock
       -2h27m10s980ms 100 04120031 volt=4316
       -2h27m05s706ms 100 04120031
       -2h26m59s710ms 100 04120041 signal_strength=great
       -2h26m57s454ms 100 04120040 brightness=dark
       -2h26m50s745ms 100 04020040 -screen
       -2h26m38s110ms 100 04120041 +screen brightness=dim
       -2h26m34s609ms 100 44120031 +wake_lock signal_strength=good
       -2h26m31s143ms 100 04120031 -wake_lock
       -2h26m28s454ms 100 04120041 signal_strength=great
       -2h26m21s343ms 100 64060041 volt=4226 -screen +phone_in_call +wake_lock +sensor
       -2h26m16s116ms 100 64060031 signal_strength=good
       -2h26m10s976ms 100 64060031 volt=4315
       -2h26m08s340ms 100 64060041 signal_strength=great
       -2h26m05s501ms 100 64060031 signal_strength=good
       -2h26m01s432ms 100 64060041 signal_strength=great
       -2h25m46s121ms 100 64060040 brightness=dark
       -2h25m32s915ms 100 44120041 volt=4280 +screen -phone_in_call -sensor brightness=dim
       -2h25m28s318ms 100 44120041
       -2h25m26s795ms 100 04120041 -wake_lock
       -2h25m22s564ms 100 04120044 brightness=bright
       -2h25m10s992ms 100 04120044 temp=291
       -2h24m46s199ms 100 04020044 -screen
       -2h24m43s920ms 099 04020044 volt=4316
       -2h17m32s686ms 099 04120044 +screen
       -2h17m25s330ms 099 44020044 -screen +wake_lock
       -2h17m25s057ms 099 04020044 -wake_lock
       -2h13m25s680ms 099 04120044 +screen
       -2h13m18s735ms 099 24120044 temp=272 volt=4285 +sensor
       -2h13m12s418ms 099 04120044 -sensor
       -2h13m09s376ms 099 04020044 -screen
       -2h07m59s699ms 099 04120044 +screen
       -2h07m46s293ms 099 04020044 -screen
       -2h01m48s671ms 099 04120044 +screen
       -2h01m46s419ms 099 00100044 -wifi -wifi_running
       -2h01m41s255ms 100 00100044
       -2h01m26s357ms 100 00000044 -screen
       -2h00m55s395ms 100 40140044 +screen +phone_in_call +wake_lock
       -2h00m53s549ms 100 00140044 -wake_lock
       -2h00m26s066ms 100 00140044 temp=296 volt=4237
       -2h00m20s886ms 100 00100044 -phone_in_call
       -2h00m18s537ms 100 00000044 -screen
       -2h00m09s250ms 100 00000044 volt=4302

mmssms database android

root@android:/ # find /data/data -name *.db | grep sms                        
/mmssms.db
cd /data/data/com.android.providers.telephony/databases && sqlite3 mmssds.db

SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
addr                 pdu                  threads          
android_metadata     pending_msgs         words            
attachments          rate                 words_content    
canonical_addresses  raw                  words_segdir      
drm                  sms                  words_segments    
part                 sr_pending  


sqlite> select * from sms;
1|1|535 123 321||1378726606185|0||1|-1|2|||Test||0|0|1
2|1|+485351236321||1378726609910|1378726608000|0|1|-1|1|0||Test|+48123998250|0|0|1

android proces list.

for example:

marek::lati { ~ }-> adb shell ps | awk '{print $9}' | grep com
krfcommd
/system/bin/sensors.qcom
/system/bin/qseecomd
/system/bin/qseecomd
com.android.systemui
com.android.inputmethod.latin
com.android.phone
com.android.nfc
com.cyanogenmod.trebuchet
com.android.nfc:handover
com.google.process.location
com.android.smspush
com.android.location.fused
com.google.process.gapps
com.google.android.gms
com.google.android.gsf.login
com.android.calendar
com.google.android.gm
com.android.deskclock
com.android.providers.calendar
com.cyanogenmod.lockclock
com.bel.android.dspmanager

niedziela, 8 września 2013

cyanogenmod after install tip

If you wan't to have all google apps: google play store, gmail app, calendar app etc. install

http://goo.im/gapps - all packages

http://www.androidfilehost.com/?fid=23060877490000128 - for last stable cyano

two way to read data from file

#!/usr/bin/python3

with open("myfile.txt") as f:
        for line in f:
                print(line)


in_file = open("myfile.txt", "rt")
text = in_file.read()
in_file.close()
print(text)

a little more advanced user error exceptions

#!/usr/bin/python3

import sys

try:
        f = open('myfile.txt')
        s = f.readline()
        i = int(s.strip())
except IOError as err:
        print("I/O error: {0}".format(err))
except ValueError:
        print("Could not convert data to an integer")
except:
        print("unexpected error",sys.exc_info()[0])
        raise
~                                  

error maping

#!/usr/bin/python3

while True:
        try:
                x = int(input("Enter number: "))
                break
        except ValueError as error:
                print ("ooops", error)


result:

marek@mbo:~/Dokumenty$ ./true.py 
Enter number: f
ooops invalid literal for int() with base 10: 'f'

czwartek, 5 września 2013

pip install python problem

root::lati { ~/Dokumenty/python }-> pip install MySQL-python
Downloading/unpacking MySQL-python
  Running setup.py egg_info for package MySQL-python
    The required version of distribute (>=0.6.28) is not available,
    and can't be installed while this script is running. Please
    install a more recent version first, using
    'easy_install -U distribute'.
   
    (Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))
    Complete output from command python setup.py egg_info:
    The required version of distribute (>=0.6.28) is not available,

and can't be installed while this script is running. Please

install a more recent version first, using

'easy_install -U distribute'.



(Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))

----------------------------------------
Command python setup.py egg_info failed with error code 2
Storing complete log in /home/marek/.pip/pip.log
root::lati { ~/Dokumenty/python }-> easy_install -U distribute
Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Best match: distribute 0.7.3
Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
Processing distribute-0.7.3.zip
Running distribute-0.7.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-czy2vB/distribute-0.7.3/egg-dist-tmp-8Dpl5x
warning: install_lib: 'build/lib.linux-x86_64-2.7' does not exist -- no Python modules to install

Adding distribute 0.7.3 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/distribute-0.7.3-py2.7.egg
Processing dependencies for distribute
Searching for setuptools>=0.7
Reading http://pypi.python.org/simple/setuptools/
Reading https://pypi.python.org/pypi/setuptools
Reading http://peak.telecommunity.com/snapshots/
Best match: setuptools 1.1.1
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-1.1.1.tar.gz#md5=c8d19510c03b0e2e01880c0d8f080083
Processing setuptools-1.1.1.tar.gz
Running setuptools-1.1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vatpeG/setuptools-1.1.1/egg-dist-tmp-87BDp5
Adding setuptools 1.1.1 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/setuptools-1.1.1-py2.7.egg
Finished processing dependencies for distribute
root::lati { ~/Dokumenty/python }-> pip install MySQL-python
Downloading/unpacking MySQL-python
  Running setup.py egg_info for package MySQL-python
    Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
    Extracting in /tmp/tmpJjLZmX
    Now working in /tmp/tmpJjLZmX/distribute-0.6.28
    Building a Distribute egg in /home/marek/Dokumenty/python/build/MySQL-python
    /home/marek/Dokumenty/python/build/MySQL-python/distribute-0.6.28-py2.7.egg
   
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
    building '_mysql' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'final',1) -D__version__=1.2.4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g
    In file included from _mysql.c:44:0:
    /usr/include/mysql/my_config.h:422:0: warning: "HAVE_WCSCOLL" redefined [enabled by default]
    /usr/include/python2.7/pyconfig.h:890:0: note: this is the location of the previous definition
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r -lpthread -lz -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
   
Successfully installed MySQL-python
Cleaning up...

środa, 4 września 2013

python modules

mymodule.py

#!/usr/bin/python
import os
import datetime

def autor():
        print 'Hello it\'s me Marek Borkowski'
def cpu():
        os.system("lscpu")

version = '1.0'
now = datetime.datetime.now()


test.py
#!/usr/bin/pypy

import mymodule
from mymodule import version
from mymodule import now

mymodule.autor()

print 'present version is: ', version, 'we have: ', now
mymodule.cpu()
~                


simple python function

#!/usr/bin/pypy

def printMax(a, b):
        if a > b:
                print a, 'is max'
        else:
                print b, 'is max'

x = int(raw_input("Enter int: "))
y = int(raw_input( "Enter int: "))

printMax(x, y)

show details about CPU

marek::lati { ~ }-> lscpu
Architecture:          x86_64
Tryb(y) pracy CPU:     32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Wątków na rdzeń:    2
Rdzeni na gniazdo:     4
Socket(s):             1
Węzłów NUMA:        1
ID producenta:         GenuineIntel
Rodzina CPU:           6
Model:                 42
Wersja:                7
CPU MHz:               800.000
BogoMIPS:              4789.10
Wirtualizacja:         VT-x
Cache L1d:             32K
Cache L1i:             32K
Cache L2:              256K
Cache L3:              6144

wtorek, 3 września 2013

ls

ls -lSrd /var/log/*{,/*} # Show a reverse sorted by size list of the files in both /var/log and subdirs of /var/log together.

niedziela, 1 września 2013

isert data to db from raw_input

#!/usr/bin/python


import MySQLdb as mdb
name = str(raw_input('enter name: '))
surname = str(raw_input('enter surname: '))
con = mdb.connect('localhost', 'root', 'password', 'baza');

with con:

        cur = con.cursor()
        cur.execute("INSERT INTO adresy(imie,nazwisko) VALUES('"+name+"', '"+surname+"')")

        cur.execute("Select * from baza.adresy")
        for row in cur.fetchall():
                id = str(row[0])
                imie = str(row[1])
                nazwisko = str(row[2])

                print "id: ",id
                print "imie: ",imie
                print "nazwisko: ",nazwisko
                print "--------"
        cur.close()