[WM][VB][當你的手機被偷用時怎麼辦]

  • 10293
  • 0

[WM][VB][當你的手機偷用時怎麼辦]

相信很多人都會手機被偷或者是掉了,這時候對方可能是拿起來佔為已有,可是如果手機裡面有重要的連絡人、行事曆、工作進度等事宜,萬一被有心人士拿來取用可能就完蛋了,前提你是Outlook重度使用者才有可能會發生此事情,不過現在很多人應該都差不多了吧,me too 一天有二個小都是在Outlook上,所以接著要分享一個小技巧,當手機不見了sim card 被抽走時我們可能立即發一封簡訊知道目前sim card使用者id及立刻刪除所有連絡人、行事曆、工作進度等資料。

 

image    image    image 

Step1:開啟vs2008新增一個vb 主控台應用程式,我們這個應用程式不需要用到任何ui 因為全程都是偷偷摸摸的進行不需要任何告知,

image

Step2:因為我們要使用到PocketOutlook裡面的功能所以我要匯入Microsoft.WindowsMobile.PocketOutlook元件到此專案裡面

Step3:撰寫取得 SIM Card ICCID 的程式碼 .net CF尚未提供任何的api來存取該值,所以我們要透過外部檔案cellcore.dll所提供的SimReadRecord() api 來取得 iccid 

01 Imports System.Runtime.InteropServices
02
03 Public Class SIM
04
05     <DllImport("cellcore.dll")> _
06 Shared Function SimInitialize( _
07         ByVal dwFlags As Integer, _
08         ByVal lpfnCallback As IntPtr, _
09         ByVal dwParam As Integer, _
10         ByRef lphSim As IntPtr) As Integer
11     End Function

12     <DllImport("cellcore.dll")> _
13     Shared Function SimDeinitialize( _
14             ByVal hSim As IntPtr) As Integer
15     End Function

16     <DllImport("cellcore.dll")> _
17     Shared Function SimReadRecord( _
18             ByVal hSim As IntPtr, _
19             ByVal dwAddress As Integer, _
20             ByVal dwRecordType As Integer, _
21             ByVal dwIndex As Integer, _
22             ByVal lpData() As Byte, _
23             ByVal dwBufferSize As Integer, _
24             ByRef dwSize As Integer) As Integer
25     End Function

26     Dim EF_ICCID As Integer = &H2FE2
27     Dim SIM_RECORDTYPE_TRANSPARENT As Integer = 1
28     '回傳SIM卡背面有20位數字組成的IC唯一標識號ICCID
29     Public Function SimSerialNumber() As String
30         Dim hSim As IntPtr
31         Dim iccid(9) As Byte
32         SimInitialize(0, IntPtr.Zero, 0, hSim)
33         SimReadRecord(hSim, _
34                       EF_ICCID, _
35                       SIM_RECORDTYPE_TRANSPARENT, _
36                       0, _
37                       iccid, _
38                       iccid.Length, _
39                       0)
40         SimDeinitialize(hSim)
41         Return FormatAsSimString(iccid)
42     End Function

43     Private Shared Function FormatAsSimString(ByVal iccid As Byte()) As String
44         Dim rawString As String = GetRawIccIDString(iccid)
45         Return [String].Format("{0} {1} {2} {3}", rawString.Substring(0, 6), rawString.Substring(6, 5), rawString.Substring(11, 4), rawString.Substring(15, 4))
46     End Function

47     Private Shared Function GetRawIccIDString(ByVal iccid As Byte()) As String
48         Dim builder As New System.Text.StringBuilder()
49         Dim i As Integer = 0
50         While i < iccid.Length
51             Dim b As Byte = iccid(i)
52             builder.Append(ConvertInt4PairToString(b))
53             Math.Max(Threading.Interlocked.Increment(i), i - 1)
54         End While
55         Return builder.ToString()
56     End Function

57     Private Shared Function ConvertInt4PairToString(ByVal byteValue As Byte) As String
58         Return (DirectCast((byteValue << 4), Byte) Or (byteValue >> 4)).ToString("x2")
59     End Function

60 End Class

 

 

Step4:撰寫主程式碼當系統執行起來先判斷機碼存不存在,在告知使用者是否要啟動此向功能,如果要的話就把iccd注冊到機碼當每次開機的時候會自動去判斷sim iccid 跟機碼是否合,如果不符的話就清空連絡人、工作、行事曆等資料。

01 Imports Microsoft.WindowsMobile.PocketOutlook
02 Module Module1
03     Dim card As New SIM
04     Sub Main()
05         '判機碼是否存在若不存的話就建立這個機砠
06         Dim reg As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\TEST", True)
07         If (reg Is Nothing) Then
08             reg = Registry.LocalMachine.CreateSubKey("SOFTWARE\TEST")
09         End If
10         '判斷機碼是否為空值
11         If reg.GetValue("sim") = "" Then
12             '提出訊息告知是否啟動這個功能
13             If MsgBox("是否設定當sim card id不符時自動發出簡訊通知", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
14                 '把目前的iccid寫入機碼
15                 reg.SetValue("sim", card.SimSerialNumber)
16             End If
17         Else
18             If reg.GetValue("sim") <> card.SimSerialNumber Then
19                 Dim Session As New OutlookSession()
20                 '刪除所有連絡人
21                 Session.Contacts.Items.Clear()
22                 '刪除所有行事曆約會
23                 Session.Appointments.Items.Clear()
24                 '刪除所有工作計畫
25                 Session.Tasks.Items.Clear()
26                 '發一封簡訊給自已所設的電話內容包含目前sim iccid
27                 Dim sms As New Microsoft.WindowsMobile.PocketOutlook.SmsMessage
28                 sms.Body = card.SimSerialNumber
29                 sms.To.Add(New Recipient("099123456"))
30                 sms.Send()
31             End If
32             reg.Close()
33         End If
34     End Sub

35
36 End Module

 

 

Step5:變更一下輸出位置到開始功能表的啟動資料夾,這樣每次在重新開機時就會自動執行這個檔案

image

Step6:按下偵錯\開始偵錯來部署應用程式測試一下

image

Step7:所以來看系統偵測sim 機碼不存在,右邊為 Registry Editor對照,在訊息對話方塊按下確定

image

Step8:接著我來模擬不同sim card ,在模擬器上按下軟啟動後系統會偵測到sim 機碼不同,自動發出一封簡訊出來到Cellulatr Emulator

image

Step9:最後來看看被我們刪除的Outlook 相關資料

image image image

ps:當然做法還有很多就靠各位的想像力了,也可以偷偷撥打電話出來顯示對方的號碼,或是把整個手機都Format…等

 

 

源碼下載

 

 

 

 

 

 

參考:http://blog.opennetcf.com/ncowburn/CommentView,guid,309b8b8e-ebc7-4078-a8ba-f174761ea7af.aspx