Skip to content

Commit f30500a

Browse files
committed
Squash PE95TIME.LUA source code more aggressively in preparation for new VS_VERSION_INFO() functions.
1 parent 38c5942 commit f30500a

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

demo/xtra/PE95TIME.LUA

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env lua
22

33
--Set PE timestamps to a constant so builds are repeatable
4-
C="cur" E="Unexpected EOF" F="<I4" S="set" V=809222400
5-
local function R(f,l) local b=f:read(l) if not b or #b<l then error(E) end return string.unpack(l==2 and"<I2"or F,b) end
6-
local function W(f,p,v) f:seek(S,p) f:write(string.pack(F,v)) end
7-
local function peo(f) f:seek(S,0) local mz=f:read(2) if mz~="MZ" then error("!MZ") end f:seek(S,0x3C) return R(f,4) end
8-
local function rsrc(f,p)
9-
f:seek(S,p) local sig=f:read(4) if sig~="PE\0\0" then error("Invalid PE") end f:seek(C,2)
10-
local n=R(f,2) f:seek(C,12) local s=R(f,2) f:seek(C,2) local h,m=f:seek(),R(f,2)
11-
if m~=0x10b and m~=0x20b then error("Unknown magic: "..string.format("%x",m)) end f:seek(S,h+s)
4+
C,E,F,S,V="cur","Unexpected EOF","<I4","set",809222400
5+
function R(f,l)local b=f:read(l)if b and#b>=l then return string.unpack(l==2 and"<I2"or F,b)end error(E)end
6+
function W(f,p,v)f:seek(S,p)f:write(string.pack(F,v))end
7+
function P(f)f:seek(S,0)local mz=f:read(2)f:seek(S,0x3C)if mz=="MZ"then return R(f,4)end error("!MZ")end
8+
function O(f,p)
9+
f:seek(S,p)local s,n,h,m=f:read(4)if s~="PE\0\0"then error("!PE")end f:seek(C,2)
10+
n=R(f,2)f:seek(C,12)s=R(f,2)f:seek(C,2)h,m=f:seek(),R(f,2)
11+
if m~=0x10b and m~=0x20b then error("!Magic")end f:seek(S,h+s)
1212
for _=1,n do
13-
local ss,o=f:seek(),f:read(8):gsub("\0.*",""),f:seek(C,4) local _,t,q=R(f,4),R(f,4),R(f,4) f:seek(S,ss+40)
14-
if o==".rsrc" then return {s=t,r=q} end
13+
local u,o,q=f:seek(),f:read(8):gsub("\0.*","")f:seek(C,12)q=R(f,4)f:seek(S,u+40)
14+
if o==".rsrc"then return q end
1515
end return nil end
16-
local function pat(f,bo,oir,l)
17-
local dp=bo+oir+4 W(f,dp,V) f:seek(C,4) local nn,ni=R(f,2),R(f,2) local te,eo=nn+ni,dp+12
18-
for j=0,te-1 do f:seek(S,eo+(j*8)) local i,d=R(f,4),R(f,4) if (d&0x80000000)~=0 then pat(f,bo,d&0x7FFFFFFF,l+1) end end
16+
function A(f,b,o,l)
17+
local d,n,i,t,e=b+o+4 W(f,d,V)f:seek(C,4)n,i=R(f,2),R(f,2)t,e=n+i,d+12
18+
for j=0,t-1 do f:seek(S,e+(j*8))i,d=R(f,4),R(f,4)if(d&0x80000000)~=0 then A(f,b,d&0x7FFFFFFF,l+1)end end
1919
--TODO: if l==1 and i==16 then parse_VS_VERSION_INFO() end
2020
end
21-
if #arg<1 then os.exit(1) end
22-
local f=assert(io.open(arg[1],"r+b")) local p=peo(f) W(f,p+8,V) local r=rsrc(f,p)
23-
if not r then error(".rsrc not found") end
24-
pat(f,r.r,0,1) f:close()
25-
print(".rsrc @: "..r.r..", size: "..r.s.." DONE")
21+
if #arg<1 then os.exit(1)end
22+
local f,p,r=assert(io.open(arg[1],"r+b"))p=P(f)W(f,p+8,V)r=O(f,p)
23+
if not r then error("!rsrc")end
24+
A(f,r,0,1)f:close()
25+
print("DONE")

0 commit comments

Comments
 (0)