Created
October 17, 2018 22:47
-
-
Save michaeleisel/a36e74864495bae8aab3a0b93fe91ef4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
raise "Usage: ./args.rb <path to executable>" unless ARGV.size == 1 | |
new_seg_name = "__MY_TEXT" | |
binary = ARGV.first | |
sect_regex = /\s*Section (\S+)/ | |
sects = `xcrun size -x -l -m #{binary}`.split("\n").drop_while do |line| | |
!line.start_with?("Segment __TEXT:") | |
end.drop(1).take_while do |line| | |
line =~ sect_regex | |
end.map do |line| | |
line.match(/^\s*Section (\S+):/)[1] | |
end | |
cmds = sects.map do |sect| | |
"-Wl,-rename_section,__TEXT,#{sect},#{new_seg_name},#{sect}" | |
end | |
puts "Sections:\n#{sects}\n\nLink commands:\n#{cmds.join("\n")}\n\nProtection link command:\n-Wl,-segprot,#{new_seg_name},rx,rx\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment