Information Technology Reference
In-Depth Information
1 import android.telephony.SmsManager;
2 import android.app.PendingIntent;
3
4 public aspect SMSSpam {
5
tracematch (String no) {
6
sym sendSms after :
7
call ( void SmsManager.sendTextMessage(..)) && args (no, ..);
8
9
sendSms[3] sendSms+ {
10
System.out.println( "SMS spam detected to no: " +no);
11
}
12
13
}
14 }
Listing 1.7. Aspect for blocking premium-rate SMS messages
alert when more than three SMS messages are sent to the same phone number
by an application, as this might indicate SMS spam. In AspectJ such counting
would have to be implemented manually. In Tracematches, we simply define the
pattern shown in Listing 1.7. Note that the name of the file and the name of the
aspect must match, i.e., SMSSpam.aj in this case.
For compiling the tracematch, we again use the AspectBench compiler abc.
The command-line is similar to the one shown in Section 3 for AspectJ, we only
need to enable the tracematch extension as shown in Listing 1.8.
1 java -cp abc-ja-exts-complete.jar abc.main.Main \
2
-cp /path/to/rt.jar: \
3
/path/to/android-support-v4.jar: \
4
/path/to/android.jar: \
5
/path/to/abc-runtime.jar \
6
-ext abc.ja.tm \
7
-android -injars /path/to/RV2013.apk \
8
/path/to/SMSSpam.aj
Listing 1.8. abc compiler command-line
5 The Machinery: Soot and Jimple
Soot [8] is an extensible program analysis and optimization framework for Java
and Java-like environments such as Dalvik. It supports various input formats
including Java source code, Java class files, and Dalvik dex files and also allows
to write out these file formats after transformation. Figure 1 gives an overview
of all possible input and output formats.
Code included in an Android application's apk file is automatically extracted
before analysis. Afterwards, a new apk file containing the transformed code is
built which can then be signed and executed on a phone or the emulator. abc
uses Soot internally to weave aspects or tracematches into Java programs or
Android apps.
Soot is organized in phases and packs [23]. Every pack contains an ordered list
of phases. The first pack applied to every single method is the Jimple Bodies pack
jb which translates the respective method's body into an intermediate represen-
tation called Jimple . Afterwards, if whole-program analysis is enabled, a number
 
Search WWH ::




Custom Search