Skip to content

Commit 371d03a

Browse files
authored
fix: use Valuelength for parseString instead of whole String size (#96)
* fix: use Valuelength for parseString instead of whole string length If a resource has a empty string, parsing value of string is parsed incorrectly(getting a next String part as string). As String.ValueLength is length in utf-16 string without null value, use 2*(s.ValueLength+1). * chore: add sample file for stringversioninfo fix * chore: add sample file to version_test
1 parent 7d77b63 commit 371d03a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

test/YourPhone.Exp.WinRT.dll

459 KB
Binary file not shown.

version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (pe *File) parseString(rva uint32, e ResourceDirectoryEntry) (string, strin
280280
return "", "", 0, err
281281
}
282282
valueOffset := alignDword(uint32(2*(len(key)+1))+offset+StringLength, e.Data.Struct.OffsetToData)
283-
b, err = pe.ReadBytesAtOffset(valueOffset, uint32(s.Length))
283+
b, err = pe.ReadBytesAtOffset(valueOffset, uint32(2*(s.ValueLength+1)))
284284
if err != nil {
285285
return "", "", 0, err
286286
}

version_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ var peVersionResourceTests = []struct {
4343
nil,
4444
map[string]string{"Assembly Version": "7.3.4.500", "Comments": "PowerShell on Windows top-level project", "CompanyName": "Microsoft Corporation", "FileDescription": "pwsh", "FileVersion": "7.3.4.500", "InternalName": "pwsh.dll", "LegalCopyright": "(c) Microsoft Corporation.", "OriginalFilename": "pwsh.dll", "ProductName": "PowerShell", "ProductVersion": "7.3.4 SHA: b59f05d5a1b2fceca231f75c53c203a02edf6203"},
4545
},
46+
{
47+
getAbsoluteFilePath("test/YourPhone.Exp.WinRT.dll"),
48+
nil,
49+
map[string]string{"CompanyName": "Microsoft Corporation", "FileDescription": "", "FileVersion": "1.24052.124.0", "OriginalFilename": "YourPhone.Exp.WinRT.dll", "LegalCopyright": "© Microsoft Corporation. All rights reserved.", "InternalName": "YourPhone.Exp.WinRT", "ProductName": "Microsoft Phone Link", "ProductVersion": "1.24052.124.0"},
50+
},
4651
}
4752

4853
func TestParseVersionResources(t *testing.T) {

0 commit comments

Comments
 (0)