Android Code Snippet VB6 VBA uses prefix mode and data structure of prefix mode.

Discussion in 'Code Snippets' started by boy8199, Jun 5, 2019.

  1. boy8199

    boy8199 New Member

    因为使用VBA,使用了 b4a 的前缀模式传输数据。但是 我查了论坛没有找到VBA VB6的代码,但是有VB.net的代码。 但是 VB.net有很多VBA VB6 没有的新功能和函数。我用了很多时间去尝试。最终我成功的使用前缀模式发送文件成功。我希望分享我的代码,帮助新的朋友。

    同时希望论坛能提供一下更详细的指导。

    1、文件名的长度,VB6, 4个字符,32位(倒序)
    2、文件名,vb6 string --> utf-8,长度为文件名长度
    3、STREAM_PREFIX标志,vb6 4个字符,long(倒序)
    4、文件数据长度,vb6(不支持)8个字符,64位,我只用了最后4位 Long(倒序)
    6、文件数据
    7、Adler-32校验码,vb6( 不支持)8个字符,64位,我只用了最后4位 Long(正序)

    上面的正序,是指VB6 中的数字存储模式:Long 类型,从左边位,开始存储数据,而V4A的socket是从右开始读取数据的。
    代码,我将完善好后在上传给大家。
    =================
    Because of the use of VBA, the prefix mode of b4a is used to transmit data. But I checked the forum did not find VBA VB6 code, but there is VB. net code. But VB.net has many new functions and functions that VBA VB6 does not have. I spent a lot of time trying. Eventually, I succeeded in sending files in prefix mode. I want to share my code and help new friends.
    At the same time, I hope the forum can provide more detailed guidance.
    1. File name length, VB6, 4 characters, 32 bits (reverse order)
    2. File name, VB6 string - > utf-8, length is file name length
    3. STREAM_PREFIX flag, vb64 characters, long (reverse order)
    4. File data length, VB6 (not supported) 8 characters, 64 bits, I only used the last 4 bits Long (reverse order)
    6. Document data
    7. Adler-32 check code, VB6 (unsupported) 8 characters, 64 bits, I only used the last 4 bits Long (positive order)
    The positive order above refers to the digital storage mode in VB6: Long type, which stores data from the left bit, while V4A socket reads data from the right.

    Code, I will improve it and upload it to you.
     
  2. boy8199

    boy8199 New Member

    这是Adler-32,的VB6代码。

    Code:
    Public Function Adler32Byte(bString() As Byte, Optional ReturnByteCount As Long = 4, _
                                 Optional A 
    As Long = 1As Byte()

        
    Dim B As Long, x As Long
        
    Dim bA(3As Byte
        
    Dim bB(3As Byte
        
    Dim bBA(3As Byte
        
    Dim bBa8(7As Byte
      
        A = (A + (bString(x) 
    And 255)) Mod 65521
      
        
    For x = 1 To UBound(bString)
            B = (B + A) 
    Mod 65521
            A = (A + (bString(x) 
    And 255)) Mod 65521
        
    Next x

        CopyMemory bA(
    0), A, 4
        CopyMemory bB(
    0), B, 4
      
        CopyMemory bBA(
    0), bB(1), 1
        CopyMemory bBA(
    1), bB(0), 1
        CopyMemory bBA(
    2), bA(1), 1
        CopyMemory bBA(
    3), bA(0), 1

        
    If ReturnByteCount = 8 Then
          
            Call CopyMemory(ByVal VarPtr(bBa8(
    4)), ByVal VarPtr(bBA(0)), 4)
            
    '8个字节,则前面4个为空白,暂未处理.
            Adler32Byte = bBa8
        
    Else
            Adler32Byte = bBA
        
    End If
     
    End Function
    ===================

    我发现一个问题: 双方的 缓冲区 应该一致才能正常工作.
    如果服务器一次性验证,那么客户端也应该该一次性验证,否则会出现CRC不匹配的情况.

    一次性验证中的 B值,会比 多次验证的情况少一次.
    =========
    A = (A + (bString(x) And 255)) Mod 65521

    For x = 1 To UBound(bString)
    B = (B + A) Mod 65521
    A = (A + (bString(x) And 255)) Mod 65521
    Next x

    这段代码 是用于 一次性验证文件的情况.
    =============

    For x = 0 To UBound(bString)
    A = (A + (bString(x) And 255)) Mod 65521
    B = (B + A) Mod 65521

    Next x
    这一段 是 正常的算法.用于分段验证.

    ==================

    I found a problem: the buffers on both sides should be consistent in order to work properly.
    If the server is authenticated once, then the client should also verify it once, otherwise there will be a CRC mismatch.

    The B value in one-time verification will be less than the case of multiple verifications.
    =========
    A = (A + (bString(x) And 255)) Mod 65521

    For x = 1 To UBound(bString)
    B = (B + A) Mod 65521
    A = (A + (bString(x) And 255)) Mod 65521
    Next x

    This code is used to verify the file once.
    =============

    For x = 0 To UBound(bString)
    A = (A + (bString(x) And 255)) Mod 65521
    B = (B + A) Mod 65521

    Next x
    This section is a normal algorithm. It is used for segmentation verification.

    =================
     
    Last edited: Jul 30, 2019
    MarcoRome and Erel like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice