ayohrling / local_security_policy

Apache License 2.0
6 stars 28 forks source link

the secedit export processing doesnt handle multiline strings #130

Open robscott64 opened 1 year ago

robscott64 commented 1 year ago

if an element such as LegalNoticeText spans multiple lines then the output from the export looks like MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText=7,line 1 line2 line3 in order to process it as an inifile the set of lines need to be converted to the format where , are used to separate lines (any commas in the text have to appear as ",")

here is my proposed patch:

mkr-services# diff .orig/policy.rb .
50,51c50,51
<         # remove /r/n and remove the BOM
<         inffile_content = file.read.force_encoding('utf-16le').encode('utf-8', universal_newline: true).delete("\xEF\xBB\xBF")
---
>         # remove /r/n, the BOM, and make multiline strings into ,  sep single lines
>         inffile_content = file.read.force_encoding('utf-16le').encode('utf-8', universal_newline: true).delete("\xEF\xBB\xBF").gsub(/(^MACHINE(?:(?!MACHINE).)*?7,(?:(?:(?!MACHINE)[^\n])*?\n)*?)\nMACHINE/m) { |m| m.gsub(/\n(?!MACHINE)/m, ',') }