Saturday, September 7, 2013

OLD Huawei Unlock/Flash Code Calculator for VB.NET and MONO


I found this unlock/flash algo for Huawei a year ago I'm not just quite sure for what model(s). This was orgininally written in C(I think?) I forgot where did I get it but still full credit goes to him. I ported this to VB.NET but will also work on MONO in Linux. Just in case you're not familiar with MONO, it's a cross-platform software that can compile and run .NET applications in Android, most Linux distributions, BSD, OS X and Solaris. Recently a few hackers cracked the new algo for Huawei's latest modems unfortunately I'm not one of those lol. Anyway I'll just share the old one for educational purposes :D.
Class HelloWorld 
    Shared Sub Main
        Dim sMD5 As String
        Dim sBit(15) As Integer
        Dim X, y As Short
        Dim sT, sF, sS, sFt As Integer
        Dim sKey As String
        Dim temp As Integer

        Dim s_Unlock As String
        Dim s_Flash As String
        Dim s_IMEI As String

Top:
        System.Console.WriteLine("Credits to the original author of the algo" & vbCrLf & "Enter your 15 Digit IMEI Code: ")
        System.Console.SetCursorPosition(31, 0)
        s_IMEI = System.Console.ReadLine

        If s_IMEI.Length <> 15 Then
            System.Console.WriteLine("Invalid IMEI...")
            GoTo Top
        End If

        sMD5 = getMD5Hash(s_IMEI & "5e8dd316726b0335")
        y = 1
        For X = 0 To 15
            Dim bit As String = Mid(sMD5, y, 2)
            sBit(X) = Int32.Parse(bit, Globalization.NumberStyles.HexNumber)
            y = y + 2
        Next

        sF = sBit(0) Xor sBit(4) Xor sBit(8) Xor sBit(12)
        sS = sBit(1) Xor sBit(5) Xor sBit(9) Xor sBit(13)
        sT = sBit(2) Xor sBit(6) Xor sBit(10) Xor sBit(14)
        sFt = sBit(3) Xor sBit(7) Xor sBit(11) Xor sBit(15)

        sKey = sF.ToString("x2") & sS.ToString("x2") & sT.ToString("x2") & sFt.ToString("x2")
        temp = Int32.Parse(sKey, Globalization.NumberStyles.HexNumber) And 33554431 Or 33554432
        s_Unlock = CStr(temp)
        '----------------------------------
        sMD5 = getMD5Hash(s_IMEI & "97b7bc6be525ab44")
        y = 1
        For X = 0 To 15
            Dim bit As String = Mid(sMD5, y, 2)
            sBit(X) = Int32.Parse(bit, Globalization.NumberStyles.HexNumber)
            y = y + 2
        Next

        sF = sBit(0) Xor sBit(4) Xor sBit(8) Xor sBit(12)
        sS = sBit(1) Xor sBit(5) Xor sBit(9) Xor sBit(13)
        sT = sBit(2) Xor sBit(6) Xor sBit(10) Xor sBit(14)
        sFt = sBit(3) Xor sBit(7) Xor sBit(11) Xor sBit(15)

        sKey = sF.ToString("x2") & sS.ToString("x2") & sT.ToString("x2") & sFt.ToString("x2")
        temp = Int32.Parse(sKey, Globalization.NumberStyles.HexNumber) And 33554431 Or 33554432
        s_Flash = CStr(temp)

        System.Console.WriteLine("Unlock Code: {0}", s_Unlock)
        System.Console.WriteLine("Flash Code: {0}", s_Flash)
        System.Console.ReadKey()
        System.Console.Clear()
        GoTo Top
    End Sub 
    
    Shared Function getMD5Hash(ByVal strToHash As String) As String
        Dim md5Obj As New System.Security.Cryptography.MD5CryptoServiceProvider
        Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)

        bytesToHash = md5Obj.ComputeHash(bytesToHash)

        Dim strResult As String = ""

        For Each b As Byte In bytesToHash
            strResult += b.ToString("x2")
        Next

        Return strResult
    End Function
End Class

You can also try it online via Programr.com

Unknown

I'm a modern human swiss knife. Not sure why I'm a coder I can't even rember the simplest syntax in any language lol. But I'll do anything for food so yeah I'm a programmer. And a fast one *wink*

1 comments:

 

Copyright 2017 Code Monkey