Skip to content

QTestDisk: Qt front-end for TestDisk using /cmd mode - #219

Open
maysaraadmin wants to merge 4 commits into
cgsecurity:masterfrom
maysaraadmin:qtestdisk
Open

maysaraadmin wants to merge 4 commits into
cgsecurity:masterfrom
maysaraadmin:qtestdisk

Conversation

@maysaraadmin

@maysaraadmin maysaraadmin commented Nov 11, 2026 •

Copy link
Copy Markdown

Adds QTestDisk (qtestdisk), a small Qt GUI for TestDisk, built and installed next to qphotorec when Qt5 or Qt6 is found.

Design: no change to TestDisk itself

QPhotoRec links the PhotoRec engine. TestDisk's ncurses UI is mixed into the analyse, search and write code, so linking it would need a large refactor. Instead, qtestdisk drives the existing /cmd mode and reads the log:

testdisk /logname <tmpdir>/testdisk.log /debug /cmd <device|image> [partition_xxx,]analyze[,search][,noconfirm,write]

It displays the Results section that interface_recovery() logs. No existing C file is modified. The new code is one C++ file, about 320 lines, with no moc, rcc or extra dependency.

Quick/Deeper Search Write confirmation After Write
search confirm written

Safety

  • Write is enabled only after a search that listed at least one partition. It asks for confirmation (default No), then reruns the same search with ,noconfirm,write.
  • The status says whether the table was written, based on testdisk logging write!.
  • Stop is disabled during a write. Closing the window during a write lets it complete instead of killing testdisk.
  • testdisk runs with stdin closed, TERM set if missing, and LINES/COLUMNS set, so no ncurses prompt can block it.

Windows

PDCurses exits with Redirection is not supported. when stdout is a pipe. On Windows, qtestdisk therefore starts testdisk /cmd with its own hidden console (setCreateProcessArgumentsModifier), so no console window appears. It also:

  • does not set LINES/COLUMNS, which PDCurses rejects above 45
  • reads the CRLF log in text mode
  • understands the Drive X: lines (device \\.\X:) printed by testdisk /list

The .exe gets the TestDisk icon and a highestAvailable manifest, like qphotorec_win.exe.

Files

  • src/qtestdisk.cpp: the app, with an assert-based check of the log parsing at startup.
  • configure.ac, src/Makefile.am: qtestdisk_LDADD and qtestdisk_CXXFLAGS for Qt6 or Qt5 (-mwindows on Windows), plus man/qtestdisk.8.
  • Same packaging as qphotorec:
    • man/qtestdisk.8.in, linux/qtestdisk.desktop
    • src/icon_qtd.rc and win/qtestdisk_win.exe.manifest (TestDisk icon, highestAvailable)
    • install, uninstall, static and EXTRA_DIST entries in Makefile.am and man/Makefile.am
    • testdisk-copr.spec, mingw-testdisk-copr.spec, .gitignore

Limitations

  • Partition statuses can't be edited before writing, because /cmd writes what the search found. The dialog and man page point to text-mode testdisk for that.
  • The Advanced menu (boot sector repair, undelete, image creation) is not exposed.
  • No translations yet. Strings use tr().

Testing

Ubuntu 24.04 containers, GUI under Xvfb driven with xdotool:

  • Qt 6.4 build and Qt 5.15 build (Qt6 absent). qtestdisk.cpp is clean with -Wall -Wextra.
  • make install, make dist, and desktop-file-validate linux/qtestdisk.desktop. The man page renders.
  • 64 MiB image, FAT32 LOSTPART with its MBR entry deleted: Quick Search finds it. After Write, sfdisk -l shows 2048 102399 100352 b W95 FAT32.
  • 20 GiB image, ext4 LOSTPART with its entry deleted: Deeper Search finds it, and Write restores it.
  • Empty image: "Done, no partition found", and Write stays disabled.
  • Stop during a Deeper Search kills testdisk and re-enables the UI.
  • Windows: cross-compiled with Fedora mingw64-gcc, mingw64-pdcurses and mingw64-qt5-qtbase (the packages from mingw-testdisk-copr.spec). Run natively on Windows 11 and driven with UI Automation:
    • /list shows the drive.
    • Open image, then Quick Search finds FAT32 ... [LOSTPART].
    • Write gives "Partition table written", and sfdisk -l confirms 2048 102399 100352 b W95 FAT32.
    • No console window appears.

🤖 Generated with Claude Code

maysaraadmin and others added 3 commits November 11, 2026 15:52
qtestdisk drives the existing "testdisk /cmd" scripting mode and shows
the partitions found from the "Results" section of the log, so the
recovery logic stays in testdisk. It offers disk/image selection,
partition table type, Quick Search, Deeper Search, Stop and a
confirmed "Write partition table".

Built alongside qphotorec when Qt5/Qt6 is detected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- man page, .desktop file, Windows icon/version/manifest (highestAvailable),
  install/uninstall/static/spec/.gitignore entries
- Stop is disabled during a write, and closing the window lets a running
  write complete instead of killing testdisk
- usual file header, version in window title, "Stopped" status after Stop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… result

A search finding nothing used to enable "Write partition table", and
testdisk then rejected "noconfirm,write" with a syntax error while the
status said "Done". Write is now enabled only when "Results" lists at
least one partition, and the status says whether testdisk logged "write!".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maysaraadmin maysaraadmin changed the title Add QTestDisk, a Qt front-end for TestDisk QTestDisk: Qt front-end for TestDisk using /cmd mode Nov 11, 2026
Found by cross-compiling with mingw64 (pdcurses, Qt5) and running on
Windows 11:
- pdcurses exits with "Redirection is not supported." when stdout is a
  pipe: "testdisk /cmd" now gets its own hidden console, results are
  still read from the log
- pdcurses rejects LINES > 45: LINES/COLUMNS/TERM are only set for
  ncurses (non-Windows)
- testdisk.log has CRLF line endings on Windows: read it in text mode
- "testdisk /list" names volumes "Drive X:" (device \.\X:) and lists
  each disk twice: parse both forms and skip duplicates
- UI no longer stays busy when the testdisk program is not found

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maysaraadmin
maysaraadmin marked this pull request as ready for review November 11, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant