Created
December 19, 2014 21:38
-
-
Save taskie/165e0ca8ab407ae915cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
(inpath, outpath, org, dst = $*) | |
unless inpath && outpath && org && dst | |
puts "usage: conv_exs infile outfile org dst" | |
exit 1 | |
end | |
binstr = nil | |
open(inpath, "rb") do |file| | |
binstr = file.read | |
end | |
pos = 0 | |
loop do | |
idx = binstr.index(org, pos) | |
break unless idx | |
newstr = binstr[idx, 256].gsub(org, dst).rstrip.ljust(256, "\0") | |
binstr[idx, 256] = newstr | |
pos = idx + 1 | |
end | |
open(outpath, "wb") do |file| | |
file.write(binstr) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment