-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfileops.py
184 lines (174 loc) · 7.1 KB
/
fileops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import os, pwd, sys, gi, time, re, struct
from subprocess import Popen, PIPE
from gi.repository import Gtk
home = pwd.getpwuid(os.getuid()).pw_dir + '/SSAK/'
execdir = os.path.dirname(os.path.realpath(sys.argv[0]))
class fileops:
def fileselect(self, widget):
chooser = Gtk.FileChooserDialog("Select file to Analyze", None, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_SAVE,Gtk.ResponseType.OK))
response = chooser.run()
if response == Gtk.ResponseType.OK:
self.filename = str(chooser.get_filename())
self.file.set_text(self.filename)
head, tail = os.path.split(self.filename)
fileselected = tail
if not os.path.isdir(home + fileselected):
os.mkdir(home + fileselected)
cmd = 'file -b ' + re.escape(self.filename)
proc = Popen(cmd, shell = True,stdout=PIPE).communicate()[0]
for cake in proc.splitlines():
self.fileinfo.set_text(cake)
chooser.destroy()
elif response == Gtk.ResponseType.CANCEL:
chooser.destroy()
chooser.connect("delete-event", lambda window, event: chooser.hide() or True)
def ident(self):
cmd = 'file -b ' + re.escape(self.outfile)
proc = Popen(cmd, shell = True,stdout=PIPE).communicate()[0]
for cake in proc.splitlines():
print cake
if "ASCII" in cake:
os.rename(self.outfile,self.outfile + ".txt")
self.outfile = self.outfile + ".txt"
elif "JPEG" in cake:
os.rename(self.outfile,self.outfile + ".jpg")
self.outfile = self.outfile + ".jpg"
elif "PNG" in cake:
os.rename(self.outfile,self.outfile + ".png")
self.outfile = self.outfile + ".png"
elif "GIF" in cake:
os.rename(self.outfile,self.outfile + ".gif")
self.outfile = self.outfile + ".gif"
elif "PC bitmap" in cake:
os.rename(self.outfile,self.outfile + ".bmp")
self.outfile = self.outfile + ".bmp"
elif "SVG Scalable Vector Graphics image" in cake:
os.rename(self.outfile,self.outfile + ".svg")
self.outfile = self.outfile + ".svg"
elif "MP4" in cake:
os.rename(self.outfile,self.outfile + ".mp4")
self.outfile = self.outfile + ".mp4"
elif "ISO 9660" in cake:
os.rename(self.outfile,self.outfile + ".iso")
self.outfile = self.outfile + ".iso"
elif "gzip" in cake:
os.rename(self.outfile,self.outfile + ".gz")
self.outfile = self.outfile + ".gz"
elif "7-zip" in cake:
os.rename(self.outfile,self.outfile + ".7z")
self.outfile = self.outfile + ".7z"
elif "Zip" in cake:
os.rename(self.outfile,self.outfile + ".zip")
self.outfile = self.outfile + ".zip"
elif "bzip2" in cake:
os.rename(self.outfile,self.outfile + ".bz2")
self.outfile = self.outfile + ".bz2"
elif "XZ compressed data" in cake:
os.rename(self.outfile,self.outfile + ".xz")
self.outfile = self.outfile + ".xz"
elif "HTML" in cake:
os.rename(self.outfile,self.outfile + ".html")
self.outfile = self.outfile + ".html"
elif "PDF" in cake:
os.rename(self.outfile,self.outfile + ".PDF")
self.outfile = self.outfile + ".pdf"
elif "XML document text" in cake:
os.rename(self.outfile,self.outfile + ".xml")
self.outfile = self.outfile + ".xml"
elif "Microsoft Word" in cake:
os.rename(self.outfile,self.outfile + ".doc")
self.outfile = self.outfile + ".doc"
elif "Microsoft PowerPoint" in cake:
os.rename(self.outfile,self.outfile + ".ppt")
self.outfile = self.outfile + ".ppt"
elif "OpenDocument Text" in cake:
os.rename(self.outfile,self.outfile + ".odt")
self.outfile = self.outfile + ".odt"
elif "OpenDocument Presentation" in cake:
os.rename(self.outfile,self.outfile + ".odp")
self.outfile = self.outfile + ".odp"
elif "PE32 executable (DLL) (GUI)" in cake:
os.rename(self.outfile,self.outfile + ".dll")
self.outfile = self.outfile + ".dll"
elif "PE32 executable (GUI)" in cake:
os.rename(self.outfile,self.outfile + ".exe")
self.outfile = self.outfile + ".exe"
elif "Java archive data" in cake:
os.rename(self.outfile,self.outfile + ".jar")
self.outfile = self.outfile + ".jar"
elif "POSIX shell script" in cake:
os.rename(self.outfile,self.outfile + ".sh")
self.outfile = self.outfile + ".sh"
elif "ELF 32-bit LSB shared object" in cake:
os.rename(self.outfile,self.outfile + ".so")
self.outfile = self.outfile + ".so"
elif "Debian binary package" in cake:
os.rename(self.outfile,self.outfile + ".deb")
self.outfile = self.outfile + ".deb"
elif "RPM" in cake:
os.rename(self.outfile,self.outfile + ".rpm")
self.outfile = self.outfile + ".rpm"
elif "MPEG ADTS, layer III" in cake:
os.rename(self.outfile,self.outfile + ".mp3")
self.outfile = self.outfile + ".mp3"
elif "Vorbis audio" in cake:
os.rename(self.outfile,self.outfile + ".ogg")
self.outfile = self.outfile + ".ogg"
elif "Python script" in cake:
os.rename(self.outfile,self.outfile + ".py")
self.outfile = self.outfile + ".py"
print self.outfile
def exif(self, widget):
filetype = self.fileinfo.get_text()
sfile = self.file.get_text()
if sfile != '':
if "JPEG" in filetype:
cmd = 'java -cp ' + re.escape(execdir) + '/programs/noarch/metadata-extractor2-2.jar:' + re.escape(execdir) + '/programs/noarch/xmpcore.jar com.drew.imaging.ImageMetadataReader ' + re.escape(sfile)
proc = Popen(cmd, shell = True,stdout=PIPE)
self.textbuffer.set_text(str(proc.communicate()[0]))
else:
self.textbuffer.set_text("File must be jpeg/jpg!!!")
else:
self.buffer1.set_text("Please select a file from the file menu!")
self.showdiag()
def strings(self, widget):
sfile = self.file.get_text()
if sfile != '':
# runs strings command on input file and
# outputs the result into textbuffer for display
sfile = self.file.get_text()
cmd = re.escape(execdir) + '/programs/' + self.arch + '/strings ' + re.escape(sfile)
proc = Popen(cmd, shell = True,stdout=PIPE)
self.stextbuffer.set_text(str(proc.communicate()[0]))
else:
self.buffer1.set_text("Please select a file from the file menu!")
self.showdiag()
def strings2(self, widget):
sfile = self.file.get_text()
if sfile != '':
# runs strings command on input file and
# outputs the result into textbuffer for display
sfile = self.file.get_text()
cmd = re.escape(execdir) + '/programs/' + self.arch + '/strings ' + re.escape(sfile)
proc = Popen(cmd, shell = True,stdout=PIPE)
self.stextbuffer.set_text(str(proc.communicate()))
else:
self.buffer1.set_text("Please select a file from the file menu!")
self.showdiag()
def carveit2(self, widget):
sfile = self.file.get_text()
if sfile != '':
head, tail = os.path.split(sfile)
outdir = home + tail + '/foremost'
if os.path.isdir(outdir):
cmd = 'rm -rf ' + outdir
proc = Popen(cmd, shell = True)
time.sleep(3)
os.mkdir(outdir)
cmd = re.escape(execdir) + '/programs/' + self.arch + '/foremost -c ' + re.escape(execdir) + '/programs/noarch/foremost.conf -o ' + re.escape(outdir) + ' -i ' + re.escape(sfile)
proc = Popen(cmd, shell = True)
self.buffer1.set_text("Output files in " + outdir + "!")
self.showdiag()
else:
self.buffer1.set_text("Please select a file from the file menu!")
self.showdiag()