Skip to content

Commit 8ff2a5f

Browse files
authored
Add files via upload
1 parent fd028a3 commit 8ff2a5f

File tree

10 files changed

+397
-85
lines changed

10 files changed

+397
-85
lines changed
798 Bytes
Loading
908 Bytes
Loading
811 Bytes
Loading

OneDriveExplorer/Images/splash.png

-1.85 KB
Loading

OneDriveExplorer/Images/splashv.png

228 Bytes
Loading

OneDriveExplorer/OneDriveExplorer.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616

1717
__author__ = "Brian Maloney"
18-
__version__ = "2022.03.04"
18+
__version__ = "2022.03.11"
1919
__email__ = "[email protected]"
2020

2121
ASCII_BYTE = rb" !#\$%&\'\(\)\+,-\.0123456789;=@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\]\^_`abcdefghijklmnopqrstuvwxyz\{\}\~\t"
@@ -52,8 +52,11 @@ def subset(dict_, keys):
5252
cache = {}
5353
final = []
5454

55-
for row in df.sort_values(by=['Level', 'ParentId', 'Type'], ascending=[False, False, False]).to_dict('records'):
56-
file = subset(row, keys=('ParentId', 'DriveItemId', 'eTag', 'Type', 'Name', 'Size', 'Children'))
55+
df.loc[df.Type == 'File', ['FileSort']] = df['Name'].str.lower()
56+
df.loc[df.Type == 'Folder', ['FolderSort']] = df['Name'].str.lower()
57+
58+
for row in df.sort_values(by=['Level', 'ParentId', 'Type', 'FileSort', 'FolderSort'], ascending=[False, False, False, True, False]).to_dict('records'):
59+
file = subset(row, keys=('ParentId', 'DriveItemId', 'eTag', 'Type', 'Path', 'Name', 'Size', 'Children'))
5760
if row['Type'] == 'File':
5861
folder = cache.setdefault(row['ParentId'], {})
5962
folder.setdefault('Children', []).append(file)
@@ -70,10 +73,12 @@ def subset(dict_, keys):
7073
'DriveItemId': '',
7174
'eTag': '',
7275
'Type': 'Root Drive',
76+
'Path': '',
7377
'Name': name,
7478
'Size': '',
7579
'Children': ''
7680
}
81+
7782
cache['Children'] = final
7883

7984
if pretty:
@@ -100,10 +105,7 @@ def subset(dict_, keys):
100105
def print_csv(df, name, csv_path, csv_name):
101106
df = df.sort_values(by=['Level', 'ParentId', 'Type'], ascending=[True, False, False])
102107
df = df.drop(['Children', 'Level'], axis=1)
103-
id_name_dict = dict(zip(df.DriveItemId, df.Name))
104-
parent_dict = dict(zip(df.DriveItemId, df.ParentId))
105108

106-
df['Path'] = df.DriveItemId.apply(lambda x: find_parent(x, id_name_dict, parent_dict).lstrip('\\\\'))
107109
csv_file = os.path.basename(name).split('.')[0]+"_OneDrive.csv"
108110
if csv_name:
109111
csv_file = csv_name
@@ -116,10 +118,7 @@ def print_csv(df, name, csv_path, csv_name):
116118
def print_html(df, name, html_path):
117119
df = df.sort_values(by=['Level', 'ParentId', 'Type'], ascending=[True, False, False])
118120
df = df.drop(['Children', 'Level'], axis=1)
119-
id_name_dict = dict(zip(df.DriveItemId, df.Name))
120-
parent_dict = dict(zip(df.DriveItemId, df.ParentId))
121121

