安卓檢測logcat輸出內容指令碼

2021-10-04 14:16:19 字數 1817 閱讀 6250

import subprocess

import datetime

import os

import re

import time

info = ["launch bugly"]

result =

timeforlog = "%m-%d %h:%m:%s"

timeforfile = "%y-%m-%d %h-%m-%s"

filetime = datetime.datetime.now().strftime(timeforfile)

path = os.getcwd()

filepath = path + r"/"+filetime+"logcat.txt"

def logcatcatcher():

result = os.popen("adb shell date '+%s'")

timestamp = result.read()

timestamp = int(timestamp)

timelocal = time.localtime(timestamp)

#手機系統當前時間,手機時間有改動最好清一下logcat

phonetime = time.strftime("%m-%d %h:%m:%s",timelocal)

#'adb logcat -v time |findstr keyword'

ps = subprocess.popen('adb logcat -v time ',stdin=subprocess.pipe,stdout=subprocess.pipe,shell=true)

with open(filepath,"a", encoding='utf-8') as file:

file.write("**********=開始**********=")

file.close()

for lines in ps.stdout:

for inf in info :

#每行的內容,有需要可以加入正則提取

line = str(lines, encoding = "utf-8")

mat = re.search(r"(\d-\d\s\d:\d:\d)",line)

logtime = datetime.datetime.now().strftime(timeforlog)

if inf in line:

mat = re.search(r"(\d-\d\s\d:\d:\d)",line)

logtime = datetime.datetime.now().strftime(timeforlog)

#生成時間要比程式啟動要晚

if mat.group(0) >= phonetime:

print(result[inf])

# 輸出符合條件的行

# print(line)

logtime = datetime.datetime.now().strftime(timeforlog)

res = "\n"+logtime+result[inf]+"\n"

#輸出到檔案

with open(filepath,"a", encoding='utf-8') as file:

file.write(res)

# 輸出符合條件的行到檔案

# file.write(line)

file.close()

if __name__=='__main__':

logcatcatcher()

安卓 jni C C logcat 除錯輸出

最近在弄 ndk jni,記錄下除錯技巧 1.在 中加入 include define log tag jnidebug define logv android log print android log verbose log tag va args define logd android log...

安卓 內容提供者

1.contentprovider內容提供者 四大元件之一 主要用於在不同的應用程式之間實現資料共享的功能。自定義內容提供者 1 自定義類繼承sqliteopenhelper an highlighted block public class myopenhelper extends sqliteo...

安卓黑模組過非法檢測

許多安卓 不都是見得人的,我們都懂!像稍微高大上點的廣告植入。但為了讓使用者手機上面裝有的防毒軟體不檢測出廣告,我們就需要採取以下非正常的手段,如下 在編寫安卓應用 時候,我們會就所有的 都放在src目錄下,但是在打包安卓程式的時候,這些 將會編譯成乙個dex檔案,這個防毒軟體就會查詢這個檔案下面是...