-
Notifications
You must be signed in to change notification settings - Fork 2
/
snoop.cpp
505 lines (483 loc) · 18.9 KB
/
snoop.cpp
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#include <iostream>
#include <fstream>
#include <cstring>
#include <cerrno>
#include <ctime>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <map>
// Function to get the file type based on the file extension
std::string getFileType(const std::string& filename) {
static const std::map<std::string, std::string> extensionMap = {
{".cpp", "C++ Source Code"},
{".cc", "C++ Source Code"},
{".cxx", "C++ Source Code"},
{".c", "C Source Code"},
{".h", "C/C++ Header"},
{".py", "Python Source Code"},
{".sh", "Bash Script"},
{".java", "Java Source Code"},
{".js", "Javascript Source Code"},
{".rb", "Ruby Source Code"},
{".pl", "Perl Source Code"},
{".pm", "Perl Source Code"},
{".php", "PHP Source Code"},
{".swift", "Swift Source Code"},
{".kt", "Kotlin Source Code"},
{".rs", "Rust Source Code"},
{".go", "Go Source Code"},
{".ts", "Typescript Source Code"},
{".scala", "Scala Source Code"},
{".lua", "Lua Source Code"},
{".hs", "Java HelpSet File"},
{".r", "R Source Code"},
{".m", "Matlab Source Code"},
{".asm", "Assembly Source Code"},
{".S", "Assembly Source Code"},
{".txt", "Plain Text File"},
{".pdf", "PDF Document"},
{".doc", "Microsoft Word Document (Legacy)"},
{".docx", "Microsoft Word Document"},
{".xls", "Microsoft Excel Spreadsheet"},
{".xlsx", "Microsoft Excel Spreadsheet"},
{".ppt", "Microsoft PowerPoint Presentation"},
{".pptx", "Microsoft PowerPoint Presentation"},
{".gif", "Graphics Interchange Format"},
{".png", "Portable Network Graphics"},
{".jpg", "JPEG Image"},
{".jpeg", "JPEG Image"},
{".bmp", "Bitmap Image"},
{".svg", "Scalable Vector Graphics"},
{".mp3", "MP3 Audio"},
{".mp4", "MP4 Video"},
{".mkv", "Matroska Video"},
{".zip", "Zip Archive"},
{".tar", "Tape Archive"},
{".exe", "Windows Executable File"},
{".deb", "Debian/Ubuntu Package File"},
{".rpm", "Red Hat/Fedora Package File"},
{".iso", "CD/DVD Disk Image"},
{".so", "Shared Object Library"},
{".odt", "OpenDocument Text Document"},
{".rtf", "Rich Text Format File"},
{".html", "HTML Document"},
{".xml", "XML Document"},
{".ods", "OpenDocument Spreadsheet"},
{".csv", "Comma-Separated Values"},
{".tsv", "Tab-Separated Values"},
{".odp", "Organ Definition Project"},
{".wav", "Waveform Audio File"},
{".aac", "Advanced Audio Coding"},
{".flac", "Free Lossless Audio Codec"},
{".ogg", "Ogg Vorbis"},
{".midi", "Musical Instrument Digital Interface"},
{".avi", "Audio Video Interleave"},
{".mov", "QuickTime Movie"},
{".wmv", "Windows Media Video"},
{".flv", "Flash Video"},
{".rar", "RAR Archive"},
{".7z", "7-Zip Compressed File"},
{".bz2", "Bzip2 Compressed File"},
{".sql", "Structured Query Language"},
{".db", "Database File"},
{".accdb", "Microsoft Access Database"},
{".json", "JavaScript Object Notation"},
{".dll", "Dynamic Link Library"},
{".apk", "Android Package File"},
{".ttf", "TrueType Font File"},
{".otf", "OpenType Font File"},
{".org", "Emacs Org Text Document"},
{".dat", "Prison Architect Asset Archive"},
{".tmvx", "TextMaker Document Template"},
{".adoc", "AsciiDoc Document"},
{".dotx", "Microsoft Word Template"},
{".smf", "StarMath Formula File"},
{".sty", "LaTeX Style"},
{".lst", "FoxPro Documenting Wizard List"},
{".man", "Unix Manual"},
{".upd", "Program Update Information"},
{".gform", "Google Forms Shortcut"},
{".fpt", "FoxPro Table Memo"},
{".sam", "Ami Pro Document"},
{".qbl", "QuickBooks License File"},
{".dotm", "Microsoft Word Macro-Enabled Document Template"},
{".save", "Nano Temporary Save File"},
{".gsite", "Google Sites Shortcut"},
{".embed", "Embed Notes Note"},
{".wtt", "Write! Document"},
{".dsc", "Text Description File"},
{".diz", "Description in Zip File"},
{".fcf", "Final Draft Converter File"},
{".me", "Readme Text File"},
{".mnt", "FoxPro Menu Memo"},
{".ltxd", "Light Text Editor Document"},
{".lxfml", "LEGO Digital Designer XML File"},
{".story", "Storyist Document"},
{".ltx", "LaTeX Document"},
{".fountain", "Fountain Script File"},
{".mpd", "MPEG-DASH Media Presentation Description"},
{".eio", "Yozo Office File"},
{".lue", "Norton LiveUpdate Log File"},
{".tmdx", "TextMaker Document"},
{".gpd", "Generic Printer Description File"},
{".rft", "Revisable Form Text Document"},
{".b", "Brainf*ck Source Code File"},
{".apt", "Almost Plain Text File"},
{".odm", "OpenDocument Master Document"},
{".ans", "ANSI Text File"},
{".fbl", "CADfix Command Level Log File"},
{".gdoc", "Google Docs Shortcut"},
{".aww", "Ability Write Document"},
{".vnt", "Mobile Phone vNote File"},
{".log", "Log File"},
{".klg", "Log File"},
{".fadein.template", "Fade In Template"},
{".pwdpl", "Password Pad Lite Document"},
{".cec", "Studio C Alpha Upgrade File"},
{".aim", "AIMMS ASCII Model File"},
{".ipf", "OS/2 Help File"},
{".readme", "Readme File"},
{".tex", "LaTeX Source Document"},
{".rpt", "Generic Report"},
{".nfo", "Warez Information File"},
{".lis", "SQR Output File"},
{".gsd", "General Station Description File"},
{".tlb", "VAX Text Library"},
{".dropbox", "Dropbox Shared Folder Tracker"},
{".asc", "ASCII Text File"},
{".rst", "reStructuredText File"},
{".scm", "Schema File"},
{".opeico", "Opeico Text File"},
{".dxb", "Duxbury Braille File"},
{".docm", "Microsoft Word Macro-enabled Document"},
{".fodt", "OpenDocument Flat XML Document"},
{".wps", "Kingsoft Writer Document"},
{".text", "Plain Text File"},
{".u3i", "U3 Application Information File"},
{".ipynb", "Jupyter Notebook"},
{".emulecollection", "eMule Data File"},
{".wpt", "Kingsoft Writer Template"},
{".wpd", "ACT! 2 Word Processing Document"},
{".jarvis", "Jarvis Subscriber File"},
{".bib", "BibTeX Bibliography Database"},
{".1st", "Readme File"},
{"._docx", "Renamed Microsoft Word Document"},
{".md5.txt", "Message Digest 5 Hash File"},
{".bdr", "Exchange Non-Delivery Report Body File"},
{".gscript", "Google Apps Script Shortcut"},
{".jnp", "Java Web Start File"},
{".bf", "Brainf*ck Source Code File"},
{".tfrproj", "theFrame Project File"},
{".xy", "XYWrite Document"},
{".rad", "Radar ViewPoint Radar Data"},
{".aty", "Association Type Placeholder"},
{".ott", "OpenDocument Document Template"},
{".luf", "Lipikar Uniform Format File"},
{".tm", "TeXmacs Document"},
{".dm", "BYOND Dream Maker Code"},
{".etf", "ENIGMA Transportable File"},
{".wpw", "WP Works Word Processor File"},
{".knt", "KeyNote Note File"},
{".gtable", "Google Fusion Table Shortcut"},
{".ris", "Research Information Systems Citation File"},
{".textclipping", "Mac OS X Text Clipping File"},
{".strings", "Text Strings File"},
{".err", "FoxPro Compilation Error"},
{".docz", "ThinkFree Online Note Document"},
{".copf", "Copy Operation File"},
{".wri", "Microsoft Write Document"},
{".fdx", "Final Draft Document"},
{".run", "Runscanner Scan File"},
{".pages", "Apple Pages Document"},
{".faq", "Frequently Asked Questions Document"},
{".msg", "Outlook Message Item File"},
{".scc", "Scenarist Closed Caption File"},
{".wp7", "WordPerfect 7 Document"},
{".se", "Shuttle Document"},
{".fdt", "Final Draft 5-7 Template"},
{".gjam", "Google Jamboard Shortcut"},
{".tmd", "TextMaker Document"},
{".kes", "Kurzweil 3000 Document"},
{".omfl", "Open Multiple Files File List"},
{".eml", "E-Mail Message"},
{".rtx", "Rich Text Document"},
{".gmap", "Google My Maps Shortcut"},
{".saf", "SafeText File"},
{".lp2", "iLEAP Word Processing Document"},
{".mbox", "Email Mailbox"},
{".note", "Notability Note File"},
{".sgm", "SGML File"},
{".pwd", "Pocket Word Document"},
{".zzs", "Zyzzyva Search"},
{".charset", "Character Set"},
{".bdp", "Exchange Diagnostic Message"},
{".appodeal", "Appodeal Text File"},
{".etx", "Structure Enhanced Text (Setext) File"},
{".dfti", "FlexiWrite Document"},
{".bean", "Bean Rich Text Document"},
{".fdr", "Final Draft Document"},
{".lnk42", "Windows 93 Desktop Shortcut"},
{".cod", "Atlantis Word Processor Encrypted Document"},
{".dca", "DisplayWrite Document"},
{".gslides", "Google Slides Shortcut"},
{".stw", "StarOffice Document Template"},
{".qdl", "QDL Program"},
{".ipspot", "iPhoto Spot File"},
{".dx", "DEC WPS Plus File"},
{".bad", "Exchange Badmail File"},
{".sdm", "StarOffice Mail Message"},
{".xwp", "Crosstalk Session File"},
{".jis", "Japanese Industry Standard Text"},
{".odif", "Open Document Interchange Format"},
{".ngloss", "Nisus Writer Glossary"},
{".cast", "Asciicast Terminal Recording"},
{".dvi", "Device Independent Format File"},
{".rvf", "RichView Format File"},
{".shim", "Scoop Shim File"},
{".sxw", "StarOffice Writer Document"},
{".rtfd", "Rich Text Format Directory File"},
{".odo", "Online Operating System Write Document"},
{".602", "Text602 Document"},
{".bibtex", "BibTeX Bibliography Database"},
{".ndoc", "Naver Word"},
{".utf8", "Unicode UTF8-Encoded Text Document"},
{".vwr", "Velconoe Write Document"},
{".vcf", "Variant Call Format File"},
{".emlx", "Apple Mail Message"},
{".sla", "Scribus Document"},
{".sdoc", "Satra Khmer Document"},
{".tab", "Tab Separated Data File"},
{".psw", "Pocket Word Document"},
{".eit", "Yozo Office Template File"},
{".sublime-project", "Sublime Text Project File"},
{".trelby", "Trelby File"},
{".p7s", "Digitally Signed Email Message"},
{".chord", "Song Chords File"},
{".docxml", "Microsoft Word XML Document"},
{".abw", "AbiWord Document"},
{".hwp", "Hangul Text Document"},
{".idx", "Outlook Express Mailbox Index File"},
{".uot", "Uniform Office Document"},
{".xyw", "XYWrite for Windows Document"},
{".sms", "Exported SMS Text Message"},
{".frt", "FoxPro Report Memo"},
{".plain", "Plain Text File"},
{".pwi", "Pocket Word Document"},
{"._doc", "Renamed Microsoft Word Document"},
{".hbk", "Mathcad Handbook File"},
{".prt", "Crypt Edit Protected Text Format File"},
{".pvm", "Photo Video Manifest File"},
{".pwr", "PowerWrite Document"},
{".xy3", "XYWrite III Document"},
{".jp1", "Japanese (Romaji) Text File"},
{".bml", "Braille 2000 Braille File"},
{".latex", "LaTeX Document"},
{".now", "Readme File"},
{".tpc", "Topic Connection Placeholder"},
{".mml", "Map Markup Language File"},
{".graph", "GRAPH Hierarchical Data File"},
{".pages-tef", "Pages iCloud Document"},
{".arc", "WWE 2K18 and 2K19 Cache File"},
{".bloonset", "Bloons Tower Defense Battles Bloonset"},
{".fluid", "Loop Component"},
{".jlqm", "LG QuickMemo Info File"},
{".md", "MuseData Musical Score"},
{".license", "Software License File"},
{".highland", "Highland Document"},
{".calca", "Calca Document"},
{".scrivx", "Scrivener XML Document"},
{".ytdl", "Youtube-dl Download Progress File"},
{".sla.gz", "Scribus Compressed Document"},
{".mwd", "Mariner Write Document"},
{".bna", "Barna Word Processor Document"},
{".notes", "Memento Notes File"},
{".rzn", "Red Zion Notes File"},
{".hht", "Help and Support Center HHT File"},
{".mwp", "Lotus Word Pro SmartMaster File"},
{".mellel", "Mellel Document"},
{".boc", "EasyWord Big Document"},
{".lbt", "FoxPro Label Memo"},
{".njk", "Nunjucks Template"},
{".scriv", "Scrivener Document"},
{".wp", "WordPerfect Document"},
{".wp4", "WordPerfect 4 Document"},
{".zrtf", "Nisus Compressed Rich Text File"},
{".safetext", "SafeText File"},
{".xdl", "XML Schema File"},
{".pimx", "Adobe Package Installation Management File"},
{".mw", "MacWrite Text Document"},
{".flr", "Flare Decompiled ActionScript File"},
{".fdf", "Acrobat Forms Data Format"},
{".lwp", "Lotus Word Pro Document"},
{".btd", "Business-in-a-Box Document"},
{".xbdoc", "Xiosis Scribe Document"},
{".cnm", "NoteMap Outline File"},
{".utxt", "Unicode Text File"},
{".joe", "JOE Document"},
{".act", "FoxPro Documenting Wizard Action Diagram"},
{".ort", "Rich Text Editor Document"},
{".mell", "Mellel Word Processing File"},
{".lyx", "LyX Document"},
{".wpl", "DEC WPS Plus Text Document"},
{".hz", "Chinese (Hanzi) Text"},
{".euc", "Extended Unix Code File"},
{".wbk", "WordPerfect Workbook"},
{".ascii", "ASCII Text File"},
{".dgs", "Dagesh Pro Document"},
{".ofl", "Ots File List"},
{".session", "Mozilla Firefox Session File"},
{".jtd", "JustSystems Ichitaro Document"},
{".pfx", "First Choice Word Processing Document"},
{".plantuml", "PlantUML File"},
{".mss", "CartoCSS Map Stylesheet"},
{".pmo", "Pegasus Saved Message File"},
{".awt", "AbiWord Template"},
{".rtd", "RagTime Document"},
{".wp6", "WordPerfect 6 Document"},
{".fwdn", "fWriter Document"},
{".gpn", "GlidePlan Map Document"},
{".sp1", "Windows XP Service Pack 1 Identification File"},
{".tdf", "Xserve Test Definition File"},
{".awp", "Ability Write Template"},
{".xbplate", "Xiosis Scribe Template"},
{".bxt", "Balabolka Text Document"},
{".unauth", "SiteMinder Unauthorized Message File"},
{".btxt", "BTXTPad Document"},
{".tvj", "TrueView Job Ticket"},
{".fft", "Final Form Text File"},
{".quid", "QuidProQuo Document"},
{".ltr", "Letter File"},
{".gv", "Graphviz DOT File"},
{".dwd", "DavkaWriter File"},
{".sdw", "StarOffice Writer Text Document"},
{".openbsd", "OpenBSD Readme File"},
{".sxg", "Apache OpenOffice Master Document"},
{".njx", "NJStar Document"},
{".crwl", "Windows Crawl File"},
{".pu", "PlantUML File"},
{".nb", "Nota Bene File"},
{".xyp", "XYWrite Plus Document"},
{".vct", "Visual Class Library Memo"},
{".rzk", "File Crypt Password File"},
{".nwctxt", "NoteWorthy Composer Text File"},
{".sct", "FoxPro Form Memo"},
{".del", "Delimited ASCII File"},
{".ocr", "FAXGrapper Fax Text File"},
{".lyt", "TurboTax Install Log File"},
{".description", "Youtube-dl Video Description"},
{".tmv", "TextMaker Template"},
{".bbs", "Bulletin Board System Text"},
{".ase", "Autodesk ASCII Scene Export File"},
{".ebp", "Express Burn Project"},
{".dne", "Netica Text File"},
{".pvj", "ProofVision Job Ticket"},
{".kwd", "KWord Document"},
{".wsd", "WordStar Document"},
{".loop", "Loop Component"},
{".brx", "Beam Report Document"},
{".nwm", "Nisus Macro"},
{".dxp", "Duxbury Print File"},
{".uof", "Uniform Office Document"},
{".unx", "Unix Text File"},
{".skcard", "Starfish Sidekick Card File"},
{".vw", "Volkswriter Text File"},
{".cws", "Claris Works Template"},
{".tid", "TiddlyWiki Tiddler"},
{".cyi", "Clustify Input File"},
{".bwd", "BanglaWord Document"},
{".pwdp", "Password Pad Document"},
{".vpdoc", "VoodooPad Document"},
{".zzq", "Zyzzyva Quiz"},
{".wg", "WordGrinder Document Set"},
{".sgt", "ShareGate Template"},
{".sw3", "Scriptware Screenplay"},
{".webdoc", "Box.net Web Document"},
{".lnt", "Laego Note Taker File"},
{".fdxt", "Final Draft 8 Template"},
{".ptnx", "EasyBeadPatterns Pattern"},
{".meltem", "Mellel Template"},
{".fgs", "Fig Figure Settings File"},
{".nwp", "Now Contact WP Document"},
{".qpf", "QuickPad Encrypted Document"},
{".iil", "CleanSweep Installation Log"},
{".sublime-workspace", "Sublime Text Workspace File"},
{".emf", "Jasspa MicroEmacs Macro File"},
{".wp5", "WordPerfect 5 Document"},
{".zw", "Chinese Text File"},
{".wtx", "Text Document"},
{".gthr", "Gather Log File"},
{".jrtf", "JAmes OS Rich Text File"},
{".wpa", "ACT! Word Processing Document"},
{".min", "Mint Source File"},
{".wn", "WriteNow Text Document"},
{".scw", "Movie Magic Screenwriter Document"},
{".pdpcmd", "Pdplayer Command File"},
{".fds", "Final Draft Secure Copy"},
{".gmd", "GroupMail Message"},
{".mcw", "MacWrite II Document"},
{".dox", "MultiMate Document"},
};
std::size_t dotIndex = filename.find_last_of(".");
if (dotIndex != std::string::npos) {
std::string extension = filename.substr(dotIndex);
auto it = extensionMap.find(extension);
if (it != extensionMap.end()) {
return it->second;
}
}
return "Regular File";
}
// Function to get the string representation of file permissions
std::string getPermissionString(mode_t mode) {
std::string permissionString;
// Owner permissions
permissionString += (mode & S_IRUSR) ? "r" : "-";
permissionString += (mode & S_IWUSR) ? "w" : "-";
permissionString += (mode & S_IXUSR) ? "x" : "-";
// Group permissions
permissionString += (mode & S_IRGRP) ? "r" : "-";
permissionString += (mode & S_IWGRP) ? "w" : "-";
permissionString += (mode & S_IXGRP) ? "x" : "-";
// Others permissions
permissionString += (mode & S_IROTH) ? "r" : "-";
permissionString += (mode & S_IWOTH) ? "w" : "-";
permissionString += (mode & S_IXOTH) ? "x" : "-";
return permissionString;
}
// Function to check if a file is executable
bool isExecutable(const std::string& filename) {
return access(filename.c_str(), X_OK) == 0;
}
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " [filename]\n";
return 1;
}
const char* filename = argv[1];
std::ifstream file(filename, std::ios::binary);
if (!file) {
std::cerr << "Error: " << std::strerror(errno) << "\n";
return 1;
}
file.seekg(0, std::ios::end);
std::streampos size = file.tellg();
struct stat fileStat;
if (stat(filename, &fileStat) != 0) {
std::cerr << "Error: " << std::strerror(errno) << "\n";
return 1;
}
std::string filePath = "./" + std::string(filename);
bool executable = isExecutable(filePath);
std::time_t lastModified = fileStat.st_mtime;
std::string fileType = getFileType(filename);
std::string permissionString = getPermissionString(fileStat.st_mode);
std::cout << "File Name: \033[0;32m" << filename << "\033[0m\n";
std::cout << "File Size: \033[0;33m" << size << " bytes\033[0m\n";
std::cout << "Last Modified: \033[1;36m" << std::asctime(std::localtime(&lastModified));
std::cout << "\033[0mFile Type: \033[1;32m" << fileType << "\033[0m\n";
std::cout << "Linux Executable: " << (executable ? "\x1b[1;35mYes\x1b[0m" : "\x1b[1;35mNo\x1b[0m") << "\n";
std::cout << "File Permissions: \033[0;31m" << permissionString << "\033[0m\n";
file.close();
return 0;
}