Modify infos of numerous files

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Modify infos of numerous files

Post by Kwai chang caine »

Hello at all

I need to modify this information in numerous exe
FileVersion
FileDescription
LegalCopyright
InternalName
OriginalFilename
ProductName
ProductVersion
CompanyName
LegalTrademarks
SpecialBuild
PrivateBuild
Comments
Language
I have find this code of "ABC123" who apparently works, but it modify only the version :|
http://forums.purebasic.com/english/vie ... 5d#p205903

Code: Select all

#RT_VERSION = 16

Structure VS_VERSIONINFO
  wLength.w
  wValueLength.w
  wType.w
  szKey.w[16]
  Padding1.w
  Value.VS_FIXEDFILEINFO
  Padding2.w
  Children.w
EndStructure

Procedure.w MakeLangID(p.w, s.w)
  ProcedureReturn (s << 10) | p
EndProcedure

Macro MAKEINTRESOURCE(I)
  (I)
EndMacro

Procedure.l SetFileVersion(AFileName.s, Major.w, Minor.w, Release.w, Build.w)
  Protected lHLib.l, lHRes.l, lHResLoad.l, lPResLock.l
  Protected lSz.l
  Protected lFS.l
  Protected *lpVersionInfo.VS_VERSIONINFO
  Protected *lFV.l ; TFileVer
  Protected lPt.l
  Protected lVer.s
  Protected lVarFileInfo ; Unknown type
  Protected lHResUpd.l
  Protected lDiscard.l
  Protected Result.l
  Result = 0
  If FileSize(AFileName) < 0
    ProcedureReturn Result
  EndIf
  lHLib = LoadLibrary_(AFileName)
  If lHLib = 0
    ProcedureReturn Result
  EndIf
  lHRes = FindResource_(lHlib, MAKEINTRESOURCE(1), #RT_VERSION)
  If lHRes = 0
    FreeLibrary_(lHLib)
    ProcedureReturn Result
  EndIf
  lHResLoad = LoadResource_(lHLib, lHRes)
  lSz = SizeofResource_(lHLib, lHRes)
  If lHResLoad = 0
    FreeLibrary_(lHLib)
    ProcedureReturn Result
  EndIf
  LPResLock = LockResource_(lHResLoad)
  lPt = AllocateMemory(lSz)
  MoveMemory(lPResLock, lPt, lSz)
  FreeLibrary_(lHLib)
 
  *lpVersionInfo = lPt
  With *lpVersionInfo\Value
    \dwFileVersionMS = (Major << 16) | Minor
    \dwFileVersionLS = (Release << 16) | Build
    \dwProductVersionMS = \dwFileVersionMS
    \dwProductVersionLS = \dwFileVersionLS
  EndWith
  lHResUpd = BeginUpdateResource_(AFilename, 0)
  If lHResUpd = 0
    Goto Except
  EndIf
  lDiscard = 1
  lDiscard = -UpdateResource_(lHResUpd, #RT_VERSION, MAKEINTRESOURCE(1), 0, lPt, lSz) + 1
  EndUpdateResource_(lHResUpd, lDiscard)
  Except:
  FreeMemory(lPt)
EndProcedure

;SetFileVersion("D:\Documents and Settings\User\Desktop\File.exe", 1, 0, 0, 0)
Do you know how modify the others parameters ?

Have a good day
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Modify infos of numerous files

Post by Kwai chang caine »

I have found a code of a german PB friend "Knight_Rider_2000" 8)
https://www.purebasic.fr/german/viewtop ... 75#p211975
It works perfectly with PB exe :D

But surely nobody have the answer of my next question :|
I ask them when even, because with all the masters of this forum, a miracle is always possible 8)

I thought all the EXE is the same :oops:, because WINDOWS can read the informations also good in an EXE PB, than a EXE VB6, etc...
Then why this code can't modify the information of a VB6 EXE :shock: :|
ImageThe happiness is a road...
Not a destination
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Modify infos of numerous files

Post by firace »