122-
df['Path'] = df.DriveItemId.apply(lambda x: find_parent(x, id_name_dict, parent_dict).lstrip('\\\\'))
123122
html_file = os.path.basename(name).split('.')[0]+"_OneDrive.html"
124123
file_extension = os.path.splitext(name)[1][1:]
125124
if file_extension == 'previous':
@@ -160,25 +159,32 @@ def parse_onedrive(usercid, reghive, json_path, csv_path, csv_name, pretty, html
160159
'Size',
161160
'Children'])
162161
dir_index = []
163-
for match in re.finditer(uuid4hex, f.read()):
164-
s = match.start()
165-
eTag = match.group(1).decode("utf-8")
162+
entries = re.finditer(uuid4hex, f.read())
163+
current = next(entries, total)
164+
while isinstance(current, re.Match):
165+
s = current.start()
166+
eTag = current.group(1).decode("utf-8")
166167
count = s
167168
diroffset = s - 39
168169
objoffset = s - 78
169170
f.seek(objoffset)
170171
ouuid = f.read(32).decode("utf-8").strip('\u0000')
171172
f.seek(diroffset)
172173
duuid = f.read(32).decode("utf-8").strip('\u0000')
173-
name, name_s = unicode_strings(f.read(400))
174+
n_current = next(entries, total)
175+
try:
176+
buffer = n_current.start() - f.tell()
177+
except AttributeError:
178+
buffer = n_current - f.tell()
179+
name, name_s = unicode_strings(f.read(buffer))
174180
try:
175181
sizeoffset = diroffset + 24 + name_s
176182
f.seek(sizeoffset)
177183
size = int.from_bytes(f.read(8), "little")
178184
except:
179185
size = name_s
180186
f.seek(diroffset + 32)
181-
logging.error(f'An error occured trying to find the name of {ouuid}. Raw Data:{f.read(400)}')
187+
logging.error(f'An error occured trying to find the name of {ouuid}. Raw Data:{f.read(buffer)}')
182188
if not dir_index:
183189
if reghive and personal:
184190
try:
@@ -212,18 +218,15 @@ def parse_onedrive(usercid, reghive, json_path, csv_path, csv_name, pretty, html
212218

213219
dir_index.append(input)
214220
progress(count, total, status='Building folder list. Please wait....')
221+
current = n_current
215222

216223
print('\n')
217224

218225
df = pd.DataFrame.from_records(dir_index)
219226
df.loc[(df.DriveItemId.isin(df.ParentId)) | (df.Size == 2880154368), ['Type', 'Size']] = ['Folder', '']
220227
df.at[0, 'Type'] = 'Root Default'
221-
id_name_dict = dict(zip(df.DriveItemId, df.Name))
222-
parent_dict = dict(zip(df.DriveItemId, df.ParentId))
223-
224-
df['Level'] = df.DriveItemId.apply(lambda x: len(find_parent(x, id_name_dict, parent_dict).lstrip('\\\\').split('\\\\')))
225228

226-
share_df = df.loc[(df.Level == 1) & (~df.ParentId.isin(df.DriveItemId)) & (df.Type != 'Root Default')]
229+
share_df = df.loc[(~df.ParentId.isin(df.DriveItemId)) & (df.Type != 'Root Default')]
227230
share_list = list(set(share_df.ParentId))
228231
share_root = []
229232

@@ -251,6 +254,12 @@ def parse_onedrive(usercid, reghive, json_path, csv_path, csv_name, pretty, html
251254
logging.warning(f'Unable to read registry hive! {e}')
252255
pass
253256

257+
id_name_dict = dict(zip(df.DriveItemId, df.Name))
258+
parent_dict = dict(zip(df.DriveItemId, df.ParentId))
259+
df['Path'] = df.DriveItemId.apply(lambda x: find_parent(x, id_name_dict, parent_dict).lstrip('\\\\').split('\\\\'))
260+
df['Level'] = df['Path'].str.len()
261+
df['Path'] = df['Path'].str.join('\\')
262+
254263
if csv_path:
255264
print_csv(df, f.name, csv_path, csv_name)
256265
if html_path:

0 commit comments

Comments
 (0)