StrConv Alternative Function

Iniciado por Swellow, 7 Octubre 2012, 17:03 PM

0 Miembros y 2 Visitantes están viendo este tema.

Swellow

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..

Danyfirex

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).


Swellow

Cita de: 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).



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? :(

Psyke1

#23
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 (vb) [Seleccionar]

Option Explicit

'// kernel32.dll
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
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

'// Const
Private Const CP_UTF8                           As Long = &HFDE9 '65001

'// Enum
Public Enum CONV_TYPE
    Unicode = vbUnicode
    UTF8 = vbFromUnicode
End Enum

'// Function
Public Function StrConversion(ByRef vEntry As Variant, eConv As CONV_TYPE) As Variant
Dim lRet                                        As Long
Dim lLen                                        As Long
Dim lBuffer                                     As Long
Dim sBuffer                                     As String
Dim bvOutput()                                  As Byte

    On Error GoTo Exit_
   
    If eConv = Unicode Then
        lLen = LenB(vEntry) \ 2
       
        If lLen Then
            lBuffer = lLen + lLen + lLen + 1
            ReDim bvOutput(lBuffer - 1) As Byte
           
            lRet = WideCharToMultiByte(CP_UTF8, 0, StrPtr(vEntry), lLen, bvOutput(0), lBuffer, vbNullString, 0)
           
            If lRet Then
                ReDim Preserve bvOutput(lRet - 1) As Byte
                StrConversion = bvOutput
            End If
        End If
    Else
        lLen = UBound(vEntry) + 1
       
        If lLen > 1 Then
            lBuffer = lLen + lLen
            sBuffer = Space$(lBuffer)
           
            lRet = MultiByteToWideChar(CP_UTF8, 0, vEntry(0), lLen, StrPtr(sBuffer), lBuffer)
           
            If lRet Then
                StrConversion = Left$(sBuffer, lRet)
            End If
        End If
    End If

Exit_:
End Function


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

DoEvents! :P

Swellow

#24
@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?

Psyke1

Cita de: Swellow en 12 Octubre 2012, 16:07 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.

DoEvents! :P

Danyfirex

Cita de: Swellow en 12 Octubre 2012, 14:06 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.  

Swellow

Cita de: Psyke1 en 12 Octubre 2012, 17:49 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.

DoEvents! :P

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

Swellow

Cita de: Danyfirex en 12 Octubre 2012, 17:50 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...