Advertisement
LDDestroier

Progdor Self-Extract

Jun 11th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.   PROGDOR SELF-EXTRACT
  3.  INSTRUCTIONS
  4.  
  5.  1. Use a CC emulator, such as CCEmuRedux, so you can access your filesystem ("~/.ccemuredux/sessions/computer" on linux, something else for windows)
  6.  2. Put all the files you want to archive in a single folder.
  7.  3. Get progdor (pastebin get YXx5jjMV progdor), and choose whether or not to edit the 11th line to compress or not. (Uses CCA algorithm)
  8.  4. Use progdor on that folder. It should be a file now!
  9.  5. Get out of CCEmuRedux, and navigate to the file in the .ccemuredux/sessions/computer/[ID] folder.
  10.  6. Open it up with a text editor, remove the first line (true or false), then select all and copy it as 'data' (defined below).
  11.     Don't paste it INSIDE of data; replace the existing {}.
  12.  7. If it is compressed, set the doCompress (defined below) to true. Otherwise, set it to false.
  13.  8. Set the variable fullname (defined below) to the full name of your program/files.
  14.  
  15.  You are done! Be sure to remove this whole comment.
  16. --]]
  17.  
  18. local fullname = "full_name_here"
  19. local doCompress = false
  20. local data = {} --paste archive data here
  21.  
  22. local tArg = {...}
  23. local outpath = ((tArg[1] ~= "") and tArg[1]) or (shell and shell.getRunningProgram() or "")
  24. if fs.combine("",outpath) == "rom/programs/http/pastebin" then outpath = (shell and shell.dir() or "") end
  25.  
  26. local progdor = fs.getName(shell.getRunningProgram())
  27. local dir = shell.dir()
  28.  
  29. -- CCA API START --
  30.  
  31. local bit = bit32
  32. local function pack(bn1, bn2)
  33.     return bit.band(bn1, 0xFF), bit.rshift(bn1, 8) + bit.lshift(bit.band(bn2, 0xF), 4), bit.rshift(bn2, 4)
  34. end
  35. local function upack(b1, b2, b3)
  36.     return (b1 + bit.lshift(bit.band(b2, 0xF), 8)), (bit.lshift(b3,4) + bit.band(bit.rshift(b2, 4), 0xF))
  37. end
  38. local function createDict(bool)
  39.     local ret = {}
  40.     for i = 1, 255 do
  41.         if bool then
  42.             ret[string.char(i)] = i
  43.         else
  44.             ret[i] = string.char(i)
  45.         end
  46.     end
  47.     if not bool then ret[256] = 256 end
  48.     return ret
  49. end
  50. local function cp(sInput)
  51.     local dic = createDict(true)
  52.     local s = ""
  53.     local ch
  54.     local dlen = 256
  55.     local result = {}
  56.     local temp
  57.     for i = 1, #sInput do
  58.         if dlen == 4095 then
  59.             result[#result + 1] = dic[s]
  60.             result[#result + 1] = 256
  61.             dic = createDict(true)
  62.             dlen = 256
  63.             s = ""
  64.         end
  65.         ch = sInput:sub(i, i)
  66.         temp = s..ch
  67.         if dic[temp] then
  68.             s = temp
  69.         else
  70.             result[#result + 1] = dic[s]
  71.             dlen = dlen +1
  72.             dic[temp] = dlen       
  73.             s = ch
  74.         end
  75.     end
  76.     result[#result + 1] = dic[s]
  77.    
  78.     return result
  79. end
  80. local function dc(data)
  81.     local dic = createDict(false)  
  82.     local entry
  83.     local ch
  84.     local currCode
  85.     local result = {}
  86.     result[#result + 1] = dic[data[1]]
  87.     prefix = dic[data[1]]
  88.     for i = 2, #data do
  89.         currCode = data[i]
  90.         if currCode == 256 then
  91.             dic = createDict(false)
  92.             prefix = ""
  93.         else
  94.             entry = dic[currCode]
  95.             if entry then --exists in dictionary
  96.                 ch = entry:sub(1, 1)       
  97.                 result[#result + 1] = entry
  98.                 if prefix ~= "" then
  99.                     dic[#dic+1] = prefix .. ch
  100.                 end
  101.             else   
  102.                 ch = prefix:sub(1, 1)
  103.                 result[#result + 1] = prefix..ch
  104.                 dic[#dic + 1] = prefix..ch
  105.             end
  106.        
  107.             prefix = dic[currCode]
  108.         end
  109.     end
  110.    
  111.     return table.concat(result)
  112. end
  113. local function trim(inp)
  114.     for i = 0,2 do
  115.         if inp[#inp] == 0 then
  116.             inp[#inp] = nil
  117.         end
  118.     end
  119. end
  120. local function decompress(input)
  121.     local rec = {}
  122.     for i = 1, #input, 3 do
  123.         if i % 66 == 0 then
  124.             coroutine.yield()
  125.         end
  126.         rec[#rec+1], rec[#rec+2] = upack(input[i], input[i+1] or 0, input[i+2] or 0)
  127.     end
  128.     trim(rec)
  129.     return dc(rec)
  130. end
  131. local function compress(input)
  132.     local rec = {}
  133.     local data = cp(input)
  134.     for i=1, #data, 2 do
  135.         coroutine.yield()
  136.         rec[#rec+1], rec[#rec+2], rec[#rec+3] = pack(data[i], data[i+1] or 0)
  137.     end
  138.     trim(rec)
  139.     return rec
  140. end
  141.  
  142. -- CCA API END --
  143.  
  144. local explode = function(div,str)
  145.     if (div=='') then return false end
  146.     local pos,arr = 0,{}
  147.     for st,sp in function() return string.find(str,div,pos,true) end do
  148.         table.insert(arr,str:sub(pos,st-1))
  149.         pos = sp + 1
  150.     end
  151.     table.insert(arr,str:sub(pos))
  152.     return arr
  153. end
  154. local sanitize = function(sani,tize)
  155.     local _,x = string.find(sani,tize)
  156.     if x then
  157.         return sani:sub(x+1)
  158.     else
  159.         return sani
  160.     end
  161. end
  162. local tablize = function(input)
  163.     if type(input) == "string" then
  164.         return explode("\n",input)
  165.     elseif type(input) == "table" then
  166.         return table.concat(input,"\n")
  167.     end
  168. end
  169. local compyress = function(input)
  170.     return string.char(unpack(compress(input)))
  171. end
  172. local decompyress = function(input)
  173.     local out = {}
  174.     for a = 1, #input do
  175.         table.insert(out,string.byte(input:sub(a,a)))
  176.     end
  177.     return decompress(out)
  178. end
  179.  
  180. if not outpath then
  181.     outpath = input
  182. end
  183.  
  184. local choice = function(input,verbose)
  185.     if not input then
  186.         input = "yn"
  187.     end
  188.     if verbose then
  189.         write("[")
  190.         for a = 1, #input do
  191.             write(input:sub(a,a):upper())
  192.             if a < #input then
  193.                 write(",")
  194.             end
  195.         end
  196.         write("]?")
  197.     end
  198.     local evt,char
  199.     repeat
  200.         evt,char = os.pullEvent("char")
  201.     until string.find(input:lower(),char:lower())
  202.     if verbose then
  203.         print(char:upper())
  204.     end
  205.     local pos = string.find(input:lower(),char:lower())
  206.     return pos, char:lower()
  207. end
  208.  
  209. local doPack = function(list,output,doCompress,verbose)
  210.     local tx = term.getTextColor()
  211.     if fs.isReadOnly(output) and (fs.combine("",output) ~= "") then return 5 end
  212.     local packageSelf = true
  213.     local packageReadOnly = true
  214.     local ro_asked = false
  215.     local ps_asked = false
  216.     if fs.exists(output) and (not fs.isDir(output)) then
  217.         fs.delete(output)
  218.     end
  219.     local amnt = 0
  220.     for k,v in pairs(list) do
  221.         amnt = amnt + 1
  222.     end
  223.     local num = 0
  224.     for k,v in pairs(list) do
  225.         num = num + 1
  226.         if v == true then
  227.             fs.makeDir(fs.combine(output,k))
  228.         else
  229.             local file = fs.open(fs.combine(output,k),"w")
  230.             if verbose then
  231.                 write("[")
  232.                 if term.isColor() then term.setTextColor(colors.lightGray) end
  233.                 write(k)
  234.                 term.setTextColor(tx)
  235.                 write("]")
  236.             end
  237.             if doCompress then
  238.                 file.write(decompyress(tablize(v)))
  239.             else
  240.                 file.write(tablize(v))
  241.             end
  242.             file.close()
  243.             local tx = term.getTextColor()
  244.             if fs.getName(k):lower() == "peasant" then
  245.                 if term.isColor() then
  246.                     term.setTextColor(colors.orange)
  247.                 end
  248.                 print(" UNBURNINATED")
  249.             else
  250.                 if term.isColor() then
  251.                     term.setTextColor(colors.green)
  252.                 end
  253.                 print(" GOOD")
  254.             end
  255.             term.setTextColor(tx)
  256.         end
  257.     end
  258.     return 2
  259. end
  260.  
  261. if not fs.isDir(outpath) then
  262.     fs.delete(outpath)
  263. end
  264.  
  265. local success, res = pcall( function() return doPack(data,outpath,doCompress,true) end )
  266.  
  267. if not success then
  268.     term.setTextColor(colors.white)
  269.     print("\n***Something went wrong!***")
  270.     return printError(res)
  271. end
  272.  
  273. if res then
  274.     local msgs = {
  275.         [2] = "Successfully unpacked '"..fullname.."' to '"..outpath.."/'",
  276.         [5] = "You don't have permission.",
  277.     }
  278.     print(msgs[res])
  279. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement