Ejemplo n.º 1
0
def update_db():
	adb = ADB()
        adb.set_adb_path('adb')

	adb.connect_remote(smartphone_addr)

        cmd = "su -c 'cat /data/data/com.android.providers.telephony/databases/mmssms.db > /sdcard/mmssms.db'"
        adb.shell_command(cmd)

        adb.get_remote_file('/sdcard/mmssms.db','./')

        cmd = "su -c 'rm /sdcard/mmssms.db'"
        adb.shell_command(cmd)
Ejemplo n.º 2
0
class SmsReader():
    def __init__(self, adb_path, local_sms_db = "sms/", remote_sms_db = '/data/data/com.android.providers.telephony/databases/mmssms.db'):
        #Thread.__init__:
        self.ADB_PATH = adb_path
        # avoid using ~/ at the beginning of path
        self.phone = ADB(self.ADB_PATH)
        self.LOCAL_SMS_DB = local_sms_db + 'mmssms.db'        
        self.REMOTE_SMS_DB = remote_sms_db
        self.phone.get_remote_file(
                self.REMOTE_SMS_DB, 
                self.LOCAL_SMS_DB
                )
        self.engine = create_engine('sqlite:///%s' % self.LOCAL_SMS_DB, echo=False)
        self.metadata = MetaData(self.engine)
        self.sms_table = Table('sms', self.metadata, autoload=True)
        mapper(Sms,self.sms_table )
        Session = sessionmaker(bind=self.engine)
        self.session = Session()
        
        self.sms = self.session.query(Sms)
        self.messages = [msg.body for msg in self.sms]
        self.num_sms = self.sms.count()
        self.last_sms_num = self.num_sms
        self.new_sms  = []
        self.session.close()

    #copy sms database
    def update(self):
        self.phone.get_remote_file(
                self.REMOTE_SMS_DB, 
                self.LOCAL_SMS_DB 
                )
        self.sms = self.session.query(Sms)
        self.messages = [msg.body for msg in self.sms]
        self.sms_num = self.sms.count()
        if self.sms_num > self.last_sms_num:
            difference = self.sms_num - self.last_sms_num
            temp_sms = self.sms.slice(self.last_sms_num, self.sms_num).all()
            self.new_sms = [x.body for x in temp_sms]
            self.last_sms_num = self.sms_num

        self.session.close()

    def quit(self):
        self.session.close() 
Ejemplo n.º 3
0
class SmsReader():
    def __init__(self):

        self.ADB_PATH = '/Users/cmart/code/android/android-sdk-macosx/platform-tools/adb'
        # avoid using ~/ at the beginning of path
        self.phone = ADB(self.ADB_PATH)
        self.DATABASE_PATH = 'db/mmssms.db'
        self.phone.get_remote_file(
                '/data/data/com.android.providers.telephony/databases/mmssms.db', 
                self.DATABASE_PATH
                )

        self.engine = create_engine('sqlite:///%s' % self.DATABASE_PATH, echo=False)
        self.metadata = MetaData(self.engine)
        self.sms_table = Table('sms', self.metadata, autoload=True)
        mapper(Sms,self.sms_table )
        Session = sessionmaker(bind=self.engine)
        self.session = Session()
        
        self.sms = self.session.query(Sms)
        self.messages = [msg.body for msg in self.sms]
        self.num_sms = self.sms.count()
        self.last_sms_num = self.num_sms
        self.new_sms  = []
        self.session.close()

    #copy sms database
    def update(self):
        self.phone.get_remote_file(
                '/data/data/com.android.providers.telephony/databases/mmssms.db', 
                self.DATABASE_PATH  
                )
        self.sms = self.session.query(Sms)
        self.messages = [msg.body for msg in self.sms]
        self.sms_num = self.sms.count()
        if self.sms_num > self.last_sms_num:
            difference = self.sms_num - self.last_sms_num
            temp_sms = self.sms.slice(self.last_sms_num, self.sms_num).all()
            self.new_sms = [x.body for x in temp_sms]
            self.last_sms_num = self.sms_num

        self.session.close() 
Ejemplo n.º 4
0
print "getting devices list..."
error,lst_device=adb.get_devices()
print "found " + str(len(lst_device)/2) + " devices."
print lst_device
#device_id=raw_input("input device id:")
print "locating thumbdata files.."
thumbfiles=adb.shell_command("ls -a /sdcard/DCIM/.thumbnails/ ")
lst_thumb=thumbfiles.split("\n")

for item in lst_thumb:
    if item.find(".thumbdata")!=-1:
        print "found:" + item
        print "copying..."
        #adb.run_cmd("pull /storage/emulated/0/DCIM/.thumbnails/" + item[:-1] + " " + os.getcwd() + "/tmp/" + item[:-1] )
        if not  os.path.isfile(os.getcwd() + "/tmp/" + item[:-1]):
            adb.get_remote_file("/sdcard/DCIM/.thumbnails/" + item[:-1] ,os.getcwd() + "/tmp/" + item[:-1] )
            print "copy OK!"
        else:
            print "cache found. skipping..."
        print "extracting thumb pictures..."
        if not os.path.exists(os.getcwd() + "/extract/" + item[:-1] ): # make a new dir
            os.makedirs(os.getcwd() + "/extract/" + item[:-1]  )
        file_size=os.path.getsize(os.getcwd() + "/tmp/" + item[:-1])
        print "file size:" + str(file_size)
        f=open(os.getcwd() + "/tmp/" + item[:-1],"rb")
        offset=0
        while(offset<file_size):
            f.seek(offset)
            tmp=f.read(10000)
            if tmp[0]=="\x01":
                #print offset
