RegQueryValueEx problem

This is a discussion on RegQueryValueEx problem within the Windows Programming forums, part of the Platform Specific Boards category; I have an application that stores and retrieves binary data from the registry. The application writes the data correctly to ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059

    RegQueryValueEx problem

    I have an application that stores and retrieves binary data from the registry. The application writes the data correctly to the registry but it cannot read all the data from the key if a 0x00 (zero, NULL) appears anywhere in the data written to the registry key. RegQueryValueEx appears to only read all the binary data up to the 0x00. For example, if I store 7b d1 13 74 00 d8 24 a3 in the registry, RegQueryValueEx only returns 7b d1 13 74. The key is a REG_BINARY key.

    The data that is written to the key is first encrypted using the Rijndael method. So, I have no control over what is written to the reigstry. The Rijndael method occassionally generates a 0x00 when encrypting.

    The code that I use to read the binary data is as follows:

    Code:
    char szEncryptedHAIKey[81] = {0};
    char szHAIKey[81] = {0};
    
     memset(szHAIKey, 0, sizeof szHAIKey);
     iDatasize = sizeof (szEncryptedHAIKey);
     RegQueryValueEx(hKey, "HAIKey",
         NULL, NULL, (unsigned char *)&szEncryptedHAIKey, (unsigned long *)&iDatasize); 
     Decrypt(szEncryptedHAIKey,szHAIKey , 80, ECB);
    Any assistance would be greatly appreciated.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Never hit that issue, can you work round it?

    Can you check the string and generate a new one if it contains nulls?

    Can you store the data in another format that allows nulls?

    Can you store the length or the string so you know how much to read?

    Can you store the info somewhere else (windows ini file)?

    Can you use a diff API call that will not present this error?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Can you check the string and generate a new one if it contains nulls?
    Unfortunately, I cannot do this. The app acquires a 16 byte hex string from a security controller and passes this string onto the Rijndael encryption function. The encryption function will always generate the same binary encrypted values. I'm using the Electronic Code Book Rijndael method that is required by the controller which as indicated above always generates the same encrypted values. I do have a temporary solution that requires the end user to change the hex value on the controller that generates the 0x00 to some other value. But this is a major inconvenience to the end user.
    Can you store the data in another format that allows nulls?
    I'm currently using the REG_BINARY type for the key. I'm not aware of any other registry type that would allow a null value, 0x00 in particular and binary data in general.
    Can you store the length or the string so you know how much to read?
    I can store the length of the string in another key. But how would I use the registry API to read past the 0x00 value? RegQueryValueEx stops reading at the 0x00 value.
    Can you store the info somewhere else (windows ini file)?
    I'm currently working on moving this data out of the registry and into a Sqllite3 database. Sqllite3 has an "extension" for lack of a better description to store BLOB data in a field.
    Can you use a diff API call that will not present this error?
    I'm not aware of any other API to read/write the registry.

    Thanx

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    novacain,

    I just realized that I made a really stupid mistake in another part of my code. I used strlen instead of sizeof. Thus, the problem with the 0x00, NULL terminator. This was the source of my problem.

    I wish to apologize for not reviewing my code more carefully before posting and to thank you for the response.

    In the future, I'll try to be more careful.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Not a problem, glad to help.

    What matters that your bug has been resolved, not what caused it....

    I just realized that I made a really stupid mistake in another part of my code.
    If your like me, this won't be the first or the last really stupid mistake (this week)......

    IMO the test of a programmer is how you deal with your mistakes/bugs...
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21