Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Swellow en 7 Octubre 2012, 17:03 pm



Título: StrConv Alternative Function
Publicado por: Swellow en 7 Octubre 2012, 17:03 pm
Hola amigos!

Does anyone could help me fixing this function? It works but fails with unicode chars.... Here it is:

Código:
Public Function AltStrConv(Temp As Variant, Conversion As VbStrConv) As Variant
Dim i As Long, lLen As Long, bvHack(0) As Byte, lHackDelta As Long
Dim bArr() As Byte, sString As String
 
lHackDelta = VarPtr(bvHack(0))
 
If Conversion = vbFromUnicode Then
    sString = Temp
    lLen = Len(sString)
    ReDim bArr(0 To lLen - 1)
    For i = 0 To lLen - 1
        bvHack(VarPtr(bArr(0)) - lHackDelta + i) = bvHack(StrPtr(sString) - lHackDelta + (i * 2))
    Next i
    AltStrConv = bArr
ElseIf Conversion = vbUnicode Then
    bArr = Temp
    lLen = UBound(Temp) + 1
    sString = Space$(lLen)
    For i = 0 To lLen - 1
        bvHack(StrPtr(sString) - lHackDelta + (i * 2)) = bvHack(VarPtr(bArr(0)) - lHackDelta + i)
    Next i
    AltStrConv = sString
End If
 
End Function

Thanks A lot!


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 7 Octubre 2012, 22:09 pm
aquí te la dejo como se me ocurrió.  ;D

Código
  1. Private Function AltStrConv(Temp As Variant, Conversion As VbStrConv) As Variant
  2. Dim i As Long, lLen As Long
  3. Dim bArr() As Byte, sString As String
  4.  
  5.  
  6.  
  7. If Conversion = vbFromUnicode Then
  8.    sString = Temp
  9.    lLen = Len(sString) - 1
  10.    ReDim bArr(lLen)
  11.    For i = 0 To lLen
  12.       bArr(i) = Asc(Mid(Temp, (i + 1), 1))
  13.       Next i
  14.    AltStrConv = bArr
  15.  
  16. ElseIf Conversion = vbUnicode Then
  17.    bArr = Temp
  18.    lLen = UBound(Temp)
  19.    sString = Space$(lLen + 1)
  20.    For i = 0 To lLen
  21.    sString = sString & Chr(bArr(i))
  22.    Next i
  23.    AltStrConv = sString
  24. End If
  25.  
  26. End Function
  27.  


saludos


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 7 Octubre 2012, 23:02 pm
aquí te la dejo como se me ocurrió.  ;D

Código
  1. Private Function AltStrConv(Temp As Variant, Conversion As VbStrConv) As Variant
  2. Dim i As Long, lLen As Long
  3. Dim bArr() As Byte, sString As String
  4.  
  5.  
  6.  
  7. If Conversion = vbFromUnicode Then
  8.    sString = Temp
  9.    lLen = Len(sString) - 1
  10.    ReDim bArr(lLen)
  11.    For i = 0 To lLen
  12.       bArr(i) = Asc(Mid(Temp, (i + 1), 1))
  13.       Next i
  14.    AltStrConv = bArr
  15.  
  16. ElseIf Conversion = vbUnicode Then
  17.    bArr = Temp
  18.    lLen = UBound(Temp)
  19.    sString = Space$(lLen + 1)
  20.    For i = 0 To lLen
  21.    sString = sString & Chr(bArr(i))
  22.    Next i
  23.    AltStrConv = sString
  24. End If
  25.  
  26. End Function
  27.  


saludos


Yeah I know this one but it uses Asc/Mid/Space/Chr and this is not good, if anyone can mod it without using Mid at least. Thanks


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 8 Octubre 2012, 03:56 am
maybe using copymemory. Tomorrow I'll try to make something.  :)


Título: Re: StrConv Alternative Function
Publicado por: Karcrack en 8 Octubre 2012, 13:51 pm
I made a post in HH time ago where I put all the different methods I found... Ofc HH is down so I can't paste them here... Anyway I throw some ideas: MultiByteToWideChar() and __vbaStrToUnicode()...

@Danyfirex: Working with memory is the same as using the "bvHack()" thingy.


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 8 Octubre 2012, 15:37 pm
I made a post in HH time ago where I put all the different methods I found... Ofc HH is down so I can't paste them here... Anyway I throw some ideas: MultiByteToWideChar() and __vbaStrToUnicode()...

