Results 1 to 5 of 5

Thread: [RESOLVED] Convert function to VB6 (doubt)

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2020
    Posts
    15

    [RESOLVED] Convert function to VB6 (doubt)

    Hello, guys.

    Please, may someone convert this simple function to vb6? I'm having trouble with BinaryToString().

    --- 1 ---
    This:
    Code:
    '; check if string < 16 then read name from $addr_start
    'If $str_length < 16 Then
    'Return BinaryToString(_MemoryRead($addr_start, $handle, 'char[15]'))    ;==> 'King Medivius'

    My attempt into converting to V6 (First, read the address addr_start and then return its string value):
    Code:
    If str_length < 16 Then
    Dim ret As Long
    ReadProcessMemory lProcessHandle, addr_start, ret, 4, 0
    MemoryReadStdString = *binaryToString* (ret)
    Exit Function
    Last edited by oclipper; Jun 28th, 2021 at 01:59 PM.

  2. #2
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    Re: Convert function to VB6 (doubt)

    It depends very much on what format the binary data is in. If the binary data originated from Unicode data, the process is simple.
    Code:
    Public Function ByteToUni(bArray() As Byte) As String
        ByteToUni = bArray
    End Function
    If the data is known to be ASCII only (0 - 127), the StrConv routine can be used. If however the data is ANSI (0 - 255), it is not quite as straight forward. StrConv causes problems on computers set to use non-latin character sets, and some characters above 127 get interpreted as Unicode characters in the background without your knowledge. This is what I use.
    Code:
    Public Function ByteToStr(bArray() As Byte) As String
        Dim lPntr As Long
        Dim bTmp() As Byte
        On Error GoTo ByteErr
        ReDim bTmp(UBound(bArray) * 2 + 1)
        For lPntr = 0 To UBound(bArray)
            bTmp(lPntr * 2) = bArray(lPntr)
        Next lPntr
        Let ByteToStr = bTmp
        Exit Function
    ByteErr:
        ByteToStr = ""
    End Function
    J.A. Coutts

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2020
    Posts
    15

    Re: Convert function to VB6 (doubt)

    Quote Originally Posted by couttsj View Post
    It depends very much on what format the binary data is in. If the binary data originated from Unicode data, the process is simple.
    Code:
    Public Function ByteToUni(bArray() As Byte) As String
        ByteToUni = bArray
    End Function
    If the data is known to be ASCII only (0 - 127), the StrConv routine can be used. If however the data is ANSI (0 - 255), it is not quite as straight forward. StrConv causes problems on computers set to use non-latin character sets, and some characters above 127 get interpreted as Unicode characters in the background without your knowledge. This is what I use.
    Code:
    Public Function ByteToStr(bArray() As Byte) As String
        Dim lPntr As Long
        Dim bTmp() As Byte
        On Error GoTo ByteErr
        ReDim bTmp(UBound(bArray) * 2 + 1)
        For lPntr = 0 To UBound(bArray)
            bTmp(lPntr * 2) = bArray(lPntr)
        Next lPntr
        Let ByteToStr = bTmp
        Exit Function
    ByteErr:
        ByteToStr = ""
    End Function
    J.A. Coutts
    Thanks for your reply, it was faster than I expected. Could you gimme an example how to apply in my case? Its returning error type mismatch. EDIT: this error may be related to my doubt (2) since its reading incorrect value due to my syntax error

    Code:
    If str_length < 16 Then
    Dim ret2 As Long
    ReadProcessMemory lProcessHandle, addr_start, ret2, 4, 0
    MemoryReadStdString = ByteToStr(ret2)
    Exit Function
    Last edited by oclipper; Jun 19th, 2021 at 11:17 AM.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Convert function to VB6 (doubt)

    Sounds like another question about game cheat recipes.

  5. #5
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,470

    Re: Convert function to VB6 (doubt)

    Quote Originally Posted by oclipper View Post
    Thanks for your reply, it was faster than I expected. Could you gimme an example how to apply in my case? Its returning error type mismatch. EDIT: this error may be related to my doubt (2) since its reading incorrect value due to my syntax error
    Not sure what you are trying to do but see if this helps.
    Code:
    Option Explicit
    
    Private Function ByteToStr(bArray() As Byte) As String
        Dim lPntr As Long
        Dim bTmp() As Byte
        On Error GoTo ByteErr
        ReDim bTmp(UBound(bArray) * 2 + 1)
        For lPntr = 0 To UBound(bArray)
            bTmp(lPntr * 2) = bArray(lPntr)
        Next lPntr
        Let ByteToStr = bTmp
        Exit Function
    ByteErr:
        ByteToStr = ""
    End Function
    
    Private Sub DebugPrintByte(sDescr As String, bArray() As Byte)
        Dim lPtr As Long
        On Error GoTo Done
        Debug.Print sDescr & ":"
        For lPtr = 0 To UBound(bArray)
            Debug.Print Right$("0" & Hex$(bArray(lPtr)), 2) & " ";
            If (lPtr + 1) Mod 16 = 0 Then Debug.Print
        Next lPtr
    Done:
        Debug.Print
    End Sub
    
    Private Function HexToByte(HexStr As String) As Byte()
        Dim lLen As Long
        Dim lPntr As Long
        Dim bTmp() As Byte
        Dim bHex() As Byte
        If Len(HexStr) > 1 Then
            lLen = Len(HexStr) / 2
            ReDim bHex(lLen - 1)
            For lPntr = 0 To UBound(bHex)
                bHex(lPntr) = Val("&H" & Mid$(HexStr, lPntr * 2 + 1, 2))
            Next lPntr
            HexToByte = bHex
        Else
            bHex = bTmp
        End If
    End Function
    
    Private Sub Command1_Click()
        Dim bTmp() As Byte
        Dim sTmp As String
        bTmp = HexToByte("54657374204D657373616765")
        DebugPrintByte "bTmp", bTmp
        sTmp = ByteToStr(bTmp)
        Debug.Print sTmp
    End Sub
    J.A. Coutts

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width