2
2
import subprocess
3
3
import time
4
4
from datetime import datetime
5
+ import modules .sha_hashes as sha_hashes
5
6
6
7
7
8
class Bcolors :
@@ -109,21 +110,28 @@ def get_acquistion(APP, DEVICE, DATA, callback=None, folder=''):
109
110
FILENAME = APP + "-v" + str (VERSION ) + "-" + DATA + "--" + DEVNAME + str (ANDROID ) + "-u" + str (
110
111
USER ) + "--" + datetime .now ().strftime ("%Y%m%d-%H%M%S" ) + ".tar"
111
112
113
+ OUTPUT_FOLDER = FILENAME [:- 4 ]
114
+ if folder != '' :
115
+ OUTPUT_FOLDER = folder + "/" + OUTPUT_FOLDER
116
+ OUTPUT_FILE = OUTPUT_FOLDER + "/" + "sha256_hashes.txt"
117
+ # create the folder
118
+ if not os .path .exists (OUTPUT_FOLDER ):
119
+ os .makedirs (OUTPUT_FOLDER )
120
+
112
121
print_message (callback , "[Info ] " + APP + " version: " + str (VERSION ))
113
122
print_message (callback , "[Info ] Android version: " + str (ANDROID ))
114
123
115
124
print_message (callback , "[Info ] Copying data from " + APP + " version " + VERSION + " ..." )
116
125
117
126
if DATA == "private" or DATA == "public" :
118
127
if DATA == "private" :
119
- print ("[Info ] Calculating hashes..." )
120
- hashes_output = subprocess .run (ADB + " " + DEVICE + " shell " + CMD + "'find /data/data/" + APP + END + " -type f -exec sha256sum {} \;'" , stdout = subprocess .PIPE , shell = True )
121
- output = hashes_output .stdout .decode ("utf-8" ).strip ()
122
128
print_message (callback , "[Info ] Acquiring private data" )
123
129
# Primary method used to copy the data from the application
124
130
# In windows this process was better when dealing with threads such as in the GUI
125
131
if callback is not None and os .name == 'nt' :
126
- subprocess .run (ADB + " " + DEVICE + " shell " + CMD + " tar -cvzf /sdcard/Download/" + FILENAME + " /data/data/" + APP + END , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , shell = True )
132
+ subprocess .run (
133
+ ADB + " " + DEVICE + " shell " + CMD + " tar -cvzf /sdcard/Download/" + FILENAME + " /data/data/" + APP + END ,
134
+ stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , shell = True )
127
135
else :
128
136
# Method used in the bash script to copy the data from the application
129
137
# Check for filename with spaces
@@ -138,23 +146,27 @@ def get_acquistion(APP, DEVICE, DATA, callback=None, folder=''):
138
146
stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , shell = True )
139
147
140
148
elif DATA == "public" :
141
- print ("[Info ] Calculating hashes..." )
142
- hashes_output = subprocess .run (
143
- ADB + " " + DEVICE + " shell " + CMD + "'find /storage/emulated/0/Android/data/" + APP + END + " -type f -exec sha256sum {} \;'" ,
144
- stdout = subprocess .PIPE , shell = True )
145
- output = hashes_output .stdout .decode ("utf-8" ).strip ()
146
149
print_message (callback , "[Info ] Acquiring public data" )
147
150
# Primary method used to copy the data from the application
148
151
# In windows this process was better when dealing with threads such as in the GUI
149
152
if callback is not None and os .name == 'nt' :
150
- subprocess .run (ADB + " " + DEVICE + " shell " + CMD + " tar -cvzf /sdcard/Download/" + FILENAME + " /storage/emulated/0/Android/data/" + APP + END , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , shell = True )
153
+ subprocess .run (
154
+ ADB + " " + DEVICE + " shell " + CMD + " tar -cvzf /sdcard/Download/" + FILENAME + " /storage/emulated/0/Android/data/" + APP + END ,
155
+ stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , shell = True )
151
156
else :
152
157
# Method used in the bash script to copy the data from the application
153
158
# Check for filename with spaces
154
159
subprocess .run (
155
160
ADB + " " + DEVICE + " shell " + CMD + " tar -cvzf /sdcard/Download/" + FILENAME + " /storage/emulated/0/Android/data/" + APP + END ,
156
161
stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , shell = SHELL )
157
162
163
+ OUTPUT_FOLDER = FILENAME [:- 4 ]
164
+ if folder != '' :
165
+ OUTPUT_FOLDER = folder + "/" + OUTPUT_FOLDER
166
+ OUTPUT_FILE = OUTPUT_FOLDER + "/" + "sha256_hashes.txt"
167
+ # create the folder
168
+ if not os .path .exists (OUTPUT_FOLDER ):
169
+ os .makedirs (OUTPUT_FOLDER )
158
170
# Retrieve the file from the device and save it to the current directory and remove the file from the device
159
171
print_message (callback , "[Info ] Copying to local storage ..." )
160
172
print_message (callback , "[Info ] Compressing " + FILENAME + " ..." )
@@ -163,25 +175,25 @@ def get_acquistion(APP, DEVICE, DATA, callback=None, folder=''):
163
175
print_message (callback , "[Info] Compressing Terminated." )
164
176
165
177
print_message (callback , "[Info ] Copying to local storage ..." )
166
- if folder == '' :
167
- subprocess .run (ADB + " " + DEVICE + " pull /sdcard/Download/" + FILENAME + ".gz" , stdout = subprocess .DEVNULL ,
168
- shell = True )
169
- else :
170
- subprocess .run (ADB + " " + DEVICE + " pull /sdcard/Download/" + FILENAME + ".gz " + folder ,
171
- stdout = subprocess .DEVNULL , shell = True )
178
+ subprocess .run (ADB + " " + DEVICE + " pull /sdcard/Download/" + FILENAME + ".gz " + OUTPUT_FOLDER ,
179
+ stdout = subprocess .DEVNULL ,
180
+ shell = True )
172
181
print_message (callback , "[Info ] Copy Terminated." )
173
182
print ("[Info ] Creating hashes file..." )
174
183
# Check if the command executed successfully
175
- if output == '' :
176
- print_message (callback , "[Info ] No hashes to store." , "error" )
177
- return
178
184
# Save the output to a file
179
- #remove any \r\n
180
- H_APP = APP .replace ('\r ' , '' )
181
- H_FILENAME = H_APP + "-" + DATA + "--sha256_hashes"
182
- OUTPUT_FILE = folder + "/" + H_FILENAME + ".txt"
183
- with open (OUTPUT_FILE , 'w' ) as f :
184
- f .write (output )
185
+
186
+ # unzip the file
187
+ print_message (callback , "[Info ] Unzipping file..." )
188
+ subprocess .run ("gzip -d " + OUTPUT_FOLDER + "/" + FILENAME + ".gz" , stdout = subprocess .DEVNULL , shell = True )
189
+ print_message (callback , "[Info ] Unzip Terminated." )
190
+ # untar the file
191
+ print_message (callback , "[Info ] Untaring file..." )
192
+ subprocess .run ("tar -xvf " + OUTPUT_FOLDER + "/" + FILENAME + " -C " + OUTPUT_FOLDER , stdout = subprocess .DEVNULL ,
193
+ stderr = subprocess .DEVNULL , shell = True )
194
+ print_message (callback , "[Info ] Untar Terminated." )
195
+ print_message (callback , "[Info ] Calculating hashes." )
196
+ sha_hashes .calculate_sha256_for_directory (OUTPUT_FOLDER , OUTPUT_FILE )
185
197
186
198
print_message (callback , "[Info ] Cleaning acquisition files from phone..." )
187
199
subprocess .run (ADB + " " + DEVICE + " shell rm /sdcard/Download/" + FILENAME + ".gz" , stdout = subprocess .DEVNULL ,
@@ -195,31 +207,20 @@ def get_acquistion(APP, DEVICE, DATA, callback=None, folder=''):
195
207
APK = APK .stdout .decode ("utf-8" ).strip ()
196
208
APK = APK .split (":" )[1 ]
197
209
print_message (callback , "[Info ] APK: " + APK )
198
- if folder == '' :
199
- subprocess .run (ADB + " " + DEVICE + " pull " + APK + " " + APP + ".apk" , shell = True )
200
- else :
201
- subprocess .run (ADB + " " + DEVICE + " pull " + APK + " " + folder + "/" + APP + ".apk" , shell = True )
202
210
203
- #calculate sha256 of the apk
211
+ subprocess .run (ADB + " " + DEVICE + " pull " + APK + " " + APP + ".apk" , stdout = subprocess .DEVNULL , shell = True )
212
+ os .rename ("base.apk" , APP + ".apk" )
213
+ # move the apk to the output folder
214
+ os .rename (APP + ".apk" , OUTPUT_FOLDER + "/" + APP + ".apk" )
215
+
216
+ # calculate sha256 of the apk
204
217
print_message (callback , "[Info ] Calculating hashes..." )
205
- hashes_output = subprocess .run (
206
- ADB + " " + DEVICE + " shell " + CMD + "'sha256sum " + APK + "'" ,
207
- stdout = subprocess .PIPE , shell = True )
208
- output = hashes_output .stdout .decode ("utf-8" ).strip ()
209
- print_message (callback , "[Info ] Creating hashes file..." )
210
- # Check if the command executed successfully
211
- if output == '' :
212
- print_message (callback , "[Info ] No hashes to store." , "error" )
213
- return
214
- # Save the output to a file
215
- # remove any \r\n
216
- H_APP = APP .replace ('\r ' , '' )
217
- H_FILENAME = H_APP + "-" + DATA + "--sha256_hashes"
218
- OUTPUT_FILE = folder + "/" + H_FILENAME + ".txt"
219
- with open (OUTPUT_FILE , 'w' ) as f :
220
- f .write (output )
221
- print_message (callback , "[Done ] Operation Completed with success, generated file: " + APP + ".apk" , "ok" )
218
+ sha256 = sha_hashes .calculate_sha256 (OUTPUT_FOLDER + "/" + APP + ".apk" )
219
+ # save the sha256 to a file
220
+ with open (OUTPUT_FILE , "w" ) as file :
221
+ file .write (f"{ sha256 } *{ APP } .apk\n " )
222
222
223
+ print_message (callback , "[Done ] Operation Completed with success, generated file: " + APP + ".apk" , "ok" )
223
224
else :
224
- print_message (callback , "[ERROR] Invalid data type!" , "error" )
225
+ print_message (callback , "[ERROR] Invalid data type!" , "error" )
225
226
return
0 commit comments