Récupérer les codes imei, imsi, oem [managed tapi]

Description

J'ai créé un exemple sur l'utilisation de la bibliothèque TAPI pour récupérer des informations sur la machine
Dans cette source: les informations à récupérer sont:
La résolution horizontale (sans api).
La résolution verticale (sans api).
-------------------------------------
Utilisation de la biblio TAPI pour récupérer:
Le code IMEI (International Mobile Equipment Identity).
Le code IMSI (International Mobile Subscriber Identity).
L'OEM (Original Equipment Manufacturer).
Le model de la machine.
Le numéros de révision.
---------------------------------------
J'ai inclus aussi le projet Tapi wrapper for managed code (Code source de la biblio Managed Tapi)
Mais il y a quelques problèmes,
L'application marche très bien avec les version Windows Mobile 2003 et (-) mais elle nécessite un certificat pour qu'elle marchera avec les versions 5 et 6 de Windows Mobile
Donc il est necessaire d'obtenir un certificat et signer les deux projet (tapi et l'application qui l'utilise) pour l'executer.

L'utilité du code,
L'IMEI est généralement utiliser pour générer les cles des produits pour les sécuriser.

Source / Exemple :


using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using OpenNETCF.Tapi;
// Référence a ajouter : Biblio TapiLib.dll
namespace Tapi_IMEI_EMSI_OEM
{
    public partial class frmMain : Form
    {
        // fonctions des dll PINVOKE.
        [DllImport("cellcore.dll")] 
        internal static extern int lineGetGeneralInfo(IntPtr hLine, byte[] bCache);
        //OEM:pour Original Equipment Manufacturer
        //IMSI:pour International Mobile Subscriber Identity 
        //IMEI:pour International Mobile Equipment Identity
        internal struct GeneralInfos
        {
            internal string OEM;
            internal string Model;
            internal string Revision;
            internal string IMEI;
            internal string IMSI;
        }
        public frmMain()
        { 
            InitializeComponent(); 
        }

        static public String GetDisplayHorzRes()
        { 
            return Screen.PrimaryScreen.Bounds.Width.ToString(); 
        }
        static public String GetDisplayVertRes()
        { 
            return Screen.PrimaryScreen.Bounds.Height.ToString(); 
        }

        internal static GeneralInfos GetGeneralInfos()
        {
            //Creation d'un objet Tapi
            Tapi t = new Tapi();
            t.Initialize();
            //Objet line
            Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, LINECALLPRIVILEGE.MONITOR);
            //Reservation d'un espace mémoire pour la lecture des infos.
            byte[] buffer = new byte[512];
            BitConverter.GetBytes(512).CopyTo(buffer, 0);
            // Lecture des infos, vérification du resultat de l'opération.
            if (lineGetGeneralInfo(l.hLine, buffer) != 0)
            {
                throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
            }
            // preparations pour l'extraction des informations.
            GeneralInfos gi = new GeneralInfos();

            // OEM.
            int manuSize = BitConverter.ToInt32(buffer, 12);
            int manuOffset = BitConverter.ToInt32(buffer, 16);
            gi.OEM = System.Text.Encoding.Unicode.GetString(buffer, manuOffset, manuSize);
            gi.OEM = gi.OEM.Substring(0, gi.OEM.IndexOf(Convert.ToChar(0)));
            
            // Model        
            int modelSize = BitConverter.ToInt32(buffer, 20);
            int modelOffset = BitConverter.ToInt32(buffer, 24);
            gi.Model = System.Text.Encoding.Unicode.GetString(buffer, modelOffset, modelSize);
            gi.Model = gi.Model.Substring(0, gi.Model.IndexOf(Convert.ToChar(0)));
            
            //Révision
            int revSize = BitConverter.ToInt32(buffer, 28);
            int revOffset = BitConverter.ToInt32(buffer, 32);
            gi.Revision = System.Text.Encoding.Unicode.GetString(buffer, revOffset, revSize);
            gi.Revision = gi.Revision.Substring(0, gi.Revision.IndexOf(Convert.ToChar(0)));

            //IMEI
            int IMEI = BitConverter.ToInt32(buffer, 36);
            int IMEIoffset = BitConverter.ToInt32(buffer, 40);
            gi.IMEI = System.Text.Encoding.Unicode.GetString(buffer, IMEIoffset, IMEI);
            gi.IMEI = gi.IMEI.Substring(0, gi.IMEI.IndexOf(Convert.ToChar(0)));

            //IMSI
            int IMSIsize = BitConverter.ToInt32(buffer, 44);
            int IMSIoffset = BitConverter.ToInt32(buffer, 48);
            gi.IMSI = System.Text.Encoding.Unicode.GetString(buffer, IMSIoffset, IMSIsize);
            gi.IMSI = gi.IMSI.Substring(0, gi.IMSI.IndexOf(Convert.ToChar(0)));
            
            l.Dispose();
            t.Shutdown();
            return gi;
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            GeneralInfos gi = GetGeneralInfos();

            lblHorizRes.Text +=  GetDisplayHorzRes();
            lblVertRes.Text += GetDisplayVertRes();
            lblIMEICode.Text += gi.IMEI;
            lblIMSICode.Text += gi.IMSI;
            lblOEM.Text += gi.OEM;
            lblModel.Text += gi.Model;
            lblRevision.Text += gi.Revision;
        }

        private void mnuQuit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Conclusion :


Voici un article pour signer l'application
http://msdn.microsoft.com/fr-fr/library/ms839681(en-us).aspx

La biblio TapiLib est un wrapper pour c# et vb.net permettant l'utilisation de l'api native de téléphonie (Telephony API) mais son utilisation nécessite l'obtention d'un certificat.
visiter le site http://www.mobile2market.net

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.