Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT Applications - Replacing embedded resources

Tags:

c++

linux

binary

qt

Is it possible to replace embedded resources [e.g. styles, images, text] in a Linux [ELF] binary?

I noticed that I can change text but if I type more text or if I remove text, then the segmentation faults start coming up. I have not gone through the ELF spec yet but I am wondering if it is possible.

I managed to extract the images from the binary using the mediaextract project but I need to do just the opposite without breaking the binary structure.

like image 325
Timmo Avatar asked Mar 03 '16 12:03

Timmo


People also ask

What is RCC in Qt?

The rcc tool is used to embed resources into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (. qrc) file.

What is QRC in Qt?

qrc file are files that are part of the application's source tree. The specified paths are relative to the directory containing the . qrc file. Note that the listed resource files must be located in the same directory as the . qrc file, or one of its subdirectories.

What is a QRC document?

what is a . qrc file? The Qt Resource Collection File is stored in the QRC format and is affixed with the QRC extension, and is used by the Qt application and toolkit. These QRC files are generally classified as settings file that contain a list of application resources like image files or icons in XML format.

How do I add a resource file to Qt?

In the Location field, specify a location for the file. Select Add to create a . qrc file and to open it in the Qt Resource Editor. To add resources to the file, select Add > Add Files.


1 Answers

This answer is specific for Qt's resource system (.qrc, rcc).

From the docs:

Currently, Qt always stores the data directly in the executable, even on Windows, macOS, and iOS, where the operating system provides native support for resources. This might change in a future Qt release.

So yes, the Qt resources are contained in the binary.

rcc'ing a .qrc file yields a .cpp file containing (mainly) simple char arrays which represent resource data, the resource names and some other metadata.

Compiling such a .cpp file creates byte fields in the binary.

You can alter such resources within a binary, but only in very limited ways.

  • For starters, if the binary contains any kind of self-check (like hashing the data section and comparing it to some pre-calculated hash), you will not be able to change the data in a reasonable way.

  • If your data doesn't have the same byte length as the original data, you can't simply replace it because it would alter the internal layout of the binary and invalidate relative addresses.

  • In case of replacing with shorter strings you might get away with zero-padding at the end.

Resources are compressed by default (in the ZIP format). It is possible to turn off compression.

  • If compression was turned on during compilation (which you don't control, as it seems), you'd need to create new data which compresses to the same length as the original.
like image 65
Martin Hennings Avatar answered Sep 18 '22 04:09

Martin Hennings