strip-binaries.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. import argparse
  3. import os
  4. import sys
  5. from lib.config import enable_verbose_mode
  6. from lib.util import execute, get_linux_binaries, get_out_dir
  7. def strip_binaries(directory, target_cpu):
  8. for binary in get_linux_binaries():
  9. binary_path = os.path.join(directory, binary)
  10. if os.path.isfile(binary_path):
  11. strip_binary(binary_path, target_cpu)
  12. def strip_binary(binary_path, target_cpu):
  13. if target_cpu == 'arm':
  14. strip = 'arm-linux-gnueabihf-strip'
  15. elif target_cpu == 'arm64':
  16. strip = 'aarch64-linux-gnu-strip'
  17. else:
  18. strip = 'strip'
  19. execute([
  20. strip, '--discard-all', '--strip-debug', '--preserve-dates',
  21. binary_path])
  22. def main():
  23. args = parse_args()
  24. if args.verbose:
  25. enable_verbose_mode()
  26. if args.file:
  27. strip_binary(args.file, args.target_cpu)
  28. else:
  29. strip_binaries(args.directory, args.target_cpu)
  30. def parse_args():
  31. parser = argparse.ArgumentParser(description='Strip linux binaries')
  32. parser.add_argument('-d', '--directory',
  33. help='Path to the dir that contains files to strip.',
  34. default=get_out_dir(),
  35. required=False)
  36. parser.add_argument('-f', '--file',
  37. help='Path to a specific file to strip.',
  38. required=False)
  39. parser.add_argument('-v', '--verbose',
  40. action='store_true',
  41. help='Prints the output of the subprocesses')
  42. parser.add_argument('--target-cpu',
  43. default='',
  44. required=False,
  45. help='Target cpu of binaries to strip')
  46. return parser.parse_args()
  47. if __name__ == '__main__':
  48. sys.exit(main())