Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for utf-8 encoded data #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ntdissector/ntds/ntds.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __getBootKey(self, bootKey=None, systemHive=None):
def __loadCache(self) -> None:
for k, p in self.__cacheFiles.items():
try:
self.__setattr__(f"_{self.__class__.__name__}{k}" if k.startswith("__") else k, loads(open(p, "r").read()))
self.__setattr__(f"_{self.__class__.__name__}{k}" if k.startswith("__") else k, loads(open(p, "r", encoding='utf-8').read()))
logging.debug("Loaded cache file %s into %s" % (p, k))
except Exception as e:
logging.error("Couldn't load cache file %s -> %s" % (p, e))
Expand All @@ -222,7 +222,7 @@ def __saveCache(self):
Path(self.__cachedir).mkdir(parents=True, exist_ok=True)
for k, v in self.__cacheFiles.items():
logging.debug("Saving %s into cache file %s" % (k, v))
open(v, "w").write(json_dumps(self.__getattribute__(f"_{self.__class__.__name__}{k}" if k.startswith("__") else k)))
open(v, "w", encoding='utf-8').write(json_dumps(self.__getattribute__(f"_{self.__class__.__name__}{k}" if k.startswith("__") else k)))

def __buildSchemas(self) -> None:
if self.__cacheLoaded and len(self.objectClassSchema["resolve"]) and len(self.attributeSchema["resolve"]) and self.rawEncPekList is not None:
Expand Down Expand Up @@ -710,7 +710,7 @@ def __dumpObjectWorker(self, workersQ: mp.Queue, workerLock: mp.Lock) -> None:
with workerLock:
logging.debug("Lock acquired by Worker-%s, dumping results" % wid)
for cName, res in results.items():
with open(f"{self.__outdir}/{cName}.json", "a") as outFile:
with open(f"{self.__outdir}/{cName}.json", "a", encoding='utf-8') as outFile:
outFile.write("\n".join([json_dumps(r) for r in res]))
outFile.write("\n")
break
Expand Down Expand Up @@ -768,7 +768,7 @@ def __reduce(record):
if cName not in stats:
stats[cName] = 0
# create empty file, zeroes out any existing output
open(f"{self.__outdir}/{cName}.json", "w").close()
open(f"{self.__outdir}/{cName}.json", "w", encoding='utf-8').close()
a = __reduce(record)
a["cName"] = cName
workersQ.put(a, block=True)
Expand Down
2 changes: 1 addition & 1 deletion ntdissector/tools/user_to_secretsdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
args = parser.parse_args()

for fl in args.files:
with open(fl, 'r') as f:
with open(fl, 'r', encoding='utf-8') as f:
for l in f:
try:
j = json.loads(l)
Expand Down