-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparseManifest.sh
More file actions
94 lines (65 loc) · 2.29 KB
/
parseManifest.sh
File metadata and controls
94 lines (65 loc) · 2.29 KB
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
#!/bin/bash
### Description
## Will analyze an AndroidManifest.xml file and record
## Usage ./parseManifest.sh <commitID> <filepath>/<filename>
## Location of output files
outputFiles=mainOutput/
MainScriptLoc=`pwd`
## DB location
db=$MainScriptLoc/db/AndrosecDatabase.sqlite
### Logging
mkdir -p logs/
date1=$(date +"%s") ## Start date of the script
logLocation=logs/parseManifest.log
rm -f $logLocation ## Clear the log file if it exists
touch $logLocation
echo "Start Parsemanifest: " `date` >> $logLocation
## Function to parse an AndroidManifest.xml file
function parseXMLFile { # appName, commit_ID, full path
#echo $1 $2 $3
echo "Begin Analyzing: " $3
cat $3
}
## Loop through all main output files
FILES=$(find $outputFiles -maxdepth 1 -mindepth 1 -type d)
for f in $FILES
do
#echo $f
## Now loop through all of the sub folders
FILES=$(find $f -maxdepth 1 -mindepth 1 -type d)
for f2 in $FILES
do
appName=$(dirname $f2)
appName=${appName/${outputFiles}/ /""}
appName=${appName//[-.\/_]/} # remove special characthers from the string
Commit_Folder=$(basename $f2)
### Get the path to the manifest file in each sub folder
FILES=$(find $f2 -maxdepth 1 -mindepth 1 -type f)
for f3 in $FILES
do
## Make sure that the file is named AndroidManifest.xml
if [ $(basename $f3) = "AndroidManifest.xml" ] ; then
#echo $f3
### Get the CommitID from Android_Manifest_commitinfo
Commit_ID=`sqlite3 $db "SELECT Commit_ID FROM Android_Manifest_commitinfo WHERE Commit_val='$Commit_Folder';"`
#echo $Commit_ID
if [[ $Commit_ID = "" ]]; then
#This should not occur unless record is not found in DB
echo "Commit_Folder: " $Commit_Folder " not found"
echo "***Commit_Folder: " $Commit_Folder " not found " `date` >> $logLocation
else
echo "*** Analyze CommitFolder" $Commit_Folder "->" $Commit_ID `date` >> $logLocation
parseXMLFile $appName $Commit_ID $f3
exit
fi
### If not found, log and output an error message to the screen
fi
done
done
done
diff=$(($date2-$date1))
echo "Total Running Time $(($diff / 60)) minutes and $(($diff % 60)) seconds." >> $logLocation
echo "End:" `date` >> $logLocation
# Todo
# Make sure parameter is passed in
# Logging