Last active
October 18, 2017 13:31
-
-
Save SakiiR/4f7d6a1477cd0891c584fa5c956ff9e4 to your computer and use it in GitHub Desktop.
Parse la sortie d'un ls /s Windows.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
CODEC = "latin-1" | |
def process(lines): | |
current_dir = None | |
filepaths = [] | |
for line in lines: | |
if "Directory of" in line: | |
current_dir = line.split(" ") | |
current_dir = current_dir[3] | |
else: | |
if len(line) > 5 and "<DIR>" not in line and "File(s)" not in line: | |
data = list(filter(None, line.split(" "))) | |
filepath = "".join(data[4:]) | |
if current_dir is not None: | |
filepath = current_dir + "\\" + filepath | |
if filepath not in filepaths: | |
filepaths.append(filepath) | |
return filepaths | |
def main(filepath): | |
""" Main prcoess """ | |
with open(filepath, "rb") as f: | |
print("[^] Reading file %s" % filepath) | |
lines = f.read().splitlines() | |
print("[^] Decoding %d lines" % len(lines)) | |
decoded = [] | |
for line in lines: | |
decoded.append(line.decode(CODEC)) | |
print("[^] Processing %d lines" % len(decoded)) | |
files = process(decoded) | |
print("[+] Here is your files: ") | |
list(filter(print, files)) | |
f.close() | |
print("[+] Done !") | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("[+] USAGE: %s OUTPUT_FILEPATH" % sys.argv[0]) | |
exit() | |
main(sys.argv[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Affiche le chemin complet de touts les fichiers sur la sortie standard