-
Notifications
You must be signed in to change notification settings - Fork 527
/
Copy pathstrip_binary.py
41 lines (30 loc) · 1.11 KB
/
strip_binary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# pyre-strict
"""
Strip a binary file using the ELF `strip` tool specified by a Skycastle workflow.
Usage:
strip_binary.py input_path output_path
Strip the ELF binary given by `input_path`, outputting the stripped
binary to `output_path`.
"""
import subprocess
import sys
from pathlib import Path
def main():
if len(sys.argv) != 3:
print("Must specify input and output file paths")
sys.exit(1)
input_file = Path(sys.argv[1])
output_file = Path(sys.argv[2])
# Assumes `strip` tool is in the path (should be specified by Skycastle workflow).
# GNU `strip`, or equivalent, should work for x86 and ARM ELF binaries. This might
# not be appropriate for more exotic, non-ELF toolchains.
completed = subprocess.run(["strip", "--strip-all", input_file, "-o", output_file])
sys.exit(completed.returncode)
if __name__ == "__main__":
main()