I'm currently developing an application using Electron. One of the actions this application does is "verify the version" of a TeamSpeak 3 Client-addon. To do this, I run a command that checks the SHA256 hash of the addon file, and compare it against another string.
powershell.exe Get-FileHash $env:APPDATA\TS3Client\plugins\tokovoip_win32.dll
I run the same command for tokovoip_win64.dll
. This works, for most people. However, for one of the users of my application, it breaks.
After running a regular expression over the command
const win32ActualHash = /SHA256\s+?(\S+?)\s/gm.exec(await child.execSync(
'powershell.exe Get-FileHash $env:APPDATA\\TS3Client\\plugins\\tokovoip_win32.dll'))[1];
const win64ActualHash = /SHA256\s+?(\S+?)\s/gm.exec(await child.execSync(
'powershell.exe Get-FileHash $env:APPDATA\\TS3Client\\plugins\\tokovoip_win64.dll'))[1];
the expected output is
win32ActualHash = 'DDCF282FDC439DE4E560F74231B22850EB7016573730A0CD94B08AAEECDEC167';
win64ActualHash = 'AA38ED69966741C4D68E964F05CB16351EC5700E337D953B07DB81D7FB3891C7';
However, the output this user gets, is
win32ActualHash = 'DDCF282FDC439DE4E560F74231B22850EB7016573730A0CD94B08AAEECDE...';
win64ActualHash = 'AA38ED69966741C4D68E964F05CB16351EC5700E337D953B07DB81D7FB38...';
I have a very limited setup to test solutions, as I'm not able to recreate this scenario, and I don't want to spam this user with possible fixes.
What is causing these strings to be truncated, and how can I prevent this from happening?
I managed to work around this by piping it into Format-List
within the powershell command:
powershell.exe "Get-FileHash $env:APPDATA\TS3Client\plugins\tokovoip_win32.dll | Format-List"
And then changing the RegExp to extract the hash
const win32ActualHash = /Hash\s*?:\s*(\S*)\s*/gm.exec(await child.execSync(
'powershell.exe "Get-FileHash $env:APPDATA\\TS3Client\\plugins\\tokovoip_win32.dll | Format-List"'))[1];
const win64ActualHash = /Hash\s*?:\s*(\S*)\s*/gm.exec(await child.execSync(
'powershell.exe "Get-FileHash $env:APPDATA\\TS3Client\\plugins\\tokovoip_win64.dll | Format-List"'))[1];
The Format-List
never seems to truncate strings and thus delivers a consistent output