So what exactly happens with a VB6 EXE? Can you provide an example?
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Modify infos of numerous files

Post by Denis »

Salut KCC,

may be due to UpdateResource

"Adds, deletes, or replaces a resource in a portable executable (PE) file. There are some restrictions on resource updates in files that contain Resource Configuration (RC Config) data: language-neutral (LN) files and language-specific resource (.mui) files."
A+
Denis
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Modify infos of numerous files

Post by Denis »

KCC,

To try to pass over the restrictions,
in PureIconmanager,
i change the value of item Characteristics of the structure IMAGE_FILE_HEADER.
First of all, i read this value and store it.
I change with the value #IMAGE_FILE_DLL|#IMAGE_FILE_32BIT_MACHINE
Then i use Beginupdate etc.
Finally i rewrite the initial value of Characteristics.

This method do not rocks all the time!
Before using it, make a copy of the file.

I spend a lot of time of this without finding a correct solution;
May be you can change the file witout MS APIs :mrgreen: .

The code is like that

Code: Select all

      ;// mémorise les caractéristiques du fichier PE
      Protected Characteristics.unicode, Characteristics_To_write.unicode

      ;// on modifie les attributs du fichier avant modifs
      SetFileAttributes(*hModule\File_Name$, #PB_FileSystem_Normal)

      ;/ retrouve les caractéristiques du fichier
      If PIM_Read_Characteristics_Of_PE_File(*hModule\File_Name$, @Characteristics) = #Return_Error
	  
			
      ;//écriture des caractériques pour permettre les modifs du fichier PE
      Characteristics_To_write\u = #IMAGE_FILE_DLL|#IMAGE_FILE_32BIT_MACHINE
      PIM_Write_Characteristics_Of_PE_File(*hModule\File_Name$, @Characteristics_To_write)


Procedure.i PIM_Read_Characteristics_Of_PE_File(FileName$, *Characteristics.unicode)
      ;// teste le fichier passé en paramètre (Dll, EXE, ICL etc) pour déterminer si le format est PE (32 bits)
      ;// retourne #True si c'est le cas, sinon #False
      ;// mémorise les données lues dans le fichier
      Protected Datas
      ;// mémorise le résultat de fonctions
      Protected result
      ;// mémorise le handle du fichier
      Protected hFile
      ;// pointeur sur la structure IMAGE_FILE_HEADER
      Protected *pt.IMAGE_FILE_HEADER
      
      If FileSize(FileName$) <= 0
            MAC_PIM_SetError_Code(#Error_Bad_File_Name)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If *Characteristics = 0
            MAC_PIM_SetError_Code(#Sub_Error_21_Error_Bad_Pointer_Value|#Error_Bad_Pointer_Value)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// ouverture du fichier
      hFile = CreateFile_(FileName$, #GENERIC_READ, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #Null, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, #Null)
      If hFile = #INVALID_HANDLE_VALUE
            MAC_PIM_SetError_Code(#Sub_Error_16_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// lecture des données du fichier
      If(ReadFile_(hFile, @Datas, SizeOf(word), @Result, #Null) = #Return_Error) Or (Result <> SizeOf(word))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_17_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If (datas) <> #IMAGE_DOS_SIGNATURE
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_2_Error_Code_IMAGE_DOS_SIGNATURE|#Error_Code_IMAGE_DOS_SIGNATURE)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// déplacement du pointeur fichier sur la valeur de l'offset donnant la position de la signature #IMAGE_NT_SIGNATURE
      Result = SetFilePointer_(hFile, OffsetOf(IMAGE_DOS_HEADER\e_lfanew), #Null, #FILE_BEGIN)
      If Result = #INVALID_SET_FILE_POINTER And GetLastError_() = #NO_ERROR
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Error_Code_SetFilePointer)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      Result = 0
      ;// lecture de la valeur Offset_PE_Header
      If(ReadFile_(hFile, @Datas, SizeOf(word), @Result, #Null) = #Return_Error) Or (Result<>SizeOf(word))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_18_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// déplacement du pointeur fichier sur l'emplacement de la signature
      ;// FileSeek(file, Offset_NE_PE_Header)
      Result = SetFilePointer_(hFile, Datas, #Null, #FILE_BEGIN)
      If Result = #INVALID_SET_FILE_POINTER And GetLastError_() = #NO_ERROR
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Error_Code_SetFilePointer)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If(ReadFile_(hFile, @Datas, SizeOf(long), @Result, #Null) = #Return_Error) Or (Result<>SizeOf(long))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_19_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If (datas) <> #IMAGE_NT_SIGNATURE
            ;// If (datas)=#IMAGE_OS2_SIGNATURE Or (datas)=#IMAGE_OS2_SIGNATURE_LE
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_1_Error_Code_DWORD_IMAGE_NT_SIGNATURE|#Error_Code_DWORD_IMAGE_NT_SIGNATURE)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// on se déplace sur l'élément Characteristics de la structure la structure IMAGE_FILE_HEADER
      ;// qui est pointé par le pointeur de fichier
      Result = SetFilePointer_(hFile, OffsetOf(IMAGE_FILE_HEADER\Characteristics), #Null, #FILE_CURRENT)
      If Result = #INVALID_SET_FILE_POINTER And GetLastError_() = #NO_ERROR
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Error_Code_SetFilePointer)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If(ReadFile_(hFile, *Characteristics, SizeOf(unicode), @Result, #Null) = #Return_Error) Or (Result <> SizeOf(unicode))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_20_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// le fichier est inutile, on ferme
      CloseHandle_(hFile)
      
      ProcedureReturn #Return_No_Error
EndProcedure


Procedure.i PIM_Write_Characteristics_Of_PE_File(FileName$, *Characteristics.unicode)
      ;// teste le fichier passé en paramètre (Dll, EXE, ICL etc) pour déterminer si le format est PE (32 bits)
      ;// retourne #True si c'est le cas, sinon #False
      ;// mémorise les données lues dans le fichier
      Protected Datas
      ;// mémorise le résultat de fonctions
      Protected result
      ;// mémorise le handle du fichier
      Protected hFile
      ;// pointeur sur la structure IMAGE_FILE_HEADER
      Protected *pt.IMAGE_FILE_HEADER
      ;// mémorise les attributs du fichier
      Protected Attributs
      ;// Mémorise l'action à faire si le fichier est protégé en écriture ou systeme
      Protected action
      
      If FileSize(FileName$) <= 0
            MAC_PIM_SetError_Code(#Error_Bad_File_Name)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If *Characteristics = 0
            MAC_PIM_SetError_Code(#Sub_Error_22_Error_Bad_Pointer_Value|#Error_Bad_Pointer_Value)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// ouverture du fichier
      hFile = CreateFile_(FileName$, #GENERIC_WRITE|#GENERIC_READ, 0 | #FILE_SHARE_WRITE, #Null, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, #Null)
      If hFile = #INVALID_HANDLE_VALUE
            MAC_PIM_SetError_Code(#Sub_Error_21_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// lecture des données du fichier
      If(ReadFile_(hFile, @Datas, SizeOf(word), @Result, #Null) = #Return_Error) Or (Result <> SizeOf(word))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_22_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If (datas) <> #IMAGE_DOS_SIGNATURE
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_3_Error_Code_IMAGE_DOS_SIGNATURE|#Error_Code_IMAGE_DOS_SIGNATURE)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// déplacement du pointeur fichier sur la valeur de l'offset donnant la position de la signature #IMAGE_NT_SIGNATURE
      Result = SetFilePointer_(hFile, OffsetOf(IMAGE_DOS_HEADER\e_lfanew), #Null, #FILE_BEGIN)
      If Result = #INVALID_SET_FILE_POINTER And GetLastError_() = #NO_ERROR
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Error_Code_SetFilePointer)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      Result = 0
      ;// lecture de la valeur Offset_NE_PE_Header
      If(ReadFile_(hFile, @Datas, SizeOf(word), @Result, #Null) = #Return_Error) Or (Result<>SizeOf(word))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_23_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// déplacement du pointeur fichier sur l'emplacement de la signature
      ;// FileSeek(file, Offset_NE_PE_Header)
      Result = SetFilePointer_(hFile, Datas, #Null, #FILE_BEGIN)
      If Result = #INVALID_SET_FILE_POINTER And GetLastError_() = #NO_ERROR
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Error_Code_SetFilePointer)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If(ReadFile_(hFile, @Datas, SizeOf(long), @Result, #Null) = #Return_Error) Or (Result<>SizeOf(long))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_24_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If (datas) <> #IMAGE_NT_SIGNATURE
            ;// If (datas)=#IMAGE_OS2_SIGNATURE Or (datas)=#IMAGE_OS2_SIGNATURE_LE
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_2_Error_Code_DWORD_IMAGE_NT_SIGNATURE|#Error_Code_DWORD_IMAGE_NT_SIGNATURE)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// on se déplace sur l'élément Characteristics de la structure la structure IMAGE_FILE_HEADER
      ;// qui est pointé par le pointeur de fichier
      Result = SetFilePointer_(hFile, OffsetOf(IMAGE_FILE_HEADER\Characteristics), #Null, #FILE_CURRENT)
      If Result = #INVALID_SET_FILE_POINTER And GetLastError_() = #NO_ERROR
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Error_Code_SetFilePointer)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      If(WriteFile_(hFile, *Characteristics, SizeOf(unicode), @Result, #Null) = #Return_Error) Or (Result <> SizeOf(unicode))
            CloseHandle_(hFile)
            MAC_PIM_SetError_Code(#Sub_Error_25_Error_Code_ReadFile_Open|#Error_Code_ReadFile_Open)
            MAC_ProcedureReturn_Return_Error()
      EndIf
      
      ;// le fichier est inutile, on ferme
      CloseHandle_(hFile)
      
      ProcedureReturn #Return_No_Error
EndProcedure
A+
Denis
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Modify infos of numerous files

Post by Denis »

Salut KCC,

may be VB PE file format could be different of common PE file format, i don't know.
You can use a PE editor to take a closer look.

https://msdn.microsoft.com/en-us/library/ms809762.aspx

https://fr.wikipedia.org/wiki/Portable_Executable
A+
Denis
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Modify infos of numerous files

Post by Kwai chang caine »

@FIRACE and DENIS
Finally, i believe i have found the problem :D
I must fill all the fields of the information VB6 EXE.
I have put a "_" into all field, and apparently that works :shock:
I do more try later for see if i have found the solution

@DENIS
Thanks for your code 8)
They are a very long time, i have not read you in the french forum, i missing you, and be very surprising to see your answer 8)
I hope, you back to PB ...like say the french proverb "PB one day..PB allways" :wink:

Again thanks at you two for your interest to my problem 8)
ImageThe happiness is a road...
Not a destination
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Modify infos of numerous files

Post by Denis »

Slt KCC,

still working with PB 8)

I left the fr forum forever i think.
Now, I have more time to work on my projects.
A+
Denis
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Modify infos of numerous files

Post by Kwai chang caine »

I left the fr forum forever i think.
It's a little bit what i have thinking :wink:
But i'm when even happy, to talk to you (even in english) here :D

I must recognize, it's when even a pleasure, and mainly really more simple for me, to talk PB and French in the same time
It's right, here they are the most big quantity of kind genious in programming at the m2, i have never seen... 8)
I'm so proud to can talking with all this masters, but the price to pay, is try to read english, and mainly try to talking english for to be understandable :oops:

All my numerous problems each days, i need helped, is often complicated :oops:
But explained in "kcc english", that not help more, my generous masters to help me :lol:

Image

At the pleasure to read you, french friend 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Modify infos of numerous files

Post by Kwai chang caine »

I don't understand anything, yesterday that works.....today not :shock:

Image

Pleaaaaasee HELP me !!!!

I have create a full folder of my works for better explain my problem, in case of someone want help little KCC :oops:

http://erdsjb.free.fr/purestorage/provi ... ifyEXE.zip

In the ZIP there is :

[Original EXE] ==> A copy of the two originals EXE (one in PB, other in VB6) in both i have put an underscore in each field
[Sources] ==> The sources of all the exe
ExePb.exe ==> The original EXE of PB to modify
ExeVB6.exe ==> The original EXE of VB6 to modify
ModifieInfos.exe ==> The EXE for modify the two EXE
ResourceHacker.exe ==> for read the resources inside the EXE

First, i run the "ExePb.exe"
I have the original EXE Pb not modified (Normal) 8)

Image

In ResourceHacker, i see that for the original PB EXE

Image

I modify the PbExe with "ModifieInfos.exe"
I run "ModifieInfos.exe" and choose "ExePb.exe"
Now i run the "ExePb.exe" modified and i have that
The constant PB have not modified, and the resources informations is modified (Each line of infos, the underscore replaced by "Test xxx") (Normal too) 8)

Image

In ResourceHacker, i see that for the PB EXE modified

The 0

Image

The 1033

Image

ALL are DONE !!!! PB IS THE BEST!!! (Everybody know that :mrgreen: )

Now see the bad and mysterious VB6

Image

of his tortured brain creator :?

I run the original "ExeVB6.exe" and i have that (Normal i have fill all fields by an underscore)

Image

In ResourceHacker, i see that for the original PB EXE

Image

I modify the Vb6Exe with "ModifieInfos.exe"
I run "ModifieInfos.exe" and choose "ExeVb6.exe"
Now i run the "ExeVb6.exe" modified and i have that

Image

Nothing have changed :shock:
So i open ResourceHacker and it's the real whorehouse in the Vb6 EXE modified by PB
I have now 3 resources (0, 1033, 1036)

The 0

Image

The 1033 (Apparently cutting and not full) :shock:

Image

The 1036

Image

And the worst, it's i'm pratically sure yesterday that worked, but i don't know what i have doing for modify the VB6.exe with succes :oops:
If someone understand something.......

I give to him a big french "SMAC" :mrgreen:

Image
Last edited by Kwai chang caine on Wed Jun 06, 2018 4:01 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Modify infos of numerous files

Post by JHPJHP »

Hi Kwai chang caine,

Have you tried this code by netmaestro: HOWTO Get file version ?
- Imports updated from ANSI (changed an A to a W)

Code: Select all

;///////////////////////////////////////////////////////////////////
;
; Demo:             Windows API File Version Info
; Author:           Lloyd Gallant (netmaestro)
; Date:             May 06, 2010
; Target Compiler:  PureBasic 4.20 and later
; Target OS:        Microsoft Windows All (x86)
; License:          Free, no restrictions, no warranty whatsoever
;
;//////////////////////////////////////////////////////////////////

Pattern$ = "Executables (*.exe)|*.exe;|Dynamic Link Library (*.dll)|*.dll;|All files (*.*)|*.*"
Filename$ = OpenFileRequester("Please choose file to load", "", Pattern$, 0)

Import "version.lib"
  GetFileVersionInfoSizeW( *lptstrFilename, *lpdwHandle )
  GetFileVersionInfoW( *lptstrFilename, dwHandle, dwLen, *lpData)
  VerQueryValueW( *pBlock, *lpSubBlock, *lplpBuffer, *puLen)
EndImport

Global Dim Stringname$(12)
Restore stringnames
For i=1 To 12
  Read$ Stringname$(i)
Next

Structure LANGANDCODEPAGE 
  wLanguage.w
  wCodePage.w
EndStructure

infosize = GetFileVersionInfoSizeW( @filename$, @handle.i)
If infosize
  *lpData = AllocateMemory(infosize)
  If GetFileVersionInfoW( @filename$, 0, infosize, *lpdata)
    If VerQueryValueW( *lpdata, @"\VarFileInfo\Translation", @*lplpBuffer, @puLen)
      *readptr.LANGANDCODEPAGE = *lplpBuffer
      For i=0 To puLen/SizeOf(LANGANDCODEPAGE) - 1
        langandcodepage$ = RSet(Hex(*readptr\wLanguage),4,"0") + RSet(Hex(*readptr\wCodePage), 4, "0")
        For j=1 To 12
          SubBlock$ ="\\StringFileInfo\\" + langandcodepage$ + "\\" + Stringname$(j)
          If VerQueryValueW( *lpdata, @SubBlock$, @*stringbuffer, @Bytes) And Bytes
            Debug Stringname$(j)+": "+PeekS(*stringbuffer, Bytes)
          EndIf
        Next
        *readptr + SizeOf(LANGANDCODEPAGE)
      Next
    EndIf
  Else
    Debug "No version information available"
  EndIf
  FreeMemory(*lpData)
Else
  Debug "No version information available"
EndIf

DataSection 
  stringnames:
  Data.s "Comments",        "InternalName",     "ProductName"
  Data.s "CompanyName",     "LegalCopyright",   "ProductVersion"
  Data.s "FileDescription", "LegalTrademarks",  "PrivateBuild"
  Data.s "FileVersion",     "OriginalFilename", "SpecialBuild"
EndDataSection
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Modify infos of numerous files

Post by JHPJHP »

Hi Kwai chang caine,

Sorry, I just realized that you are looking to modify an executables File Information; the code provided by netmaestro is read-only.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Modify infos of numerous files

Post by Kwai chang caine »

Hello master JHPJHP :D

Yes i have see this splendid code of the not less splendid frog 8)
But it's only a reader of the ressources inside an EXE, not a modifier :|

Furthermore i have try it for read the Vb6ExeModified, and the result is not modified :|

and always this bads resources (0,1033,1036) with the 1033

Image
Master JHPJHP wrote:Sorry, I just realized that you are looking to modify an executables File Information; the code provided by netmaestro is read-only.
Yes it's exactely what i say before :mrgreen: :lol: :lol:
But thanks when even for have answered to my help 8)
ImageThe happiness is a road...
Not a destination
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Modify infos of numerous files

Post by Denis »

Salut KCC,

resource use languages
0 Neutral language
1036 French (France)
1033 English US

Resource use language to be able to distinguish different resource for the same item.

I've taken a quick look to the code.

SetFileVersion() use :

Code: Select all

lDiscard = -UpdateResource_(lHResUpd, #RT_VERSION, MAKEINTRESOURCE(1), 0, lPt, lSz) + 1
parameter 0 indicate a neutral language

ChangeVersionData() use :

Code: Select all

 If Not UpdateResource_(hUpdateRes, #RT_VERSION, MAKEINTRESOURCE(#VS_VERSION_INFO), MAKELANGID(#LANG_ENGLISH, #SUBLANG_ENGLISH_US), Buffer2, MemorySize(Buffer2))

So, MAKELANGID(#LANG_ENGLISH, #SUBLANG_ENGLISH_US) value is 1033

The code generate for the same item the different group and it doesn't remove french item.

I don't know why it's Ok for PB exe (may be due to language 1033 wich could be defaut language.), but you have to enumerate language used before changing values to change correctly data.
MS use default language (if i remember) when language is not put to access resource value.

Instead of FindResource_(), use FindResourceEx_() .
UpdateResource_() use a language to update value, but if you access data without the correct one, what append?

You have to change all API to use correctly item languages.
that's how I would do.
A+
Denis
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Modify infos of numerous files

Post by Kwai chang caine »

One thousand of thanks Denis for your very precious help.
Since several i search how do that, and apparently it's not an interesting subject, in all the forums only 2/3 subject for read and for write it's the désert of gergovie :|

Fortunately you come from anywhere on your white horse, and you have learned this subject, and have the kindness to help little kcc, alone in the dark (but not the game) 8)

Again thanks i take a look to your precious explanation
ImageThe happiness is a road...
Not a destination
Post Reply