|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Diagnostics; |
| 3 | +using System.IO; |
| 4 | +using System.Security.Cryptography; |
| 5 | + |
| 6 | +namespace LazySchoolboyUtil |
| 7 | +{ |
| 8 | + public static class Util |
| 9 | + { |
| 10 | + public static string version = "1.3"; |
| 11 | + public static double progress; |
| 12 | + |
| 13 | + static RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider(); |
| 14 | + |
| 15 | + public static void GenerateFile(string path, int size, Format format) |
| 16 | + { |
| 17 | + progress = 0; |
| 18 | + byte[] bytesToBeSaved = new byte[size]; |
| 19 | + |
| 20 | + rand.GetBytes(bytesToBeSaved); |
| 21 | + for (int i = format.GetOffset(); i <= format.GetOffset() + format.GetMagicNumbers().Length - 1; i++) |
| 22 | + { |
| 23 | + try |
| 24 | + { |
| 25 | + Debug.WriteLine("b1"); |
| 26 | + progress = i / (format.GetMagicNumbers().LongLength / 100); |
| 27 | + } |
| 28 | + catch (System.Exception ex) |
| 29 | + { |
| 30 | + Debug.WriteLine("b2"); |
| 31 | + Debug.WriteLine(ex.Message); |
| 32 | + } |
| 33 | + |
| 34 | + bytesToBeSaved[i] = format.GetMagicNumbers()[i - format.GetOffset()]; |
| 35 | + } |
| 36 | + using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write)) |
| 37 | + { |
| 38 | + fs.Write(bytesToBeSaved, 0, bytesToBeSaved.Length); |
| 39 | + } |
| 40 | + progress = 100; |
| 41 | + } |
| 42 | + |
| 43 | + public static List<Format> GetListOfFormats() |
| 44 | + { |
| 45 | + List<Format> toReturn = new List<Format>(); |
| 46 | + toReturn.Add(new Format("123", "application/vnd.lotus-1-2-3", 0, new byte[] { 0x00, 0x00, 0x1A, 0x00, 0x05, 0x10, 0x04 })); |
| 47 | + toReturn.Add(new Format("cpl", "application/cpl+xml", 0, new byte[] { 0x4D, 0x5A })); |
| 48 | + toReturn.Add(new Format("epub", "application/epub+zip", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04, 0x0A, 0x00, 0x02, 0x00 })); |
| 49 | + toReturn.Add(new Format("ttf", "application/font-sfnt", 0, new byte[] { 0x00, 0x01, 0x00, 0x00, 0x00 })); |
| 50 | + toReturn.Add(new Format("gz", "application/gzip", 0, new byte[] { 0x1F, 0x8B, 0x08 })); |
| 51 | + toReturn.Add(new Format("tgz", "application/gzip", 0, new byte[] { 0x1F, 0x8B, 0x08 })); |
| 52 | + toReturn.Add(new Format("hqx", "application/mac-binhex40", 0, new byte[] { 0x28, 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6C, 0x65, 0x20, 0x6D, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 0x20, 0x63, 0x6F, 0x6E, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x42, 0x69, 0x6E, 0x48, 0x65, 0x78, 0x20 })); |
| 53 | + toReturn.Add(new Format("doc", "application/msword", 0, new byte[] { 0x0D, 0x44, 0x4F, 0x43 })); |
| 54 | + toReturn.Add(new Format("mxf", "application/mxf", 0, new byte[] { 0x06, 0x0E, 0x2B, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0x02 })); |
| 55 | + toReturn.Add(new Format("lha", "application/octet-stream", 2, new byte[] { 0x2D, 0x6C, 0x68 })); |
| 56 | + toReturn.Add(new Format("lzh", "application/octet-stream", 2, new byte[] { 0x2D, 0x6C, 0x68 })); |
| 57 | + toReturn.Add(new Format("exe", "application/octet-stream", 0, new byte[] { 0x4D, 0x5A })); |
| 58 | + toReturn.Add(new Format("class", "application/octet-stream", 0, new byte[] { 0xCA, 0xFE, 0xBA, 0xBE })); |
| 59 | + toReturn.Add(new Format("dll", "application/octet-stream", 0, new byte[] { 0x4D, 0x5A })); |
| 60 | + toReturn.Add(new Format("img", "application/octet-stream", 0, new byte[] { 0xEB, 0x3C, 0x90, 0x2A })); |
| 61 | + toReturn.Add(new Format("iso", "application/octet-stream", 0, new byte[] { 0x43, 0x44, 0x30, 0x30, 0x31 })); |
| 62 | + toReturn.Add(new Format("ogx", "application/ogg", 0, new byte[] { 0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 63 | + toReturn.Add(new Format("oxps", "application/oxps", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 64 | + toReturn.Add(new Format("pdf", "application/pdf", 0, new byte[] { 0x25, 0x50, 0x44, 0x46 })); |
| 65 | + toReturn.Add(new Format("p10", "application/pkcs10", 0, new byte[] { 0x64, 0x00, 0x00, 0x00 })); |
| 66 | + toReturn.Add(new Format("pls", "application/pls+xml", 0, new byte[] { 0x5B, 0x70, 0x6C, 0x61, 0x79, 0x6C, 0x69, 0x73, 0x74, 0x5D })); |
| 67 | + toReturn.Add(new Format("eps", "application/postscript", 0, new byte[] { 0x25, 0x21, 0x50, 0x53, 0x2D, 0x41, 0x64, 0x6F, 0x62, 0x65, 0x2D, 0x33, 0x2E, 0x30, 0x20, 0x45, 0x50, 0x53, 0x46, 0x2D, 0x33, 0x20, 0x30 })); |
| 68 | + toReturn.Add(new Format("ai", "application/postscript", 0, new byte[] { 0x25, 0x50, 0x44, 0x46 })); |
| 69 | + toReturn.Add(new Format("rtf", "application/rtf", 0, new byte[] { 0x7B, 0x5C, 0x72, 0x74, 0x66, 0x31 })); |
| 70 | + toReturn.Add(new Format("tsa", "application/tamp-sequence-adjust", 0, new byte[] { 0x47 })); |
| 71 | + toReturn.Add(new Format("msf", "application/vnd.epson.msf", 0, new byte[] { 0x2F, 0x2F, 0x20, 0x3C, 0x21, 0x2D, 0x2D, 0x20, 0x3C, 0x6D, 0x64, 0x62, 0x3A, 0x6D, 0x6F, 0x72, 0x6B, 0x3A, 0x7A })); |
| 72 | + toReturn.Add(new Format("fdf", "application/vnd.fdf", 0, new byte[] { 0x25, 0x50, 0x44, 0x46 })); |
| 73 | + toReturn.Add(new Format("fm", "application/vnd.framemaker", 0, new byte[] { 0x3C, 0x4D, 0x61, 0x6B, 0x65, 0x72, 0x46, 0x69, 0x6C, 0x65, 0x20 })); |
| 74 | + toReturn.Add(new Format("kmz", "application/vnd.google-earth.kmz", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 75 | + toReturn.Add(new Format("tpl", "application/vnd.groove-tool-template", 0, new byte[] { 0x00, 0x20, 0xAF, 0x30 })); |
| 76 | + toReturn.Add(new Format("kwd", "application/vnd.kde.kword", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 77 | + toReturn.Add(new Format("wk4", "application/vnd.lotus-1-2-3", 0, new byte[] { 0x00, 0x00, 0x1A, 0x00, 0x02, 0x10, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 78 | + toReturn.Add(new Format("wk3", "application/vnd.lotus-1-2-3", 0, new byte[] { 0x00, 0x00, 0x1A, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 79 | + toReturn.Add(new Format("wk1", "application/vnd.lotus-1-2-3", 0, new byte[] { 0x00, 0x00, 0x02, 0x00, 0x06, 0x04, 0x06, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 80 | + toReturn.Add(new Format("apr", "application/vnd.lotus-approach", 0, new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })); |
| 81 | + toReturn.Add(new Format("nsf", "application/vnd.lotus-notes", 0, new byte[] { 0x1A, 0x00, 0x00, 0x04, 0x00, 0x00 })); |
| 82 | + toReturn.Add(new Format("ntf", "application/vnd.lotus-notes", 0, new byte[] { 0x4E, 0x49, 0x54, 0x46, 0x30 })); |
| 83 | + toReturn.Add(new Format("org", "application/vnd.lotus-organizer", 0, new byte[] { 0x41, 0x4F, 0x4C, 0x56, 0x4D, 0x31, 0x30, 0x30 })); |
| 84 | + toReturn.Add(new Format("lwp", "application/vnd.lotus-wordpro", 0, new byte[] { 0x57, 0x6F, 0x72, 0x64, 0x50, 0x72, 0x6F })); |
| 85 | + toReturn.Add(new Format("sam", "application/vnd.lotus-wordpro", 0, new byte[] { 0x5B, 0x50, 0x68, 0x6F, 0x6E, 0x65, 0x5D })); |
| 86 | + toReturn.Add(new Format("mif", "application/vnd.mif", 0, new byte[] { 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x20 })); |
| 87 | + toReturn.Add(new Format("xul", "application/vnd.mozilla.xul+xml", 0, new byte[] { 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x22, 0x31, 0x2E, 0x30, 0x22, 0x3F, 0x3E })); |
| 88 | + toReturn.Add(new Format("asf", "application/vnd.ms-asf", 0, new byte[] { 0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C })); |
| 89 | + toReturn.Add(new Format("cab", "application/vnd.ms-cab-compressed", 0, new byte[] { 0x49, 0x53, 0x63, 0x28 })); |
| 90 | + toReturn.Add(new Format("xls", "application/vnd.ms-excel", 0, new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })); |
| 91 | + toReturn.Add(new Format("xla", "application/vnd.ms-excel", 0, new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })); |
| 92 | + toReturn.Add(new Format("chm", "application/vnd.ms-htmlhelp", 0, new byte[] { 0x49, 0x54, 0x53, 0x46 })); |
| 93 | + toReturn.Add(new Format("ppt", "application/vnd.ms-powerpoint", 0, new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })); |
| 94 | + toReturn.Add(new Format("pps", "application/vnd.ms-powerpoint", 0, new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })); |
| 95 | + toReturn.Add(new Format("wks", "application/application/vnd.ms-works", 0, new byte[] { 0xFF, 0x00, 0x02, 0x00, 0x04, 0x04, 0x05, 0x54, 0x02, 0x00 })); |
| 96 | + toReturn.Add(new Format("wpl", "application/vnd.ms-wpl", 84, new byte[] { 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x57, 0x69, 0x6E, 0x64, 0x6F, 0x77, 0x73, 0x20, 0x4D, 0x65, 0x64, 0x69, 0x61, 0x20, 0x50, 0x6C, 0x61, 0x79, 0x65, 0x72, 0x20, 0x2D, 0x2D, 0x20 })); |
| 97 | + toReturn.Add(new Format("xps", "application/vnd.ms-xpsdocument", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 98 | + toReturn.Add(new Format("cif", "application/vnd.multiad.creator.cif", 2, new byte[] { 0x5B, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E })); |
| 99 | + toReturn.Add(new Format("odp", "application/vnd.oasis.opendocument.presentation", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 100 | + toReturn.Add(new Format("odt", "application/vnd.oasis.opendocument.text", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 101 | + toReturn.Add(new Format("ott", "application/vnd.oasis.opendocument.text-template", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04 })); |
| 102 | + toReturn.Add(new Format("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x06, 0x00 })); |
| 103 | + toReturn.Add(new Format("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x06, 0x00 })); |
| 104 | + toReturn.Add(new Format("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x06, 0x00 })); |
| 105 | + toReturn.Add(new Format("prc", "application/vnd.palm", 0, new byte[] { 0x42, 0x4F, 0x4F, 0x4B, 0x4D, 0x4F, 0x42, 0x49 })); |
| 106 | + toReturn.Add(new Format("pdb", "application/vnd.palm", 0, new byte[] { 0x4D, 0x2D, 0x57, 0x20, 0x50, 0x6F, 0x63, 0x6B, 0x65, 0x74, 0x20, 0x44, 0x69, 0x63, 0x74, 0x69 })); |
| 107 | + toReturn.Add(new Format("qxd", "application/vnd.Quark.QuarkXPress", 0, new byte[] { 0x00, 0x00, 0x4D, 0x4D, 0x58, 0x50, 0x52 })); |
| 108 | + toReturn.Add(new Format("rar", "application/vnd.rar", 0, new byte[] { 0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00 })); |
| 109 | + toReturn.Add(new Format("mmf", "application/vnd.smaf", 0, new byte[] { 0x4D, 0x4D, 0x4D, 0x44, 0x00, 0x00 })); |
| 110 | + toReturn.Add(new Format("cap", "application/vnd.tcpdump.pcap", 0, new byte[] { 0x52, 0x54, 0x53, 0x53 })); |
| 111 | + toReturn.Add(new Format("dmp", "application/vnd.tcpdump.pcap", 0, new byte[] { 0x4D, 0x44, 0x4D, 0x50, 0x93, 0xA7 })); |
| 112 | + toReturn.Add(new Format("wpd", "application/vnd.wordperfect", 0, new byte[] { 0xFF, 0x57, 0x50, 0x43 })); |
| 113 | + toReturn.Add(new Format("xar", "application/vnd.xara", 0, new byte[] { 0x78, 0x61, 0x72, 0x21 })); |
| 114 | + toReturn.Add(new Format("spf", "application/vnd.yamaha.smaf-phrase", 0, new byte[] { 0x53, 0x50, 0x46, 0x49, 0x00 })); |
| 115 | + toReturn.Add(new Format("dtd", "application/xml-dtd", 0, new byte[] { 0x07, 0x64, 0x74, 0x32, 0x64, 0x64, 0x74, 0x64 })); |
| 116 | + toReturn.Add(new Format("zip", "application/zip", 0, new byte[] { 0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 117 | + toReturn.Add(new Format("amr", "application/AMR", 0, new byte[] { 0x23, 0x21, 0x41, 0x4D, 0x52 })); |
| 118 | + toReturn.Add(new Format("au", "audio/basic", 0, new byte[] { 0x2E, 0x73, 0x6E, 0x64 })); |
| 119 | + toReturn.Add(new Format("m4a", "audio/mp4", 0, new byte[] { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x4D, 0x34, 0x41, 0x20 })); |
| 120 | + toReturn.Add(new Format("mp3", "audio/mpeg", 0, new byte[] { 0x49, 0x44, 0x33 })); |
| 121 | + toReturn.Add(new Format("oga", "audio/ogg", 0, new byte[] { 0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 122 | + toReturn.Add(new Format("ogg", "audio/ogg", 0, new byte[] { 0x4F, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })); |
| 123 | + toReturn.Add(new Format("qcp", "audio/qcelp", 0, new byte[] { 0x52, 0x49, 0x46, 0x46 })); |
| 124 | + toReturn.Add(new Format("koz", "audio/vnd.audikoz", 0, new byte[] { 0x49, 0x44, 0x33, 0x03, 0x00, 0x00, 0x00 })); |
| 125 | + toReturn.Add(new Format("bmp", "image/bmp", 0, new byte[] { 0x42, 0x4D })); |
| 126 | + toReturn.Add(new Format("dib", "image/bmp", 0, new byte[] { 0x42, 0x4D })); |
| 127 | + toReturn.Add(new Format("emf", "image/emf", 0, new byte[] { 0x01, 0x00, 0x00, 0x00 })); |
| 128 | + toReturn.Add(new Format("fits", "image/fits", 0, new byte[] { 0x53, 0x49, 0x4D, 0x50, 0x4C, 0x45, 0x20, 0x20, 0x3D, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x54 })); |
| 129 | + toReturn.Add(new Format("gif", "image/gif", 0, new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 })); |
| 130 | + toReturn.Add(new Format("jp2", "image/jp2", 0, new byte[] { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A })); |
| 131 | + toReturn.Add(new Format("jpg", "image/jpeg", 0, new byte[] { 0xFF, 0xD8 })); |
| 132 | + toReturn.Add(new Format("jpeg", "image/jpeg", 0, new byte[] { 0xFF, 0xD8 })); |
| 133 | + toReturn.Add(new Format("jpe", "image/jpeg", 0, new byte[] { 0xFF, 0xD8 })); |
| 134 | + toReturn.Add(new Format("jfif", "image/jpeg", 0, new byte[] { 0xFF, 0xD8 })); |
| 135 | + |
| 136 | + //TODO: Add other formats |
| 137 | + |
| 138 | + return toReturn; |
| 139 | + } |
| 140 | + } |
| 141 | +} |
0 commit comments