Huazhong university of science and technology



Download 31.25 Kb.
Date20.06.2017
Size31.25 Kb.
#21152






HUAZHONG UNIVERSITY OF SCIENCE AND TECHNOLOGY

《Malicious Code Detection——Android Application Installation Package Scanning》

Experiment guidance

Experiment: Android Application Installation Package Scanning

Experimental Objective


  • Students should understand the structure of Android application installation package;

  • Students should master the programming, debugging and release of Android application;

  • Students should master the method of obtaining the permissions information of Android application.

Experimental Requirements


  • Students should use eclipse to code Android applications;

  • Students should get the permissions information of Android application by calling a function;

  • Students should test and master the process of APK release.

Experimental Environment


  • Operating System: Microsoft windows XP SP3;

  • Software Environment: JDK+ADT+Android SDK;

  • Design Tool: eclipse.

Experimental Content


  1. Students should learn the architecture of Android and a preliminarily understand Android system;

  2. Students should understand the structure of Android application program;

  3. Students should install the JDK;

  4. Students should install the Android SDK and configure system parameters;

  5. Students should download eclipse and install ADT tools;

  6. Then students could open eclipse and code the program of obtaining the permissions information of Android application installation package;

  7. Debugging process and testing the availability and stability of the program by using the Android simulator;

  8. Releasing the APK file.

Experimental Summary


In this experiment, the architecture of Android and the structure of Android application are relatively well understood. Related documents and books can help us.

Everyone should be carefully when the environment is configured. Students could code Android application when the code environment was configured and the environment parameters were setted up.

It is difficulty that students find out the function of corresponding features and obtain the permissions information of application by using function. More preparation and more accumulation are required, otherwise it will spend a lot of time to be familiar with Android program and function etc.. However, students could use the previous accumulation and surf on the CSDN and PUDN technology website to search the relevant technical information. The former could give us well guidance and help.

Experimental Code


The source code of the APK file of the experimental release:

package com.example.administrator.permissionread;

import android.app.Activity;

import android.content.Context;

import android.content.pm.ApplicationInfo;

import android.content.pm.PackageInfo;

import android.content.pm.PackageManager;

import android.content.pm.PackageManager.NameNotFoundException;

import android.content.pm.PermissionGroupInfo;

import android.content.pm.PermissionInfo;

import android.os.Bundle;

import android.util.Log;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.ListView;

import android.widget.SimpleAdapter;

import android.widget.TextView;
import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;


public class MyActivity extends Activity {
private Context context;

// 生成动态数组,加入数据

private ArrayList> listItem;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// 绑定Layout里面的ListView

ListView list = (ListView) findViewById(R.id.ListView01);
final LayoutInflater inflater = LayoutInflater.from(this);

final LinearLayout lin = (LinearLayout) findViewById(R.id.Layout01);


listItem = new ArrayList>();

PackageManager pm = this.getPackageManager();

List applicationInfos = pm.getInstalledApplications(PackageManager.GET_ACTIVITIES);

HashMap resultMap = new HashMap();

Iterator iterator = applicationInfos.iterator();

while (iterator.hasNext()) {

ApplicationInfo applicationInfo = iterator.next();

HashMap map = new HashMap();

map.put("APP_CLASS_NAME",

applicationInfo.packageName);// APP包名

map.put("APP_NAME", pm.getApplicationLabel(applicationInfo).toString());

listItem.add(map);


}
// 生成适配器的Item和动态数组对应的元素

SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,// 数据源

R.layout.listview,// ListItem的XML实现

// 动态数组与ImageItem对应的子项

new String[]{"APP_NAME"},

// ImageItem的XML文件里面的一个ImageView,两个TextView ID

new int[]{R.id.APP_NAME});
// 添加并且显示

list.setAdapter(listItemAdapter);


// 添加点击

list.setOnItemClickListener(new OnItemClickListener() {


@Override

public void onItemClick(AdapterView arg0, View arg1, int arg2,

long arg3) {
getPermisson(MyActivity.this, inflater, lin,

listItem.get(arg2).get("APP_CLASS_NAME"));


}

});
}


private void getPermisson(Context context, LayoutInflater inflater,

LinearLayout lin, String pkgName) {


setContentView(R.layout.info);
TextView tv = (TextView) findViewById(R.id.TextView_info);
Button bt = (Button) findViewById(R.id.Button1);
bt.setOnClickListener(new Button.OnClickListener(){
@Override

public void onClick(View view) {

setContentView(R.layout.activity_main);

// 绑定Layout里面的ListView

ListView list = (ListView) findViewById(R.id.ListView01);
final LayoutInflater inflater = LayoutInflater.from(MyActivity.this);

final LinearLayout lin = (LinearLayout) findViewById(R.id.Layout01);


listItem = new ArrayList>();

PackageManager pm = MyActivity.this.getPackageManager();

List applicationInfos = pm.getInstalledApplications(PackageManager.GET_ACTIVITIES);

HashMap resultMap = new HashMap();

Iterator iterator = applicationInfos.iterator();

while (iterator.hasNext()) {

ApplicationInfo applicationInfo = iterator.next();

HashMap map = new HashMap();

map.put("APP_CLASS_NAME",

applicationInfo.packageName);// APP包名

map.put("APP_NAME", pm.getApplicationLabel(applicationInfo).toString());

listItem.add(map);


}
// 生成适配器的Item和动态数组对应的元素

SimpleAdapter listItemAdapter = new SimpleAdapter(MyActivity.this, listItem,// 数据源

R.layout.listview,// ListItem的XML实现

// 动态数组与ImageItem对应的子项

new String[]{"APP_NAME"},

// ImageItem的XML文件里面的一个ImageView,两个TextView ID

new int[]{R.id.APP_NAME});
// 添加并且显示

list.setAdapter(listItemAdapter);


// 添加点击

list.setOnItemClickListener(new OnItemClickListener() {


@Override

public void onItemClick(AdapterView arg0, View arg1, int arg2,

long arg3) {
getPermisson(MyActivity.this, inflater, lin,

listItem.get(arg2).get("APP_CLASS_NAME"));


}

});
}

});
try {

PackageManager pm = context.getPackageManager();

// PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
PermissionGroupInfo pgi;

PackageInfo pkgInfo = pm.getPackageInfo(pkgName,

PackageManager.GET_PERMISSIONS);

String sharedPkgList[] = pkgInfo.requestedPermissions;


for (int i = 0; i < sharedPkgList.length; i++) {

String permName = sharedPkgList[i];


PermissionInfo tmpPermInfo = pm.getPermissionInfo(permName, 0);
tv.append(i + "-" + permName + "\n");

pgi = pm.getPermissionGroupInfo(tmpPermInfo.group, 0);


tv.append(i + "-" + pgi.loadLabel(pm).toString() + "\n");

tv.append(i + "-" + tmpPermInfo.loadLabel(pm).toString() + "\n");

tv.append(i + "-" + tmpPermInfo.loadDescription(pm).toString()

+ "\n");


tv.append("-------------------------------------------" + "\n");
}

} catch (NameNotFoundException e) {

Log.e("##ddd", "Could'nt retrieve permissions for package");
}

}
}



Download 31.25 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page