Results 1 to 5 of 5

Thread: methods to obfuscate strings from hexdumps

  1. #1
    Join Date
    Apr 2014
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Cool methods to obfuscate strings from hexdumps

    Anybody have a secure method of hiding sensitive
    text constants in program executables?

  2. #2
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: methods to obfuscate strings from hexdumps

    you must code your string. The simplest way is to use Base64 encoding.
    QByteArray has 2 methods:
    ::toBase64(..) // use function to get the byte array to be inserted in source code.
    ::fromBase64(..) // use function to decode the string in your application code

    run this part of code during code editing and replace the result in the source code:
    Qt Code:
    1. QByteArray str("secret"); // the variable you want to hidden
    2. qDebug() << str.data() << "-->" << str.toBase64(); // the encoded variable in Base64
    To copy to clipboard, switch view to plain text mode 

    in your application:
    Qt Code:
    1. // declare and initialize your variable
    2. QByteArray encoded("c2VjcmV0"); // this is your encoded string
    3. // use your variable
    4. QByteArray decoded = QByteArray::fromBase64( encoded ); // this is your decoded string as QByteArray
    5. QString decodedString = QString( QByteArray::fromBase64( encoded )); // alternatively as QString
    6. qDebug() << encoded.data() << "-->" << decoded.data();
    To copy to clipboard, switch view to plain text mode 

    the debug output is:
    secret --> "c2VjcmV0"
    c2VjcmV0 --> secret

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: methods to obfuscate strings from hexdumps

    Of course, any clever hacker would recognize a Base64 string in the data section of code and run a decoder on it... if you really want it to be secure, encrypt it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Apr 2014
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: methods to obfuscate strings from hexdumps

    Agreed. The constant must be processed by the same method beforehand.
    I was hoping someone had came up with a script or precompile step to automate the obfuscation.

    Thanks for responding!

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: methods to obfuscate strings from hexdumps

    You might be able to automate this by putting your strings into a file that is compiled into a resource (qrc) file. Your precompile step would be to take the plain-text string file, encrypt it into a second file, and that second file is compiled into the resource file. You can treat a file in resources pretty much like any other file, so you could load that file at run-time into a QMap or similar that looks up encrypted strings by keyword. The only place the plain-text strings live is on your development system; the resource file is compiled into your program binary and contains only the encrypted version.

    You could look at using an INI-formatted QSettings bound to a file in the resources as a convenient way to do the lookup by key. Your encryption step converts one QSettings file into another containing the encrypted values.
    Last edited by d_stranz; 28th July 2016 at 16:32.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Get and Set Methods
    By 020394 in forum Qt Programming
    Replies: 10
    Last Post: 18th July 2013, 02:57
  2. What is the general rule for onX methods in Qt?
    By piotr.dobrogost in forum Qt Programming
    Replies: 8
    Last Post: 17th August 2009, 23:10
  3. wrapper of methods
    By mickey in forum General Programming
    Replies: 8
    Last Post: 15th August 2008, 15:33
  4. The Methods of quick search...
    By Xagen in forum General Discussion
    Replies: 1
    Last Post: 27th February 2006, 19:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.