niklasfrykholm

Untitled

Dec 28th, 2011
327
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This ruby program will patch the linker executable (link.exe)
  2. # so that linker warning LNK4099 is ignorable.
  3. #
  4. # Reference: http://www.bottledlight.com/docs/lnk4099.html
  5.  
  6. require "fileutils"
  7.  
  8. def link_exes()
  9.     res = []
  10.     res << File.join(ENV["VS90COMNTOOLS"], "../../VC/bin/link.exe") if ENV["VS90COMNTOOLS"]
  11.     res << File.join(ENV["VS100COMNTOOLS"], "../../VC/bin/link.exe") if ENV["VS100COMNTOOLS"]
  12.     res << File.join(ENV["XEDK"], "bin/win32/link.exe") if ENV["XEDK"]
  13.     return res
  14. end
  15.  
  16. def patch_link_exe(exe)
  17.     data = nil
  18.     File.open(exe, "rb") {|f| data = f.read}
  19.     unpatched = [4088, 4099, 4105].pack("III")
  20.     patched = [4088, 65535, 4105].pack("III")
  21.  
  22.     if data.scan(patched).size > 0
  23.         puts "* Already patched #{exe}"
  24.         return
  25.     end
  26.  
  27.     num_unpatched = data.scan(unpatched).size
  28.     raise "Multiple patch locations in #{exe}" if num_unpatched > 1
  29.     raise "Patch location not found in #{exe}" if num_unpatched == 0
  30.  
  31.     offset = data.index(unpatched)
  32.     puts "* Found patch location #{exe}:#{offset}"
  33.     bak = exe + "-" + Time.now.strftime("%y%m%d-%H%M%S") + ".bak"
  34.     puts "  Creating backup #{bak}"
  35.     FileUtils.cp(exe, bak)
  36.     puts "  Patching exe"
  37.     data[offset,unpatched.size] = patched
  38.     File.open(exe, "wb") {|f| f.write(data)}
  39.     return true
  40. end
  41.  
  42. link_exes.each do |exe|
  43.     patch_link_exe(exe)
  44. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×