Ylianst / Authenticode-JS

Pure NodeJS module and tool for code signing Windows executables
Apache License 2.0
29 stars 7 forks source link

createAuthenticodeHandler keeps returning null #3

Open si458 opened 1 year ago

si458 commented 1 year ago

Code:

const path = require('path');
const file = path.resolve('dist\\ourbackups-win64.exe');
console.log(file);
const exehandler = require("authenticode-js").createAuthenticodeHandler(file);
console.log(exehandler);

Output:

PS C:\Users\sas_2\Documents\Developer\ourbackups> node .\mytest.js
C:\Users\sas_2\Documents\Developer\ourbackups\dist\ourbackups-win64.exe
null
PS C:\Users\sas_2\Documents\Developer\ourbackups> 

But the file does exist

PS C:\Users\sas_2\Documents\Developer\ourbackups> C:\Users\sas_2\Documents\Developer\ourbackups\dist\ourbackups-win64.exe
2022-08-21 10:08:52.290 missing which backup
PS C:\Users\sas_2\Documents\Developer\ourbackups> 
si458 commented 1 year ago

found the issue, it seems to start reading the file no problem BUT then suddenly fails reading one section? https://github.com/Ylianst/Authenticode-JS/blob/df108bee5c297448528264440a3740e18d7ff53a/authenticode.js#L297-L316

EDIT: i=4 numberOfSections=7 buf[0] = 95 sectionName = _RDATA

EDIT2: i found 2 fixes and both seem to still work but not sure which is best? from my understanding anything with an underscore in should be ignored?

FIX1: ignore underscores and dont do data stuff if(buf[0] != 46){ if(buf[0] == 95){ continue; }else{ obj.close(); return false; } }

FIX2: if not underscore or fullstop then carry on with data stuff if (buf[0] != 46 && buf[0] != 95) { obj.close(); return false; };