Last active
February 20, 2022 13:19
-
-
Save hisui/9f4d7562fefd050d28757fd008912f20 to your computer and use it in GitHub Desktop.
Disassemble specific functions with "llvm-objdump" in macOS.
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/env ruby | |
LLVM_OBJDUMP = "objdump" | |
options = %w( | |
--no-leading-addr | |
--no-show-raw-insn | |
--symbolize-operands | |
--x86-asm-syntax=intel | |
) | |
if ARGV.size < 2 | |
$stderr.puts("Usage: ruby dasym.rb $obj_file $pattern") | |
exit(-1) | |
end | |
obj_file = ARGV[0] | |
pattern = ARGV[1] | |
def get_syms(src) | |
src.lines.flat_map { |row| row.scan(/(?<=^.{24} __TEXT,__text ).+/) } | |
end | |
rows_raw = get_syms `#{LLVM_OBJDUMP} -t #{obj_file}` | |
rows_dec = get_syms `#{LLVM_OBJDUMP} -t #{obj_file} -C` | |
raise if rows_raw.size != rows_dec.size | |
rows_raw.zip(rows_dec).each { |sym, name| | |
system("#{LLVM_OBJDUMP} #{obj_file} --disassemble-symbols='#{sym}' #{options.join(' ')} | c++filt") if name.include?(pattern) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment