Decrypt file before loading
-
@Roberrt said in Decrypt file before loading:
It states that QFile is used to read the files from the Qt resources, I'll try put a debug in some of these functions and see if one of them are being used to load the stylesheet files.
The first part is largely irrelevant since you are not using the Qt resource system.
The way you are using it, the provided path is transformed to native separators and passed to the underlying C/C++ libraries and operating system.QFile knows nothing of what purpose a file may have in your application: an icon image being accessed by a stylesheet is just the same as a cat video to QFile. If you want to impact only files referenced from stylesheets then you need to intercept that much earlier.
If you really want to change the entire file handling behaviour for anything that uses QFile then you probably want to be looking at
qfsfileengine*
in the IO code. The decision between native file and resource system occurs inqfilesystemengine.cpp
. The handling for the resource system lives inqresource*
in the same location.If you want to impact only files referenced from stylesheets then you need to intercept that much earlier.
This is my goal, impact any file being referenced from stylesheets the QPushButton on my previous post was just an example.
If you really want to change the entire file handling behaviour for anything that uses QFile
Not exactly, I don't want to change files handled by QFile, I'm trying to find in which function the stylesheet URL file is loaded, then I could decrypt and return the file decrypted.
Thank you for pointing these files, I'm reading the functions of
qfsfileengine_win.cpp
, i think its probably one of these? -
This sounds like a use case of QQuickImageProvider, at least if you have control over the code loading the image, so that you can use a different scheme.
-
kkoehne i would like to hardcode the decryption into the sources, then I wouldn't need to care about coding anything else in the project as mostly of the pictures are added using stylesheet.
I have added some
OutputDebugString
into the functions underqfsfileengine_win.cpp
, but none of them got called. -
kkoehne i would like to hardcode the decryption into the sources, then I wouldn't need to care about coding anything else in the project as mostly of the pictures are added using stylesheet.
I have added some
OutputDebugString
into the functions underqfsfileengine_win.cpp
, but none of them got called.@Roberrt If you want to read encrypted images, why don‘t you „define“ your own file format and write a Image I/O plugin which can decrypt these files?
-
@Roberrt If you want to read encrypted images, why don‘t you „define“ your own file format and write a Image I/O plugin which can decrypt these files?
@DerReisende That looks like a good approach indeed (provided it works)!
-
@DerReisende That looks like a good approach indeed (provided it works)!
@JonB Don‘t know as I never used it. But in my small ideal plugin world I would decrypt to a temp file (or byte array of this works), use QImage or whatever to read the decrypted file (which can now be handled by the qt image format plugins), return it and discard the temp file.
-
I need this feature as well. It would be nice if Qt can provide this function. The idea of DerReisende is not bad. But if the file is big and loading takes long, the tmp file can be copied and encryption does not make sense anymore.
@JoeCFD
So try it using memory instead of external file.Goodness knows what you guys are trying to encrypt to hide from the user, an image that you're presumably going to show anyway. You would be talking about a symmetric encryption/decryption algorithm, right? So between that, and whether it be Qt's code or your code both likely to be publicly visible, isn't it likely that a user who wants to see the image file decrypted could do so anyway?
-
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
-
kkoehne i would like to hardcode the decryption into the sources, then I wouldn't need to care about coding anything else in the project as mostly of the pictures are added using stylesheet.
I have added some
OutputDebugString
into the functions underqfsfileengine_win.cpp
, but none of them got called.@Roberrt said in Decrypt file before loading:
kkoehne i would like to hardcode the decryption into the sources, then I wouldn't need to care about coding anything else in the project as most of the pictures are added using stylesheet.
Doing this also would work when testing the UI in qt designer, with encrypted files.
-
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
-
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
@Roberrt said in Decrypt file before loading:
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
Well AFAIK unless you are using a commercial license of Qt, every modification of Qt source you make must be made available to other users - including your encryption modification. If that is the case you win nothing and your customers may easily decrypt the resources...but I guess it will be a lot easier for them to just make screenshots and edit those.
-
@JoeCFD
So try it using memory instead of external file.Goodness knows what you guys are trying to encrypt to hide from the user, an image that you're presumably going to show anyway. You would be talking about a symmetric encryption/decryption algorithm, right? So between that, and whether it be Qt's code or your code both likely to be publicly visible, isn't it likely that a user who wants to see the image file decrypted could do so anyway?
-
@JoeCFD QImage::loadFromData() with a byte array.
-
@JoeCFD QImage::loadFromData() with a byte array.
@DerReisende said in Decrypt file before loading:
QImage::loadFromData()
Thanks. Then it is doable for images. How about videos?
-
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
@Roberrt said in Decrypt file before loading:
the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
One can do a simple screen shot of running app and cut all the icons, personal art, logo. Don't see how encryption can help here...
-
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
@Roberrt said in Decrypt file before loading:
Well I didn't expect it was going to be a 'hard' task, the reason to encrypt is to avoid easily copy of icons, personal art, logo, etc
For my money, using the Qt resource system is going to achieve this goal. There is no on-disk file to copy. Anyone savvy enough, and with enough motivation, to find and decompress the image data embedded in your executable or DLL is probably going to be able to subvert this several ways.
@DerReisende 's suggestion is a good one if it is only images involved. This has the benefit of working anywhere the encrypted image is used.
A QImageIOPlugin should be quite quick to produce. The plugin
create()
method would have to create your QImageIOHandler subclass for *.enc images and ensure it gets a decryption key if one is needed.
The QImageIOHandler may be more involved but could be as simple as theread()
method loading the target QIODevice data into a QByteArray, decrypting/de-obfuscating in-place, calling QImage::loadFromData(), and destroying the interim QByteArray. -
@DerReisende said in Decrypt file before loading:
QImage::loadFromData()
Thanks. Then it is doable for images. How about videos?