CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2004
    Posts
    12

    Hide A Passw string in code

    Hello

    Where can I hide a password string inside a vc++ code, to not have it displayed in an hexa editor. If I make a simple:
    char key[5]="pepe"
    The hexa editor simple shows it unchanged.

    What about placing it in a string table in resource editor?

    What is safer option?

    Thanks

  2. #2
    Join Date
    Oct 2002
    Posts
    1,134

    Re: Hide A Passw string in code

    You'll have to encode it somehow. You could invert the bits for each character; you could add some number to each character and store the result as an integer; etc.

    Putting it in a string table won't do much to protect it.
    Regards
    Robert Thompson

  3. #3
    Join Date
    May 2002
    Location
    Phoenix, AZ
    Posts
    95

    Re: Hide A Passw string in code

    You could try it this way

    char code[6] = {'H','E','L','L','O',0};

    String table would still show under a hex editor

  4. #4
    Join Date
    Oct 2002
    Posts
    1,134

    Re: Hide A Passw string in code

    You could try it this way

    char code[6] = {'H','E','L','L','O',0};
    Given the way the compiler allocates memory, I think your solution will produce code that is identical to specifying a string, which would stand out when displayed by a hex editor.
    Regards
    Robert Thompson

  5. #5
    Join Date
    May 2002
    Location
    Phoenix, AZ
    Posts
    95

    Re: Hide A Passw string in code

    I just checked, in both debug and release builds.

    char code[6] = {'H','E','L','L','O',0}; // Does not show up in a hex editor (Release or debug build).

    char code[6] = "HELLO"; // Shows up in a hex editor in debug build, but not in release build

    The second scenario was pretty surprising actually, as i thought "HELLO" would be stored in the PE files data segment!!!

    Any ideas why not?

  6. #6
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Hide A Passw string in code

    What about this:
    Code:
    char code[6] = {73,70,77,77,80,0};
    (I hope I did put the correct codes.)
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  7. #7
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Hide A Passw string in code

    Quote Originally Posted by raghupathys
    char code[6] = "HELLO";
    char code[6] = {'H','E','L','L','O',0};
    Quote Originally Posted by cilu
    char code[6] = {73,70,77,77,80,0};
    All of these lines will produce exactly the same compiled code, regardless of a debug or release build, when you declare it static or outside any block scope (not on the stack). It will always show in a hex editor. As for declaring it on the stack: It will we compiler dependent what happens here: The compiler might generate single instructions to push the characters on the stack, or a contiguous block which is copied - so you can't rely on that technique for effectively hiding the string. As TSYS said, you will need to encode the string in some way.

    Quote Originally Posted by raghupathys
    The second scenario was pretty surprising actually, as i thought "HELLO" would be stored in the PE files data segment!!!
    The reason it didn't show up in a release build is most probably that you declared it, but never used it, so the data was optimized away in a release build.
    Last edited by gstercken; December 2nd, 2004 at 04:03 AM.

  8. #8
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: Hide A Passw string in code

    Beside encoding your string to make it not displayable on hex editor, you can divide your string into several parts and spread them all over your code. You then need a function to gather and reconstruct them back to the original string.

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

Featured