Skip to content

Instantly share code, notes, and snippets.

@taskie
Created December 19, 2014 21:38
Show Gist options
  • Save taskie/165e0ca8ab407ae915cd to your computer and use it in GitHub Desktop.
Save taskie/165e0ca8ab407ae915cd to your computer and use it in GitHub Desktop.
#!/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