Change
Code:
sed -i "s/A/B/g" file
Code:
rpl -e "A" "B" file
Could be useful for other scripts as well. rpl is much smaller than ruby.
sed -i "s/A/B/g" file
rpl -e "A" "B" file
#!/usr/bin/env ruby if !File.exists?(`which objdump`.chomp!) || !File.exists?(`which awk`.chomp!) puts "Can't find objdump; please check your installation." Process.exit!(false) end if ARGV[0].nil? || !File.exists?(ARGV[0]) fglrx = "/usr/lib64/xorg/modules/drivers/fglrx_drv.so" if !File.exists?(fglrx) fglrx = "/usr/lib/xorg/modules/drivers/fglrx_drv.so" if !File.exists?(fglrx) puts "Can't find fglrx_drv.so; try to specify it as a command-line argument" Process.exit!(false) end end else fglrx = ARGV[0] end fglrx_str = IO.read(fglrx) puts "Read #{fglrx}: #{fglrx_str.bytesize}" if fglrx_str.bytesize < 1000 puts "Can't read from #{fglrx} or file is very small; something is wrong!" Process.exit!(false) end dump = `objdump -d "#{fglrx}"` puts "objdump returned #{dump.bytesize} bytes" if dump.bytesize < 1 puts "objdump failed on #{fglrx}; something is wrong!" Process.exit!(false) end awkcmd = %q!/callq/&&/atiddxEnableLogo/{print "\\\\x"$2"\\\\x"$3"\\\\x"$4"\\\\x"$5"\\\\x"$6}! proc = IO.popen(%Q!awk '#{awkcmd}'!, mode="w+") proc.write(dump) proc.close_write awkresult = proc.read if awkresult.bytesize < 1 puts "awk failed on #{fglrx}; either something is wrong, or you have no EnableLogo calls left to substitute out!" Process.exit!(false) end puts "awk result: #{awkresult}" results = awkresult.split("\n") puts "Results: #{results.count} items" results.each { |result| puts "Looking for #{result}" fglrx_str.gsub!(/#{result}/, "\x90\x90\x90\x90\x90") } ofile = File.open(fglrx, "w") written = ofile.write(fglrx_str) ofile.flush ofile.fsync ofile.close puts "#{written} bytes written to #{fglrx}" Process.exit(true)
Leave a comment: