|
1 | 1 | #!/usr/bin/env lua |
2 | 2 |
|
3 | 3 | --Set PE timestamps to a constant so builds are repeatable |
4 | | -C,E,F,S,V="cur","!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 then error("!10")end f:seek(S,h+s) |
12 | | - for _=1,n do local u,o,q=f:seek(),f:read(8):gsub("\0.*","")f:seek(C,12)q=R(f,4)f:seek(S,u+40) if o==".rsrc"then return q end end end |
13 | | -function B(f,o) |
14 | | - local r,s=R(f,4),R(f,4) |
| 4 | +C,E,I,S,V,F="cur","!EOF","<I4","set",809222400 |
| 5 | +function 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(E)end |
| 6 | +function W(p,v)F:seek(S,p)F:write(string.pack(I,v))end |
| 7 | +function P()F:seek(S,0)local mz=F:read(2)F:seek(S,0x3C)if mz=="MZ"then return R(4)end error("!MZ")end |
| 8 | +function O(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)n=R(2)F:seek(C,12)s=R(2)F:seek(C,2)h,m=F:seek(),R(2) |
| 10 | + if m~=0x10b then error("!10")end F:seek(S,h+s) |
| 11 | + for _=1,n do local u,o,q=F:seek(),F:read(8):gsub("\0.*","")F:seek(C,12)q=R(4)F:seek(S,u+40)if o==".rsrc"then return q end end end |
| 12 | +function B(o) |
| 13 | + local r,s=R(4),R(4) |
15 | 14 | print("TODO: handle VS_VERSION_INFO @" .. r .. " (size " .. s .. ")") |
16 | 15 | end |
17 | | -function A(f,b,o,l,v) |
18 | | - 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 |
19 | | - for j=0,t-1 do f:seek(S,e+(j*8))i,d=R(f,4),R(f,4) |
20 | | - if(d&0x80000000)~=0 then A(f,b,d&0x7FFFFFFF,l+1,v or(l==1 and i==16)) |
21 | | - elseif v and l==3 then B(f,b+d)end |
| 16 | +function A(b,o,l,v) |
| 17 | + local d,n,i,t,e=b+o+4 W(d,V)F:seek(C,4)n,i=R(2),R(2)t,e=n+i,d+12 |
| 18 | + for j=0,t-1 do F:seek(S,e+(j*8))i,d=R(4),R(4) |
| 19 | + if(d&0x80000000)~=0 then A(b,d&0x7FFFFFFF,l+1,v or(l==1 and i==16)) |
| 20 | + elseif v and l==3 then B(F,b+d)end |
22 | 21 | end |
23 | 22 | end |
24 | 23 | if #arg<1 then os.exit(1)end |
25 | | -local f,p,r=assert(io.open(arg[1],"r+b"))p=P(f)W(f,p+8,V)r=O(f,p) |
| 24 | +F=assert(io.open(arg[1],"r+b"))local p,r=P()W(p+8,V)r=O(p) |
26 | 25 | if not r then error("!rsrc")end |
27 | | -A(f,r,0,1)f:close() |
| 26 | +A(r,0,1)F:close() |
28 | 27 | print("DONE") |
0 commit comments