Wednesday, February 8, 2012

VB.net defeat simple padding obfuscation

There is an applicationthat obfuscates a serial number by padding each character. Here is a de-obfuscator I made.

First: define the array with all the characters the algorithm uses:






    Public charArray() As Char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", _
                           "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", _
                           "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", _
                           "V", "W", "X", "Y", "Z"}

Function that will deobfuscate it.

    Private Function OffsetAChar(ByVal chartooffset As Char, ByVal offset As Integer)
        Dim posInArray As Integer = Array.IndexOf(charArray, chartooffset)
        Dim ArrayLength As Integer = charArray.Length

        If posInArray + offset = ArrayLength Then
            Return "0"
        End If

        If (posInArray + offset) <= ArrayLength And (posInArray + offset) > 0 Then
            Return charArray(posInArray + offset)
        End If

        If posInArray + offset = 0 Then
            Return 0
        End If

        If (posInArray + offset) < 0 Then
            Return charArray(ArrayLength + posInArray + offset)
        End If

        If (posInArray + offset) > ArrayLength Then
            Return charArray(Math.Abs(ArrayLength - (posInArray + offset)))
        End If

    End Function


Usage is simple:

        Dim charArray2() As Char

        Dim ArraySTring As String = txtDecode.Text
        ArraySTring = ArraySTring.Replace("-", "")
        charArray2 = ArraySTring


       txtCodeDecoded.Text += OffsetAChar(charArray2(0), -19).ToString.ToUpper


Figuring out the offset of two letters


    Public Function OffsetFinder(ByVal letter1 As Char, ByVal letter2 As Char)

        Dim CharPos1 = Array.IndexOf(charArray, letter1)
        Dim CharPos2 = Array.IndexOf(charArray, letter2)
        Return CharPos2 - CharPos1

    End Function

1 comment:

  1. Casino Online | Casino Games | DrmCD
    Free Casino Games from DrmCD. Play your 군산 출장마사지 favorite 군포 출장샵 games and win real money. Check out our 김천 출장안마 exclusive selection of great 전라남도 출장안마 casino slots and 통영 출장안마 table games.

    ReplyDelete