* 출처 : http://www.dreamy.pe.kr/zbxe/CodeClip/163974
ADB PM 명령어 정리 ( pkg 파일 가져오기 )
안드로이드 최신 버전의 SDK에서 pm명령어 모음입니다. adb shell로 접근하여 얻을 수 있는 명령어입니다. adb shell 접근 방법은 아래에서 설명하겠습니다.
명령어를 통해 앱을 설치하거나, 삭제하고, 사용자를 추가하고, 삭제 할 수 있는 명령어도 있습니다. 현재 기본값으로 셋팅 된 설치 경로를 가져오는 get-install-location 도 있습니다. 일반적으로 [0/auto]가 설정되어 있습니다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | usage: pm list packages [-f] [-d] [-e] [-s] [-e] [-u] [FILTER] pm list permission- groups pm list permissions [-g] [-f] [-d] [-u] [GROUP] pm list instrumentation [-f] [TARGET-PACKAGE] pm list features pm list libraries pm path PACKAGE pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH pm uninstall [-k] PACKAGE pm clear PACKAGE pm enable PACKAGE_OR_COMPONENT pm disable PACKAGE_OR_COMPONENT pm disable-user PACKAGE_OR_COMPONENT pm set - install -location [0 /auto ] [1 /internal ] [2 /external ] pm get- install -location pm createUser USER_NAME pm removeUser USER_ID pm list packages: prints all packages, optionally only those whose package name contains the text in FILTER. Options: -f: see their associated file . -d: filter to only show disbled packages. -e: filter to only show enabled packages. -s: filter to only show system packages. -3: filter to only show third party packages. -u: also include uninstalled packages. pm list permission- groups : prints all known permission groups . pm list permissions: prints all known permissions, optionally only those in GROUP. Options: -g: organize by group. -f: print all information. -s: short summary. -d: only list dangerous permissions. -u: list only the permissions users will see. pm list instrumentation: use to list all test packages; optionally supply <target-package> to list the test packages for a particular application. Options: -f: list the .apk file for the test package. pm list features: prints all features of the system. pm path: print the path to the .apk of the given PACKAGE. pm install : installs a package to the system. Options: -l: install the package with FORWARD_LOCK. -r: reinstall an exisiting app, keeping its data. -t: allow test .apks to be installed. -i: specify the installer package name. -s: install package on sdcard. -f: install package on internal flash. pm uninstall: removes a package from the system. Options: -k: keep the data and cache directories around after package removal. pm clear : deletes all data associated with a package. pm enable , disable, disable-user: these commands change the enabled state of a given package or component (written as "package/class" ). pm get- install -location: returns the current install location. 0 [auto]: Let system decide the best location 1 [internal]: Install on internal device storage 2 [external]: Install on external media pm set - install -location: changes the default install location. NOTE: this is only intended for debugging; using this can cause applications to break and other undersireable behavior. 0 [auto]: Let system decide the best location 1 [internal]: Install on internal device storage 2 [external]: Install on external media < /target-package > |
이 중 가장 많이 사용하는 명령어가 앱을 강제로 SD카드로 이동하는 명령어 일 겁니다. 해당 명령어도 아래와 같이 변경되었습니다.
설치 경로의 기본 값을 가져오는 명령어와 설정하는 명령어입니다.
pm get-install-location //기본값으로 지정된 설치 경로를 불러옵니다.
pm set-install-location 0/1/2 //강제로 경로를 설정합니다.
[adb를 이용한 apk 파일 추출 및 인스톨]
c:\> adb shell
# pm list packages -f
...
package:/system/app/SettingsProvider.apk=com.android.providers.settings
package:/system/app/TtsService.apk=android.tts
package:/system/app/Mms.apk=com.android.mms << 이걸 가져오고 싶으면...
package:/system/app/MediaProvider.apk=com.android.providers.media
package:/system/app/CertInstaller.apk=com.android.certinstaller
package:/system/app/DownloadProvider.apk=com.android.providers.downloads
...
# exit
c:\>adb pull /system/app/Mms.apk .
adb pull (가져올 파일 경로/파일명.apk) (받을 경로/파일명.apk)
출처: http://www.dreamy.pe.kr/zbxe/CodeClip/163972
* ADB AM 명령어 정리 ( Activity 실행하기 )
[Usage]
- am start -a android.intent.action.MAIN -n 패키지명/액티비티 경로명
- am startservice -n 패키지명/서비스경로명
- adb shell am broadcast -a "브로드캐스트명"
쉘에서 액티비티나 서비스를 실행하는 방법입니다.
쉘의 AM 명령어를 사용합니다.
1. 액티비스 실행하는 방법
*명령어
adb shell am start -a android.intent.action.MAIN -n 패키지명/액티비티 경로명
예)
am start -a android.intent.action.MAIN -n com.example.echo/com.example.echo.echodemo
2. 서비스 실행하는 방법
*명령어
adb shell am startservice -n 패키지명/서비스경로명
예)
am startservice -n com.example.echo/com.example.echo.echoservice
3. broadcast 테스트하기
*명령어
adb shell am broadcast -a "브로드캐스트명"
ex)
adb shell am broadcast -a android.accounts.LOGIN_ACCOUNTS_CHANGED
자주쓰는 am 옵션
- device 인식이 잘 안될때 케이블을 꼽았다 꼽거나 adb server를 죽입니다.
adb kill-server
- 연결되있는 devices 리스트를 볼수있습니다.
adb devices
- 여러개의 device를 연결했을 경우 선택해서 사용할 수 있습니다.
adb -d logcat (device)
adb -e logcat (emulator)
adb -s emulator-xxx logcat (device serial)
- 쉘
adb -d shell
- apk 설치
adb -d install test.apk
adb -d shell
# pm install /sdcard/test.apk
- 재설치
adb -d install -r test.apk
- 사인 문제로 재설치 안될 경우 오버라이트로 설치
adb -d push test.apk /system/app
- 텍스트 입력입니다. 주로 터치키보드로 긴 URL이나 긴 비밀번호 입력하기 힘들때 사용합니다.
adb shell input text "삼천궁녀"
- 디버깅 용도로 아주 가끔 사용합니다. 랜덤 이벤트로 테스트합니다.
adb shell monkey -v 1000 com.test.app1
- 특정 액티비티를 실행합니다.
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings
페이스북 앱 실행
am start -a android.intent.action.VIEW -d facebook://facebook.com/inbox
sd카드
am start -a android.intent.action.VIEW -d file:///sdcard/me.vcard -t text/x-vcard
갤러리 실행
am start -a android.intent.action.GET_CONTENT -t image/jpeg
카메라 실행
am start -a android.media.action.IMAGE_CAPTURE
환경설정 실행
am start -a android.intent.action.MAIN -n com.android.settings/.Settings
브라우저로 구글띄우기
am start -a android.intent.action.VIEW http://www.google.com
전화걸기 다이얼 입력
am start -a android.intent.action.DIAL tel:010XXXXXXX
전화걸기
am start -a android.intent.action.CALL tel:010XXXXXXX
전화걸기
am start -a android.intent.action.DAIL -d tel:010-XXXX-XXXX
문자전송
am start -a android.intent.action.SENDTO -d sms:"010XXXXXXXX" --es sms_body "test message!!" --ez exit_on_sent true
==============================
미결
$ adb shell input keyevent 22
$ adb shell input keyevent 6
==============================
패턴?
am start -n com.android.settings/com.android.settings.ChooseLockGeneric --ez confirm_credentials false --ei lockscreen.password_type 0 --activity-clear-task
GPS
am start -a android.intent.action.VIEW geo:37.111111-222.333333
달력실행
am start -n com.android.calendar/com.android.calendar.LaunchActivity
출처 : http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
* ADB Capture 정리
Grab Android screenshot to computer via ADB
There are many ways to take a screen shot on Android device. One simple way to capture the screen on Galaxy Nexus is to simultaneously press and hold Power and Volume Down buttons. The image will be saved in a "Screenshot" directory and accessible via Gallery.
Quite often, however, I need to copy the captured image over to my computer. Usually, I do this with adb pull
command, but if I'm going to use CLI to retrieve the file, why don't I take the screen shot with it as well?
One method is to use screencap
command via adb shell
like so:
adb shell screencap -p /sdcard/screen.png adb pull /sdcard/screen.png adb shell rm /sdcard/screen.png
Not bad, but seems like there's some room for improvement.
Information provided by
screencap -h
indicates that screen shot can be sent to stdout, but running adb shell screencap -p > screen.png
results in seemingly corrupt file.Luckily, I wasn't the first person looking into this issue. Apparently, adb shell is performing an EOL (end-of-line) character conversion, from LF (line feed, '\n', 0x0A) to CR+LF (carriage return followed by line feed, '\r\n', 0x0D0A).
If that sounds familiar, that's because I've dealt with this before. Unfortunately, this time we're working with binary data, so using
tr -d '\r'
command to remove all 0x0D will likely corrupt it by also removing bytes that aren't part of the 0x0D0A sequence. We want to only remove carriage return characters when they are followed by a line feed.The solution is to use sed search and replace as follows:
adb shell screencap -p | sed 's/\r$//' > screen.png
Unfortunately, I found that sed fix while works on Ubuntu doesn't work on OS X. This solution using perl handles binary search and replace better:
adb shell screencap -p | perl -pe 's/\x0D\x0D\x0A/\x0A/g' > screen.png
Now we have a one-liner that grabs a screen shot from the Android device and stores directly on the computer executing the command. Beautiful.
* 출처 : http://www.dreamy.pe.kr/zbxe/index.php?mid=CodeClip&category=113507&page=3&document_srl=165558
* mongkey 테스트 ( 무작위 테스트 )
몽키 테스트 (Monkey Test)
1) 몽키 테스트란?
Monkey는 Android SDK에서 제공하는 프로그램으로, emulator나 device에 대해 random한 event stream을 발생시킵니다. 마치 원숭이가 기기를 작동하는 것처럼 random event를 발생시키기 때문에 monkey라는 이름이 붙여졌습니다. Event는 click, touch, gesture, system level event 등이 있습니다.
2) 몽키 테스트의 목적.
Smart phone을 사용함에 있어, 인간은 선행 학습에 의해 device와 상호작용을 합니다.
따라서 극단적인 사용이나 Edge case 들에 대해 Error 가 발생하는지를 확인하기가 어렵습니다.
Ex) Android phone에 OK 버튼을 포함한 Pop up 메뉴가 나오면 인간은 OK 버튼을 클릭하지만,
Monkey는 이를 인지하지 못하고 아무 버튼이나 누르거나 아무곳이나 터치하게 됩니다.
Monkey test는 adb shell 환경에서 작동하는 어플리케이션입니다.
ex) adb shell monkey 500 -> 500개의 random event를 생성합니다.
adb ?s emulator-<emulator number> shell monkey <count>
--pct-motion <percent> 드래그 event 발생 빈도 조절
--pct-trackball <percent> 트랙볼 event 발생 빈도 조절
--pct-nav <percent> Navigation event 발생 빈도 조절
--pct-majornav <percent> Back, Home 버튼등의 major navigation event 발생 빈도 조절
--pct-syskeys <percent> System event 발생 빈도 조절 (Volume, home, end call 등)
--pct-appswitch <percent> 새로운 app. 실행 event 발생 빈도 조절
--pct-anyevent <percent> 기타 event 발생 빈도 조절
: trackball, navigation 0%, touch 60%, motion 20%의 이벤트 비율로 event 500개 발생
(Seed를 설정하지 않거나, 동일한 seed로 event를 발생시키면 항상 같은 event를 발생합니다.)
--throttle <milliseconds> Event 사이의 delay 조정
-v <number of events> 설정한 수만큼의 event 발생
: 1234를 seed로 1초(1000msec)마다, 총 500개의 event를 발생시킴
: email application에 대해 200회의 event 발생
ADB 셸에서 Exerciser/Monkey 도구를 이용해서 특정 응용프로그램에 무작위한 사용자 사건들을 보낼 수 있다.
Monkey라는 이름은 이 도구가 마치 단말기를 원숭이에게 넘겨준 후 마음대로 키를 누르거나 화면을 만지게 할 때와 비슷한 효과를 내기 때문에 붙은 것이다. 튼튼하게 설계되지 않았다면, 그런 무작위한 입력 사건들에 의해 응용프로그램이 죽게 될 것이다. 그런 일이 생기면 Monkey 도구는 무작위 입력을 중단하고 오류를 보고한다.
이런 기능은 품질 보증 작업에 아주 유용하다.
응용프로그램에 대해 Monkey 실행
monkey의 명령 구문은 다음과 같다.
adb shell monkey -p <package> <options> <event count>
다음은 에뮬레이터에 있는 GroceryList 응용프로그램에 다섯 개의 무작위 사건을 보내는 예이다.
adb -s emulator-5554 shell
# monkey -p com.androidbook.grocerylist 5
Monkey의 행동보기
-v 옵션을 주면 Monkey가 발생하는 사건들을 볼 수 있다. 예를 들어 Monkey가 GroceryList 응용 프로그램에게 무작위 사건 다섯 개를 보내게 하되 그 사건들이 구체적으로 어떤 것인지를 알고 싶다면 다음과 같이 하면 된다.
adb -s emulator-5554 shell
#monkey -p com.androidbook.grocerylist -v 5
위의 명령어를 치면 테스팅한 리스트 내용이 찍혀 나온다.
Monkey의 행동 제어하기
사건 종류에 가중치를 부여함으로써 Monkey가 특정 종류의 사건들을 더/덜 발생하게 만들 수 있다. Monkey가 발생하는 사건 종류와 기본 백분율이 표에 정리 되어 있다.
<안드로이드 프로그래밍 부록 C p610 표 C.1 참고>
예) monkey -p com.androidbook.grocerylist --pct-nav 50 --pct-majornav 50 -v 5
( 기본 내비게이션과 주 내비게이션 사건들이 50 대 50 의 비율로 발생하게 하는 예이다. )
재현 가능한 무작위 사건 발생
무작위 사건 발생을 위해 Monkey 가 사용하는 난수열의 종잣값(seed)을 명시적으로 지정할 수 있다.
이 기능을 이용하면, 무작위한 사건들을 발생하되 필요하다면 나중에 그 사건들을 똑같이 다시 재현 하는 것이 가능하다 ( 이를 테면 버그가 제대로 고쳐졌는지를 확인하는 데 활용할 수 있다.)
종잣값을 지정하는 옵션은 -s이다.
monkey -p <패키지> -s <종잣값> -v <사건 개수>
다음은 555라는 종잣값에 비롯된 다섯 무작위 사건들을 GroceryList에 보내는 예이다,.
monkey - p com.androidbook.grocerylist -s 555 -v 5
종잣값이 다르면 Monkey가 발생하는 사건들도 달라진다. 반대로, 같은 종잣값을 지정하면 항상 동일한 사건들이 발생한다. 이는, 사건들을 재현하기 위해서는 종잣값을 기억해 둘 필요가 있다는 뜻이다. 한가지 방법은, 미리 무작위한 종잣값들을 만들어 두고, 그 종잣값을 (또한 종류별 발생 비율 등 기타 옵션들도)버그 보고서나 디버그 로그에 기록해 두는 것이다. 이후 버그 교정을 확인할 때 그 종잣값을 다시 지정함으로써 오작동을 일으킨 사건들을 재현 할 수 있다.
사건 발생 속도 제어
기본적으로 Monkey는 사건들을 최대한 빠르게 발생한다. 발생 속도를 변경하고 싶다면 다음과 같이 --throttle 옵션을 사용하면 된다:
monkey --throttle <밀리 초 단위 시간> <사건 개수>
다음은 다섯 개의 무작위 사건을 1초(1000밀리초) 간격으로 GroceryList 응용프로그램에 보내는 예이다.
monkey -p com.androidbook.grocerylist -v --throttle 1000 5
http://developer.android.com/tools/help/monkey.html
UI/Application Exerciser Monkey
The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
Overview
The Monkey is a command-line tool that that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.
The Monkey includes a number of options, but they break down into four primary categories:
- Basic configuration options, such as setting the number of events to attempt.
- Operational constraints, such as restricting the test to a single package.
- Event types and frequencies.
- Debugging options.
When the Monkey runs, it generates events and sends them to the system. It also watches the system under test and looks for three conditions, which it treats specially:
- If you have constrained the Monkey to run in one or more specific packages, it watches for attempts to navigate to any other packages, and blocks them.
- If your application crashes or receives any sort of unhandled exception, the Monkey will stop and report the error.
- If your application generates an application not responding error, the Monkey will stop and report the error.
Depending on the verbosity level you have selected, you will also see reports on the progress of the Monkey and the events being generated.
Basic Use of the Monkey
You can launch the Monkey using a command line on your development machine or from a script. Because the Monkey runs in the emulator/device environment, you must launch it from a shell in that environment. You can do this by prefacing adb shell
to each command, or by entering the shell and entering Monkey commands directly.
The basic syntax is:
$ adb shell monkey [options] <event-count>
With no options specified, the Monkey will launch in a quiet (non-verbose) mode, and will send events to any (and all) packages installed on your target. Here is a more typical command line, which will launch your application and send 500 pseudo-random events to it:
$ adb shell monkey -p your.package.name -v 500
Command Options Reference
The table below lists all options you can include on the Monkey command line.
Category | Option | Description |
---|---|---|
General | --help | Prints a simple usage guide. |
-v | Each -v on the command line will increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, and final results. Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. Level 2 provides more detailed setup information such as activities selected or not selected for testing. | |
Events | -s <seed> | Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events. |
--throttle <milliseconds> | Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there is no delay and the events are generated as rapidly as possible. | |
--pct-touch <percent> | Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen.) | |
--pct-motion <percent> | Adjust percentage of motion events. (Motion events consist of a down event somewhere on the screen, a series of pseudo-random movements, and an up event.) | |
--pct-trackball <percent> | Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click.) | |
--pct-nav <percent> | Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.) | |
--pct-majornav <percent> | Adjust percentage of "major" navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key.) | |
--pct-syskeys <percent> | Adjust percentage of "system" key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.) | |
--pct-appswitch <percent> | Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing coverage of all activities within your package. | |
--pct-anyevent <percent> | Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth. | |
Constraints | -p <allowed-package-name> | If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you'll need to specify those packages as well. If you don't specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times ? one -p option per package. |
-c <main-category> | If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don't specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times ? one -c option per category. | |
Debugging | --dbg-no-events | When specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. This provides an environment in which you can monitor package transitions invoked by your application. |
--hprof | If set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~5Mb) files in data/misc, so use with care. See Traceview for more information on trace files. | |
--ignore-crashes | Normally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey will continue to send events to the system, until the count is completed. | |
--ignore-timeouts | Normally, the Monkey will stop when the application experiences any type of timeout error such as a "Application Not Responding" dialog. If you specify this option, the Monkey will continue to send events to the system, until the count is completed. | |
--ignore-security-exceptions | Normally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. If you specify this option, the Monkey will continue to send events to the system, until the count is completed. | |
--kill-process-after-error | Normally, when the Monkey stops due to an error, the application that failed will be left running. When this option is set, it will signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process(es) are not stopped, and the device is simply left in the last state after the final event. | |
--monitor-native-crashes | Watches for and reports crashes occurring in the Android system native code. If --kill-process-after-error is set, the system will stop. | |
--wait-dbg | Stops the Monkey from executing until a debugger is attached to it. |
'보안 > 도구' 카테고리의 다른 글
AFL fuzzer / fuzzing (0) | 2019.06.27 |
---|---|
hollywood 스크립트 설치 (헐리우드) (0) | 2019.01.25 |
공유 게시판 이더패드 (0) | 2015.03.30 |
[NMAP] MS-SQL pentest (0) | 2014.11.17 |
[Security] Fillder Menual / UseCase (0) | 2014.02.27 |