GuidoBartoli / sherloq

An open-source digital image forensic toolset

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Header Structure not working as intended (invalid URL for file)

LorenzNickel opened this issue · comments

Hey,

if I try to open the "Header Structure", the WebView does not open the file properly. It tries to open file://c/Users/Lorenz/AppData/Local/Temp/Sherloq-mcAXVc%5Cstructure.html when instead file:///C:/Users/Lorenz/AppData/Local/Temp/Sherloq-mcAXVc/structure.html should be opened.

image

I'm running the most recent version of sherloq on a Windows Machine.

Mmmh I admit I tested Header Structure only under Linux, this is clearly a Windows issue. I know how to fix this, already, just give me some days until I come back from holidays and I will notify you.

Thanks for this report.

Hello,
I recently cloned Sherloq and ran into the same issue when trying on Windows (Windows10, Python 3.10.4).
Actually there were 3 issues:

  1. the exiftool_exe call in utility.py was not optimal and asked for a "Press Enter" event in stdout
  2. there was a broken escape sequence in the path to the structure.html file
  3. the QWebEngineView usage was not loading the structure.html file because of the 'file://' prefix

I fixed the bugs on my side like that:

  1. Rename /pyexiftool/exiftool/win/exiftool(-k).exe to /pyexiftool/exiftool/win/exiftool.exe and modify the exiftool call accordingly in function exiftool.exe() (utility.py). The "Press Enter" request will be gone.
  2. Fix the broken escape sequence in init function from class HeaderWidget (header.py)
  3. Load the structure.html file without the "file://" prefix

This is my fixed code in script header.py:

`
class HeaderWidget(ToolWidget):

def __init__(self, filename, parent=None):
    super(HeaderWidget, self).__init__(parent)
    self.temp_dir = QTemporaryDir()
    if self.temp_dir.isValid():
        temp_file = os.path.join(self.temp_dir.path(), "structure.html")

        p = run([exiftool_exe(), "-htmldump0", filename], stdout=PIPE)
        with open(temp_file, "w") as file:
            file.write(p.stdout.decode("utf-8"))

        web_view = QWebEngineView()
        if sys.platform.startswith("win32"):
            temp_file = self.temp_dir.path() + "//" + "structure.html"      # fixes the broken ESC sequence
            web_view.load(QUrl(temp_file))                                  # load without 'file://' prefix
        else:
            web_view.load(QUrl("file://" + temp_file))

        layout = QVBoxLayout()
        layout.addWidget(web_view)
        self.setLayout(layout)
        self.setMinimumWidth(900)`

Now everthing works as expected without any delay (only Windows, no Linux verification!):
windows_fix

Many thanks @TechiBBB, tonight I will commit your fix! 👍🏻

Does the commit f437b9c fix the bug on Windows?

Does the commit f437b9c fix the bug on Windows?

Yes, the issue seems to be fixed.
image

The "Press Enter"-issue mentioned by @TechiBBB still remains, but I think it's tracked separately in #22.

However, applying what @TechiBBB wrote also worked for me to resolve #22 here, maybe you could consider doing that somehow:

Rename /pyexiftool/exiftool/win/exiftool(-k).exe to /pyexiftool/exiftool/win/exiftool.exe and modify the exiftool call accordingly in function exiftool.exe() (utility.py). The "Press Enter" request will be gone.

I can confirm the fix in header.py from my side as well.
Regarding the annoing "Press ENTER" issue, I don't see a possibility to fix that from the source code. It seems to be a by design problem in the precompiled exiftool executable. A solution could be to switch to another exif analysis tool, e.g. this one: https://github.com/ianare/exif-py