Ejemplo n.º 5
0
class ADBFS(Fuse):
    opened = {}

    def __init__(self, *args, **kw):
        Fuse.__init__(self, *args, **kw)
        self.adb = ADB('adb')

    def connect(self):
        print 'Connect device to computer...'
        self.adb.wait_for_device()
        err = self.adb.get_error()
        if err:
            print 'ADB error:', err.strip()
            exit(5)

        print 'Driver enabled!'

    def _sh(self, cmd):
        try:
            return self.adb.shell_command("'%s'" % cmd) or ""
        except Exception as e:
            print 'Command ', cmd, 'failed:', self.adb.get_error()
            raise e
    
    def _ls(self, path):
        if USE_LS:
            return self._sh('ls "%s"' % path).split()
        return self._sh('ls -a "%s"' % path).splitlines()

    # ---- DIRECTORIES ----
    def readdir(self, path, offset):
        if self._sh('test -d "%s"&&echo true' % path).strip() == 'true':
            if path[:-1] != '/':
                path += '/'
            dd = self._ls(path)
            for i in dd:
                yield Direntry(i)

    def rmdir(self, path):
        self.adb.shell_command('rmdir "%s"' % path)
        non_cached(path)

    def mkdir(self, path, mode):
        self.adb.shell_command('mkdir "%s"' % path)
        self.adb.shell_command('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    # ---- FILES ----
    def create(self, path, mode):
        self.adb.shell_command('echo "" >"%s"' % path)
        self.adb.shell_command('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    def mknod(self, path, mode, dev):
        self.adb.shell_command('touch "%s"' % path)
        self.adb.shell_command('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    def open(self, path, flags):
        if self._sh('test -e "%s"&&echo true' % path).strip() != 'true':
            return -ENOENT

        if path in self.opened:
            self.opened[path][1] += 1
        else:
            rfn = cached(path, lambda x: self.adb.get_remote_file(path, x))
            self.opened[path] = [open(rfn, 'rb+'), 1]

    def release(self, path, flags):
        f = self.opened[path]
        f[1] -= 1
        if f[1] == 0:
            f[0].close()
            del self.opened[path]

    def read(self, path, size, offset):
        f = self.opened[path][0]
        f.seek(0, 2)
        slen = f.tell()
        if offset < slen:
            if offset + size > slen:
                size = slen - offset

            f.seek(offset)
            return f.read(size)
        return ''

    def write(self, path, data, offset):
        f = self.opened[path][0]
        f.seek(0, 2)
        slen = f.tell()
        if offset < slen:

            f.seek(offset)
            l = f.write(data)

            rfn = cached(path, lambda x: self.adb.get_remote_file(path, x))
            self.adb.push_local_file(rfn, path)
            return l
        return 0

    def fsync(self, path):
        if path in FILES_CACHE:
            rfn = FILES_CACHE[path]
            self.adb.push_local_file(rfn, path)
            non_cached(path)

    def unlink(self, path):
        self.adb.shell_command('rm "%s"' % path)
        non_cached(path)

    # ---- OTHER ----
    @lru_cache
    def getattr(self, path):
        st = Stat()
        st.st_nlink = 1
        if self._sh('test -e "%s"&&echo true' % path).strip() != 'true':
            return -ENOENT

        elif self._sh('test -h "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFLNK

        elif self._sh('test -d "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFDIR

        elif self._sh('test -f "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFREG

        elif self._sh('test -c "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFCHR

        elif self._sh('test -b "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFBLK

        elif self._sh('test -p "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFIFO

        elif self._sh('test -s "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFSOCK

        else:
            st.st_mode = 0

        st.st_mode |= int(self._sh('stat -c%%a "%s"' % path) or '0', 8)
        st.st_size = int(self._sh('stat -c%%s "%s"' % path) or '0')
        print "file:", path, "size: ", st.st_size, "mode:", oct(st.st_mode)

        return st

    def chmod(self, path, mode):
        self._sh('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    def chown(self, oid, gid, path):
        pass # TODO: chown

    def rename(self, path, new):
        self._shd('mv "%s" "%s"' % (path, new))
        non_cached(path)
        non_cached(new)

    def statfs(self):
        st = StatVfs()
        st.f_bsize = 1024
        st.f_frsize = 1024
        st.f_bfree = 0
        st.f_bavail = 0
        st.f_files = 2
        st.f_blocks = 4
        st.f_ffree = 0
        st.f_favail = 0
        st.f_namelen = 255
        return st
Ejemplo n.º 6
0
        stickers_json = json.load(jf)

    if not args.skipadb:
        adb = ADB('{0}/platform-tools/adb'.format(os.environ['ANDROID_HOME']))

        if args.clean:
            adb.shell_command(
                'rm -rf /sdcard/Android/data/jp.naver.line.android/stickers')
            exit(0)

        print json.dumps(stickers_json,
                         sort_keys=True,
                         indent=2,
                         separators=(',', ': '))

        adb.get_remote_file(
            '/sdcard/Android/data/jp.naver.line.android/stickers', 'stickers')
        for d in os.listdir('stickers'):
            if d in stickers_json:
                stickers = os.listdir('stickers/{0}'.format(d))
                if len(stickers) == int(stickers_json[d]['count']) + 3:
                    print 'keep {0}'.format(d)
                    continue
            if not args.keep:
                print 'remove {0}'.format(d)
                shutil.rmtree('{0}/{1}'.format('stickers', d))

    with open('index.html', 'w') as index_html:
        index_html.write('<html><head></head><body>')

        for d in sorted(os.listdir('stickers')):
            with open('{0}.html'.format(d), 'w') as d_html: