Last active
January 7, 2025 19:43
-
-
Save pmarkowsky/e49ef98c86f1df7a7af03beee5929fe6 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
| # Description: Convert Santa JSON rules to static rules | |
| # | |
| #$ python3 ./json-rules-to-static-rules.py --help | |
| #usage: json-rules-to-static-rules.py [-h] input output | |
| # | |
| #Convert Santa JSON rules to static rules | |
| # | |
| #positional arguments: | |
| # input Input JSON file | |
| # output Output file | |
| # | |
| #options: | |
| # -h, --help show this help message and exit | |
| # | |
| import argparse | |
| import json | |
| # Convert JSON to plist-like format (manually creating XML structure) | |
| def dict_to_plist(data): | |
| plist = [] | |
| for key, value in data.items(): | |
| plist.append(f"<key>{key}</key>") | |
| if isinstance(value, list): | |
| plist.append("<array>") | |
| for item in value: | |
| plist.append(" <dict>") | |
| for sub_key, sub_value in item.items(): | |
| plist.append(f" <key>{sub_key}</key>") | |
| plist.append(f" <string>{sub_value}</string>") | |
| plist.append(" </dict>") | |
| plist.append("</array>") | |
| else: | |
| plist.append(f"<string>{value}</string>") | |
| plist.append("</dict>") | |
| return "\n".join(plist) | |
| def main(): | |
| parser = argparse.ArgumentParser(description='Convert Santa JSON rules to static rules') | |
| parser.add_argument('input', type=str, help='Input JSON file') | |
| parser.add_argument('output', type=str, help='Output file') | |
| args = parser.parse_args() | |
| with open(args.input, "r") as f: | |
| json_data = json.load(f) | |
| with open(args.output, "w") as f: | |
| f.write(dict_to_plist(json_data)) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment