#1
|
|||
|
|||
Reading File Version from Memory
I faced a strange problem:
GetFileVersionInfoSize And GetFileVersionInfo return nothing from an .EXE file with a valid RT_VERSION. Using Resource Hacker the Record List appear as italic. What I don't know what means, But the record is there. By the way, my goal is to determinate the version of running executable that loaded my Proxy DLL. The workaround was read the RT_VERSION resource using HInstance value from already loaded data into memory. Code:
function FileVersion(Module: HINST = 0): String; var verblock:PVSFIXEDFILEINFO; versionMS,versionLS:cardinal; verlen:cardinal; rs:TResourceStream; m:TMemoryStream; p:pointer; s:cardinal; begin m:=TMemoryStream.Create; try if Module = 0 then Module := HInstance; rs:=TResourceStream.CreateFromID(Module,1,RT_VERSION); try m.CopyFrom(rs,rs.Size); finally rs.Free; end; m.Position:=0; if VerQueryValue(m.Memory,'\',pointer(verblock),verlen) then begin VersionMS:=verblock.dwFileVersionMS; VersionLS:=verblock.dwFileVersionLS; Result:= IntToStr(versionMS shr 16)+'.'+ IntToStr(versionMS and $FFFF)+'.'+ IntToStr(VersionLS shr 16)+'.'+ IntToStr(VersionLS and $FFFF); end; if VerQueryValue(m.Memory,PChar('\\StringFileInfo\\'+ IntToHex(GetThreadLocale,4)+IntToHex(GetACP,4)+'\\FileDescription'),p,s) or VerQueryValue(m.Memory,'\\StringFileInfo\\040904E4\\FileDescription',p,s) then //en-us Result:=PChar(p)+' '+Result; finally m.Free; end; end; Code:
GetModuleHandle(nil); |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Reading process memory | FEARHQ | General Discussion | 10 | 01-22-2005 21:24 |
Is it possbile to play a file from the memory without caching it on the HDD? | raladin | General Discussion | 10 | 04-22-2004 01:49 |