Guest User

Untitled

a guest
Jun 25th, 2011
330
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2.  
  3. if !File.exists?(`which objdump`.chomp!) || !File.exists?(`which awk`.chomp!)
  4. puts "Can't find objdump; please check your installation."
  5. Process.exit!(false)
  6. end
  7.  
  8. if ARGV[0].nil? || !File.exists?(ARGV[0])
  9. fglrx = "/usr/lib64/xorg/modules/drivers/fglrx_drv.so"
  10. if !File.exists?(fglrx)
  11. fglrx = "/usr/lib/xorg/modules/drivers/fglrx_drv.so"
  12. if !File.exists?(fglrx)
  13. puts "Can't find fglrx_drv.so; try to specify it as a command-line argument"
  14. Process.exit!(false)
  15. end
  16. end
  17. else
  18. fglrx = ARGV[0]
  19. end
  20.  
  21.  
  22. fglrx_str = IO.read(fglrx)
  23. puts "Read #{fglrx}: #{fglrx_str.bytesize}"
  24. if fglrx_str.bytesize < 1000
  25. puts "Can't read from #{fglrx} or file is very small; something is wrong!"
  26. Process.exit!(false)
  27. end
  28.  
  29. dump = `objdump -d "#{fglrx}"`
  30. puts "objdump returned #{dump.bytesize} bytes"
  31. if dump.bytesize < 1
  32. puts "objdump failed on #{fglrx}; something is wrong!"
  33. Process.exit!(false)
  34. end
  35.  
  36. awkcmd = %q!/callq/&&/atiddxEnableLogo/{print "\\x"$2"\\x"$3"\\x"$4"\\x"$5"\\x"$6}!
  37. #puts %Q!awk '#{awkcmd}'!
  38. proc = IO.popen(%Q!awk '#{awkcmd}'!, mode="w+")
  39. proc.write(dump)
  40. proc.close_write
  41. awkresult = proc.read
  42. if awkresult.bytesize < 1
  43. puts "awk failed on #{fglrx}; either something is wrong, or you have no EnableLogo calls left to substitute out!"
  44. Process.exit!(false)
  45. end
  46.  
  47. results = awkresult.split("\n")
  48. puts "Results: #{results.count} items: #{results}"
  49.  
  50. results.each { |result|
  51. puts "Looking for #{result}"
  52.  
  53. fglrx_str.gsub!(/#{result}/, "\x90\x90\x90\x90\x90") }
  54.  
  55. ofile = File.open(fglrx, "w")
  56. written = ofile.write(fglrx_str)
  57. ofile.flush
  58. ofile.fsync
  59. ofile.close
  60. puts "#{written} bytes written to #{fglrx}"
  61.  
  62. Process.exit(true)
RAW Paste Data