Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This ruby program will patch the linker executable (link.exe)
- # so that linker warning LNK4099 is ignorable.
- #
- # Reference: http://www.bottledlight.com/docs/lnk4099.html
- require "fileutils"
- def link_exes()
- res = []
- res << File.join(ENV["VS90COMNTOOLS"], "../../VC/bin/link.exe") if ENV["VS90COMNTOOLS"]
- res << File.join(ENV["VS100COMNTOOLS"], "../../VC/bin/link.exe") if ENV["VS100COMNTOOLS"]
- res << File.join(ENV["XEDK"], "bin/win32/link.exe") if ENV["XEDK"]
- return res
- end
- def patch_link_exe(exe)
- data = nil
- File.open(exe, "rb") {|f| data = f.read}
- pattern = [4099].pack("I")
- offset = 0
- i = 0
- while true
- i = data.index(pattern, offset)
- return false unless i
- offset = i+1
- next unless i%4 == 0
- int_before = data[i-4,4].unpack("I")[0]
- int_after = data[i+4,4].unpack("I")[0]
- break if int_before == 4088 && int_after == 4105
- end
- puts "* Found patch location #{exe}:#{i}"
- bak = exe + "-" + Time.now.strftime("%y%m%d-%H%M%S") + ".bak"
- puts " Creating backup #{bak}"
- FileUtils.cp(exe, bak)
- puts " Patching exe"
- data[i,4] = [65535].pack("I")
- File.open(exe, "wb") {|f| f.write(data)}
- return true
- end
- link_exes.each do |exe|
- patch_link_exe(exe)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement