| 4 | import base64 |
| 5 | |
| 6 | def detect(path): |
| 7 | print("Checking model", path) |
| 8 | |
| 9 | with open(path, "rb") as f: |
| 10 | content = f.read().decode("latin-1") |
| 11 | |
| 12 | body = re.search("{(.*)}", content).group() |
| 13 | model = json.loads(body) |
| 14 | found = 0 |
| 15 | for layer in model["config"]["layers"]: |
| 16 | if layer['class_name'] != "Lambda": |
| 17 | continue |
| 18 | |
| 19 | print("\nFound Lambda layer with name \"" + layer["config"]["name"] + "\"") |
| 20 | |
| 21 | func = layer["config"]["function"] |
| 22 | print("With body function:") |
| 23 | print("Raw base64:") |
| 24 | print(func[0]) |
| 25 | decoded = base64.b64decode(func[0]).decode("latin-1") |
| 26 | print("Decoded:") |
| 27 | print(decoded) |
| 28 | found += 1 |
| 29 | |
| 30 | print("\nFound {} Lambda functions".format(found)) |
| 31 | |
| 32 | |
| 33 | if __name__ == "__main__": |