'OS/Android'에 해당되는 글 7건

  1. 2022.11.09 권한에 따른 안드로이드 앱 종류
  2. 2022.01.11 Adb 연결 편하게 wifi로 하기
  3. 2022.01.03 Android sepolicy 상태 확인 하기
  4. 2021.12.30 adb logcat 주요 옵션
  5. 2021.12.07 Apk 파일 한꺼번에 decompile 하기
  6. 2021.12.03 Android System Font list 가져오기, 적용하기
  7. 2021.11.26 adb shell 명령 log 로 logcat 출력하기

권한에 따른 안드로이드 앱 종류

OS/Android 2022. 11. 9. 22:49
반응형

System app : platform key sign + android:sharedUserId="android.uid.system"

 

Platform app : platform key sign

 

Priviliged app : /system/priv-app 에 있는 앱

 

Untrusted app : 나머지

 

* /system/priv-app 에 있고 platform key sign 이 된 경우 Platform app

반응형
:

Adb 연결 편하게 wifi로 하기

OS/Android 2022. 1. 11. 21:01
반응형

https://developer.android.com/studio/command-line/adb?hl=ko 

 

Android 디버그 브리지(adb)  |  Android 개발자  |  Android Developers

기기와 통신할 수 있는 다목적 명령줄 도구인 Android 디버그 브리지를 알아보세요.

developer.android.com

 

Android 11 이상

1. 개발자 옵션 > 무선 디버깅 진입

2. "사용안함" -> "사용 중" 으로 변경

3. 페어링 코드로 기기 페어링 선택

    팝업 내용 확인

4. PC : adb pair ip:pair_port

    ip:pair_port는 팝업에 나오는 정보로 설정

5. PC : "Enter pairing code:" 에서 팝업에 나오는 페어링 코드 입력

6. PC : adb connect ip:logcat_port

    무선 디버깅 화면에 나오는 ip, port 사용

7. PC : adb logcat

 

Android 10 이하(Android 11 에서도 동작함)

1. 개발자 옵션 > USB 디버깅

2. "사용안함" -> "사용 중" 으로 변경

3. USB로 디바이스 PC 연결

4. PC : adb tcpip 5555

5. PC : adb connect ip:5555

6. PC : adb logcat

 

 

반응형
:

Android sepolicy 상태 확인 하기

OS/Android 2022. 1. 3. 22:49
반응형

Process 별 sepolicy 보기

1. android 기기에 adb 연결

2. adb shell ps -eZ

......
u:r:priv_app:s0:c522,c768      u10_a248      29036    825 33799276 202616 0                  0 S com.google.android.googlequicksearchbox:search
u:r:priv_app:s0:c522,c768      u10_a247      29162    825 15532196 85196 0                   0 S com.google.process.gapps
u:r:gmscore_app:s0:c522,c768   u10_a247      29170    825 16504752 154944 0                  0 S com.google.android.gms
u:r:priv_app:s0:c522,c768      u10_a248      29251    825 16446808 150508 0                  0 S com.google.android.googlequicksearchbox:interactor
u:r:untrusted_app:s0:c1,c257,c512,c768 u0_a257 29267  825 32630088 143932 0                  0 S com.android.chrome:privileged_process2
u:r:app_zygote:s0:c512,c768    u0_a257       29274    825 16171312 74484 0                   0 S com.android.chrome_zygote
u:r:untrusted_app:s0:c5,c257,c522,c768 u10_a261 29314 825 15570464 85916 0                   0 S com.google.android.webview:webview_service
......

파일 별 sepolicy 보기

1. android 기기에 adb 연결

2. adb shell ls -lZ

......
drwxr-xr-x  18 root   system    u:object_r:tmpfs:s0                    380 2019-11-22 01:22 mnt
drwxr-xr-x   4 root   root      u:object_r:vendor_file:s0             4096 2009-01-01 00:00 odm
drwxr-xr-x   2 root   root      u:object_r:oemfs:s0                   4096 2009-01-01 00:00 oem
drwxrwx--x   3 root   system    u:object_r:omr_file:s0                4096 2019-01-06 12:31 omr
drwxr-xr-x   4 root   root      u:object_r:vendor_file:s0             4096 2009-01-01 00:00 optics
drwxr-xr-x   7 root   root      u:object_r:system_file:s0             4096 2009-01-01 00:00 prism
dr-xr-xr-x 846 root   root      u:object_r:proc:s0                       0 1970-01-01 09:00 proc
drwxr-xr-x   9 root   root      u:object_r:system_file:s0             4096 2009-01-01 00:00 product
......

 