@Danyfirex: Working with memory is the same as using the "bvHack()" thingy.

It's no problem if it use memory (bvHack) but do not use APIs..


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 8 Octubre 2012, 16:42 pm
I made a post in HH time ago where I put all the different methods I found... Ofc HH is down so I can't paste them here... Anyway I throw some ideas: MultiByteToWideChar() and __vbaStrToUnicode()...



@Danyfirex: Working with memory is the same as using the "bvHack()" thingy.

si ya veo, es que no recordaba ese tema.

voy a mirar con bvHack().


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 8 Octubre 2012, 17:38 pm
well before reading about Karcrack says , I notice that is necesary to remove array bounds checks and try out of Visual Basic IDE, it means Compiled, And work Correctly.

try it.

(http://www.techrepublic.com/i/tr/cms/contentPics/u00220020311adm02_01.gif)



Título: Re: StrConv Alternative Function
Publicado por: Swellow en 8 Octubre 2012, 17:50 pm
well before reading about Karcrack says , I notice that is necesary to remove array bounds checks and try out of Visual Basic IDE, it means Compiled, And work Correctly.

try it.

(http://www.techrepublic.com/i/tr/cms/contentPics/u00220020311adm02_01.gif)



Yes I already checked that but It's not the problem, the function works but fails with unicode chars, try using it on this function and then try encrypting a string you will realize that it does not work...

Código:
Function ROTXDecrypt(ByVal strData As String, ByVal strKey As String)
    On Error Resume Next
    Dim bData() As Byte, bKey() As Byte
    bData = AltStrConv(strData, vbFromUnicode)
    bKey = AltStrConv(strKey, vbFromUnicode)
    For i = 0 To UBound(bData)
        If i <= UBound(bKey) Then
            bData(i) = bData(i) - bKey(i)
        Else
            bData(i) = bData(i) - bKey(i Mod UBound(bKey))
        End If
    Next i
    ROTXDecrypt = AltStrConv(bData, vbUnicode)
End Function

Function ROTXEncrypt(ByVal strData As String, ByVal strKey As String)
    On Error Resume Next
    Dim bData() As Byte
    Dim bKey() As Byte
    bData = StrConv(strData, vbFromUnicode)
    bKey = StrConv(strKey, vbFromUnicode)
    For i = 0 To UBound(bData)
        If i <= UBound(bKey) Then
            bData(i) = bData(i) + bKey(i)
        Else
            bData(i) = bData(i) + bKey(i Mod UBound(bKey))
        End If
    Next i
    ROTXEncrypt = StrConv(bData, vbUnicode)
End Function


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 8 Octubre 2012, 18:07 pm
Maybe you're trying before compiling. because If you're running into vb IDE doesn't work. but if you compile work correctly. at least for me work correclty.


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 8 Octubre 2012, 18:55 pm
Maybe you're trying before compiling. because If you're running into vb IDE doesn't work. but if you compile work correctly. at least for me work correclty.


Did you try using the StrConv alt I posted with the ROTXDecrypt? I do use Karcrack's memory funcs since a while now and I can tell you that the problem is not because of what you think. Just encrypt a string with ROTXEncrypt then use StrConv Alternative on the decrypt function and see if it gives a result, it won't... Now use StrConv normal and it'll work, that is because the Alt function does not work with unicode chars.


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 8 Octubre 2012, 19:50 pm
Put some example that doesn't work to you, I don't got  it :huh:

I'm trying this and work correctly

Código
  1. Dim str As String
  2. Dim str2 As String
  3. 'Dim str3() As Byte
  4.  
  5.  
  6. str = ROTXEncrypt("Work", "pass")
  7. MsgBox (str)
  8. MsgBox (ROTXDecrypt(str, "pass"))
  9.  
  10.  


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 8 Octubre 2012, 20:25 pm
Ok try this and make sure to compile:

http://www.xup.in/dl,15300297/Desktop.rar/ (http://www.xup.in/dl,15300297/Desktop.rar/)


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 8 Octubre 2012, 21:47 pm
for me it doesn't work with alternative "AltStrConv" neither StrConv.

now I have to go out. I'll come back later.


Título: Re: StrConv Alternative Function
Publicado por: Karcrack en 9 Octubre 2012, 00:32 am
Paste the ROTxEncrypt() function please.


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 9 Octubre 2012, 00:45 am
Paste the ROTxEncrypt() function please.

Es esta:

Código
  1. Private Sub Form_Load()
  2. Dim str As String
  3. Dim str2 As String
  4.  
  5.  
  6. str = ROTXEncrypt("-978ç___#{~#{~#'é(-è", "pass")
  7. MsgBox (str)
  8. MsgBox (ROTXDecrypt(str, "pass"))
  9. End Sub
  10.  
  11. Public Function AltStrConv(Temp As Variant, Conversion As VbStrConv) As Variant
  12. Dim i As Long, lLen As Long, bvHack(0) As Byte, lHackDelta As Long
  13. Dim bArr() As Byte, sString As String
  14.  
  15. lHackDelta = VarPtr(bvHack(0))
  16.  
  17. If Conversion = vbFromUnicode Then
  18.    sString = Temp
  19.    lLen = Len(sString)
  20.    ReDim bArr(0 To lLen - 1)
  21.    For i = 0 To lLen - 1
  22.        bvHack(VarPtr(bArr(0)) - lHackDelta + i) = bvHack(StrPtr(sString) - lHackDelta + (i * 2))
  23.    Next i
  24.    AltStrConv = bArr
  25. ElseIf Conversion = vbUnicode Then
  26.    bArr = Temp
  27.    lLen = UBound(Temp) + 1
  28.    sString = Space$(lLen)
  29.    For i = 0 To lLen - 1
  30.        bvHack(StrPtr(sString) - lHackDelta + (i * 2)) = bvHack(VarPtr(bArr(0)) - lHackDelta + i)
  31.    Next i
  32.    AltStrConv = sString
  33. End If
  34.  
  35. End Function
  36.  
  37. Function ROTXDecrypt(ByVal strData As String, ByVal strKey As String)
  38.    On Error Resume Next
  39.    Dim bData() As Byte, bKey() As Byte
  40.    bData = AltStrConv(strData, vbFromUnicode)
  41.    bKey = AltStrConv(strKey, vbFromUnicode)
  42.    For i = 0 To UBound(bData)
  43.        If i <= UBound(bKey) Then
  44.            bData(i) = bData(i) - bKey(i)
  45.        Else
  46.            bData(i) = bData(i) - bKey(i Mod UBound(bKey))
  47.        End If
  48.    Next i
  49.    ROTXDecrypt = AltStrConv(bData, vbUnicode)
  50. End Function
  51.  
  52. Function ROTXEncrypt(ByVal strData As String, ByVal strKey As String)
  53.    On Error Resume Next
  54.    Dim bData() As Byte
  55.    Dim bKey() As Byte
  56.    bData = StrConv(strData, vbFromUnicode)
  57.    bKey = StrConv(strKey, vbFromUnicode)
  58.    For i = 0 To UBound(bData)
  59.        If i <= UBound(bKey) Then
  60.            bData(i) = bData(i) + bKey(i)
  61.        Else
  62.            bData(i) = bData(i) + bKey(i Mod UBound(bKey))
  63.        End If
  64.    Next i
  65.    ROTXEncrypt = StrConv(bData, vbUnicode)
  66. End Function
  67.  



Título: Re: StrConv Alternative Function
Publicado por: Swellow en 9 Octubre 2012, 13:54 pm
Some chars cannot be encrypted using ROTX cause it is a poor encryption but u can see a big difference when u decrypt using original StrConv and AltStrConv... This is because it doesnt support unicode chars, Karcrack I count on you :P


Título: Re: StrConv Alternative Function
Publicado por: Karcrack en 9 Octubre 2012, 14:24 pm
Remove "On error resume next" and learn to debug your own codes. You are getting overflow.


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 9 Octubre 2012, 14:27 pm
Remove "On error resume next" and learn to debug your own codes. You are getting overflow.

Yeah now use StrConv normal you won't get overflow.


Título: Re: StrConv Alternative Function
Publicado por: Karcrack en 9 Octubre 2012, 14:35 pm
Yeah now use StrConv normal you won't get overflow.
False.


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 9 Octubre 2012, 14:37 pm
On ROTXEncrypt yes but that's no problem, just use On Error Resume Next but remove it on ROTXDecrypt you won't get overflow, then use AltStrConv and u will get overflow..


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 9 Octubre 2012, 18:28 pm
the error is byte array are in range  0 y 255. so ROTXEncrypt try to put over 255 making overflow. so, for that Can't  Encrypt/Decrypt extended character over chr(143).



Título: Re: StrConv Alternative Function
Publicado por: Swellow en 12 Octubre 2012, 14:06 pm
the error is byte array are in range  0 y 255. so ROTXEncrypt try to put over 255 making overflow. so, for that Can't  Encrypt/Decrypt extended character over chr(143).



I can tell you that the problem does not come from the encryption, I'm using it since a long time. Nobody enough skilled to fix this Alt StrConv func dude? :(


Título: Re: StrConv Alternative Function
Publicado por: Psyke1 en 12 Octubre 2012, 15:17 pm
Hello mate!  :D
I've done this function some years ago, I don't know if it works... actually, I don't remember if it came to work. :silbar:
I can't test it because in this PC I have only installed Ubuntu... :-\

Código
  1. Option Explicit
  2.  
  3. '// kernel32.dll
  4. Private Declare Function MultiByteToWideChar Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
  5. Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
  6.  
  7. '// Const
  8. Private Const CP_UTF8                           As Long = &HFDE9 '65001
  9.  
  10. '// Enum
  11. Public Enum CONV_TYPE
  12.    Unicode = vbUnicode
  13.    UTF8 = vbFromUnicode
  14. End Enum
  15.  
  16. '// Function
  17. Public Function StrConversion(ByRef vEntry As Variant, eConv As CONV_TYPE) As Variant
  18. Dim lRet                                        As Long
  19. Dim lLen                                        As Long
  20. Dim lBuffer                                     As Long
  21. Dim sBuffer                                     As String
  22. Dim bvOutput()                                  As Byte
  23.  
  24.    On Error GoTo Exit_
  25.  
  26.    If eConv = Unicode Then
  27.        lLen = LenB(vEntry) \ 2
  28.  
  29.        If lLen Then
  30.            lBuffer = lLen + lLen + lLen + 1
  31.            ReDim bvOutput(lBuffer - 1) As Byte
  32.  
  33.            lRet = WideCharToMultiByte(CP_UTF8, 0, StrPtr(vEntry), lLen, bvOutput(0), lBuffer, vbNullString, 0)
  34.  
  35.            If lRet Then
  36.                ReDim Preserve bvOutput(lRet - 1) As Byte
  37.                StrConversion = bvOutput
  38.            End If
  39.        End If
  40.    Else
  41.        lLen = UBound(vEntry) + 1
  42.  
  43.        If lLen > 1 Then
  44.            lBuffer = lLen + lLen
  45.            sBuffer = Space$(lBuffer)
  46.  
  47.            lRet = MultiByteToWideChar(CP_UTF8, 0, vEntry(0), lLen, StrPtr(sBuffer), lBuffer)
  48.  
  49.            If lRet Then
  50.                StrConversion = Left$(sBuffer, lRet)
  51.            End If
  52.        End If
  53.    End If
  54.  
  55. Exit_:
  56. End Function

I hope it works, or at least it helps you to make your own function.
Good luck! ;)

DoEvents! :P


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 12 Octubre 2012, 16:07 pm
@Psyke1

Thanks for this mate I'll try it tonight but it use two APIs which is not a good thing, possible to remove/replace them?


Título: Re: StrConv Alternative Function
Publicado por: Psyke1 en 12 Octubre 2012, 17:49 pm
Thanks for this mate I'll try it tonight but it use two APIs which is not a good thing, possible to remove/replace them?

Yes I think it's possible. :rolleyes:
May be loading an array of the unicode numbers and using CharUpperBuffW() and CharUpperBuffA() apis.
Here are some examples: vbspeed (http://www.xbeat.net/vbspeed/).

DoEvents! :P


Título: Re: StrConv Alternative Function
Publicado por: Danyfirex en 12 Octubre 2012, 17:50 pm
I can tell you that the problem does not come from the encryption, I'm using it since a long time. Nobody enough skilled to fix this Alt StrConv func dude? :(

I'm sure yes.  


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 12 Octubre 2012, 20:43 pm
Yes I think it's possible. :rolleyes:
May be loading an array of the unicode numbers and using CharUpperBuffW() and CharUpperBuffA() apis.
Here are some examples: vbspeed (http://www.xbeat.net/vbspeed/).

DoEvents! :P

I've tried your alternative function and it doesn't work, dunno what part is wrong...


Título: Re: StrConv Alternative Function
Publicado por: Swellow en 12 Octubre 2012, 20:44 pm
I'm sure yes.  

You sure it's from the encryption? Well, in another project I'm using hamavb's StrConv alternative which use MSVBVM60 APIs and the encryption works perfectly with it... The problem comes from the AltStrConv, even author said that there were a problem with unicode characters but I never found a fix...