#!/usr/bin/env python
import os

GHIDRA_BIN_FILE = "ghidra_bin_location.txt"

dir = open(GHIDRA_BIN_FILE, "rb")
dir_str = dir.read().decode("utf-8").rstrip("\n\r")
pwd = os.path.dirname(os.path.realpath(__file__))
if(len(dir_str) < 1) :
    print("empty string in file")
    exit(0)
java_files = []
for root, dirs, files in os.walk(pwd):
    for f in files:
        if(f.endswith(".java")):
            java_files.append(str(f[:-5]))
for root, dirs, files in os.walk(dir_str):
    for f in files:
        if(f.endswith(".class") and f[:-6] in java_files):
            if(not(root.endswith("/"))): root = root+"/"
            os.remove(root + f)
            print("deleted: "+root[len(dir_str):]+f)