반응형
:

adb logcat 주요 옵션

OS/Android 2021. 12. 30. 20:58
반응형

테스트 adb 버전

$ adb --version
Android Debug Bridge version 1.0.41
Version 31.0.2-7242960

전체 옵션 보기

$ adb logcat -h              
Usage: logcat [options] [filterspecs]

General options:
  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
......

logcat 버퍼 크기 확인

  -g, --buffer-size           Get the size of the ring buffers within logd.



$ adb logcat -g
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 2 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

logcat 버퍼 크기 변경

  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
                              'security' for Device Owner installations.
                              Multiple -b parameters or comma separated list of buffers are
                              allowed. Buffers are interleaved.
                              Default -b main,system,crash,kernel.

  -G, --buffer-size=<size>    Set size of a ring buffer in logd. May suffix with K or M.
                              This can individually control each buffer's size with -b.



set system buffer

$ adb logcat -G 5M -b system

$ adb logcat -g             
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

set all buffer

$ adb logcat -G 5M          

$ adb logcat -g   
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

기존 로그 지우기

  -c, --clear                 Clear (flush) the entire log and exit.
                              if -f is specified, clear the specified file and its related rotated
                              log files instead.
                              if -L is specified, clear pstore log instead.



$ adb logcat -c

로그 덤프(non block)

  -d                          Dump the log and then exit (don't block).



$ adb logcat -d
--------- beginning of system
12-30 15:11:05.979  1132  5037 I ActivityManager: Process com.samsung.android.dqagent
--------- beginning of main
12-30 15:11:05.980   825   825 I Zygote  : Process 25662 exited due to signal 9 (Killed)
12-30 15:11:05.980   604   604 I lmkd    : cached 5, sandbox(not0) 2
12-30 15:11:05.981  1132  1423 I libprocessgroup: Successfully killed process cgroup 
......
12-30 15:11:14.978   805   805 E audit   : type=1327 audit(1640844674.973:574366029):
12-30 15:11:14.978   805   805 E audit   : type=1400 audit(1640844674.977:574366030):
12-30 15:11:14.978   805   805 E audit   : type=1300 audit(1640844674.977:574366030):
$

로그 저장(block)

Option (adb logcat -h)
Outfile files:
  -f, --file=<file>           Log to file instead of stdout.
  -r, --rotate-kbytes=<n>     Rotate log every <n> kbytes. Requires -f option.
  -n, --rotate-count=<count>  Sets max number of rotated logs to <count>, default 4.



1000K, 최대 20개, /storage/emulated/0/logcat에 저장

$ adb logcat -r 1000 -n 20 -f /storage/emulated/0/logcat/logcat.log

$ adb shell ls -lh /storage/emulated/0/logcat/
total 676K
-rw-rw---- 1 root everybody 634K 2021-12-30 15:24 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01

$ adb shell ls -lh /storage/emulated/0/logcat/
total 1.0M
-rw-rw---- 1 root everybody 222K 2021-12-30 15:25 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.02

필터링

Filtering:
  -s                          Set default filter to silent. Equivalent to filterspec '*:S'
......

filterspecs are a series of 
  <tag>[:priority]

where <tag> is a log component tag (or * for all) and priority is:
  V    Verbose (default for <tag>)
  D    Debug (default for '*')
  I    Info
  W    Warn
  E    Error
  F    Fatal
  S    Silent (suppress all output)



$ adb logcat -s "AlarmManager:*" "BatteryStatsService:*"
12-30 15:39:24.326  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive
12-30 15:39:24.353  1132  4035 I BatteryStatsService: In wakeup_callback: resumed from 
12-30 15:39:25.054  1132  4935 I BatteryStatsService: In wakeup_callback: suspend aborted
12-30 15:39:26.410  1132  3545 V AlarmManager: unblockMARsRestrictedAlarmsForUidPackage

thread, time 정보 출력

-v <format>, --format=<format> options:
  Sets log print format verb and adverbs, where <format> is:
    brief long process raw tag thread threadtime time


default : Depends on the adb version
$ adb logcat -s "AlarmManager:*"
12-30 15:26:40.860  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

$ adb logcat -s "AlarmManager:*" -v time
12-30 15:22:01.749 E/AlarmManager( 1132): Set nextNonWakeup as mNextNonWakeupDeliveryTime

$ adb logcat -s "AlarmManager:*" -v thread
E( 1132: 1836) Set nextNonWakeup as mNextNonWakeupDeliveryTime=781912438 , orig nextNonWakeup=0

$ adb logcat -s "AlarmManager:*" -v threadtime
12-30 15:14:24.021  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

로그 레벨별 색 적용

$ adb logcat -v color

 

 

 

반응형
:

Apk 파일 한꺼번에 decompile 하기

OS/Android 2021. 12. 7. 11:06
반응형

1. Decompiler 다운로드 및 압축 풀기

https://github.com/skylot/jadx/releases

 

Releases · skylot/jadx

Dex to Java decompiler. Contribute to skylot/jadx development by creating an account on GitHub.

github.com

$ mkdir jadx          
$ mv jadx-1.3.0.zip jadx
$ cd jadx 
$ unzip jadx-1.3.0.zip 
Archive:  jadx-1.3.0.zip
  inflating: NOTICE                  
   creating: lib/
  inflating: lib/logback-classic-1.2.7.jar  
  inflating: lib/error_prone_annotations-2.5.1.jar  
  inflating: lib/jsr305-3.0.2.jar    
  inflating: lib/aapt2-proto-4.2.1-7147631.jar  
  inflating: lib/smali-2.5.2.jar     
  inflating: lib/dexlib2-2.5.2.jar   
  inflating: lib/ST4-4.0.8.jar       
  inflating: lib/guava-30.1.1-jre.jar  
  inflating: lib/reactive-streams-1.0.3.jar  
  inflating: lib/flatlaf-1.6.4.jar   
........

 

2. apk2java.sh

#! sh
apks=(test1.apk
    test2.apk
    test3.apk)

mkdir extract
cd extract
for (( i = 0 ; i < ${#apks[@]} ; i++ )) ; do
    ~/jadx/bin/jadx ../${apks[$i]}
done

 

3. 실행 결과

$ ls
apk2java.sh  test1.apk  test2.apk  test3.apk

$ ./apk2java.sh                               
INFO  - loading ...
INFO  - processing ...
ERROR - finished with errors, count: 4
INFO  - loading ...
INFO  - processing ...
ERROR - finished with errors, count: 4
INFO  - loading ...
INFO  - processing ...
ERROR - finished with errors, count: 4

$ ls extract 
test1  test2  test3
반응형
:

Android System Font list 가져오기, 적용하기

OS/Android 2021. 12. 3. 12:36
반응형

system/fonts 디렉토리에 있는 폰트 파일 리스트 출력

 

폰트 파일 적용

 

테스트 코드

import android.graphics.Typeface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.util.Log.*
import android.widget.TextView
import java.io.File

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onResume() {
        changeFont()
        super.onResume()
    }

    fun changeFont() {
    	// get font files
        val FONT_DIR = "/system/fonts/"
        val fontPaths = ArrayList<String>()
        val fontDir = File(FONT_DIR)
        val fontSuffix = ".ttf";

        for(font in fontDir.listFiles()) {
            if(font.name.endsWith(fontSuffix)) {
                fontPaths.add(font.absolutePath);
            }
        }

        for (fontFile in fontPaths) {
            Log.i("Font test","Font : $fontFile")
        }

		// apply font file
        val textView1 : TextView = findViewById(R.id.textview1)
        val textView2 : TextView = findViewById(R.id.textview2)

        val typeface1 = Typeface.createFromFile("/system/fonts/NotoSerif-Bold.ttf")
        textView1.typeface = typeface1
        textView1.text = "TestView 123 "

        val typeface2 = Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf")
        textView2.typeface = typeface2
        textView2.text = "TestView 123 "
    }
}

 

반응형
:

adb shell 명령 log 로 logcat 출력하기

OS/Android 2021. 11. 26. 18:46
반응형

log 명령을 통해 logcat 로그 추가 하는 방법

$ log --help
usage: log [-p PRI] [-t TAG] MESSAGE...

Logs message to logcat.

-p	Use the given priority instead of INFO:
	d: DEBUG  e: ERROR  f: FATAL  i: INFO  v: VERBOSE  w: WARN  s: SILENT
-t	Use the given tag instead of "log"

반응형
: