Skip to content

Instantly share code, notes, and snippets.

@emonti
Created October 23, 2015 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emonti/bbba44bd3cac4f4fcc46 to your computer and use it in GitHub Desktop.
Save emonti/bbba44bd3cac4f4fcc46 to your computer and use it in GitHub Desktop.
extract_lockdownd_services.rb
#!/usr/bin/env ruby
fname = ARGV.shift
fname || exit!
offset = nil
size = nil
`otool -l \"#{fname}\" |grep -A11 ^Section`.split(/^--$/).each do |sect_txt|
lines = sect_txt.lines.map(&:chomp)
info = Hash[ lines[1..-1].map{|ln| ln.strip.split(' ',2)} ]
segname, sectname, off, sz = info.values_at("segname","sectname","offset","size")
if segname == "__TEXT" and sectname == "__services"
offset = off.to_i
size = sz.hex
break
end
end
unless offset and size
$stderr.puts "Couldn't find __TEXT,__services"
exit!
end
dat = IO.binread(fname, size, offset)
outfile = "#{fname}_services.plist"
$stderr.puts "Writing #{size} bytes to #{outfile}"
File.open(outfile, "wb") {|out| out.write dat}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment