Information Technology Reference
In-Depth Information
After signing the application, Google [21] recommends to use the zipalign tool
to optimize the final APK. It ensures that all uncompressed data starts with
a particular alignment relative to the start of the file. The zipalign tool comes
with the Android SDK and Listing 1.4 shows the corresponding command.
1 $ zipalign -v 4 my_application.apk my_application_release.apk
Listing 1.4. Alignment of my application.apk befor release
3 Instrumentation with abc and AspectJ
In this section, we describe how AspectJ and the AspectBench Compiler abc [9]
can be used to declaratively instrument Android applications. Our goal is to
modify the example application from Listing 1.1 such that no premium SMS
messages to costly 0900 phone numbers can be sent anymore. Instead, an error
message shall be written into the log file whenever the target phone number
starts with 0900. SMS messages to normal phone numbers should be sent as
usual. Obviously, this requires us to inline a monitor since no static analysis can
know the target phone number the user is going to enter.
We create a new file SendPremiumSMS.aj with the contents shown in List-
ing 1.5. Note that the name of the file must match the name of the aspect. We
first declare a pointcut for the SmsManager.sendTextMessage method. We could
also have inlined it into the advice definition, but we are using it twice (once
for blocking premium-rate SMS messages and once for logging that a message
has actually been sent), so we keep it separate. The pointcut matches calls to
the SMS sending method in the Android operating system, not our own user
code. This way, we ensure that actually all SMS messages are intercepted which
is especially useful when instrumenting unknown target applications.
1 import android.telephony.SmsManager;
2 import android.app.PendingIntent;
3 import android.util.Log;
4
5 public aspect SendSMS_PremiumAspect {
6
pointcut sendSms(String no) :
7
call ( void SmsManager.sendTextMessage(..)) && args (no, ..);
8
9
after (): sendSms(*) {
10
Log.i( "Aspect" , "SMS message sent" );
11
}
12
13
void around (String no): sendSms(no) {
14
if (no.startsWith( "0900" ))
15
Log.i( "Aspect" , "Premium SMS message blocked" );
16
else proceed (no);
17
}
18 }
Listing 1.5. Aspect for blocking premium-rate SMS messages
 
Search WWH ::




Custom Search