03-15-2014, 01:21 AM
I have completed your script; It can now be used to 1. Write scripts from Scripts.rxdata to individual script files and 2. Reconstitute the scripts from the individual scripts saved from the first use.
The resultant Scripts.rxdata is in fact a perfect binary match for the original, sharing the same md5sum and sha512sum. Note, this is only because the dumped scripts were not edited; but, obviously, if you make changes to the script it will affect the output of the final scriptfile. I only state the fact its identical because it proves the process is perfect.
Usage:
dissassemble_scripts("Scripts.rxdata", "ScriptIndex.dat") will write out all the scripts in Scripts.rxdata into individual script text files and save an index file as ScriptIndex.dat
assemble_scripts("ScriptIndex.dat", "Scripts.rxdata") will reconstitute the (edited, if so desired) scripts using the index we saved as ScriptIndex.dat and save the reconstituted file as Scripts.rxdata; I've not tested with a file named Scripts.rxdata actually existing, so not sure if it will work (I had deleted the file after disassembly in order to make sure I wasn't simply seeing the original Scripts.rxdata and assuming success)
The resultant Scripts.rxdata is in fact a perfect binary match for the original, sharing the same md5sum and sha512sum. Note, this is only because the dumped scripts were not edited; but, obviously, if you make changes to the script it will affect the output of the final scriptfile. I only state the fact its identical because it proves the process is perfect.
Code:
#!/usr/bin/env ruby
require 'zlib'
def load_data(filename)
File.open(filename, "rb") { |f|
obj = Marshal.load(f)
}
end
def save_data(obj, filename)
File.open(filename, "wb") { |f|
Marshal.dump(obj, f)
}
end
def dump_script(scriptfile, scriptindex)
script = load_data(scriptfile)
script.each { |s|
file = File.open(s.at(1), 'wb')
file.write(Zlib::Inflate.inflate(s.at(2)))
file.close
s.delete_at(2)
save_data(script, scriptindex)
}
end
def assemble_scripts(scriptindex, scriptfile)
index = load_data(scriptindex)
index.each { |s|
file = File.readlines(s.at(1))
s.push(Zlib::Deflate.deflate(file.join))
save_data(index, scriptfile)
}
end
dissassemble_scripts("Scripts.rxdata", "ScriptIndex.dat") will write out all the scripts in Scripts.rxdata into individual script text files and save an index file as ScriptIndex.dat
assemble_scripts("ScriptIndex.dat", "Scripts.rxdata") will reconstitute the (edited, if so desired) scripts using the index we saved as ScriptIndex.dat and save the reconstituted file as Scripts.rxdata; I've not tested with a file named Scripts.rxdata actually existing, so not sure if it will work (I had deleted the file after disassembly in order to make sure I wasn't simply seeing the original Scripts.rxdata and assuming success)