Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LZSS SEP-Maker (Online Built-in LZSS) https://pastebin.com/MxnRb6E8
- --
- -- This program was made to create self-extracting archives.
- --
- -- That kind of self-extracting programs(SEP) has built-in LZSS
- -- unpack function, so they can be launched without LZSS installed.
- -- You can run them with pastebin or wget or directly from
- -- shell (or.run is posible but unrecomended)
- local B,A,R,S=bit32,bit32.band,bit32.rshift,string.sub
- local lzss_pack=function(I)local L,o,r,w,f,b,s,p=B.lshift,1,'',''while#I>=o do
- f,b=0,''for i=0,7 do
- if#I>=o then
- for j=17,2,-1 do
- s=S(I,o,o+j)p=w:find(s,1,1)if p then break end
- end
- if p and#s>=3 then
- b=b..('>I2'):pack(B.bor(L(p-1,4),#s-3))else
- f=B.bor(f,L(1,i))s=S(I,o,o)b=b..s
- end
- w=S(w..s,-4^6)o=o+#s
- else
- break
- end
- end
- if#b>0 then
- r=r..r.char(f)..b
- end
- end
- return r
- end
- -- Help message
- local tArgs={...}
- if not ... then print"Usage: <src> [dest] [wget] [uneffective] [rewrite]"return end
- --main part (part that will be inserted at the start of file)
- local extractor_base=[==[P=P:sub(SiZ,ZiS)while#P>=o do f=P:byte(o)o=o+1
- for _=0,7 do s=nil
- if 0<A(f,1)then
- if#P>=o then s=S(P,o,o)o=o+1
- end
- elseif#P>=o+1 then
- t=('>I2'):unpack(P,o)p=1+R(t,4)s=S(w,p,p+A(t,15)+2)o=o+2
- end
- f=R(f,1)if s then w=S(w..s,-4096)r=r..s end
- end
- end
- return load(r,O,nil,_ENV)(...)--[]==]
- --advanced extractor (biger then default, but can be launched directly from wget/pastebin)
- local extractor_wget=[==[local D,A,R,o,r,w,f,t,p,s,S,O,G,L,P=debug or{},bit32.band,bit32.rshift,1,'',''G=D.getinfo or r.char
- L=D.getlocal
- O=(G(3)or{}).source or""P=O:find"wget.lua$"and 4 or O:find"pastebin.lua$"and 6 or P
- S=O.sub
- if P then D,O=L(3,P)D,P=L(3,7)else L=shell O=L and"@/"..L.resolveProgram(arg[0])or(G(1)or{}).source or""D,L=io.open(S(O,2),'rb')L=L and error(L)P=D:read"*a"D:close()end
- ]==]
- --default extractor (can start from file only, but smaller)
- local extractor_def =[==[local D,A,R,L,o,r,w,f,t,p,s,S,O,P=debug or{},bit32.band,bit32.rshift,shell,1,'',''S=r.sub
- O=L and"@/"..L.resolveProgram(arg[0])or(D.getinfo or r.char)(1).source or""D,L=io.open(S(O,2),'rb')L=L and error(L)P=D:read"*a"D:close()]==]
- -- "@/" - needed to make chunknames of packed programs similar to unpacked ones
- -- read source
- local eq_count=0
- local file=fs.open(...or"",'r') or error"LZSS> Can't open source file..."
- local before=file.readAll()
- local prog=lzss_pack(before)
- file.close()
- -- choose/print extractor
- local wget
- write"LZSSEPM> Add wget/pastebin support? [Y/n]: "
- if tArgs[3]=="true"or tArgs[3]=="Y"or tArgs[3]=="y"then print(tArgs[3]) wget=1
- elseif tArgs[3]=="false" or tArgs[3]=="N"or tArgs[3]=="n" then print(tArgs[3])
- else
- wget = read():find"^[Yy]"
- end
- print("LZSSEPM> Extractor type :",wget and"WGET/PASTEBIN Support"or"Default")
- local extractor = (wget and extractor_wget or extractor_def)..extractor_base
- print(("LZSSEPM> Extractor size : %.2f"):format(#extractor/1024),"Kb's\n")
- -- make container for compressed code
- k=false
- repeat
- if prog:find('([%[%]])'..("="):rep(eq_count)..'%1') then
- eq_count=eq_count+1
- else
- k=true
- end
- until k
- --print stats
- print(("LZSSEPM> Default size : %.2f"):format(#before/1024),"Kb's")
- print(("LZSSEPM> After LZSS size: %.2f"):format(#prog/1024),"Kb's")
- print(("LZSSEPM> Final size : %.2f"):format((#prog+#extractor+3+eq_count*2)/1024),"Kb's\n")
- --Warning if compression is bad
- if #before <= #prog+#extractor+3+eq_count*2 then
- print"LZSSEPM> Ineffective compression!"
- write"LZSSEPM> Continue? [Y/n]: "
- if tArgs[4]=="false"or tArgs[4]=="N" or tArgs[4]=="n"then print(tArgs[4])return
- elseif tArgs[4]=="true"or tArgs[4]=="Y" or tArgs[4]=="y"then print(tArgs[4])
- elseif read():find"^[^Yy]" then return
- end
- print()
- end
- -- set dest file
- local dest = tArgs[2] or ... .. ".sep"
- if fs.exists(dest) then
- print"LZSSEPM> Destination already exists!"
- write"LZSSEPM> Continue? [Y/n]: "
- if tArgs[5]=="true"or tArgs[5]=="Y"or tArgs[5]=="y"then print(tArgs[5])
- elseif tArgs[5]=="false"or tArgs[5]=="N"or tArgs[5]=="n"then print(tArgs[5])return
- elseif read():find"^[^Yy]"then return
- end
- end
- -- write dest file
- file=fs.open(dest,'wb')
- file.write(extractor:gsub("SiZ",#extractor+2+eq_count):gsub("ZiS",("%.2d"):format(-3-eq_count)))--extractior
- file.write(("="):rep(eq_count).."["..prog.."]"..("="):rep(eq_count).."]")--code
- file.close()
- print("LZSSEPM> Packing complete:",dest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement