Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Decrypt file before loading
Forum Updated to NodeBB v4.3 + New Features

Decrypt file before loading

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 9 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Roberrt

    @Christian-Ehrlicher If i decrypt the file after the source load it why it wouldn't work?

    Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by Christian Ehrlicher
    #4

    @Roberrt said in Decrypt file before loading:

    If i decrypt the file after the source load it why it wouldn't work?

    Because QImage can't load your image since it's encrypted. How should this work without modifying the Qt sources? You can't intercept the loading and decoding of an image.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    R 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @Roberrt said in Decrypt file before loading:

      If i decrypt the file after the source load it why it wouldn't work?

      Because QImage can't load your image since it's encrypted. How should this work without modifying the Qt sources? You can't intercept the loading and decoding of an image.

      R Offline
      R Offline
      Roberrt
      wrote on last edited by Roberrt
      #5

      @Christian-Ehrlicher But I'm going to modify the qt source, this I why I'm asking for help finding where the file is parsed in the sources.

      I have found this comment inside of the class QFile:

      \class QFile
      \inmodule QtCore
      \brief The QFile class provides an interface for reading from and writing to files.
      QFile is an I/O device for reading and writing text and binary
      files and \l{The Qt Resource System}{resources}.

      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.

      Christian EhrlicherC C 2 Replies Last reply
      0
      • R Roberrt

        @Christian-Ehrlicher But I'm going to modify the qt source, this I why I'm asking for help finding where the file is parsed in the sources.

        I have found this comment inside of the class QFile:

        \class QFile
        \inmodule QtCore
        \brief The QFile class provides an interface for reading from and writing to files.
        QFile is an I/O device for reading and writing text and binary
        files and \l{The Qt Resource System}{resources}.

        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.

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @Roberrt said in Decrypt file before loading:

        But I'm going to modify the qt source

        So you can't decrypt it during load and have to load it by your own function, decrypt it and the set the icon to your QPushButton.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • R Roberrt

          @Christian-Ehrlicher But I'm going to modify the qt source, this I why I'm asking for help finding where the file is parsed in the sources.

          I have found this comment inside of the class QFile:

          \class QFile
          \inmodule QtCore
          \brief The QFile class provides an interface for reading from and writing to files.
          QFile is an I/O device for reading and writing text and binary
          files and \l{The Qt Resource System}{resources}.

          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.

          C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #7

          @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 in qfilesystemengine.cpp. The handling for the resource system lives in qresource* in the same location.

          R 1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #8

            Another alternative is that you create a new, small disk partition D: which you format with the builtin encryption in NTFS.

            1 Reply Last reply
            0
            • C ChrisW67

              @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 in qfilesystemengine.cpp. The handling for the resource system lives in qresource* in the same location.

              R Offline
              R Offline
              Roberrt
              wrote on last edited by
              #9

              @ChrisW67

              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?

              1 Reply Last reply
              0
              • kkoehneK Offline
                kkoehneK Offline
                kkoehne
                Moderators
                wrote on last edited by
                #10

                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.

                Director R&D, The Qt Company

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Roberrt
                  wrote on last edited by Roberrt
                  #11

                  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 under qfsfileengine_win.cpp, but none of them got called.

                  D R 2 Replies Last reply
                  0
                  • R Roberrt

                    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 under qfsfileengine_win.cpp, but none of them got called.

                    D Offline
                    D Offline
                    DerReisende
                    wrote on last edited by
                    #12

                    @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?

                    JonBJ 1 Reply Last reply
                    1
                    • D DerReisende

                      @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?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #13

                      @DerReisende That looks like a good approach indeed (provided it works)!

                      D 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @DerReisende That looks like a good approach indeed (provided it works)!

                        D Offline
                        D Offline
                        DerReisende
                        wrote on last edited by
                        #14

                        @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.

                        1 Reply Last reply
                        0
                        • JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by JoeCFD
                          #15

                          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.

                          JonBJ 1 Reply Last reply
                          0
                          • JoeCFDJ JoeCFD

                            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.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #16

                            @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?

                            JoeCFDJ 1 Reply Last reply
                            1
                            • R Offline
                              R Offline
                              Roberrt
                              wrote on last edited by
                              #17

                              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

                              JonBJ JoeCFDJ D jsulmJ C 5 Replies Last reply
                              0
                              • R Roberrt

                                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

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #18

                                @Roberrt
                                OK, but then for you the issue @JoeCFD raised about unencrypting to a temporary file (if it is even needed) should not be an issue.

                                1 Reply Last reply
                                0
                                • R Roberrt

                                  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 under qfsfileengine_win.cpp, but none of them got called.

                                  R Offline
                                  R Offline
                                  Roberrt
                                  wrote on last edited by
                                  #19

                                  @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.

                                  1 Reply Last reply
                                  0
                                  • R Roberrt

                                    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

                                    JoeCFDJ Offline
                                    JoeCFDJ Offline
                                    JoeCFD
                                    wrote on last edited by
                                    #20

                                    @Roberrt Maybe save the temp files into an invisible dir.

                                    1 Reply Last reply
                                    0
                                    • R Roberrt

                                      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

                                      D Offline
                                      D Offline
                                      DerReisende
                                      wrote on last edited by
                                      #21

                                      @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.

                                      1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @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?

                                        JoeCFDJ Offline
                                        JoeCFDJ Offline
                                        JoeCFD
                                        wrote on last edited by
                                        #22

                                        @JonB How to use memory for the encrypted files?

                                        D 1 Reply Last reply
                                        0
                                        • JoeCFDJ JoeCFD

                                          @JonB How to use memory for the encrypted files?

                                          D Offline
                                          D Offline
                                          DerReisende
                                          wrote on last edited by
                                          #23

                                          @JoeCFD QImage::loadFromData() with a byte array.

                                          JoeCFDJ 1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved