FileSignatures.mjs 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159
  1. /**
  2. * File signatures and extractor functions
  3. *
  4. * @author n1474335 [n1474335@gmail.com]
  5. * @copyright Crown Copyright 2018
  6. * @license Apache-2.0
  7. *
  8. */
  9. import Stream from "./Stream.mjs";
  10. /**
  11. * A categorised table of file types, including signatures to identify them and functions
  12. * to extract them where possible.
  13. */
  14. export const FILE_SIGNATURES = {
  15. "Images": [
  16. {
  17. name: "Joint Photographic Experts Group image",
  18. extension: "jpg,jpeg,jpe,thm,mpo",
  19. mime: "image/jpeg",
  20. description: "",
  21. signature: {
  22. 0: 0xff,
  23. 1: 0xd8,
  24. 2: 0xff,
  25. 3: [0xc0, 0xc4, 0xdb, 0xdd, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe7, 0xe8, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xfe]
  26. },
  27. extractor: extractJPEG
  28. },
  29. {
  30. name: "Graphics Interchange Format image",
  31. extension: "gif",
  32. mime: "image/gif",
  33. description: "",
  34. signature: {
  35. 0: 0x47, // GIF
  36. 1: 0x49,
  37. 2: 0x46,
  38. 3: 0x38, // 8
  39. 4: [0x37, 0x39], // 7|9
  40. 5: 0x61 // a
  41. },
  42. extractor: extractGIF
  43. },
  44. {
  45. name: "Portable Network Graphics image",
  46. extension: "png",
  47. mime: "image/png",
  48. description: "",
  49. signature: {
  50. 0: 0x89,
  51. 1: 0x50, // PNG
  52. 2: 0x4e,
  53. 3: 0x47,
  54. 4: 0x0d,
  55. 5: 0x0a,
  56. 6: 0x1a,
  57. 7: 0x0a
  58. },
  59. extractor: extractPNG
  60. },
  61. {
  62. name: "WEBP Image",
  63. extension: "webp",
  64. mime: "image/webp",
  65. description: "",
  66. signature: {
  67. 8: 0x57,
  68. 9: 0x45,
  69. 10: 0x42,
  70. 11: 0x50
  71. },
  72. extractor: null
  73. },
  74. {
  75. name: "Camera Image File Format",
  76. extension: "crw",
  77. mime: "image/x-canon-crw",
  78. description: "",
  79. signature: {
  80. 6: 0x48, // HEAPCCDR
  81. 7: 0x45,
  82. 8: 0x41,
  83. 9: 0x50,
  84. 10: 0x43,
  85. 11: 0x43,
  86. 12: 0x44,
  87. 13: 0x52
  88. },
  89. extractor: null
  90. },
  91. { // Place before tiff check
  92. name: "Canon CR2 raw image",
  93. extension: "cr2",
  94. mime: "image/x-canon-cr2",
  95. description: "",
  96. signature: [
  97. {
  98. 0: 0x49,
  99. 1: 0x49,
  100. 2: 0x2a,
  101. 3: 0x0,
  102. 8: 0x43,
  103. 9: 0x52
  104. },
  105. {
  106. 0: 0x4d,
  107. 1: 0x4d,
  108. 2: 0x0,
  109. 3: 0x2a,
  110. 8: 0x43,
  111. 9: 0x52
  112. }
  113. ],
  114. extractor: null
  115. },
  116. {
  117. name: "Tagged Image File Format image",
  118. extension: "tif",
  119. mime: "image/tiff",
  120. description: "",
  121. signature: [
  122. {
  123. 0: 0x49,
  124. 1: 0x49,
  125. 2: 0x2a,
  126. 3: 0x0
  127. },
  128. {
  129. 0: 0x4d,
  130. 1: 0x4d,
  131. 2: 0x0,
  132. 3: 0x2a
  133. }
  134. ],
  135. extractor: null
  136. },
  137. {
  138. name: "Bitmap image",
  139. extension: "bmp",
  140. mime: "image/bmp",
  141. description: "",
  142. signature: {
  143. 0: 0x42,
  144. 1: 0x4d,
  145. 7: 0x0,
  146. 9: 0x0,
  147. 14: [0x0c, 0x28, 0x38, 0x40, 0x6c, 0x7c],
  148. 15: 0x0,
  149. 16: 0x0,
  150. 17: 0x0
  151. },
  152. extractor: extractBMP
  153. },
  154. {
  155. name: "JPEG Extended Range image",
  156. extension: "jxr",
  157. mime: "image/vnd.ms-photo",
  158. description: "",
  159. signature: {
  160. 0: 0x49,
  161. 1: 0x49,
  162. 2: 0xbc
  163. },
  164. extractor: null
  165. },
  166. {
  167. name: "Photoshop image",
  168. extension: "psd",
  169. mime: "image/vnd.adobe.photoshop",
  170. description: "",
  171. signature: {
  172. 0: 0x38, // 8BPS
  173. 1: 0x42,
  174. 2: 0x50,
  175. 3: 0x53,
  176. 4: 0x0,
  177. 5: 0x1,
  178. 6: 0x0,
  179. 7: 0x0,
  180. 8: 0x0,
  181. 9: 0x0,
  182. 10: 0x0,
  183. 11: 0x0
  184. },
  185. extractor: null
  186. },
  187. {
  188. name: "Photoshop Large Document",
  189. extension: "psb",
  190. mime: "application/x-photoshop",
  191. description: "",
  192. signature: {
  193. 0: 0x38, // 8BPS
  194. 1: 0x42,
  195. 2: 0x50,
  196. 3: 0x53,
  197. 4: 0x0,
  198. 5: 0x2,
  199. 6: 0x0,
  200. 7: 0x0,
  201. 8: 0x0,
  202. 9: 0x0,
  203. 10: 0x0,
  204. 11: 0x0,
  205. 12: 0x0
  206. },
  207. extractor: null
  208. },
  209. {
  210. name: "Paint Shop Pro image",
  211. extension: "psp",
  212. mime: "image/psp",
  213. description: "",
  214. signature: [
  215. {
  216. 0: 0x50, // Paint Shop Pro Im
  217. 1: 0x61,
  218. 2: 0x69,
  219. 3: 0x6e,
  220. 4: 0x74,
  221. 5: 0x20,
  222. 6: 0x53,
  223. 7: 0x68,
  224. 8: 0x6f,
  225. 9: 0x70,
  226. 10: 0x20,
  227. 11: 0x50,
  228. 12: 0x72,
  229. 13: 0x6f,
  230. 14: 0x20,
  231. 15: 0x49,
  232. 16: 0x6d
  233. },
  234. {
  235. 0: 0x7e,
  236. 1: 0x42,
  237. 2: 0x4b,
  238. 3: 0x0
  239. }
  240. ],
  241. extractor: null
  242. },
  243. {
  244. name: "The GIMP image",
  245. extension: "xcf",
  246. mime: "image/x-xcf",
  247. description: "",
  248. signature: {
  249. 0: 0x67, // gimp xcf
  250. 1: 0x69,
  251. 2: 0x6d,
  252. 3: 0x70,
  253. 4: 0x20,
  254. 5: 0x78,
  255. 6: 0x63,
  256. 7: 0x66,
  257. 8: 0x20,
  258. 9: [0x66, 0x76],
  259. 10: [0x69, 0x30],
  260. 11: [0x6c, 0x30],
  261. 12: [0x65, 0x31, 0x32, 0x33]
  262. },
  263. extractor: null
  264. },
  265. {
  266. name: "Icon image",
  267. extension: "ico",
  268. mime: "image/x-icon",
  269. description: "",
  270. signature: {
  271. 0: 0x0,
  272. 1: 0x0,
  273. 2: 0x1,
  274. 3: 0x0,
  275. 4: [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15],
  276. 5: 0x0,
  277. 6: [0x10, 0x20, 0x30, 0x40, 0x80],
  278. 7: [0x10, 0x20, 0x30, 0x40, 0x80],
  279. 9: 0x0,
  280. 10: [0x0, 0x1]
  281. },
  282. extractor: null
  283. },
  284. {
  285. name: "Radiance High Dynamic Range image",
  286. extension: "hdr",
  287. mime: "image/vnd.radiance",
  288. description: "",
  289. signature: {
  290. 0: 0x23, // #?RADIANCE
  291. 1: 0x3f,
  292. 2: 0x52,
  293. 3: 0x41,
  294. 4: 0x44,
  295. 5: 0x49,
  296. 6: 0x41,
  297. 7: 0x4e,
  298. 8: 0x43,
  299. 9: 0x45,
  300. 10: 0x0a
  301. },
  302. extractor: null
  303. },
  304. {
  305. name: "Sony ARW image",
  306. extension: "arw",
  307. mime: "image/x-raw",
  308. description: "",
  309. signature: {
  310. 0: 0x05,
  311. 1: 0x0,
  312. 2: 0x0,
  313. 3: 0x0,
  314. 4: 0x41,
  315. 5: 0x57,
  316. 6: 0x31,
  317. 7: 0x2e
  318. },
  319. extractor: null
  320. },
  321. {
  322. name: "Fujifilm Raw Image",
  323. extension: "raf",
  324. mime: "image/x-raw",
  325. description: "",
  326. signature: {
  327. 0: 0x46, // FUJIFILMCCD-RAW
  328. 1: 0x55,
  329. 2: 0x4a,
  330. 3: 0x49,
  331. 4: 0x46,
  332. 5: 0x49,
  333. 6: 0x4c,
  334. 7: 0x4d,
  335. 8: 0x43,
  336. 9: 0x43,
  337. 10: 0x44,
  338. 11: 0x2d,
  339. 12: 0x52,
  340. 13: 0x41,
  341. 14: 0x57
  342. },
  343. extractor: null
  344. },
  345. {
  346. name: "Minolta RAW image",
  347. extension: "mrw",
  348. mime: "image/x-raw",
  349. description: "",
  350. signature: {
  351. 0: 0x0,
  352. 1: 0x4d, // MRM
  353. 2: 0x52,
  354. 3: 0x4d
  355. },
  356. extractor: null
  357. },
  358. {
  359. name: "Adobe Bridge Thumbnail Cache",
  360. extension: "bct",
  361. mime: "application/octet-stream",
  362. description: "",
  363. signature: {
  364. 0: 0x6c,
  365. 1: 0x6e,
  366. 2: 0x62,
  367. 3: 0x74,
  368. 4: 0x02,
  369. 5: 0x0,
  370. 6: 0x0,
  371. 7: 0x0
  372. },
  373. extractor: null
  374. },
  375. {
  376. name: "Microsoft Document Imaging",
  377. extension: "mdi",
  378. mime: "image/vnd.ms-modi",
  379. description: "",
  380. signature: {
  381. 0: 0x45,
  382. 1: 0x50,
  383. 2: 0x2a,
  384. 3: 0x00
  385. },
  386. extractor: null
  387. },
  388. {
  389. name: "Joint Photographic Experts Group image (under Base64)",
  390. extension: "B64",
  391. mime: "application/octet-stream",
  392. description: "",
  393. signature: {
  394. 0: 0x2f,
  395. 1: 0x39,
  396. 2: 0x6a,
  397. 3: 0x2f,
  398. 4: 0x34
  399. },
  400. extractor: null
  401. },
  402. {
  403. name: "Portable Network Graphics image (under Base64)",
  404. extension: "B64",
  405. mime: "application/octet-stream",
  406. description: "",
  407. signature: {
  408. 0: 0x69,
  409. 1: 0x56,
  410. 2: 0x42,
  411. 3: 0x4f,
  412. 4: 0x52,
  413. 5: 0x77,
  414. 6: 0x30
  415. },
  416. extractor: null
  417. },
  418. {
  419. name: "AutoCAD Drawing",
  420. extension: "dwg,123d",
  421. mime: "application/acad",
  422. description: "",
  423. signature: {
  424. 0: 0x41,
  425. 1: 0x43,
  426. 2: 0x31,
  427. 3: 0x30,
  428. 4: [0x30, 0x31],
  429. 5: [0x30, 0x31, 0x32, 0x33, 0x34, 0x35],
  430. 6: 0x00
  431. },
  432. extractor: null
  433. },
  434. {
  435. name: "AutoCAD Drawing",
  436. extension: "dwg,dwt",
  437. mime: "application/acad",
  438. description: "",
  439. signature: [
  440. {
  441. 0: 0x41,
  442. 1: 0x43,
  443. 2: 0x31,
  444. 3: 0x30,
  445. 4: 0x31,
  446. 5: 0x38,
  447. 6: 0x00
  448. },
  449. {
  450. 0: 0x41,
  451. 1: 0x43,
  452. 2: 0x31,
  453. 3: 0x30,
  454. 4: 0x32,
  455. 5: 0x34,
  456. 6: 0x00
  457. },
  458. {
  459. 0: 0x41,
  460. 1: 0x43,
  461. 2: 0x31,
  462. 3: 0x30,
  463. 4: 0x32,
  464. 5: 0x37,
  465. 6: 0x00
  466. }
  467. ],
  468. extractor: null
  469. },
  470. ],
  471. "Video": [
  472. { // Place before webm
  473. name: "Matroska Multimedia Container",
  474. extension: "mkv",
  475. mime: "video/x-matroska",
  476. description: "",
  477. signature: {
  478. 31: 0x6d,
  479. 32: 0x61,
  480. 33: 0x74,
  481. 34: 0x72,
  482. 35: 0x6f,
  483. 36: 0x73,
  484. 37: 0x6b,
  485. 38: 0x61
  486. },
  487. extractor: null
  488. },
  489. {
  490. name: "WEBM video",
  491. extension: "webm",
  492. mime: "video/webm",
  493. description: "",
  494. signature: {
  495. 0: 0x1a,
  496. 1: 0x45,
  497. 2: 0xdf,
  498. 3: 0xa3
  499. },
  500. extractor: null
  501. },
  502. { // Place before MPEG-4
  503. name: "Flash MP4 video",
  504. extension: "f4v",
  505. mime: "video/mp4",
  506. description: "",
  507. signature: {
  508. 4: 0x66,
  509. 5: 0x74,
  510. 6: 0x79,
  511. 7: 0x70,
  512. 8: [0x66, 0x46],
  513. 9: 0x34,
  514. 10: [0x76, 0x56],
  515. 11: 0x20
  516. },
  517. extractor: null
  518. },
  519. {
  520. name: "MPEG-4 video",
  521. extension: "mp4",
  522. mime: "video/mp4",
  523. description: "",
  524. signature: [
  525. {
  526. 0: 0x0,
  527. 1: 0x0,
  528. 2: 0x0,
  529. 3: [0x18, 0x20],
  530. 4: 0x66,
  531. 5: 0x74,
  532. 6: 0x79,
  533. 7: 0x70
  534. },
  535. {
  536. 0: 0x33, // 3gp5
  537. 1: 0x67,
  538. 2: 0x70,
  539. 3: 0x35
  540. },
  541. {
  542. 0: 0x0,
  543. 1: 0x0,
  544. 2: 0x0,
  545. 3: 0x1c,
  546. 4: 0x66,
  547. 5: 0x74,
  548. 6: 0x79,
  549. 7: 0x70,
  550. 8: 0x6d,
  551. 9: 0x70,
  552. 10: 0x34,
  553. 11: 0x32,
  554. 16: 0x6d, // mp41mp42isom
  555. 17: 0x70,
  556. 18: 0x34,
  557. 19: 0x31,
  558. 20: 0x6d,
  559. 21: 0x70,
  560. 22: 0x34,
  561. 23: 0x32,
  562. 24: 0x69,
  563. 25: 0x73,
  564. 26: 0x6f,
  565. 27: 0x6d
  566. }
  567. ],
  568. extractor: null
  569. },
  570. {
  571. name: "M4V video",
  572. extension: "m4v",
  573. mime: "video/x-m4v",
  574. description: "",
  575. signature: {
  576. 0: 0x0,
  577. 1: 0x0,
  578. 2: 0x0,
  579. 3: 0x1c,
  580. 4: 0x66,
  581. 5: 0x74,
  582. 6: 0x79,
  583. 7: 0x70,
  584. 8: 0x4d,
  585. 9: 0x34,
  586. 10: 0x56
  587. },
  588. extractor: null
  589. },
  590. {
  591. name: "Quicktime video",
  592. extension: "mov",
  593. mime: "video/quicktime",
  594. description: "",
  595. signature: {
  596. 0: 0x0,
  597. 1: 0x0,
  598. 2: 0x0,
  599. 3: 0x14,
  600. 4: 0x66,
  601. 5: 0x74,
  602. 6: 0x79,
  603. 7: 0x70
  604. },
  605. extractor: null
  606. },
  607. {
  608. name: "Audio Video Interleave",
  609. extension: "avi",
  610. mime: "video/x-msvideo",
  611. description: "",
  612. signature: {
  613. 0: 0x52,
  614. 1: 0x49,
  615. 2: 0x46,
  616. 3: 0x46,
  617. 8: 0x41,
  618. 9: 0x56,
  619. 10: 0x49
  620. },
  621. extractor: null
  622. },
  623. {
  624. name: "Windows Media Video",
  625. extension: "wmv",
  626. mime: "video/x-ms-wmv",
  627. description: "",
  628. signature: {
  629. 0: 0x30,
  630. 1: 0x26,
  631. 2: 0xb2,
  632. 3: 0x75,
  633. 4: 0x8e,
  634. 5: 0x66,
  635. 6: 0xcf,
  636. 7: 0x11,
  637. 8: 0xa6,
  638. 9: 0xd9
  639. },
  640. extractor: null
  641. },
  642. {
  643. name: "MPEG video",
  644. extension: "mpg",
  645. mime: "video/mpeg",
  646. description: "",
  647. signature: {
  648. 0: 0x0,
  649. 1: 0x0,
  650. 2: 0x1,
  651. 3: 0xba
  652. },
  653. extractor: null
  654. },
  655. {
  656. name: "Flash Video",
  657. extension: "flv",
  658. mime: "video/x-flv",
  659. description: "",
  660. signature: {
  661. 0: 0x46,
  662. 1: 0x4c,
  663. 2: 0x56,
  664. 3: 0x1
  665. },
  666. extractor: extractFLV
  667. },
  668. {
  669. name: "OGG Video",
  670. extension: "ogv,ogm,opus,ogx",
  671. mime: "video/ogg",
  672. description: "",
  673. signature: [
  674. {
  675. 0: 0x4f, // OggS
  676. 1: 0x67,
  677. 2: 0x67,
  678. 3: 0x53,
  679. 4: 0x00,
  680. 5: 0x02,
  681. 28: 0x01,
  682. 29: 0x76, // video
  683. 30: 0x69,
  684. 31: 0x64,
  685. 32: 0x65,
  686. 33: 0x6f
  687. },
  688. {
  689. 0: 0x4f, // OggS
  690. 1: 0x67,
  691. 2: 0x67,
  692. 3: 0x53,
  693. 4: 0x00,
  694. 5: 0x02,
  695. 28: 0x80,
  696. 29: 0x74, // theora
  697. 30: 0x68,
  698. 31: 0x65,
  699. 32: 0x6f,
  700. 33: 0x72,
  701. 34: 0x61
  702. },
  703. {
  704. 0: 0x4f, // OggS
  705. 1: 0x67,
  706. 2: 0x67,
  707. 3: 0x53,
  708. 4: 0x00,
  709. 5: 0x02,
  710. 28: 0x66, // fishead
  711. 29: 0x69,
  712. 30: 0x73,
  713. 31: 0x68,
  714. 32: 0x65,
  715. 33: 0x61,
  716. 34: 0x64
  717. }
  718. ],
  719. extractor: null
  720. },
  721. ],
  722. "Audio": [
  723. {
  724. name: "Waveform Audio",
  725. extension: "wav",
  726. mime: "audio/x-wav",
  727. description: "",
  728. signature: {
  729. 0: 0x52,
  730. 1: 0x49,
  731. 2: 0x46,
  732. 3: 0x46,
  733. 8: 0x57,
  734. 9: 0x41,
  735. 10: 0x56,
  736. 11: 0x45
  737. },
  738. extractor: null
  739. },
  740. {
  741. name: "OGG audio",
  742. extension: "ogg",
  743. mime: "audio/ogg",
  744. description: "",
  745. signature: {
  746. 0: 0x4f,
  747. 1: 0x67,
  748. 2: 0x67,
  749. 3: 0x53
  750. },
  751. extractor: null
  752. },
  753. {
  754. name: "Musical Instrument Digital Interface audio",
  755. extension: "midi",
  756. mime: "audio/midi",
  757. description: "",
  758. signature: {
  759. 0: 0x4d,
  760. 1: 0x54,
  761. 2: 0x68,
  762. 3: 0x64
  763. },
  764. extractor: null
  765. },
  766. {
  767. name: "MPEG-3 audio",
  768. extension: "mp3",
  769. mime: "audio/mpeg",
  770. description: "",
  771. signature: [
  772. {
  773. 0: 0x49,
  774. 1: 0x44,
  775. 2: 0x33
  776. },
  777. {
  778. 0: 0xff,
  779. 1: 0xfb
  780. }
  781. ],
  782. extractor: null
  783. },
  784. {
  785. name: "MPEG-4 Part 14 audio",
  786. extension: "m4a",
  787. mime: "audio/m4a",
  788. description: "",
  789. signature: [
  790. {
  791. 4: 0x66,
  792. 5: 0x74,
  793. 6: 0x79,
  794. 7: 0x70,
  795. 8: 0x4d,
  796. 9: 0x34,
  797. 10: 0x41
  798. },
  799. {
  800. 0: 0x4d,
  801. 1: 0x34,
  802. 2: 0x41,
  803. 3: 0x20
  804. }
  805. ],
  806. extractor: null
  807. },
  808. {
  809. name: "Free Lossless Audio Codec",
  810. extension: "flac",
  811. mime: "audio/x-flac",
  812. description: "",
  813. signature: {
  814. 0: 0x66,
  815. 1: 0x4c,
  816. 2: 0x61,
  817. 3: 0x43
  818. },
  819. extractor: null
  820. },
  821. {
  822. name: "Adaptive Multi-Rate audio codec",
  823. extension: "amr",
  824. mime: "audio/amr",
  825. description: "",
  826. signature: {
  827. 0: 0x23,
  828. 1: 0x21,
  829. 2: 0x41,
  830. 3: 0x4d,
  831. 4: 0x52,
  832. 5: 0x0a
  833. },
  834. extractor: null
  835. },
  836. {
  837. name: "Audacity",
  838. extension: "au",
  839. mime: "audio/x-au",
  840. description: "",
  841. signature: {
  842. 0: 0x64, // dns.
  843. 1: 0x6e,
  844. 2: 0x73,
  845. 3: 0x2e,
  846. 24: 0x41, // AudacityBlockFile
  847. 25: 0x75,
  848. 26: 0x64,
  849. 27: 0x61,
  850. 28: 0x63,
  851. 29: 0x69,
  852. 30: 0x74,
  853. 31: 0x79,
  854. 32: 0x42,
  855. 33: 0x6c,
  856. 34: 0x6f,
  857. 35: 0x63,
  858. 36: 0x6b,
  859. 37: 0x46,
  860. 38: 0x69,
  861. 39: 0x6c,
  862. 40: 0x65
  863. },
  864. extractor: null
  865. },
  866. {
  867. name: "Audacity Block",
  868. extension: "auf",
  869. mime: "application/octet-stream",
  870. description: "",
  871. signature: {
  872. 0: 0x41, // AudacityBlockFile
  873. 1: 0x75,
  874. 2: 0x64,
  875. 3: 0x61,
  876. 4: 0x63,
  877. 5: 0x69,
  878. 6: 0x74,
  879. 7: 0x79,
  880. 8: 0x42,
  881. 9: 0x6c,
  882. 10: 0x6f,
  883. 11: 0x63,
  884. 12: 0x6b,
  885. 13: 0x46,
  886. 14: 0x69,
  887. 15: 0x6c,
  888. 16: 0x65
  889. },
  890. extractor: null
  891. },
  892. {
  893. name: "Audio Interchange File",
  894. extension: "aif",
  895. mime: "audio/x-aiff",
  896. description: "",
  897. signature: {
  898. 0: 0x46, // FORM
  899. 1: 0x4f,
  900. 2: 0x52,
  901. 3: 0x4d,
  902. 8: 0x41, // AIFF
  903. 9: 0x49,
  904. 10: 0x46,
  905. 11: 0x46
  906. },
  907. extractor: null
  908. },
  909. {
  910. name: "Audio Interchange File (compressed)",
  911. extension: "aifc",
  912. mime: "audio/x-aifc",
  913. description: "",
  914. signature: {
  915. 0: 0x46, // FORM
  916. 1: 0x4f,
  917. 2: 0x52,
  918. 3: 0x4d,
  919. 8: 0x41, // AIFC
  920. 9: 0x49,
  921. 10: 0x46,
  922. 11: 0x43
  923. },
  924. extractor: null
  925. }
  926. ],
  927. "Documents": [
  928. {
  929. name: "Portable Document Format",
  930. extension: "pdf",
  931. mime: "application/pdf",
  932. description: "",
  933. signature: {
  934. 0: 0x25,
  935. 1: 0x50,
  936. 2: 0x44,
  937. 3: 0x46
  938. },
  939. extractor: extractPDF
  940. },
  941. {
  942. name: "Portable Document Format (under Base64)",
  943. extension: "B64",
  944. mime: "application/octet-stream",
  945. description: "",
  946. signature: {
  947. 0: 0x41,
  948. 1: 0x4a,
  949. 2: 0x56,
  950. 3: 0x42,
  951. 4: 0x45,
  952. 5: 0x52,
  953. 6: 0x69
  954. },
  955. extractor: null
  956. },
  957. { // Place before PostScript
  958. name: "Adobe PostScript",
  959. extension: "ps,eps,ai,pfa",
  960. mime: "application/postscript",
  961. description: "",
  962. signature: {
  963. 0: 0x25,
  964. 1: 0x21,
  965. 2: 0x50,
  966. 3: 0x53,
  967. 4: 0x2d,
  968. 5: 0x41,
  969. 6: 0x64,
  970. 7: 0x6f,
  971. 8: 0x62,
  972. 9: 0x65
  973. },
  974. extractor: null
  975. },
  976. {
  977. name: "PostScript",
  978. extension: "ps",
  979. mime: "application/postscript",
  980. description: "",
  981. signature: {
  982. 0: 0x25,
  983. 1: 0x21
  984. },
  985. extractor: null
  986. },
  987. {
  988. name: "Encapsulated PostScript",
  989. extension: "eps,ai",
  990. mime: "application/eps",
  991. description: "",
  992. signature: {
  993. 0: 0xc5,
  994. 1: 0xd0,
  995. 2: 0xd3,
  996. 3: 0xc6
  997. },
  998. extractor: null
  999. },
  1000. {
  1001. name: "Rich Text Format",
  1002. extension: "rtf",
  1003. mime: "application/rtf",
  1004. description: "",
  1005. signature: {
  1006. 0: 0x7b,
  1007. 1: 0x5c,
  1008. 2: 0x72,
  1009. 3: 0x74,
  1010. 4: 0x66
  1011. },
  1012. extractor: extractRTF
  1013. },
  1014. {
  1015. name: "Microsoft Office document/OLE2",
  1016. extension: "ole2,doc,xls,dot,ppt,xla,ppa,pps,pot,msi,sdw,db,vsd,msg",
  1017. mime: "application/msword,application/vnd.ms-excel,application/vnd.ms-powerpoint",
  1018. description: "Microsoft Office documents",
  1019. signature: {
  1020. 0: 0xd0,
  1021. 1: 0xcf,
  1022. 2: 0x11,
  1023. 3: 0xe0,
  1024. 4: 0xa1,
  1025. 5: 0xb1,
  1026. 6: 0x1a,
  1027. 7: 0xe1
  1028. },
  1029. extractor: null
  1030. },
  1031. {
  1032. name: "Microsoft Office document/OLE2 (under Base64)",
  1033. extension: "B64",
  1034. mime: "application/octet-stream",
  1035. description: "",
  1036. signature: {
  1037. 0: 0x30,
  1038. 1: 0x4d,
  1039. 2: 0x38,
  1040. 3: 0x52,
  1041. 4: 0x34,
  1042. 5: 0x4b,
  1043. 6: 0x47,
  1044. 7: 0x78
  1045. },
  1046. extractor: null
  1047. },
  1048. {
  1049. name: "Microsoft Office 2007+ document",
  1050. extension: "docx,xlsx,pptx",
  1051. mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",
  1052. description: "",
  1053. signature: {
  1054. 38: 0x5f, // _Types].xml
  1055. 39: 0x54,
  1056. 40: 0x79,
  1057. 41: 0x70,
  1058. 42: 0x65,
  1059. 43: 0x73,
  1060. 44: 0x5d,
  1061. 45: 0x2e,
  1062. 46: 0x78,
  1063. 47: 0x6d,
  1064. 48: 0x6c
  1065. },
  1066. extractor: extractZIP
  1067. },
  1068. {
  1069. name: "Microsoft Access database",
  1070. extension: "mdb,mda,mde,mdt,fdb,psa",
  1071. mime: "application/msaccess",
  1072. description: "",
  1073. signature: {
  1074. 0: 0x00,
  1075. 1: 0x01,
  1076. 2: 0x00,
  1077. 3: 0x00,
  1078. 4: 0x53, // Standard Jet
  1079. 5: 0x74,
  1080. 6: 0x61,
  1081. 7: 0x6e,
  1082. 8: 0x64,
  1083. 9: 0x61,
  1084. 10: 0x72,
  1085. 11: 0x64,
  1086. 12: 0x20,
  1087. 13: 0x4a,
  1088. 14: 0x65,
  1089. 15: 0x74
  1090. },
  1091. extractor: null
  1092. },
  1093. {
  1094. name: "Microsoft Access 2007+ database",
  1095. extension: "accdb,accde,accda,accdu",
  1096. mime: "application/msaccess",
  1097. description: "",
  1098. signature: {
  1099. 0: 0x00,
  1100. 1: 0x01,
  1101. 2: 0x00,
  1102. 3: 0x00,
  1103. 4: 0x53, // Standard ACE DB
  1104. 5: 0x74,
  1105. 6: 0x61,
  1106. 7: 0x6e,
  1107. 8: 0x64,
  1108. 9: 0x61,
  1109. 10: 0x72,
  1110. 11: 0x64,
  1111. 12: 0x20,
  1112. 13: 0x41,
  1113. 14: 0x43,
  1114. 15: 0x45,
  1115. 16: 0x20
  1116. },
  1117. extractor: null
  1118. },
  1119. {
  1120. name: "Microsoft OneNote document",
  1121. extension: "one",
  1122. mime: "application/onenote",
  1123. description: "",
  1124. signature: {
  1125. 0: 0xe4,
  1126. 1: 0x52,
  1127. 2: 0x5c,
  1128. 3: 0x7b,
  1129. 4: 0x8c,
  1130. 5: 0xd8,
  1131. 6: 0xa7,
  1132. 7: 0x4d,
  1133. 8: 0xae,
  1134. 9: 0xb1,
  1135. 10: 0x53,
  1136. 11: 0x78,
  1137. 12: 0xd0,
  1138. 13: 0x29,
  1139. 14: 0x96,
  1140. 15: 0xd3
  1141. },
  1142. extractor: null
  1143. },
  1144. {
  1145. name: "Outlook Express database",
  1146. extension: "dbx",
  1147. mime: "application/octet-stream",
  1148. description: "",
  1149. signature: {
  1150. 0: 0xcf,
  1151. 1: 0xad,
  1152. 2: 0x12,
  1153. 3: 0xfe,
  1154. 4: [0x30, 0xc5, 0xc6, 0xc7],
  1155. 11: 0x11
  1156. },
  1157. extractor: null
  1158. },
  1159. {
  1160. name: "Personal Storage Table (Outlook)",
  1161. extension: "pst,ost,fdb,pab",
  1162. mime: "application/octet-stream",
  1163. description: "",
  1164. signature: {
  1165. 0: 0x21, // !BDN
  1166. 1: 0x42,
  1167. 2: 0x44,
  1168. 3: 0x4e
  1169. },
  1170. extractor: null
  1171. },
  1172. {
  1173. name: "Microsoft Exchange Database",
  1174. extension: "edb",
  1175. mime: "application/octet-stream",
  1176. description: "",
  1177. signature: {
  1178. 4: 0xef,
  1179. 5: 0xcd,
  1180. 6: 0xab,
  1181. 7: 0x89,
  1182. 8: [0x20, 0x23],
  1183. 9: 0x06,
  1184. 10: 0x00,
  1185. 11: 0x00,
  1186. 12: [0x00, 0x01],
  1187. 13: 0x00,
  1188. 14: 0x00,
  1189. 15: 0x00
  1190. },
  1191. extractor: null
  1192. },
  1193. {
  1194. name: "WordPerfect document",
  1195. extension: "wpd,wp,wp5,wp6,wpp,bk!,wcm",
  1196. mime: "application/wordperfect",
  1197. description: "",
  1198. signature: {
  1199. 0: 0xff,
  1200. 1: 0x57,
  1201. 2: 0x50,
  1202. 3: 0x43,
  1203. 7: [0x00, 0x01, 0x02],
  1204. 8: 0x01,
  1205. 9: 0x0a
  1206. },
  1207. extractor: null
  1208. },
  1209. {
  1210. name: "EPUB e-book",
  1211. extension: "epub",
  1212. mime: "application/epub+zip",
  1213. description: "",
  1214. signature: {
  1215. 0: 0x50,
  1216. 1: 0x4b,
  1217. 2: 0x3,
  1218. 3: 0x4,
  1219. 30: 0x6d, // mimetypeapplication/epub_zip
  1220. 31: 0x69,
  1221. 32: 0x6d,
  1222. 33: 0x65,
  1223. 34: 0x74,
  1224. 35: 0x79,
  1225. 36: 0x70,
  1226. 37: 0x65,
  1227. 38: 0x61,
  1228. 39: 0x70,
  1229. 40: 0x70,
  1230. 41: 0x6c,
  1231. 42: 0x69,
  1232. 43: 0x63,
  1233. 44: 0x61,
  1234. 45: 0x74,
  1235. 46: 0x69,
  1236. 47: 0x6f,
  1237. 48: 0x6e,
  1238. 49: 0x2f,
  1239. 50: 0x65,
  1240. 51: 0x70,
  1241. 52: 0x75,
  1242. 53: 0x62,
  1243. 54: 0x2b,
  1244. 55: 0x7a,
  1245. 56: 0x69,
  1246. 57: 0x70
  1247. },
  1248. extractor: extractZIP
  1249. },
  1250. ],
  1251. "Applications": [
  1252. {
  1253. name: "Windows Portable Executable",
  1254. extension: "exe,dll,drv,vxd,sys,ocx,vbx,com,fon,scr",
  1255. mime: "application/vnd.microsoft.portable-executable",
  1256. description: "",
  1257. signature: {
  1258. 0: 0x4d,
  1259. 1: 0x5a,
  1260. 3: [0x0, 0x1, 0x2],
  1261. 5: [0x0, 0x1, 0x2]
  1262. },
  1263. extractor: extractMZPE
  1264. },
  1265. {
  1266. name: "Executable and Linkable Format",
  1267. extension: "elf,bin,axf,o,prx,so",
  1268. mime: "application/x-executable",
  1269. description: "Executable and Linkable Format file. No standard file extension.",
  1270. signature: {
  1271. 0: 0x7f,
  1272. 1: 0x45,
  1273. 2: 0x4c,
  1274. 3: 0x46
  1275. },
  1276. extractor: extractELF
  1277. },
  1278. {
  1279. name: "MacOS Mach-O object",
  1280. extension: "dylib",
  1281. mime: "application/octet-stream",
  1282. description: "",
  1283. signature: {
  1284. 0: 0xca,
  1285. 1: 0xfe,
  1286. 2: 0xba,
  1287. 3: 0xbe,
  1288. 4: 0x00,
  1289. 5: 0x00,
  1290. 6: 0x00,
  1291. 7: [0x01, 0x02, 0x03]
  1292. },
  1293. extractor: null
  1294. },
  1295. {
  1296. name: "MacOS Mach-O 64-bit object",
  1297. extension: "dylib",
  1298. mime: "application/octet-stream",
  1299. description: "",
  1300. signature: {
  1301. 0: 0xcf,
  1302. 1: 0xfa,
  1303. 2: 0xed,
  1304. 3: 0xfe
  1305. },
  1306. extractor: null
  1307. },
  1308. {
  1309. name: "Adobe Flash",
  1310. extension: "swf",
  1311. mime: "application/x-shockwave-flash",
  1312. description: "",
  1313. signature: {
  1314. 0: [0x43, 0x46],
  1315. 1: 0x57,
  1316. 2: 0x53,
  1317. },
  1318. extractor: null
  1319. },
  1320. {
  1321. name: "Java Class",
  1322. extension: "class",
  1323. mime: "application/java-vm",
  1324. description: "",
  1325. signature: {
  1326. 0: 0xca,
  1327. 1: 0xfe,
  1328. 2: 0xba,
  1329. 3: 0xbe
  1330. },
  1331. extractor: null
  1332. },
  1333. {
  1334. name: "Dalvik Executable",
  1335. extension: "dex",
  1336. mime: "application/octet-stream",
  1337. description: "Dalvik Executable as used by Android",
  1338. signature: {
  1339. 0: 0x64,
  1340. 1: 0x65,
  1341. 2: 0x78,
  1342. 3: 0x0a,
  1343. 4: 0x30,
  1344. 5: 0x33,
  1345. 6: 0x35,
  1346. 7: 0x0
  1347. },
  1348. extractor: null
  1349. },
  1350. {
  1351. name: "Google Chrome Extension",
  1352. extension: "crx",
  1353. mime: "application/crx",
  1354. description: "Google Chrome extension or packaged app",
  1355. signature: {
  1356. 0: 0x43,
  1357. 1: 0x72,
  1358. 2: 0x32,
  1359. 3: 0x34
  1360. },
  1361. extractor: null
  1362. },
  1363. ],
  1364. "Archives": [
  1365. {
  1366. name: "PKZIP archive",
  1367. extension: "zip",
  1368. mime: "application/zip",
  1369. description: "",
  1370. signature: {
  1371. 0: 0x50,
  1372. 1: 0x4b,
  1373. 2: [0x3, 0x5, 0x7],
  1374. 3: [0x4, 0x6, 0x8]
  1375. },
  1376. extractor: extractZIP
  1377. },
  1378. {
  1379. name: "PKZIP archive (under Base64)",
  1380. extension: "B64",
  1381. mime: "application/octet-stream",
  1382. description: "",
  1383. signature: {
  1384. 0: 0x55,
  1385. 1: 0x45,
  1386. 2: 0x73,
  1387. 3: 0x44,
  1388. 4: 0x42,
  1389. 5: 0x42
  1390. },
  1391. extractor: null
  1392. },
  1393. {
  1394. name: "TAR archive",
  1395. extension: "tar",
  1396. mime: "application/x-tar",
  1397. description: "",
  1398. signature: {
  1399. 257: 0x75, // ustar
  1400. 258: 0x73,
  1401. 259: 0x74,
  1402. 260: 0x61,
  1403. 261: 0x72
  1404. },
  1405. extractor: null
  1406. },
  1407. {
  1408. name: "Roshal Archive",
  1409. extension: "rar",
  1410. mime: "application/x-rar-compressed",
  1411. description: "",
  1412. signature: {
  1413. 0: 0x52,
  1414. 1: 0x61,
  1415. 2: 0x72,
  1416. 3: 0x21,
  1417. 4: 0x1a,
  1418. 5: 0x7,
  1419. 6: [0x0, 0x1]
  1420. },
  1421. extractor: null
  1422. },
  1423. {
  1424. name: "Gzip",
  1425. extension: "gz",
  1426. mime: "application/gzip",
  1427. description: "",
  1428. signature: {
  1429. 0: 0x1f,
  1430. 1: 0x8b,
  1431. 2: 0x8
  1432. },
  1433. extractor: extractGZIP
  1434. },
  1435. {
  1436. name: "Bzip2",
  1437. extension: "bz2",
  1438. mime: "application/x-bzip2",
  1439. description: "",
  1440. signature: {
  1441. 0: 0x42,
  1442. 1: 0x5a,
  1443. 2: 0x68
  1444. },
  1445. extractor: extractBZIP2
  1446. },
  1447. {
  1448. name: "7zip",
  1449. extension: "7z",
  1450. mime: "application/x-7z-compressed",
  1451. description: "",
  1452. signature: {
  1453. 0: 0x37,
  1454. 1: 0x7a,
  1455. 2: 0xbc,
  1456. 3: 0xaf,
  1457. 4: 0x27,
  1458. 5: 0x1c
  1459. },
  1460. extractor: null
  1461. },
  1462. {
  1463. name: "Zlib Deflate",
  1464. extension: "zlib",
  1465. mime: "application/x-deflate",
  1466. description: "",
  1467. signature: {
  1468. 0: 0x78,
  1469. 1: [0x1, 0x9c, 0xda, 0x5e]
  1470. },
  1471. extractor: extractZlib
  1472. },
  1473. {
  1474. name: "xz compression",
  1475. extension: "xz",
  1476. mime: "application/x-xz",
  1477. description: "",
  1478. signature: {
  1479. 0: 0xfd,
  1480. 1: 0x37,
  1481. 2: 0x7a,
  1482. 3: 0x58,
  1483. 4: 0x5a,
  1484. 5: 0x0
  1485. },
  1486. extractor: extractXZ
  1487. },
  1488. {
  1489. name: "Tarball",
  1490. extension: "tar.z",
  1491. mime: "application/x-gtar",
  1492. description: "",
  1493. signature: {
  1494. 0: 0x1f,
  1495. 1: [0x9d, 0xa0]
  1496. },
  1497. extractor: null
  1498. },
  1499. {
  1500. name: "ISO disk image",
  1501. extension: "iso",
  1502. mime: "application/octet-stream",
  1503. description: "ISO 9660 CD/DVD image file",
  1504. signature: [
  1505. {
  1506. 0x8001: 0x43,
  1507. 0x8002: 0x44,
  1508. 0x8003: 0x30,
  1509. 0x8004: 0x30,
  1510. 0x8005: 0x31
  1511. },
  1512. {
  1513. 0x8801: 0x43,
  1514. 0x8802: 0x44,
  1515. 0x8803: 0x30,
  1516. 0x8804: 0x30,
  1517. 0x8805: 0x31
  1518. },
  1519. {
  1520. 0x9001: 0x43,
  1521. 0x9002: 0x44,
  1522. 0x9003: 0x30,
  1523. 0x9004: 0x30,
  1524. 0x9005: 0x31
  1525. }
  1526. ],
  1527. extractor: null
  1528. },
  1529. {
  1530. name: "Virtual Machine Disk",
  1531. extension: "vmdk",
  1532. mime: "application/vmdk,application/x-virtualbox-vmdk",
  1533. description: "",
  1534. signature: {
  1535. 0: 0x4b,
  1536. 1: 0x44,
  1537. 2: 0x4d,
  1538. 3: 0x56,
  1539. 5: 0x00,
  1540. 6: 0x00,
  1541. 7: 0x00
  1542. },
  1543. extractor: null
  1544. },
  1545. {
  1546. name: "Virtual Hard Drive",
  1547. extension: "vhd",
  1548. mime: "application/x-vhd",
  1549. description: "",
  1550. signature: {
  1551. 0: 0x63, // conectix
  1552. 1: 0x6f,
  1553. 2: 0x6e,
  1554. 3: 0x65,
  1555. 4: 0x63,
  1556. 5: 0x74,
  1557. 6: 0x69,
  1558. 7: 0x78
  1559. },
  1560. extractor: null
  1561. },
  1562. {
  1563. name: "Macintosh disk image",
  1564. extension: "dmf,dmg",
  1565. mime: "application/octet-stream",
  1566. description: "",
  1567. signature: {
  1568. 0: 0x78,
  1569. 1: 0x01,
  1570. 2: 0x73,
  1571. 3: 0x0d,
  1572. 4: 0x62,
  1573. 5: 0x62,
  1574. 6: 0x60,
  1575. 7: 0x60
  1576. },
  1577. extractor: null
  1578. },
  1579. {
  1580. name: "ARJ Archive",
  1581. extension: "arj",
  1582. mime: "application/x-arj-compressed",
  1583. description: "",
  1584. signature: {
  1585. 0: 0x60,
  1586. 1: 0xea,
  1587. 8: [0x0, 0x10, 0x14],
  1588. 9: 0x0,
  1589. 10: 0x2
  1590. },
  1591. extractor: null
  1592. },
  1593. {
  1594. name: "WinAce Archive",
  1595. extension: "ace",
  1596. mime: "application/x-ace-compressed",
  1597. description: "",
  1598. signature: {
  1599. 7: 0x2a, // **ACE**
  1600. 8: 0x2a,
  1601. 9: 0x41,
  1602. 10: 0x43,
  1603. 11: 0x45,
  1604. 12: 0x2a,
  1605. 13: 0x2a
  1606. },
  1607. extractor: null
  1608. },
  1609. {
  1610. name: "Macintosh BinHex Encoded File",
  1611. extension: "hqx",
  1612. mime: "application/mac-binhex",
  1613. description: "",
  1614. signature: {
  1615. 11: 0x6d, // must be converted with BinHex
  1616. 12: 0x75,
  1617. 13: 0x73,
  1618. 14: 0x74,
  1619. 15: 0x20,
  1620. 16: 0x62,
  1621. 17: 0x65,
  1622. 18: 0x20,
  1623. 19: 0x63,
  1624. 20: 0x6f,
  1625. 21: 0x6e,
  1626. 22: 0x76,
  1627. 23: 0x65,
  1628. 24: 0x72,
  1629. 25: 0x74,
  1630. 26: 0x65,
  1631. 27: 0x64,
  1632. 28: 0x20,
  1633. 29: 0x77,
  1634. 30: 0x69,
  1635. 31: 0x74,
  1636. 32: 0x68,
  1637. 33: 0x20,
  1638. 34: 0x42,
  1639. 35: 0x69,
  1640. 36: 0x6e,
  1641. 37: 0x48,
  1642. 38: 0x65,
  1643. 39: 0x78
  1644. },
  1645. extractor: null
  1646. },
  1647. {
  1648. name: "ALZip Archive",
  1649. extension: "alz",
  1650. mime: "application/octet-stream",
  1651. description: "",
  1652. signature: {
  1653. 0: 0x41, // ALZ
  1654. 1: 0x4c,
  1655. 2: 0x5a,
  1656. 3: 0x01,
  1657. 4: 0x0a,
  1658. 5: 0x0,
  1659. 6: 0x0,
  1660. 7: 0x0
  1661. },
  1662. extractor: null
  1663. },
  1664. {
  1665. name: "KGB Compressed Archive",
  1666. extension: "kgb",
  1667. mime: "application/x-kgb-compressed",
  1668. description: "",
  1669. signature: {
  1670. 0: 0x4b, // KGB_arch -
  1671. 1: 0x47,
  1672. 2: 0x42,
  1673. 3: 0x5f,
  1674. 4: 0x61,
  1675. 5: 0x72,
  1676. 6: 0x63,
  1677. 7: 0x68,
  1678. 8: 0x20,
  1679. 9: 0x2d
  1680. },
  1681. extractor: null
  1682. },
  1683. {
  1684. name: "Microsoft Cabinet",
  1685. extension: "cab",
  1686. mime: "vnd.ms-cab-compressed",
  1687. description: "",
  1688. signature: {
  1689. 0: 0x4d,
  1690. 1: 0x53,
  1691. 2: 0x43,
  1692. 3: 0x46,
  1693. 4: 0x00,
  1694. 5: 0x00,
  1695. 6: 0x00,
  1696. 7: 0x00
  1697. },
  1698. extractor: null
  1699. },
  1700. {
  1701. name: "Jar Archive",
  1702. extension: "jar",
  1703. mime: "application/java-archive",
  1704. description: "",
  1705. signature: {
  1706. 0: 0x5f,
  1707. 1: 0x27,
  1708. 2: 0xa8,
  1709. 3: 0x89
  1710. },
  1711. extractor: null
  1712. },
  1713. {
  1714. name: "lzop compressed",
  1715. extension: "lzop,lzo",
  1716. mime: "application/x-lzop",
  1717. description: "",
  1718. signature: {
  1719. 0: 0x89,
  1720. 1: 0x4c, // LZO
  1721. 2: 0x5a,
  1722. 3: 0x4f,
  1723. 4: 0x00,
  1724. 5: 0x0d,
  1725. 6: 0x0a,
  1726. 7: 0x1a
  1727. },
  1728. extractor: null
  1729. },
  1730. ],
  1731. "Miscellaneous": [
  1732. {
  1733. name: "UTF-8 text",
  1734. extension: "txt",
  1735. mime: "text/plain",
  1736. description: "UTF-8 encoded Unicode byte order mark, commonly but not exclusively seen in text files.",
  1737. signature: {
  1738. 0: 0xef,
  1739. 1: 0xbb,
  1740. 2: 0xbf
  1741. },
  1742. extractor: null
  1743. },
  1744. { // Place before UTF-16 LE text
  1745. name: "UTF-32 LE text",
  1746. extension: "utf32le",
  1747. mime: "charset/utf32le",
  1748. description: "Little-endian UTF-32 encoded Unicode byte order mark.",
  1749. signature: {
  1750. 0: 0xff,
  1751. 1: 0xfe,
  1752. 2: 0x00,
  1753. 3: 0x00
  1754. },
  1755. extractor: null
  1756. },
  1757. {
  1758. name: "UTF-16 LE text",
  1759. extension: "utf16le",
  1760. mime: "charset/utf16le",
  1761. description: "Little-endian UTF-16 encoded Unicode byte order mark.",
  1762. signature: {
  1763. 0: 0xff,
  1764. 1: 0xfe
  1765. },
  1766. extractor: null
  1767. },
  1768. {
  1769. name: "Web Open Font Format",
  1770. extension: "woff",
  1771. mime: "application/font-woff",
  1772. description: "",
  1773. signature: {
  1774. 0: 0x77,
  1775. 1: 0x4f,
  1776. 2: 0x46,
  1777. 3: 0x46,
  1778. 4: 0x0,
  1779. 5: 0x1,
  1780. 6: 0x0,
  1781. 7: 0x0
  1782. },
  1783. extractor: null
  1784. },
  1785. {
  1786. name: "Web Open Font Format 2",
  1787. extension: "woff2",
  1788. mime: "application/font-woff",
  1789. description: "",
  1790. signature: {
  1791. 0: 0x77,
  1792. 1: 0x4f,
  1793. 2: 0x46,
  1794. 3: 0x32,
  1795. 4: 0x0,
  1796. 5: 0x1,
  1797. 6: 0x0,
  1798. 7: 0x0
  1799. },
  1800. extractor: null
  1801. },
  1802. {
  1803. name: "Embedded OpenType font",
  1804. extension: "eot",
  1805. mime: "application/octet-stream",
  1806. description: "",
  1807. signature: [
  1808. {
  1809. 8: 0x2,
  1810. 9: 0x0,
  1811. 10: 0x1,
  1812. 34: 0x4c,
  1813. 35: 0x50
  1814. },
  1815. {
  1816. 8: 0x1,
  1817. 9: 0x0,
  1818. 10: 0x0,
  1819. 34: 0x4c,
  1820. 35: 0x50
  1821. },
  1822. {
  1823. 8: 0x2,
  1824. 9: 0x0,
  1825. 10: 0x2,
  1826. 34: 0x4c,
  1827. 35: 0x50
  1828. },
  1829. ],
  1830. extractor: null
  1831. },
  1832. {
  1833. name: "TrueType Font",
  1834. extension: "ttf",
  1835. mime: "application/font-sfnt",
  1836. description: "",
  1837. signature: {
  1838. 0: 0x0,
  1839. 1: 0x1,
  1840. 2: 0x0,
  1841. 3: 0x0,
  1842. 4: 0x0
  1843. },
  1844. extractor: null
  1845. },
  1846. {
  1847. name: "OpenType Font",
  1848. extension: "otf",
  1849. mime: "application/font-sfnt",
  1850. description: "",
  1851. signature: {
  1852. 0: 0x4f,
  1853. 1: 0x54,
  1854. 2: 0x54,
  1855. 3: 0x4f,
  1856. 4: 0x0
  1857. },
  1858. extractor: null
  1859. },
  1860. {
  1861. name: "SQLite",
  1862. extension: "sqlite",
  1863. mime: "application/x-sqlite3",
  1864. description: "",
  1865. signature: {
  1866. 0: 0x53,
  1867. 1: 0x51,
  1868. 2: 0x4c,
  1869. 3: 0x69
  1870. },
  1871. extractor: null
  1872. },
  1873. {
  1874. name: "BitTorrent link",
  1875. extension: "torrent",
  1876. mime: "application/x-bittorrent",
  1877. description: "",
  1878. signature: [
  1879. {
  1880. 0: 0x64, // d8:announce##:
  1881. 1: 0x38,
  1882. 2: 0x3a,
  1883. 3: 0x61,
  1884. 4: 0x6e,
  1885. 5: 0x6e,
  1886. 6: 0x6f,
  1887. 7: 0x75,
  1888. 8: 0x6e,
  1889. 9: 0x63,
  1890. 10: 0x65,
  1891. 11: 0x23,
  1892. 12: 0x23,
  1893. 13: 0x3a
  1894. },
  1895. {
  1896. 0: 0x64, // d4:infod
  1897. 1: 0x34,
  1898. 2: 0x3a,
  1899. 3: 0x69,
  1900. 4: 0x6e,
  1901. 5: 0x66,
  1902. 6: 0x6f,
  1903. 7: 0x64,
  1904. 8: [0x34, 0x35, 0x36],
  1905. 9: 0x3a
  1906. }
  1907. ],
  1908. extractor: null
  1909. },
  1910. {
  1911. name: "Cryptocurrency wallet",
  1912. extension: "wallet",
  1913. mime: "application/octet-stream",
  1914. description: "",
  1915. signature: {
  1916. 0: 0x00,
  1917. 1: 0x00,
  1918. 2: 0x00,
  1919. 3: 0x00,
  1920. 4: 0x01,
  1921. 5: 0x00,
  1922. 6: 0x00,
  1923. 7: 0x00,
  1924. 8: 0x00,
  1925. 9: 0x00,
  1926. 10: 0x00,
  1927. 11: 0x00,
  1928. 12: 0x62,
  1929. 13: 0x31,
  1930. 14: 0x05,
  1931. 15: 0x00
  1932. },
  1933. extractor: null
  1934. },
  1935. {
  1936. name: "Registry fragment",
  1937. extension: "hbin",
  1938. mime: "application/octet-stream",
  1939. description: "",
  1940. signature: {
  1941. 0: 0x68, // hbin
  1942. 1: 0x62,
  1943. 2: 0x69,
  1944. 3: 0x6e,
  1945. 4: 0x00
  1946. },
  1947. extractor: null
  1948. },
  1949. {
  1950. name: "Registry script",
  1951. extension: "rgs",
  1952. mime: "application/octet-stream",
  1953. description: "",
  1954. signature: {
  1955. 0: 0x48, // HKCR
  1956. 1: 0x4b,
  1957. 2: 0x43,
  1958. 3: 0x52,
  1959. 4: 0x0d,
  1960. 5: 0x0a,
  1961. 6: 0x5c,
  1962. 7: 0x7b
  1963. },
  1964. extractor: null
  1965. },
  1966. {
  1967. name: "WinNT Registry Hive",
  1968. extension: "registry",
  1969. mime: "application/octet-stream",
  1970. description: "",
  1971. signature: {
  1972. 0: 0x72,
  1973. 1: 0x65,
  1974. 2: 0x67,
  1975. 3: 0x66
  1976. },
  1977. extractor: null
  1978. },
  1979. {
  1980. name: "Windows Event Log",
  1981. extension: "evt",
  1982. mime: "application/octet-stream",
  1983. description: "",
  1984. signature: {
  1985. 0: 0x30,
  1986. 1: 0x00,
  1987. 2: 0x00,
  1988. 3: 0x00,
  1989. 4: 0x4c,
  1990. 5: 0x66,
  1991. 6: 0x4c,
  1992. 7: 0x65
  1993. },
  1994. extractor: null
  1995. },
  1996. {
  1997. name: "Windows Event Log",
  1998. extension: "evtx",
  1999. mime: "application/octet-stream",
  2000. description: "",
  2001. signature: {
  2002. 0: 0x45, // ElfFile
  2003. 1: 0x6c,
  2004. 2: 0x66,
  2005. 3: 0x46,
  2006. 4: 0x69,
  2007. 5: 0x6c,
  2008. 6: 0x65
  2009. },
  2010. extractor: null
  2011. },
  2012. {
  2013. name: "Windows Pagedump",
  2014. extension: "dmp",
  2015. mime: "application/octet-stream",
  2016. description: "",
  2017. signature: {
  2018. 0: 0x50, // PAGEDU(MP|64)
  2019. 1: 0x41,
  2020. 2: 0x47,
  2021. 3: 0x45,
  2022. 4: 0x44,
  2023. 5: 0x55,
  2024. 6: [0x4d, 0x36],
  2025. 7: [0x50, 0x34]
  2026. },
  2027. extractor: null
  2028. },
  2029. {
  2030. name: "Windows Prefetch",
  2031. extension: "pf",
  2032. mime: "application/x-pf",
  2033. description: "",
  2034. signature: {
  2035. 0: [0x11, 0x17, 0x1a],
  2036. 1: 0x0,
  2037. 2: 0x0,
  2038. 3: 0x0,
  2039. 4: 0x53,
  2040. 5: 0x43,
  2041. 6: 0x43,
  2042. 7: 0x41
  2043. },
  2044. extractor: null
  2045. },
  2046. {
  2047. name: "Windows Prefetch (Win 10)",
  2048. extension: "pf",
  2049. mime: "application/x-pf",
  2050. description: "",
  2051. signature: {
  2052. 0: 0x4d,
  2053. 1: 0x41,
  2054. 2: 0x4d,
  2055. 3: 0x04,
  2056. 7: 0x0
  2057. },
  2058. extractor: null
  2059. },
  2060. {
  2061. name: "PList (XML)",
  2062. extension: "plist",
  2063. mime: "application/xml",
  2064. description: "",
  2065. signature: {
  2066. 39: 0x3c, // <!DOCTYPE plist
  2067. 40: 0x21,
  2068. 41: 0x44,
  2069. 42: 0x4f,
  2070. 43: 0x43,
  2071. 44: 0x54,
  2072. 45: 0x59,
  2073. 46: 0x50,
  2074. 47: 0x45,
  2075. 48: 0x20,
  2076. 49: 0x70,
  2077. 50: 0x6c,
  2078. 51: 0x69,
  2079. 52: 0x73,
  2080. 53: 0x74
  2081. },
  2082. extractor: extractPListXML
  2083. },
  2084. {
  2085. name: "PList (binary)",
  2086. extension: "bplist,plist,ipmeta,abcdp,mdbackup,mdinfo,strings,nib,ichat,qtz,webbookmark,webhistory",
  2087. mime: "application/x-plist",
  2088. description: "",
  2089. signature: {
  2090. 0: 0x62, // bplist00
  2091. 1: 0x70,
  2092. 2: 0x6c,
  2093. 3: 0x69,
  2094. 4: 0x73,
  2095. 5: 0x74,
  2096. 6: 0x30,
  2097. 7: 0x30
  2098. },
  2099. extractor: null
  2100. },
  2101. {
  2102. name: "MacOS X Keychain",
  2103. extension: "keychain",
  2104. mime: "application/octet-stream",
  2105. description: "",
  2106. signature: {
  2107. 0: 0x6b, // keych
  2108. 1: 0x79,
  2109. 2: 0x63,
  2110. 3: 0x68,
  2111. 4: 0x00,
  2112. 5: 0x01
  2113. },
  2114. extractor: null
  2115. },
  2116. {
  2117. name: "TCP Packet",
  2118. extension: "tcp",
  2119. mime: "application/tcp",
  2120. description: "",
  2121. signature: {
  2122. 12: 0x08,
  2123. 13: 0x00,
  2124. 14: 0x45,
  2125. 15: 0x00,
  2126. 21: 0x00,
  2127. 22: b => b >= 0x01 && b <= 0x80,
  2128. 23: 0x06
  2129. },
  2130. extractor: null
  2131. },
  2132. {
  2133. name: "UDP Packet",
  2134. extension: "udp",
  2135. mime: "application/udp",
  2136. description: "",
  2137. signature: {
  2138. 12: 0x08,
  2139. 13: 0x00,
  2140. 14: 0x45,
  2141. 15: 0x00,
  2142. 16: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05],
  2143. 22: b => b >= 0x01 && b <= 0x80,
  2144. 23: 0x11
  2145. },
  2146. extractor: null
  2147. },
  2148. {
  2149. name: "Compiled HTML",
  2150. extension: "chm,chw,chi",
  2151. mime: "application/vnd.ms-htmlhelp",
  2152. description: "",
  2153. signature: {
  2154. 0: 0x49, // ITSF
  2155. 1: 0x54,
  2156. 2: 0x53,
  2157. 3: 0x46,
  2158. 4: 0x03,
  2159. 5: 0x00,
  2160. 6: 0x00,
  2161. 7: 0x00
  2162. },
  2163. extractor: null
  2164. },
  2165. {
  2166. name: "Windows Password",
  2167. extension: "pwl",
  2168. mime: "application/octet-stream",
  2169. description: "",
  2170. signature: {
  2171. 0: 0xe3,
  2172. 1: 0x82,
  2173. 2: 0x85,
  2174. 3: 0x96
  2175. },
  2176. extractor: null
  2177. },
  2178. {
  2179. name: "Bitlocker recovery key",
  2180. extension: "bitlocker",
  2181. mime: "application/octet-stream",
  2182. description: "",
  2183. signature: {
  2184. 0: 0xff,
  2185. 1: 0xfe,
  2186. 2: 0x42,
  2187. 3: 0x00,
  2188. 4: 0x69,
  2189. 5: 0x00,
  2190. 6: 0x74,
  2191. 7: 0x00,
  2192. 8: 0x4c,
  2193. 9: 0x00,
  2194. 10: 0x6f,
  2195. 11: 0x00,
  2196. 12: 0x63,
  2197. 13: 0x00,
  2198. 14: 0x6b,
  2199. 15: 0x00,
  2200. 16: 0x65,
  2201. 17: 0x00,
  2202. 18: 0x72,
  2203. 19: 0x00,
  2204. 20: 0x20,
  2205. 21: 0x00
  2206. },
  2207. extractor: null
  2208. },
  2209. {
  2210. name: "Certificate",
  2211. extension: "cer,cat,p7b,p7c,p7m,p7s,swz,rsa,crl,crt,der",
  2212. mime: "application/pkix-cert",
  2213. description: "",
  2214. signature: {
  2215. 0: 0x30,
  2216. 1: 0x82,
  2217. 4: [0x06, 0x0a, 0x30]
  2218. },
  2219. extractor: null
  2220. },
  2221. {
  2222. name: "Certificate",
  2223. extension: "cat,swz,p7m",
  2224. mime: "application/vnd.ms-pki.seccat",
  2225. description: "",
  2226. signature: {
  2227. 0: 0x30,
  2228. 1: 0x83,
  2229. 2: b => b !== 0x00,
  2230. 5: 0x06,
  2231. 6: 0x09
  2232. },
  2233. extractor: null
  2234. },
  2235. {
  2236. name: "PGP pubring",
  2237. extension: "pkr,gpg",
  2238. mime: "application/pgp-keys",
  2239. description: "",
  2240. signature: {
  2241. 0: 0x99,
  2242. 1: 0x01,
  2243. 2: [0x0d, 0xa2],
  2244. 3: 0x04
  2245. },
  2246. extractor: null
  2247. },
  2248. {
  2249. name: "PGP secring",
  2250. extension: "skr",
  2251. mime: "application/pgp-keys",
  2252. description: "",
  2253. signature: [
  2254. {
  2255. 0: 0x95,
  2256. 1: 0x01,
  2257. 2: 0xcf,
  2258. 3: 0x04
  2259. },
  2260. {
  2261. 0: 0x95,
  2262. 1: 0x03,
  2263. 2: 0xc6,
  2264. 3: 0x04
  2265. }
  2266. ],
  2267. extractor: null
  2268. },
  2269. {
  2270. name: "PGP Safe",
  2271. extension: "pgd",
  2272. mime: "application/pgp-keys",
  2273. description: "",
  2274. signature: {
  2275. 0: 0x50, // PGPdMAIN
  2276. 1: 0x47,
  2277. 2: 0x50,
  2278. 3: 0x64,
  2279. 4: 0x4d,
  2280. 5: 0x41,
  2281. 6: 0x49,
  2282. 7: 0x4e,
  2283. 8: 0x60,
  2284. 9: 0x01,
  2285. 10: 0x00
  2286. },
  2287. extractor: null
  2288. },
  2289. {
  2290. name: "Task Scheduler",
  2291. extension: "job",
  2292. mime: "application/octet-stream",
  2293. description: "",
  2294. signature: {
  2295. 0: [0x00, 0x01, 0x02, 0x03],
  2296. 1: [0x05, 0x06],
  2297. 2: 0x01,
  2298. 3: 0x00,
  2299. 20: 0x46,
  2300. 21: 0x00
  2301. },
  2302. extractor: null
  2303. },
  2304. {
  2305. name: "Windows Shortcut",
  2306. extension: "lnk",
  2307. mime: "application/x-ms-shortcut",
  2308. description: "",
  2309. signature: {
  2310. 0: 0x4c,
  2311. 1: 0x00,
  2312. 2: 0x00,
  2313. 3: 0x00,
  2314. 4: 0x01,
  2315. 5: 0x14,
  2316. 6: 0x02,
  2317. 7: 0x00,
  2318. 8: 0x00,
  2319. 9: 0x00,
  2320. 10: 0x00,
  2321. 11: 0x00,
  2322. 12: 0xc0,
  2323. 13: 0x00,
  2324. 14: 0x00,
  2325. 15: 0x00,
  2326. 16: 0x00,
  2327. 17: 0x00,
  2328. 18: 0x00,
  2329. 19: 0x46
  2330. },
  2331. extractor: null
  2332. }
  2333. ]
  2334. };
  2335. /**
  2336. * JPEG extractor.
  2337. *
  2338. * @param {Uint8Array} bytes
  2339. * @param {number} offset
  2340. * @returns {Uint8Array}
  2341. */
  2342. export function extractJPEG(bytes, offset) {
  2343. const stream = new Stream(bytes.slice(offset));
  2344. while (stream.hasMore()) {
  2345. const marker = stream.getBytes(2);
  2346. if (marker[0] !== 0xff) throw new Error(`Invalid marker while parsing JPEG at pos ${stream.position}: ${marker}`);
  2347. let segmentSize = 0;
  2348. switch (marker[1]) {
  2349. // No length
  2350. case 0xd8: // Start of Image
  2351. case 0x01: // For temporary use in arithmetic coding
  2352. break;
  2353. case 0xd9: // End found
  2354. return stream.carve();
  2355. // Variable size segment
  2356. case 0xc0: // Start of frame (Baseline DCT)
  2357. case 0xc1: // Start of frame (Extended sequential DCT)
  2358. case 0xc2: // Start of frame (Progressive DCT)
  2359. case 0xc3: // Start of frame (Lossless sequential)
  2360. case 0xc4: // Define Huffman Table
  2361. case 0xc5: // Start of frame (Differential sequential DCT)
  2362. case 0xc6: // Start of frame (Differential progressive DCT)
  2363. case 0xc7: // Start of frame (Differential lossless)
  2364. case 0xc8: // Reserved for JPEG extensions
  2365. case 0xc9: // Start of frame (Extended sequential DCT)
  2366. case 0xca: // Start of frame (Progressive DCT)
  2367. case 0xcb: // Start of frame (Lossless sequential)
  2368. case 0xcc: // Define arithmetic conditioning table
  2369. case 0xcd: // Start of frame (Differential sequential DCT)
  2370. case 0xce: // Start of frame (Differential progressive DCT)
  2371. case 0xcf: // Start of frame (Differential lossless)
  2372. case 0xdb: // Define Quantization Table
  2373. case 0xde: // Define hierarchical progression
  2374. case 0xe0: // Application-specific
  2375. case 0xe1: // Application-specific
  2376. case 0xe2: // Application-specific
  2377. case 0xe3: // Application-specific
  2378. case 0xe4: // Application-specific
  2379. case 0xe5: // Application-specific
  2380. case 0xe6: // Application-specific
  2381. case 0xe7: // Application-specific
  2382. case 0xe8: // Application-specific
  2383. case 0xe9: // Application-specific
  2384. case 0xea: // Application-specific
  2385. case 0xeb: // Application-specific
  2386. case 0xec: // Application-specific
  2387. case 0xed: // Application-specific
  2388. case 0xee: // Application-specific
  2389. case 0xef: // Application-specific
  2390. case 0xfe: // Comment
  2391. segmentSize = stream.readInt(2, "be");
  2392. stream.position += segmentSize - 2;
  2393. break;
  2394. // 1 byte
  2395. case 0xdf: // Expand reference image
  2396. stream.position++;
  2397. break;
  2398. // 2 bytes
  2399. case 0xdc: // Define number of lines
  2400. case 0xdd: // Define restart interval
  2401. stream.position += 2;
  2402. break;
  2403. // Start scan
  2404. case 0xda: // Start of scan
  2405. segmentSize = stream.readInt(2, "be");
  2406. stream.position += segmentSize - 2;
  2407. stream.continueUntil(0xff);
  2408. break;
  2409. // Continue through encoded data
  2410. case 0x00: // Byte stuffing
  2411. case 0xd0: // Restart
  2412. case 0xd1: // Restart
  2413. case 0xd2: // Restart
  2414. case 0xd3: // Restart
  2415. case 0xd4: // Restart
  2416. case 0xd5: // Restart
  2417. case 0xd6: // Restart
  2418. case 0xd7: // Restart
  2419. stream.continueUntil(0xff);
  2420. break;
  2421. default:
  2422. stream.continueUntil(0xff);
  2423. break;
  2424. }
  2425. }
  2426. throw new Error("Unable to parse JPEG successfully");
  2427. }
  2428. /**
  2429. * GIF extractor.
  2430. *
  2431. * @param {Uint8Array} bytes
  2432. * @param {Number} offset
  2433. * @returns {Uint8Array}
  2434. */
  2435. export function extractGIF(bytes, offset) {
  2436. const stream = new Stream(bytes.slice(offset));
  2437. //Move to application extension block.
  2438. stream.continueUntil([0x21, 0xff]);
  2439. //Move to Graphic Control Extension for frame #1.
  2440. stream.continueUntil([0x21, 0xf9]);
  2441. stream.moveForwardsBy(2);
  2442. while (stream.hasMore()) {
  2443. //Move to Image descriptor.
  2444. stream.moveForwardsBy(stream.getBytes(1)[0]+1);
  2445. //Move past Image descriptor to the image data.
  2446. stream.moveForwardsBy(11);
  2447. //Loop until next Graphic Control Extension.
  2448. while (stream.getBytes(2) !== [0x21, 0xf9]) {
  2449. stream.moveBackwardsBy(2);
  2450. stream.moveForwardsBy(stream.getBytes(1)[0]);
  2451. if (!stream.getBytes(1)[0])
  2452. break;
  2453. stream.moveBackwardsBy(1);
  2454. }
  2455. //When the end of the file is [0x00, 0x3b], end.
  2456. if (stream.getBytes(1)[0] === 0x3b)
  2457. break;
  2458. stream.moveForwardsBy(1);
  2459. }
  2460. return stream.carve();
  2461. }
  2462. /**
  2463. * Portable executable extractor.
  2464. * Assumes that the offset refers to an MZ header.
  2465. *
  2466. * @param {Uint8Array} bytes
  2467. * @param {number} offset
  2468. * @returns {Uint8Array}
  2469. */
  2470. export function extractMZPE(bytes, offset) {
  2471. const stream = new Stream(bytes.slice(offset));
  2472. // Read pointer to PE header
  2473. stream.moveTo(0x3c);
  2474. const peAddress = stream.readInt(4, "le");
  2475. // Move to PE header
  2476. stream.moveTo(peAddress);
  2477. // Get number of sections
  2478. stream.moveForwardsBy(6);
  2479. const numSections = stream.readInt(2, "le");
  2480. // Read Optional Header Magic to determine the state of the image file
  2481. // 0x10b = normal executable, 0x107 = ROM image, 0x20b = PE32+ executable
  2482. stream.moveForwardsBy(16);
  2483. const optionalMagic = stream.readInt(2, "le");
  2484. const pe32Plus = optionalMagic === 0x20b;
  2485. // Move to Data Directory
  2486. const dataDirectoryOffset = pe32Plus ? 112 : 96;
  2487. stream.moveForwardsBy(dataDirectoryOffset - 2);
  2488. // Read Certificate Table address and size (IMAGE_DIRECTORY_ENTRY_SECURITY)
  2489. stream.moveForwardsBy(32);
  2490. const certTableAddress = stream.readInt(4, "le");
  2491. const certTableSize = stream.readInt(4, "le");
  2492. // PE files can contain extra data appended to the end of the file called an "overlay".
  2493. // This data is not covered by the PE header and could be any arbitrary format, so its
  2494. // length cannot be determined without contextual information.
  2495. // However, the Attribute Certificate Table is stored in the overlay - usually right at
  2496. // the end. Therefore, if this table is defined, we can use its offset and size to carve
  2497. // out the entire PE file, including the overlay.
  2498. // If the Certificate Table is not defined, we continue to parse the PE file as best we
  2499. // can up to the end of the final section, not including any appended data in the overlay.
  2500. if (certTableAddress > 0) {
  2501. stream.moveTo(certTableAddress + certTableSize);
  2502. return stream.carve();
  2503. }
  2504. // Move past Optional Header to Section Header
  2505. stream.moveForwardsBy(88);
  2506. // Move to final section header
  2507. stream.moveForwardsBy((numSections - 1) * 0x28);
  2508. // Get raw data info
  2509. stream.moveForwardsBy(16);
  2510. const rawDataSize = stream.readInt(4, "le");
  2511. const rawDataAddress = stream.readInt(4, "le");
  2512. // Move to end of final section
  2513. stream.moveTo(rawDataAddress + rawDataSize);
  2514. return stream.carve();
  2515. }
  2516. /**
  2517. * PDF extractor.
  2518. *
  2519. * @param {Uint8Array} bytes
  2520. * @param {number} offset
  2521. * @returns {Uint8Array}
  2522. */
  2523. export function extractPDF(bytes, offset) {
  2524. const stream = new Stream(bytes.slice(offset));
  2525. // Find end-of-file marker (%%EOF)
  2526. stream.continueUntil([0x25, 0x25, 0x45, 0x4f, 0x46]);
  2527. stream.moveForwardsBy(5);
  2528. stream.consumeIf(0x0d);
  2529. stream.consumeIf(0x0a);
  2530. return stream.carve();
  2531. }
  2532. /**
  2533. * ZIP extractor.
  2534. *
  2535. * @param {Uint8Array} bytes
  2536. * @param {number} offset
  2537. * @returns {Uint8Array}
  2538. */
  2539. export function extractZIP(bytes, offset) {
  2540. const stream = new Stream(bytes.slice(offset));
  2541. // Find End of central directory record
  2542. stream.continueUntil([0x50, 0x4b, 0x05, 0x06]);
  2543. // Get comment length and consume
  2544. stream.moveForwardsBy(20);
  2545. const commentLength = stream.readInt(2, "le");
  2546. stream.moveForwardsBy(commentLength);
  2547. return stream.carve();
  2548. }
  2549. /**
  2550. * PNG extractor.
  2551. *
  2552. * @param {Uint8Array} bytes
  2553. * @param {number} offset
  2554. * @returns {Uint8Array}
  2555. */
  2556. export function extractPNG(bytes, offset) {
  2557. const stream = new Stream(bytes.slice(offset));
  2558. // Move past signature to first chunk
  2559. stream.moveForwardsBy(8);
  2560. let chunkSize = 0,
  2561. chunkType = "";
  2562. while (chunkType !== "IEND") {
  2563. chunkSize = stream.readInt(4, "be");
  2564. chunkType = stream.readString(4);
  2565. // Chunk data size + CRC checksum
  2566. stream.moveForwardsBy(chunkSize + 4);
  2567. }
  2568. return stream.carve();
  2569. }
  2570. /**
  2571. * BMP extractor.
  2572. *
  2573. * @param {Uint8Array} bytes
  2574. * @param {number} offset
  2575. * @returns {Uint8Array}
  2576. */
  2577. export function extractBMP(bytes, offset) {
  2578. const stream = new Stream(bytes.slice(offset));
  2579. // Move past header
  2580. stream.moveForwardsBy(2);
  2581. // Read full file size
  2582. const bmpSize = stream.readInt(4, "le");
  2583. // Move to end of file (file size minus header and size field)
  2584. stream.moveForwardsBy(bmpSize - 6);
  2585. return stream.carve();
  2586. }
  2587. /**
  2588. * FLV extractor.
  2589. *
  2590. * @param {Uint8Array} bytes
  2591. * @param {number} offset
  2592. * @returns {Uint8Array}
  2593. */
  2594. export function extractFLV(bytes, offset) {
  2595. const stream = new Stream(bytes.slice(offset));
  2596. // Move past signature, version and flags
  2597. stream.moveForwardsBy(5);
  2598. // Read header size
  2599. const headerSize = stream.readInt(4, "be");
  2600. // Skip through the rest of the header
  2601. stream.moveForwardsBy(headerSize - 9);
  2602. let tagSize = -11; // Fake size of previous tag header
  2603. while (stream.hasMore()) {
  2604. const prevTagSize = stream.readInt(4, "be");
  2605. const tagType = stream.readInt(1);
  2606. if ([8, 9, 18].indexOf(tagType) < 0) {
  2607. // This tag is not valid
  2608. stream.moveBackwardsBy(1);
  2609. break;
  2610. }
  2611. if (prevTagSize !== (tagSize + 11)) {
  2612. // Previous tag was not valid, reverse back over this header
  2613. // and the previous tag body and header
  2614. stream.moveBackwardsBy(tagSize + 11 + 5);
  2615. break;
  2616. }
  2617. tagSize = stream.readInt(3, "be");
  2618. // Move past the rest of the tag header and payload
  2619. stream.moveForwardsBy(7 + tagSize);
  2620. }
  2621. return stream.carve();
  2622. }
  2623. /**
  2624. * RTF extractor.
  2625. *
  2626. * @param {Uint8Array} bytes
  2627. * @param {number} offset
  2628. * @returns {Uint8Array}
  2629. */
  2630. export function extractRTF(bytes, offset) {
  2631. const stream = new Stream(bytes.slice(offset));
  2632. let openTags = 0;
  2633. if (stream.readInt(1) !== 0x7b) { // {
  2634. throw new Error("Not a valid RTF file");
  2635. } else {
  2636. openTags++;
  2637. }
  2638. while (openTags > 0 && stream.hasMore()) {
  2639. switch (stream.readInt(1)) {
  2640. case 0x7b: // {
  2641. openTags++;
  2642. break;
  2643. case 0x7d: // }
  2644. openTags--;
  2645. break;
  2646. case 0x5c: // \
  2647. // Consume any more escapes and then skip over the next character
  2648. stream.consumeIf(0x5c);
  2649. stream.position++;
  2650. break;
  2651. default:
  2652. break;
  2653. }
  2654. }
  2655. return stream.carve();
  2656. }
  2657. /**
  2658. * PList (XML) extractor.
  2659. *
  2660. * @param {Uint8Array} bytes
  2661. * @param {number} offset
  2662. * @returns {Uint8Array}
  2663. */
  2664. export function extractPListXML(bytes, offset) {
  2665. const stream = new Stream(bytes.slice(offset));
  2666. // Find closing tag (</plist>)
  2667. stream.continueUntil([0x3c, 0x2f, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x3e]);
  2668. stream.moveForwardsBy(8);
  2669. stream.consumeIf(0x0a);
  2670. return stream.carve();
  2671. }
  2672. /**
  2673. * GZIP extractor.
  2674. *
  2675. * @param {Uint8Array} bytes
  2676. * @param {number} offset
  2677. * @returns {Uint8Array}
  2678. */
  2679. export function extractGZIP(bytes, offset) {
  2680. const stream = new Stream(bytes.slice(offset));
  2681. /* HEADER */
  2682. // Skip over signature and compression method
  2683. stream.moveForwardsBy(3);
  2684. // Read flags
  2685. const flags = stream.readInt(1);
  2686. // Skip over last modification time
  2687. stream.moveForwardsBy(4);
  2688. // Read compression flags
  2689. stream.readInt(1);
  2690. // Skip over OS
  2691. stream.moveForwardsBy(1);
  2692. /* OPTIONAL HEADERS */
  2693. // Extra fields
  2694. if (flags & 0x4) {
  2695. const extraFieldsSize = stream.readInt(2, "le");
  2696. stream.moveForwardsby(extraFieldsSize);
  2697. }
  2698. // Original filename
  2699. if (flags & 0x8) {
  2700. stream.continueUntil(0x00);
  2701. stream.moveForwardsBy(1);
  2702. }
  2703. // Comment
  2704. if (flags & 0x10) {
  2705. stream.continueUntil(0x00);
  2706. stream.moveForwardsBy(1);
  2707. }
  2708. // Checksum
  2709. if (flags & 0x2) {
  2710. stream.moveForwardsBy(2);
  2711. }
  2712. /* DEFLATE DATA */
  2713. parseDEFLATE(stream);
  2714. /* FOOTER */
  2715. // Skip over checksum and size of original uncompressed input
  2716. stream.moveForwardsBy(8);
  2717. return stream.carve();
  2718. }
  2719. /**
  2720. * BZIP2 extractor.
  2721. *
  2722. * @param {Uint8Array} bytes
  2723. * @param {Number} offset
  2724. * @returns {Uint8Array}
  2725. */
  2726. export function extractBZIP2(bytes, offset) {
  2727. const stream = new Stream(bytes.slice(offset));
  2728. //The EOFs shifted between all possible combinations.
  2729. const lookingfor = [
  2730. [0x77, 0x24, 0x53, 0x85, 0x09],
  2731. [0xee, 0x48, 0xa7, 0x0a, 0x12],
  2732. [0xdc, 0x91, 0x4e, 0x14, 0x24],
  2733. [0xb9, 0x22, 0x9c, 0x28, 0x48],
  2734. [0x72, 0x45, 0x38, 0x50, 0x90],
  2735. [0xbb, 0x92, 0x29, 0xc2, 0x84],
  2736. [0x5d, 0xc9, 0x14, 0xe1, 0x42],
  2737. [0x2e, 0xe4, 0x8a, 0x70, 0xa1],
  2738. [0x17, 0x72, 0x45, 0x38, 0x50]];
  2739. for (let i = 0; i < lookingfor.length; i++) {
  2740. //Continue until an EOF.
  2741. stream.continueUntil(lookingfor[i]);
  2742. if (stream.getBytes(5).join("") === lookingfor[i].join(""))
  2743. break;
  2744. //Jump back to the start if invalid EOF.
  2745. stream.moveTo(0);
  2746. }
  2747. stream.moveForwardsBy(4);
  2748. return stream.carve();
  2749. }
  2750. /**
  2751. * Zlib extractor.
  2752. *
  2753. * @param {Uint8Array} bytes
  2754. * @param {number} offset
  2755. * @returns {Uint8Array}
  2756. */
  2757. export function extractZlib(bytes, offset) {
  2758. const stream = new Stream(bytes.slice(offset));
  2759. // Skip over CMF
  2760. stream.moveForwardsBy(1);
  2761. // Read flags
  2762. const flags = stream.readInt(1);
  2763. // Skip over preset dictionary checksum
  2764. if (flags & 0x20) {
  2765. stream.moveForwardsBy(4);
  2766. }
  2767. // Parse DEFLATE stream
  2768. parseDEFLATE(stream);
  2769. // Skip over final checksum
  2770. stream.moveForwardsBy(4);
  2771. return stream.carve();
  2772. }
  2773. /**
  2774. * XZ extractor.
  2775. *
  2776. * @param {Uint8Array} bytes
  2777. * @param {Number} offset
  2778. * @returns {string}
  2779. */
  2780. export function extractXZ(bytes, offset) {
  2781. const stream = new Stream(bytes.slice(offset));
  2782. // Move forward to EOF marker
  2783. stream.continueUntil([0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a]);
  2784. // Move over EOF marker
  2785. stream.moveForwardsBy(7);
  2786. return stream.carve();
  2787. }
  2788. /**
  2789. * ELF extractor.
  2790. *
  2791. * @param {Uint8Array} bytes
  2792. * @param {number} offset
  2793. * @returns {Uint8Array}
  2794. */
  2795. export function extractELF(bytes, offset) {
  2796. const stream = new Stream(bytes.slice(offset));
  2797. // Skip over magic number
  2798. stream.moveForwardsBy(4);
  2799. // Read architecture (x86 == 1, x64 == 2)
  2800. const x86 = stream.readInt(1) === 1;
  2801. // Read endianness (1 == little, 2 == big)
  2802. const endian = stream.readInt(1) === 1 ? "le" : "be";
  2803. // Skip over header values
  2804. stream.moveForwardsBy(x86 ? 26 : 34);
  2805. // Read section header table offset
  2806. const shoff = x86 ? stream.readInt(4, endian) : stream.readInt(8, endian);
  2807. // Skip over flags, header size and program header size and entries
  2808. stream.moveForwardsBy(10);
  2809. // Read section header table entry size
  2810. const shentsize = stream.readInt(2, endian);
  2811. // Read number of entries in the section header table
  2812. const shnum = stream.readInt(2, endian);
  2813. // Jump to section header table
  2814. stream.moveTo(shoff);
  2815. // Move past each section header
  2816. stream.moveForwardsBy(shentsize * shnum);
  2817. return stream.carve();
  2818. }
  2819. // Construct required Huffman Tables
  2820. const fixedLiteralTableLengths = new Array(288);
  2821. for (let i = 0; i < fixedLiteralTableLengths.length; i++) {
  2822. fixedLiteralTableLengths[i] =
  2823. (i <= 143) ? 8 :
  2824. (i <= 255) ? 9 :
  2825. (i <= 279) ? 7 :
  2826. 8;
  2827. }
  2828. const fixedLiteralTable = buildHuffmanTable(fixedLiteralTableLengths);
  2829. const fixedDistanceTableLengths = new Array(30).fill(5);
  2830. const fixedDistanceTable = buildHuffmanTable(fixedDistanceTableLengths);
  2831. const huffmanOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  2832. /**
  2833. * Steps through a DEFLATE stream
  2834. *
  2835. * @param {Stream} stream
  2836. */
  2837. function parseDEFLATE(stream) {
  2838. // Parse DEFLATE data
  2839. let finalBlock = 0;
  2840. while (!finalBlock) {
  2841. // Read header
  2842. finalBlock = stream.readBits(1);
  2843. const blockType = stream.readBits(2);
  2844. if (blockType === 0) {
  2845. /* No compression */
  2846. // Consume the rest of the current byte
  2847. stream.moveForwardsBy(1);
  2848. // Read the block length value
  2849. const blockLength = stream.readInt(2, "le");
  2850. // Move to the end of this block
  2851. stream.moveForwardsBy(2 + blockLength);
  2852. } else if (blockType === 1) {
  2853. /* Fixed Huffman */
  2854. parseHuffmanBlock(stream, fixedLiteralTable, fixedDistanceTable);
  2855. } else if (blockType === 2) {
  2856. /* Dynamic Huffman */
  2857. // Read the number of liternal and length codes
  2858. const hlit = stream.readBits(5) + 257;
  2859. // Read the number of distance codes
  2860. const hdist = stream.readBits(5) + 1;
  2861. // Read the number of code lengths
  2862. const hclen = stream.readBits(4) + 4;
  2863. // Parse code lengths
  2864. const codeLengths = new Uint8Array(huffmanOrder.length);
  2865. for (let i = 0; i < hclen; i++) {
  2866. codeLengths[huffmanOrder[i]] = stream.readBits(3);
  2867. }
  2868. // Parse length table
  2869. const codeLengthsTable = buildHuffmanTable(codeLengths);
  2870. const lengthTable = new Uint8Array(hlit + hdist);
  2871. let code, repeat, prev;
  2872. for (let i = 0; i < hlit + hdist;) {
  2873. code = readHuffmanCode(stream, codeLengthsTable);
  2874. switch (code) {
  2875. case 16:
  2876. repeat = 3 + stream.readBits(2);
  2877. while (repeat--) lengthTable[i++] = prev;
  2878. break;
  2879. case 17:
  2880. repeat = 3 + stream.readBits(3);
  2881. while (repeat--) lengthTable[i++] = 0;
  2882. prev = 0;
  2883. break;
  2884. case 18:
  2885. repeat = 11 + stream.readBits(7);
  2886. while (repeat--) lengthTable[i++] = 0;
  2887. prev = 0;
  2888. break;
  2889. default:
  2890. lengthTable[i++] = code;
  2891. prev = code;
  2892. break;
  2893. }
  2894. }
  2895. const dynamicLiteralTable = buildHuffmanTable(lengthTable.subarray(0, hlit));
  2896. const dynamicDistanceTable = buildHuffmanTable(lengthTable.subarray(hlit));
  2897. parseHuffmanBlock(stream, dynamicLiteralTable, dynamicDistanceTable);
  2898. } else {
  2899. throw new Error(`Invalid block type while parsing DEFLATE stream at pos ${stream.position}`);
  2900. }
  2901. }
  2902. // Consume final byte if it has not been fully consumed yet
  2903. if (stream.bitPos > 0)
  2904. stream.moveForwardsBy(1);
  2905. }
  2906. // Static length tables
  2907. const lengthExtraTable = [
  2908. 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0
  2909. ];
  2910. const distanceExtraTable = [
  2911. 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13
  2912. ];
  2913. /**
  2914. * Parses a Huffman Block given the literal and distance tables
  2915. *
  2916. * @param {Stream} stream
  2917. * @param {Uint32Array} litTab
  2918. * @param {Uint32Array} distTab
  2919. */
  2920. function parseHuffmanBlock(stream, litTab, distTab) {
  2921. let code;
  2922. let loops = 0;
  2923. while ((code = readHuffmanCode(stream, litTab))) {
  2924. // console.log("Code: " + code + " (" + Utils.chr(code) + ") " + Utils.bin(code));
  2925. // End of block
  2926. if (code === 256) break;
  2927. // Detect probably infinite loops
  2928. if (++loops > 10000)
  2929. throw new Error("Caught in probable infinite loop while parsing Huffman Block");
  2930. // Literal
  2931. if (code < 256) continue;
  2932. // Length code
  2933. stream.readBits(lengthExtraTable[code - 257]);
  2934. // Dist code
  2935. code = readHuffmanCode(stream, distTab);
  2936. stream.readBits(distanceExtraTable[code]);
  2937. }
  2938. }
  2939. /**
  2940. * Builds a Huffman table given the relevant code lengths
  2941. *
  2942. * @param {Array} lengths
  2943. * @returns {Array} result
  2944. * @returns {Uint32Array} result.table
  2945. * @returns {number} result.maxCodeLength
  2946. * @returns {number} result.minCodeLength
  2947. */
  2948. function buildHuffmanTable(lengths) {
  2949. const maxCodeLength = Math.max.apply(Math, lengths);
  2950. const minCodeLength = Math.min.apply(Math, lengths);
  2951. const size = 1 << maxCodeLength;
  2952. const table = new Uint32Array(size);
  2953. for (let bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) {
  2954. for (let i = 0; i < lengths.length; i++) {
  2955. if (lengths[i] === bitLength) {
  2956. let reversed, rtemp, j;
  2957. for (reversed = 0, rtemp = code, j = 0; j < bitLength; j++) {
  2958. reversed = (reversed << 1) | (rtemp & 1);
  2959. rtemp >>= 1;
  2960. }
  2961. const value = (bitLength << 16) | i;
  2962. for (let j = reversed; j < size; j += skip) {
  2963. table[j] = value;
  2964. }
  2965. code++;
  2966. }
  2967. }
  2968. bitLength++;
  2969. code <<= 1;
  2970. skip <<= 1;
  2971. }
  2972. return [table, maxCodeLength, minCodeLength];
  2973. }
  2974. /**
  2975. * Reads the next Huffman code from the stream, given the relevant code table
  2976. *
  2977. * @param {Stream} stream
  2978. * @param {Uint32Array} table
  2979. * @returns {number}
  2980. */
  2981. function readHuffmanCode(stream, table) {
  2982. const [codeTable, maxCodeLength] = table;
  2983. // Read max length
  2984. const bitsBuf = stream.readBits(maxCodeLength);
  2985. const codeWithLength = codeTable[bitsBuf & ((1 << maxCodeLength) - 1)];
  2986. const codeLength = codeWithLength >>> 16;
  2987. if (codeLength > maxCodeLength) {
  2988. throw new Error(`Invalid Huffman Code length while parsing DEFLATE block at pos ${stream.position}: ${codeLength}`);
  2989. }
  2990. stream.moveBackwardsByBits(maxCodeLength - codeLength);
  2991. return codeWithLength & 0xffff;
  2992. }