avast / pe_tools

A cross-platform Python toolkit for parsing/writing PE files.
MIT License
63 stars 15 forks source link

RuntimeError: version info string is not terminated by zero #10

Open Napo2k opened 2 years ago

Napo2k commented 2 years ago

In the version info parser (this line), it seems that it is not possible for a file to have the last number on the version be anything other than zero, and I was wondering why is that a problem?

avakar commented 2 years ago

That line is a check that UTF-16-encoded strings in the version info blob are terminated by the U+0000 character. It's a check on the validity of serialization, not on the validity of contents. Versions can end in "0" just fine.

Napo2k commented 2 years ago

I keep getting that error and I have no idea how to fix it๐Ÿ˜… I am using pe_tools as part of our binary info stamping. The version to be stamped has four fields ('XX.YY.ZZ.PP')

avakar commented 2 years ago

I can have a look if you link the binary and provide the command line you're using.

Napo2k commented 2 years ago

Thank you for the response. Let me ask if that is possible.

Napo2k commented 2 years ago

In the meantime, I have added a print in my local copy of pe_tools, and this is what I can see

b'3\x002\x00.\x000\x00.\x004\x003\x009\x00.\x008\x002\x005\x001\x00'
32.0.439.8251
(...)
โ”‚ W:\gitlab\build_tool\.env\lib\site-packages\pe_tools\version_info.py:238 in _parse_one           โ”‚
โ”‚                                                                                                  โ”‚
โ”‚   235 โ”‚   โ”‚   โ”‚   if bytes(value[-2:]) != b'\0\0':                                               โ”‚
โ”‚   236 โ”‚   โ”‚   โ”‚   โ”‚   print(bytes(value))                                                        โ”‚
โ”‚   237 โ”‚   โ”‚   โ”‚   โ”‚   print(bytes(value).decode('utf-16le'))                                     โ”‚
โ”‚ โฑ 238 โ”‚   โ”‚   โ”‚   โ”‚   raise RuntimeError('version info string is not terminated by zero')        โ”‚
โ”‚   239 โ”‚   โ”‚   โ”‚   value = bytes(value[:-2]).decode('utf-16le')                                   โ”‚
โ”‚   240 โ”‚                                                                                          โ”‚
โ”‚   241 โ”‚   children = []                                                                          โ”‚
โ”‚                                                                                                  โ”‚
โ”‚ โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ locals โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚
โ”‚ โ”‚      blob = rope()                                                                           โ”‚ โ”‚
โ”‚ โ”‚       hdr = _NODE_HEADER(wLength=60, wValueLength=13, wType=1)                               โ”‚ โ”‚
โ”‚ โ”‚       key = 'FileVersion'                                                                    โ”‚ โ”‚
โ”‚ โ”‚  key_size = 24                                                                               โ”‚ โ”‚
โ”‚ โ”‚      next = rope(<_io.BufferedReader                                                         โ”‚ โ”‚
โ”‚ โ”‚             name='W:\\zzbuilds\\output\\foo.exe'>[35188860:35189652])             โ”‚ โ”‚
โ”‚ โ”‚     value = rope(<_io.BufferedReader                                                         โ”‚ โ”‚
โ”‚ โ”‚             name='W:\\zzbuilds\\output\\foo.exe'>[35188832:35188858])             โ”‚ โ”‚
โ”‚ โ”‚ value_len = 26                                                                               โ”‚ โ”‚
โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
RuntimeError: version info string is not terminated by zero
Napo2k commented 2 years ago

Any idea?