a problem with copymem API

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antony Clements

    a problem with copymem API

    i am using the following code

    private var1 as Long
    private var2 as Long
    private var3 as Long

    ReDim bytearray(0 To 3)
    ReDim bytearray2(0 To 3)

    For a = 0 To 3
    bytearray(a) = Asc(Mid(DataSou rce, b, 1))
    bytearray2(a) = Asc(Mid(DataSou rce2, c, 1))
    b = b + 1
    c = c + 1
    Next a

    var1 = IVbytearray(0) & IVbytearray(1) & IVbytearray(2) & IVbytearray(3)
    var2 = IVbytearray2(0) & IVbytearray2(1) & IVbytearray2(2) & IVbytearray2(3)

    CopyMemory var1, var1 Xor var2, 4
    CopyMemory var1, var1 Xor var3, 4

    an overflow error is sometimes thrown up in the copymemory api, how do i fix
    it?


  • J French

    #2
    Re: a problem with copymem API

    On Thu, 15 Feb 2007 10:27:25 +1100, "Antony Clements"
    <antony.clement s@optusnet.com. auwrote:
    >i am using the following code
    >
    >private var1 as Long
    >private var2 as Long
    >private var3 as Long
    >
    >ReDim bytearray(0 To 3)
    >ReDim bytearray2(0 To 3)
    >
    >For a = 0 To 3
    bytearray(a) = Asc(Mid(DataSou rce, b, 1))
    bytearray2(a) = Asc(Mid(DataSou rce2, c, 1))
    b = b + 1
    c = c + 1
    >Next a
    >
    >var1 = IVbytearray(0) & IVbytearray(1) & IVbytearray(2) & IVbytearray(3)
    >var2 = IVbytearray2(0) & IVbytearray2(1) & IVbytearray2(2) & IVbytearray2(3)
    >
    >CopyMemory var1, var1 Xor var2, 4
    >CopyMemory var1, var1 Xor var3, 4
    >
    >an overflow error is sometimes thrown up in the copymemory api, how do i fix
    >it?
    I can't make any sense of this code
    - you don't use & for building a Long out of Bytes

    If you described what you are trying to do, then maybe we can come up
    with a suggestion.


    Comment

    • Antony Clements

      #3
      Re: a problem with copymem API

      i modified the code after i posted this, it no longer throws up an error but
      it still doesn't work correctly.

      dim var1 var2 and var3 as long

      ReDim IVbytearray(0 To 7)
      ReDim IVbytearray2(0 To 7)

      bytearray() = Mid(stream1, b, 8)
      bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
      point, the data held in bytearray() is different than the data held in
      bytearray2()

      var1 = bytearray()
      var2 = bytearray2() 'this is where the problem is as var2 returns the same
      value as var1 even though the value in bytearray() is different to the value
      in bytearray2().

      Call CopyMemory(var1 , var1 Xor var2, 8)
      Call CopyMemory(var1 , var1 Xor var3, 8)


      now here is the problem. even though the data source for bytearray() and
      bytearray2() are different, for some reason or other they both have the same
      value. var2 needs to be a value from the second data source. i hope this is
      a clear indication of what i am trying to do.

      "J French" <erewhon@nowher e.ukwrote in message
      news:45d410e0.1 920119@news.bto penworld.com...
      On Thu, 15 Feb 2007 10:27:25 +1100, "Antony Clements"
      <antony.clement s@optusnet.com. auwrote:
      >
      >>i am using the following code
      >>
      >>private var1 as Long
      >>private var2 as Long
      >>private var3 as Long
      >>
      >>ReDim bytearray(0 To 3)
      >>ReDim bytearray2(0 To 3)
      >>
      >>For a = 0 To 3
      > bytearray(a) = Asc(Mid(DataSou rce, b, 1))
      > bytearray2(a) = Asc(Mid(DataSou rce2, c, 1))
      > b = b + 1
      > c = c + 1
      >>Next a
      >>
      >>var1 = IVbytearray(0) & IVbytearray(1) & IVbytearray(2) & IVbytearray(3)
      >>var2 = IVbytearray2(0) & IVbytearray2(1) & IVbytearray2(2) &
      >>IVbytearray2( 3)
      >>
      >>CopyMemory var1, var1 Xor var2, 4
      >>CopyMemory var1, var1 Xor var3, 4
      >>
      >>an overflow error is sometimes thrown up in the copymemory api, how do i
      >>fix
      >>it?
      >
      I can't make any sense of this code
      - you don't use & for building a Long out of Bytes
      >
      If you described what you are trying to do, then maybe we can come up
      with a suggestion.
      >
      >

      Comment

      • Dean Earley

        #4
        Re: a problem with copymem API

        Antony Clements wrote:
        i modified the code after i posted this, it no longer throws up an error but
        it still doesn't work correctly.
        >
        dim var1 var2 and var3 as long
        >
        ReDim IVbytearray(0 To 7)
        ReDim IVbytearray2(0 To 7)
        These are redundant as they are replaced in the next block.
        bytearray() = Mid(stream1, b, 8)
        bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
        point, the data held in bytearray() is different than the data held in
        bytearray2()
        This copies a UNICODE string into the byte array.
        This will be 16 bytes, every other one being a null character.

        If you want each character as an item in the array, then you want:
        bytearray = StrConv(string, vbFromUnicode)
        var1 = bytearray()
        var2 = bytearray2() 'this is where the problem is as var2 returns the same
        value as var1 even though the value in bytearray() is different to the value
        in bytearray2().
        From the code below, you can't join them up like this.
        You will need to do the arithmetic manually (shifting and adding) or
        copymemory from the byte array to a long.
        Bear in mind that you can only fit 4 bytes in a long...
        Call CopyMemory(var1 , var1 Xor var2, 8)
        Call CopyMemory(var1 , var1 Xor var3, 8)
        Be VERY careful as longs are still only 4 bytes.
        you WILL be corrupting memory with this code.
        now here is the problem. even though the data source for bytearray() and
        bytearray2() are different, for some reason or other they both have the same
        value. var2 needs to be a value from the second data source. i hope this is
        a clear indication of what i am trying to do.
        It still doesn't explain what you have and what results you want at the
        end...

        --
        Dean Earley (dean.earley@ic ode.co.uk)
        i-Catcher Development Team

        iCode Systems

        Comment

        • Dean Earley

          #5
          Re: a problem with copymem API

          Dean Earley wrote:
          Antony Clements wrote:
          >bytearray() = Mid(stream1, b, 8)
          >bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at
          >this point, the data held in bytearray() is different than the data
          >held in bytearray2()
          >
          This copies a UNICODE string into the byte array.
          This will be 16 bytes, every other one being a null character.
          >
          If you want each character as an item in the array, then you want:
          bytearray = StrConv(string, vbFromUnicode)
          This does assume a normal ANSI string. It will be longer if you have non
          ANSI data in your string

          --
          Dean Earley (dean.earley@ic ode.co.uk)
          i-Catcher Development Team

          iCode Systems

          Comment

          • Antony Clements

            #6
            Re: a problem with copymem API

            if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
            value of the string. the only way i know how to do this is take each
            character convert to ascii and then place in a string and then place the
            string in bytearray(). i'm looking for a simpler way. var1 and var2 are
            always returning the value of 1306840 regardless. bytearray() will return
            1a2b3c4d. i am copying the bytearray variables to long variables. the
            problem will be solved once var1 and var2 are correct values.

            "Dean Earley" <dean.earley@ic ode.co.ukwrote in message
            news:45d438c9$0 $22115$db0fefd9 @news.zen.co.uk ...
            Antony Clements wrote:
            >i modified the code after i posted this, it no longer throws up an error
            >but it still doesn't work correctly.
            >>
            > dim var1 var2 and var3 as long
            >>
            >ReDim IVbytearray(0 To 7)
            >ReDim IVbytearray2(0 To 7)
            >
            These are redundant as they are replaced in the next block.
            >
            >bytearray() = Mid(stream1, b, 8)
            >bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
            >point, the data held in bytearray() is different than the data held in
            >bytearray2()
            >
            This copies a UNICODE string into the byte array.
            This will be 16 bytes, every other one being a null character.
            >
            If you want each character as an item in the array, then you want:
            bytearray = StrConv(string, vbFromUnicode)
            >
            >var1 = bytearray()
            >var2 = bytearray2() 'this is where the problem is as var2 returns the
            >same value as var1 even though the value in bytearray() is different to
            >the value in bytearray2().
            >
            From the code below, you can't join them up like this.
            You will need to do the arithmetic manually (shifting and adding) or
            copymemory from the byte array to a long.
            Bear in mind that you can only fit 4 bytes in a long...
            >
            >Call CopyMemory(var1 , var1 Xor var2, 8)
            >Call CopyMemory(var1 , var1 Xor var3, 8)
            >
            Be VERY careful as longs are still only 4 bytes.
            you WILL be corrupting memory with this code.
            >
            >now here is the problem. even though the data source for bytearray() and
            >bytearray2() are different, for some reason or other they both have the
            >same value. var2 needs to be a value from the second data source. i hope
            >this is a clear indication of what i am trying to do.
            >
            It still doesn't explain what you have and what results you want at the
            end...
            >
            --
            Dean Earley (dean.earley@ic ode.co.uk)
            i-Catcher Development Team
            >
            iCode Systems

            Comment

            • Antony Clements

              #7
              Re: a problem with copymem API

              the data is from the full ascii range
              "Dean Earley" <dean.earley@ic ode.co.ukwrote in message
              news:45d43a6b$0 $2449$db0fefd9@ news.zen.co.uk. ..
              Dean Earley wrote:
              >Antony Clements wrote:
              >>bytearray() = Mid(stream1, b, 8)
              >>bytearray2( ) = Mid(stream2, c, 8) 'a messagebox here proves that at this
              >>point, the data held in bytearray() is different than the data held in
              >>bytearray2( )
              >>
              >This copies a UNICODE string into the byte array.
              >This will be 16 bytes, every other one being a null character.
              >>
              >If you want each character as an item in the array, then you want:
              >bytearray = StrConv(string, vbFromUnicode)
              >
              This does assume a normal ANSI string. It will be longer if you have non
              ANSI data in your string
              >
              --
              Dean Earley (dean.earley@ic ode.co.uk)
              i-Catcher Development Team
              >
              iCode Systems

              Comment

              • Antony Clements

                #8
                Re: a problem with copymem API

                i eralilse what i said i'm trying to do is quite vague. the purpose of the
                code is the core of a stream cipher where they key is defined as

                key = var1 xor var2 xor var3 where var3 is (2147483647 * rnd). what happens
                next is cipherbyte = chr((messagebyt e xor key) mod 256)
                >Call CopyMemory(var1 , var1 Xor var2, 8)
                >Call CopyMemory(var1 , var1 Xor var3, 8)
                does actually work as written.

                the problem is that var1 and var2 are always the same constant no matter
                what the source is.

                "Dean Earley" <dean.earley@ic ode.co.ukwrote in message
                news:45d438c9$0 $22115$db0fefd9 @news.zen.co.uk ...
                Antony Clements wrote:
                >i modified the code after i posted this, it no longer throws up an error
                >but it still doesn't work correctly.
                >>
                > dim var1 var2 and var3 as long
                >>
                >ReDim IVbytearray(0 To 7)
                >ReDim IVbytearray2(0 To 7)
                >
                These are redundant as they are replaced in the next block.
                >
                >bytearray() = Mid(stream1, b, 8)
                >bytearray2() = Mid(stream2, c, 8) 'a messagebox here proves that at this
                >point, the data held in bytearray() is different than the data held in
                >bytearray2()
                >
                This copies a UNICODE string into the byte array.
                This will be 16 bytes, every other one being a null character.
                >
                If you want each character as an item in the array, then you want:
                bytearray = StrConv(string, vbFromUnicode)
                >
                >var1 = bytearray()
                >var2 = bytearray2() 'this is where the problem is as var2 returns the
                >same value as var1 even though the value in bytearray() is different to
                >the value in bytearray2().
                >
                From the code below, you can't join them up like this.
                You will need to do the arithmetic manually (shifting and adding) or
                copymemory from the byte array to a long.
                Bear in mind that you can only fit 4 bytes in a long...
                >
                >Call CopyMemory(var1 , var1 Xor var2, 8)
                >Call CopyMemory(var1 , var1 Xor var3, 8)
                >
                Be VERY careful as longs are still only 4 bytes.
                you WILL be corrupting memory with this code.
                >
                >now here is the problem. even though the data source for bytearray() and
                >bytearray2() are different, for some reason or other they both have the
                >same value. var2 needs to be a value from the second data source. i hope
                >this is a clear indication of what i am trying to do.
                >
                It still doesn't explain what you have and what results you want at the
                end...
                >
                --
                Dean Earley (dean.earley@ic ode.co.uk)
                i-Catcher Development Team
                >
                iCode Systems

                Comment

                • J French

                  #9
                  Re: a problem with copymem API

                  On Fri, 16 Feb 2007 09:46:04 +1100, "Antony Clements"
                  <antony.clement s@optusnet.com. auwrote:
                  >if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
                  >value of the string. the only way i know how to do this is take each
                  >character convert to ascii and then place in a string and then place the
                  >string in bytearray(). i'm looking for a simpler way. var1 and var2 are
                  >always returning the value of 1306840 regardless. bytearray() will return
                  >1a2b3c4d. i am copying the bytearray variables to long variables. the
                  >problem will be solved once var1 and var2 are correct values.
                  I still don't follow what you are trying to do.

                  It looks as if you want to compute some sort of 32 bit number from an
                  8 character String.


                  Comment

                  • Dean Earley

                    #10
                    Re: a problem with copymem API

                    Antony Clements wrote:
                    if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
                    value of the string. the only way i know how to do this is take each
                    character convert to ascii and then place in a string and then place the
                    string in bytearray().
                    As I said...
                    If you want each character as an item in the array, then you want:
                    bytearray = StrConv(string, vbFromUnicode)
                    From a string of "1a2b3c4d", this will give you an 8 item array
                    containing: 49, 97, 50, 98, 51, 99, 52, 100,

                    IF however, you want the 32bit equivalent of that hex encoded string (if
                    it is hex) then you will need to manually split it on every two
                    characters and pass it through val("&H" & hexvalue) and store each part
                    in the array.

                    --
                    Dean Earley (dean.earley@ic ode.co.uk)
                    i-Catcher Development Team

                    iCode Systems

                    Comment

                    • Antony Clements

                      #11
                      Re: a problem with copymem API

                      It looks as if you want to compute some sort of 32 bit number from an
                      8 character String.
                      the numbers i am trying to generate from the string has a minimum value of
                      00000000 and a maximum of 255255255255255 255255255 wich are the ascii codes
                      of 8 characters.

                      the block of code works except for those 2 little lines that don't return
                      correct values. no data type that i know of will support such a large number
                      but it is critical that the code does, and i wouldnt know where to begin to
                      write a type def that will support such a large number either.


                      Comment

                      • Antony Clements

                        #12
                        Re: a problem with copymem API

                        stream1 is a pseudorandom string that can containing every character
                        available within the ansi standard with an undefined length. stream2 has a
                        defined length of 512 bits but can still contain any combination of
                        characters within the full ansi standard. that is characters with an ascii
                        code of 0 to 255. this means that var1 and var2 must hold a maximum number
                        of 255255255255. no data type that i know of will ever hold such a large
                        number except maybe a type def variable. but i wouldnt know where to begin
                        writing one to hold such a large number. i don't think converting from
                        unicode to ansi will have any positive effect on the rest of the code.

                        "Dean Earley" <dean.earley@ic ode.co.ukwrote in message
                        news:45d5750b$0 $32030$fa0fcedb @news.zen.co.uk ...
                        Antony Clements wrote:
                        >if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
                        >value of the string. the only way i know how to do this is take each
                        >character convert to ascii and then place in a string and then place the
                        >string in bytearray().
                        >
                        As I said...
                        >
                        If you want each character as an item in the array, then you want:
                        bytearray = StrConv(string, vbFromUnicode)
                        >
                        From a string of "1a2b3c4d", this will give you an 8 item array
                        containing: 49, 97, 50, 98, 51, 99, 52, 100,
                        >
                        IF however, you want the 32bit equivalent of that hex encoded string (if
                        it is hex) then you will need to manually split it on every two characters
                        and pass it through val("&H" & hexvalue) and store each part in the array.
                        >
                        --
                        Dean Earley (dean.earley@ic ode.co.uk)
                        i-Catcher Development Team
                        >
                        iCode Systems

                        Comment

                        • Antony Clements

                          #13
                          Re: a problem with copymem API

                          correction of mistake. i am only grabbing 4 bytes of both strings instead of
                          the original 8 and am trying to generate a number between 0 and 255255255255
                          from each 4 byte block of string
                          "J French" <erewhon@nowher e.ukwrote in message
                          news:45d5626e.2 175983@news.bto penworld.com...
                          On Fri, 16 Feb 2007 09:46:04 +1100, "Antony Clements"
                          <antony.clement s@optusnet.com. auwrote:
                          >
                          >>if stream1 has a value of 1a2b3c4d i want bytearray() to return the asc
                          >>value of the string. the only way i know how to do this is take each
                          >>character convert to ascii and then place in a string and then place the
                          >>string in bytearray(). i'm looking for a simpler way. var1 and var2 are
                          >>always returning the value of 1306840 regardless. bytearray() will return
                          >>1a2b3c4d. i am copying the bytearray variables to long variables. the
                          >>problem will be solved once var1 and var2 are correct values.
                          >
                          I still don't follow what you are trying to do.
                          >
                          It looks as if you want to compute some sort of 32 bit number from an
                          8 character String.
                          >
                          >

                          Comment

                          • Dean Earley

                            #14
                            Re: a problem with copymem API

                            Antony Clements wrote:
                            stream1 is a pseudorandom string that can containing every character
                            available within the ansi standard with an undefined length. stream2
                            has a defined length of 512 bits but can still contain any
                            combination of characters within the full ansi standard. that is
                            characters with an ascii code of 0 to 255. this means that var1 and
                            var2 must hold a maximum number of 255255255255.
                            So you want ascii value string concatenation rather than just the
                            decimal value of the 4 byte string?

                            If this really is the case (I don't believe it is) then use the strconv
                            code I gave you and join the byte array items together in a string and
                            convert the result to a number rather than copymemory into a long.
                            no data type that i know of will ever hold such a large number except
                            maybe a type def variable. but i wouldnt know where to begin writing
                            one to hold such a large number.
                            The currency data type will
                            i don't think converting from unicode to ansi will have any positive
                            effect on the rest of the code.
                            Yes it will, it will give you the real ascii values in a byte array
                            rather than utf16 unicode in a byte array.

                            You seem to be missing the point by a very long way here.

                            What EXACTLY do you have as input, what do you expect the intermediary
                            and final values to be?

                            --
                            Dean Earley (dean.earley@ic ode.co.uk)
                            i-Catcher Development Team

                            iCode Systems

                            Comment

                            • Antony Clements

                              #15
                              Re: a problem with copymem API

                              So you want ascii value string concatenation rather than just the
                              decimal value of the 4 byte string?
                              i would prefer the decimal value, but the decimal value remains constant
                              regardless of what 4 bytes i pull from the streams, it is always 1306840
                              The currency data type will
                              i tried currency, it threw up an error
                              Yes it will, it will give you the real ascii values in a byte array
                              rather than utf16 unicode in a byte array.
                              >
                              You seem to be missing the point by a very long way here.
                              >
                              What EXACTLY do you have as input, what do you expect the intermediary
                              and final values to be?
                              i gave you an example for an input from stream2 "1a2b" which is input into a
                              bytearray, it is meant to return a dynamic number that changes as input
                              changes not a constant. even if the input from the stream was "help" it
                              still returns the same decimal value of 1306840. even if the input is 8
                              bytes "1a2b3c4d" it still returns the exact same value of 1306840. the point
                              i am making is that it doesn't matter what the input is, or how long the
                              input is, i get the same value from both streams regardless. the number that
                              gets returned from stream1 and stream2 must always be different depending on
                              the input.


                              Comment

                              Working...