-
Notifications
You must be signed in to change notification settings - Fork 112
/
sp_codec.py
114 lines (87 loc) · 3.51 KB
/
sp_codec.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
/*
* Android media framework fuzzer
* Copyright (c) 2015, Intel Corporation.
* Author: Alexandru Blanda (ioan-alexandru.blanda@intel.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
"""
from os import listdir
import sys
import subprocess
import re
import time
from utils import *
if sys.argv[1] == '-h':
print 'Usage:\n'
print 'codec.py <path_seed_files> <audio/video/list> <play/noplay> <seed_number> <device_id>'
print 'path_seed_files - path to directory containing the seed files'
print 'audio - seed files are of audio type'
print 'video - seed files are of video type'
print 'play/noplay - enable testing of playback capabilities'
print 'seed_number - number of the seed file to start from'
print 'device_id - device id\n'
sys.exit()
seed_files = listdir(sys.argv[1])
root_path = sys.argv[1]
length = len(seed_files)
start = int(sys.argv[4])
device_id = sys.argv[5]
# flush logcat buffer if a new campaign is started
if start == 0:
flush_log(device_id)
if sys.argv[2] == 'audio':
for x in range(start, length):
print '***** Sending file: ' + str(x) + ' - ' + seed_files[x]
# push the file to the device
cmd = 'adb -s ' + device_id + ' push ' + "'" + root_path \
+ '/' + seed_files[x] + "'" + " '/data/Music/" \
+ seed_files[x] + "'"
run_subproc(cmd)
# log the file being sent to the device
cmd = 'adb -s ' + device_id \
+ " shell log -p F -t Stagefright - sp_codec '*** " \
+ str(x) + " - Filename:'" + seed_files[x]
run_subproc(cmd)
# try to decode audio file
cmd = 'timeout 15 adb -s ' + device_id \
+ ' shell codec /data/Music/' + "'" + seed_files[x] + "'"
run_subproc(cmd)
if sys.argv[3] == 'play':
# try to play audio file
cmd = 'timeout 15 adb -s ' + device_id \
+ ' shell codec -o /data/Music/' + "'" + seed_files[x] + "'"
run_subproc(cmd)
# remove the file from the device
cmd = 'adb -s ' + device_id + ' shell rm /data/Music/*'
run_subproc(cmd)
if sys.argv[2] == 'video':
for x in range(start, length):
print '***** Sending file: ' + str(x) + ' - ' + seed_files[x]
# push the file to the device
cmd = 'adb -s ' + device_id + ' push ' + "'" + root_path \
+ '/' + seed_files[x] + "'" + " '/data/Movies/" \
+ seed_files[x] + "'"
run_subproc(cmd)
# log the file being sent to the device
cmd = 'adb -s ' + device_id \
+ " shell log -p F -t Stagefright - sp_codec '*** " \
+ str(x) + " - Filename:'" + seed_files[x]
run_subproc(cmd)
# try to decode video and audio streams from video file
cmd = 'timeout 15 adb -s ' + device_id \
+ ' shell codec /data/Movies/' + seed_files[x]
run_subproc(cmd)
# remove the file from the device
cmd = 'adb -s ' + device_id + ' shell rm /data/Movies/*'
run_subproc(cmd)