euler314 commited on
Commit
c99b4e2
·
verified ·
1 Parent(s): cf5c938

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -55
app.py CHANGED
@@ -16,8 +16,7 @@ This tool allows you to analyze various file types:
16
  - View information about .dll files
17
  """)
18
 
19
- # Maximum file size (10MB)
20
- MAX_FILE_SIZE = 10 * 1024 * 1024
21
 
22
  def unpack_exe(file_path, output_dir):
23
  """Extract information from an EXE file using pefile"""
@@ -166,61 +165,58 @@ def process_zip_file(file_path, temp_dir):
166
  uploaded_file = st.file_uploader("Upload a file (.zip, .exe, or .dll)", type=["zip", "exe", "dll"])
167
 
168
  if uploaded_file is not None:
169
- # Check file size
170
- if uploaded_file.size > MAX_FILE_SIZE:
171
- st.error(f"File too large. Maximum size is {MAX_FILE_SIZE/1024/1024}MB.")
172
- else:
173
- with tempfile.TemporaryDirectory() as temp_dir:
174
- # Save the uploaded file to the temporary directory
175
- file_path = os.path.join(temp_dir, uploaded_file.name)
176
- with open(file_path, "wb") as f:
177
- f.write(uploaded_file.getbuffer())
 
 
 
 
 
178
 
179
- st.success(f"File uploaded: {uploaded_file.name}")
180
 
181
- # Process based on file type
182
- if uploaded_file.name.lower().endswith('.zip'):
183
- st.subheader("ZIP File Contents")
184
- output_dir = os.path.join(temp_dir, "extracted")
185
- os.makedirs(output_dir, exist_ok=True)
 
186
 
187
- result = process_zip_file(file_path, output_dir)
188
-
189
- if 'error' in result:
190
- st.error(f"Error processing ZIP file: {result['error']}")
191
- else:
192
- with st.expander("ZIP Contents", expanded=True):
193
- st.write(f"Total files: {len(result['file_list'])}")
194
- st.json(result['file_list'])
195
-
196
- if result['nested_files']:
197
- st.subheader("Detected Executable Files")
198
- for file_path, file_info in result['nested_files'].items():
199
- with st.expander(f"{file_path} ({file_info['type'].upper()})"):
200
- st.json(file_info['info'])
201
 
202
- elif uploaded_file.name.lower().endswith('.exe'):
203
- st.subheader("EXE File Analysis")
204
- output_dir = os.path.join(temp_dir, "exe_unpacked")
205
- os.makedirs(output_dir, exist_ok=True)
206
 
207
- try:
208
- exe_info = unpack_exe(file_path, output_dir)
209
- st.json(exe_info)
210
-
211
- # Check if resources were extracted
212
- resource_dir = os.path.join(output_dir, "resources")
213
- if os.path.exists(resource_dir) and os.listdir(resource_dir):
214
- st.subheader("Extracted Resources")
215
- for resource_file in os.listdir(resource_dir):
216
- st.text(f"Resource: {resource_file}")
217
- except Exception as e:
218
- st.error(f"Error analyzing EXE file: {str(e)}")
219
-
220
- elif uploaded_file.name.lower().endswith('.dll'):
221
- st.subheader("DLL File Information")
222
- try:
223
- dll_info = analyze_dll(file_path)
224
- st.json(dll_info)
225
- except Exception as e:
226
- st.error(f"Error analyzing DLL file: {str(e)}")
 
16
  - View information about .dll files
17
  """)
18
 
19
+ # No size limit
 
20
 
21
  def unpack_exe(file_path, output_dir):
22
  """Extract information from an EXE file using pefile"""
 
165
  uploaded_file = st.file_uploader("Upload a file (.zip, .exe, or .dll)", type=["zip", "exe", "dll"])
166
 
167
  if uploaded_file is not None:
168
+ # Process file without size check
169
+ with tempfile.TemporaryDirectory() as temp_dir:
170
+ # Save the uploaded file to the temporary directory
171
+ file_path = os.path.join(temp_dir, uploaded_file.name)
172
+ with open(file_path, "wb") as f:
173
+ f.write(uploaded_file.getbuffer())
174
+
175
+ st.success(f"File uploaded: {uploaded_file.name}")
176
+
177
+ # Process based on file type
178
+ if uploaded_file.name.lower().endswith('.zip'):
179
+ st.subheader("ZIP File Contents")
180
+ output_dir = os.path.join(temp_dir, "extracted")
181
+ os.makedirs(output_dir, exist_ok=True)
182
 
183
+ result = process_zip_file(file_path, output_dir)
184
 
185
+ if 'error' in result:
186
+ st.error(f"Error processing ZIP file: {result['error']}")
187
+ else:
188
+ with st.expander("ZIP Contents", expanded=True):
189
+ st.write(f"Total files: {len(result['file_list'])}")
190
+ st.json(result['file_list'])
191
 
192
+ if result['nested_files']:
193
+ st.subheader("Detected Executable Files")
194
+ for file_path, file_info in result['nested_files'].items():
195
+ with st.expander(f"{file_path} ({file_info['type'].upper()})"):
196
+ st.json(file_info['info'])
197
+
198
+ elif uploaded_file.name.lower().endswith('.exe'):
199
+ st.subheader("EXE File Analysis")
200
+ output_dir = os.path.join(temp_dir, "exe_unpacked")
201
+ os.makedirs(output_dir, exist_ok=True)
 
 
 
 
202
 
203
+ try:
204
+ exe_info = unpack_exe(file_path, output_dir)
205
+ st.json(exe_info)
 
206
 
207
+ # Check if resources were extracted
208
+ resource_dir = os.path.join(output_dir, "resources")
209
+ if os.path.exists(resource_dir) and os.listdir(resource_dir):
210
+ st.subheader("Extracted Resources")
211
+ for resource_file in os.listdir(resource_dir):
212
+ st.text(f"Resource: {resource_file}")
213
+ except Exception as e:
214
+ st.error(f"Error analyzing EXE file: {str(e)}")
215
+
216
+ elif uploaded_file.name.lower().endswith('.dll'):
217
+ st.subheader("DLL File Information")
218
+ try:
219
+ dll_info = analyze_dll(file_path)
220
+ st.json(dll_info)
221
+ except Exception as e:
222
+ st.error(f"Error analyzing DLL file: {str(e)}")