We have large executable files (>1,2 GB) which contain custom Version Info. I try to retrieve this 'Version Info' from these files by using the 'GetVersionInfo' of the 'FileVersionInfo' Class. For some reason this method doesn't return the version information for larger files (Tested with > 1 GB) in Windows XP. It did work for a file with a size of 18 MB. When I try the same in Windows 7 (x86 and X64) it works for all files, even the larger onces!
I used a Reflector tool to take a look into the FileVersionInfo class and I've created a small console app to retrieve the 'File Version Info'-Size, just as the 'GetVersionInfo' method does. A size of 0 (zero) is returned in Windows XP and in Windows 7 a size of 1428 is returned for the same files. The Last Error in XP is 1812 ('The specified image file did not contain a resource section').
What's the reason why this doesn't work in Windows XP and does work in Windows 7? Is there a work around to retrieve the Version Info?
Below the code I've tested with:
class Program
{
[DllImport("version.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetFileVersionInfoSize(string lptstrFilename, out int handle);
static void Main(string[] args)
{
Console.Write("Path which contains the executables: ");
string path = Console.ReadLine();
foreach (string fileName in Directory.EnumerateFiles(path))
{
int num;
int fileVersionInfoSize = GetFileVersionInfoSize(fileName, out num);
int error = Marshal.GetLastWin32Error();
Console.WriteLine("File Version Info Size: " + fileVersionInfoSize);
if (error != 0)
{
Console.WriteLine("Last Error: " + error);
}
}
Console.ReadKey();
}
}
Open the file you want to restore and go to File > Info. If the file has previous versions, you'll see a button called Version History. Select it to open the pane. Select a version to view it.
View previous versions of a file Open the file you want to view. Click File > Info > Version history. Select a version to open it in a separate window. If you want to restore a previous version you've opened, select Restore.
Right-click the file or folder, and then click Restore previous versions. You'll see a list of available previous versions of the file or folder. The list will include version(s) for any restore points. then click Open to view it to make sure it's the version you want.
The loader probably failed to map the entire file into its address space. Feel free to read up on the PE file format to find the version resource.
However, what are you doing with such a large PE Image? If its custom resources, it works better to append them to the .exe so the loader only has to map a little bit, then access them directly. This requires you to know your size (there are 4 bytes at offset 124 that can be overwritten safely as they are pad after the "This Program cannot be run in MS-DOS mode." error message stub).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With