Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-03

Reading exe version info on Linux?

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

The program below works fine on Windows for reading e.g. info on explorer.exe
It fails on Linux (FPC trunk x64, compiled 2013/03/14) when testing with explorer.exe:
Going to read version resource for /tmp/explorer.exe An unhandled exception occurred at $0000000000443607: EResNotFound: Resource "1" not found
$0000000000443607

In a bug I raised, Michael van Canneyt indicated this error may be due to the filename not being picked up.
However, the checking code seems to pick up the correct name.

What am I still doing wrong?

Thanks,
Reinier

program exeinfodemo; //not exeinfo, that's already a ppu
{$mode objfpc}{$H+}
uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  SysUtils, Classes,
  fileinfo, winpeimagereader;
var
  TargetFile: string;
  WindowsExeInfo: TFileVersionInfo;
  i: integer;
begin
  TargetFile:=paramstr(1);
  if TargetFile='' then
  begin
    writeln('No file specified, substituting c:\windows\explorer.exe');
        TargetFile:='c:\windows\explorer.exe';
  end;
  if not(fileexists(TargetFile)) then
    writeln('The file you specified does not exist. Aborting.')
  else
    writeln('Going to read version resource for ',TargetFile);
  WindowsExeInfo := TFileVersionInfo.Create(nil);
  try
    WindowsExeInfo.FileName:=TargetFile;
    WindowsExeInfo.ReadFileInfo;
    for i:=0 to WindowsExeInfo.VersionStrings.Count-1 do
    begin
      writeln('Version string ',i,': ',WindowsExeInfo.VersionStrings[i]);
    end;
  finally
    WindowsExeInfo.Free;
  end;
end.
Michael Van Canneyt
to Reinier Olislagers
Reinier Olislagers wrote 15 lines
The program below works fine on Windows for reading e.g. info on explorer.exe It fails on Linux (FPC trunk x64, compiled 2013/03/14) when testing with explorer.exe: Going to read version resource for /tmp/explorer.exe An unhandled exception occurred at $0000000000443607: EResNotFound: Resource "1" not found $0000000000443607 In a bug I raised, Michael van Canneyt indicated this error may be due to the filename not being picked up. However, the checking code seems to pick up the correct name. What am I still doing wrong?
It should work as is;
but can you test with strace, and see if it attempts to read the correct file ?

Michael.

Reinier Olislagers
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
On Wed, 20 Mar 2013, Reinier Olislagers wrote: > The program below works fine on Windows for reading e.g. info on > explorer.exe > It fails on Linux (FPC trunk x64, compiled 2013/03/14) when testing with > explorer.exe:

<snip>

It should work as is; but can you test with strace, and see if it attempts to read the correct file ?

Thanks. Slightly modified test program shows
WindowsExeInfo.FileName is indeed empty :(

cd /tmp
strace ./exeinfodemo /tmp/explorer.exe
execve("./exeinfodemo", ["./exeinfodemo", "/tmp/explorer.exe"], [/* 17 vars */]) = 0
<snip>
readlink("/proc/self/exe", "/tmp/exeinfodemo", 255) = 16 <snip timezone stuff>
access("/tmp/explorer.exe", F_OK) = 0
write(1, "Going to read version resource f"..., 53Going to read version resource for /tmp/explorer.exe
) = 53
access("/tmp/explorer.exe", F_OK) = 0
write(1, "WindowsExeInfo.FileName:=\n", 26WindowsExeInfo.FileName:= ) = 26
write(1, "An unhandled exception occurred "..., 54An unhandled exception occurred at $0000000000443657:
) = 54
write(1, "EResNotFound: Resource \"1\" not f"..., 37EResNotFound: Resource "1" not found
) = 37
<snip>
ls -al /tmp/explorer.exe
-rw-r--r-- 1 pascaldev pascaldev 3079168 Mar 20 16:59 /tmp/explorer.exe

Michael Van Canneyt
to Reinier Olislagers
Reinier Olislagers wrote 13 lines
On 20-3-2013 21:30, Michael Van Canneyt wrote: > On Wed, 20 Mar 2013, Reinier Olislagers wrote: >> The program below works fine on Windows for reading e.g. info on >> explorer.exe >> It fails on Linux (FPC trunk x64, compiled 2013/03/14) when testing with >> explorer.exe: <snip> > It should work as is; > but can you test with strace, and see if it attempts to read the correct > file ? Thanks. Slightly modified test program shows WindowsExeInfo.FileName is indeed empty :(

Are you using revision 23920 of fileinfo on linux ?

Michael.

Reinier Olislagers
to Michael Van Canneyt
Michael Van Canneyt wrote 20 lines
On Thu, 21 Mar 2013, Reinier Olislagers wrote: > On 20-3-2013 21:30, Michael Van Canneyt wrote: >> On Wed, 20 Mar 2013, Reinier Olislagers wrote: >>> The program below works fine on Windows for reading e.g. info on >>> explorer.exe >>> It fails on Linux (FPC trunk x64, compiled 2013/03/14) when testing >>> with >>> explorer.exe: > <snip> >> It should work as is; >> but can you test with strace, and see if it attempts to read the correct >> file ? > > Thanks. Slightly modified test program shows > WindowsExeInfo.FileName is indeed empty :( Are you using revision 23920 of fileinfo on linux ?

Blast, (@)*@()@#$@, that's probably it - sorry to waste your time again.

Should do these things when not too tired.