|
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","Unexpected EOF","<I4","set",809222400 |
| 4 | +C,E,F,S,V="cur","!EOF","<I4","set",809222400 |
5 | 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 | 6 | function W(f,p,v)f:seek(S,p)f:write(string.pack(F,v))end |
7 | 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 | 8 | function O(f,p) |
9 | 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 | 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) |
12 | | - for _=1,n do |
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 |
15 | | - end return nil end |
16 | | -function A(f,b,o,l) |
| 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) |
| 15 | + print("TODO: handle VS_VERSION_INFO @" .. r .. " (size " .. s .. ")") |
| 16 | +end |
| 17 | +function A(f,b,o,l,v) |
17 | 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 |
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 |
19 | | - --TODO: if l==1 and i==16 then parse_VS_VERSION_INFO() end |
| 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 |
| 22 | + end |
20 | 23 | end |
21 | 24 | if #arg<1 then os.exit(1)end |
22 | 25 | local f,p,r=assert(io.open(arg[1],"r+b"))p=P(f)W(f,p+8,V)r=O(f,p) |
|
0 commit comments