Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Created August 26, 2023 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uyjulian/8c887336703cb158d070289b87cfa298 to your computer and use it in GitHub Desktop.
Save uyjulian/8c887336703cb158d070289b87cfa298 to your computer and use it in GitHub Desktop.
# http://www.csn.ul.ie/~caolan/publink/winresdump/winresdump/doc/pefile.html
# Contains a reasonable description of the format.
import sys
import pefile
newdic = {
"Comments" : "hoge",
"FileDescription" : "hoge",
"FileVersion" : "hoge",
"InternalName" : "hoge",
"LegalCopyright" : "hoge",
"OriginalFilename" : "hoge.dll",
"ProductName" : "hoge",
"ProductVersion" : "hoge",
}
##############################################################################
# This is the main function that should be called externally, that copies over
# the icons.
# def change_icons(oldexe, icofn):
def change_icons(oldexe, newexe):
global resource_virtual
pe = pefile.PE(oldexe)
print(hex(pe.VS_VERSIONINFO[0].Length))
print(hex(pe.VS_VERSIONINFO[0].Type))
print(hex(pe.VS_VERSIONINFO[0].ValueLength))
print(hex(pe.VS_FIXEDFILEINFO[0].Signature))
print(hex(pe.VS_FIXEDFILEINFO[0].FileFlags))
print(hex(pe.VS_FIXEDFILEINFO[0].FileOS))
for fileinfo in pe.FileInfo[0]:
if fileinfo.Key == b'StringFileInfo':
for st in fileinfo.StringTable:
entries = st.entries
for entry in entries:
print('%s: %s' % (entry, entries[entry]))
for entry in sorted(entries.keys()):
entry_str = entry.decode("ASCII")
entryval = entries[entry]
if entry_str in newdic:
entryval_new = newdic[entry_str].encode("ASCII")
if len(entryval) < len(entryval_new):
entryval_new = entryval_new[:len(entryval)]
else:
entryval_new += b" " * (len(entryval) - len(entryval_new))
entries[entry] = entryval_new
if fileinfo.Key == b'VarFileInfo':
for var in fileinfo.Var:
entries = var.entry
for entry in entries:
print('%s: %s' % (entry, entries[entry]))
pe.OPTIONAL_HEADER.CheckSum = pe.generate_checksum()
pe.write(filename=newexe)
return
if __name__ == "__main__":
change_icons(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment