研究root权限

http://blog.csdn.net/hxdanya/article/details/39371759

PIE这个安全机制从4.1引入,但是Android L之前的系统版本并不会去检验可执行文件是否基于PIE编译出的。因此不会报错。但是Android L已经开启验证,如果调用的可执行文件不是基于PIE方式编译的,则无法运行。解决办法非常简单,在Android.mk中加入如下flag就行。

LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE_

http://hold-on.iteye.com/blog/1901152

Android应用程序永久获取root权限方法的基本思路,引入zlsu

http://blog.csdn.net/fengqiaoyebo2008/article/details/8843966

解决办法:

  1. 最简单的,adb remount

  2. 不行的话,adb shell su之后将文件系统remount为读写权限: mount -o remount rw /system。出于安全考虑,记得完事后remount回只读: mount -o ro,remount /system

  3. 和方法2类似,mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system

    chown 0:0 /system/bin/su

busybox chown 0:0 /system/bin/su

http://blog.csdn.net/wan_ing/article/details/53407748

android 版本更新 静默安装及自启动

http://www.jianshu.com/p/9ece07344630

Android上app_process启动java进程

python 5-2如何处理二进制文件

掌握二进制处理方法,比如struct.unpack;file.seek();file.tell();file.readinfo();aray.array()

file = open('', 'rb')
info = file.read(44)
import struct
struct.unpack('h', info[22:24]); #解析字节
 struct.unpack('i', info[24:28]);

import array
file.seek(0,2)#把指针挪到末尾
file.tell()#指针的位置
n = (file.tell() - 44) / 2
buf = array.array('h', (0 for _ in range(n)))
file.seek(44)
file.readinfo(buf)
for i in range(n): buf[i] /= 8

f2 = open('demo2.wav', 'wb')
f2.write(info)
buf.tofile(f2)
f2.close()

python 4-5如何对字符串进行左, 右, 居中对齐

字符串对齐使用ljust,ojust,center或者format的’<‘’>’’^’三个字符

s = 'abd'
s.ljust(10, '_')
s.rjust(10, '_')
s.center(10, '_')
format(s, '<10')
format(s, '>10')
format(s, '^10')

d ={'a':100,'adb3dd':9,'lof':3444}
map(len, d.keys())
list(map(len, d.keys()))
k = max(map(len, d.keys()))
for x in d:
      print(x.ljust(k), ':', d[x])
rmax = max(map(len, [str(x) for x in d.values()]))
rmax
for x in d:
     print(x.ljust(k), ':', str(d[x]).rjust(rmax))

python 4-3如何调整字符串中文本的格式

读入一个日志文件,把里面的时间格式换成另外一种格式,用到了re模块正则表达式的分组

file = open("./catalina.2016-11-02.log").read()    
import re 
result = re.sub(r'(\d{2}), (\d{4}) (\d{2}):(\d{2}):(\d{2})', r'\2,\1,\5:\4:\3', file)
result = re.sub(r'(?P<day>\d{2}), (?P<year>\d{4}) (?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})', r'\g<year>,\g<day>,\g<second>:\g<minute>:\g<hour>', file)
print(result)

python 4-2如何判断字符串a是否以字符串b开头或结尾

主要运用endswith()和startswith()识别字符串开头和结尾

import os
os.listdir(".")
[name for name in os.listdir('.') if name.endswith('txt')]
os.stat('./history.txt')
ls -l
os.stat('./history.txt').st_mode
oct[os.stat('./history.txt').st_mode]
import stat
#设置当前位为1
os.chmod('./history.txt', os.stat('./history.txt').st_mode | stat.S_IXUSR)
#设置当前位取反
os.chmod('./history.txt', os.stat('./history.txt').st_mode ^ stat.S_IXUSR)

python 4-1如何拆分含有多种分隔符的字符串

如果是对字符串做一个字符的分割,用str.split()分割效率比较高;如果是多个字符的分割,用re.split()分割效率比较高

def strSplit(x, d):
    return x.split(d)

def mySplit(s, ds):
    res = [s]
    for d in ds:
        t = []
        #对二维数据降成一维数组
        map(lambda x: t.extend(x.split(d)), res)
        res = t

    return [x for x in res if x]

s = 'ab;dd:fdfd\dfsa+ddf=vfv%dfdf'
print(mySplit(s, '=!+-=;:^%$\\'))

#使用re正则表达式分割字符串
import re
print(re.split(r'[=!+-=;:^%$\\]+', s))

python 3-6如何在一个for语句中迭代多个可迭代对象

主要是使用了zip和chain分别对迭代器的串行和并行处理

e1 = [1, 2, 3, 4]
e2 = [9, 8, 7, 6]
for x in zip(e1, e2):
   ...:     print(x)
from itertools import chain
for x in chain(e1, e2):
    ...:     print(x)

结果是

zip并行的输出是
(1, 9)
(2, 8)
(3, 7)
(4, 6)

chain串行的输出是
1
2
3
4
9
8
7
6

title: python 2-5如何对迭代器做切片操作
date: 2017-05-23 22:18:36
tags:

使用islice来让迭代器支持切片操作,节省资源,不用一次性读完全部

from itertools import islice
l = range(1, 21)
for x in  l:
   ...:     print(x)
t = iter(l)
for x in islice(t, 5, 10): 
    ...:    print(x)
for x in t:
    ...:     print(x)