11#! /usr/bin/env lua
22
3- I ,X ,V ,H = " <I4" ,0x80000000 ,809222400 ,[[ This script will edit timestamps in a PE EXE with the Windows 95 release date.
4- Doing so allows repeatable builds to be verified by checksum. Make a backup of your EXE before using this tool on it.]]
3+ I ,X ,V ,H = " <I4" ,0x80000000 ,809222400 ,[[ This script edits timestamps in a PE formatted EXE to the Windows 95 release date.
4+ This allows repeatable builds to be verified by checksum tools. Backup the EXE before using this tool on it.]]
55function C (x )return F :seek (" cur" ,x )end
66function S (x )return F :seek (" set" ,x )end
77function R (l )local b = F :read (l )if b and# b >= l then return string.unpack (l == 2 and " <I2" or I ,b )end error (" !EOF" )end
@@ -13,14 +13,13 @@ function O()
1313 for _ = 1 ,n do local u ,o = C (),F :read (8 ):gsub (" \0 .*" ," " )C (4 )J = R (4 )C (4 )K = R (4 )S (u + 40 )if o == " .rsrc" then return end end error (" !rsrc" )end
1414function B (p ,s )
1515 S ((p - J )+ K )local d ,t ,k = F :read (s ),(" VS_VERSION_INFO" ):gsub (" ." ," \0 %1" ).. " \0\0 " k = d :find (t ,1 ,true )
16- if k then k = k +# t + ((4 - ((k +# t )% 4 ))% 4 )+ 44 d ,t = C ()+ (k - s )W (d ,0 )W (d + 4 ,V )end
17- end
16+ if k then k = k +# t + ((4 - ((k +# t )% 4 ))% 4 )+ 44 d ,t = C ()+ (k - s )W (d ,0 )W (d + 4 ,V )end end
1817function A (o ,l ,v )
1918 local d ,n ,i ,t ,e = K + o + 4 W (d ,V )C (4 )n ,i = R (2 ),R (2 )t ,e = n + i ,d + 12
2019 for j = 0 ,t - 1 do S (e + (j * 8 ))i ,d = R (4 ),R (4 )
2120 if (d &X )~= 0 then A (d &(X - 1 ),l + 1 ,v or (l == 1 and i == 16 ))
2221 elseif v and l == 3 then local r = C ()S (K + d )B (R (4 ),R (4 ))S (r )end end end
23- if # arg < 1 then print (H )os.exit (1 )end
22+ if # arg < 1 then print (arg [ 0 ], " 'PEFORMAT.EXE' \n\n " .. H )os.exit (1 )end
2423F = assert (io.open (arg [1 ]," r+b" ))J = P ()W (J + 8 ,V )O ()
2524A (0 ,1 )F :close ()
2625print (" OK" )
0 commit comments