FileSignatures.mjs 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382
  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: extractWAV
  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: extractSQLITE
  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: extractEVT
  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: extractEVTX
  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. name: "Bash",
  2335. extension: "bash",
  2336. mime: "application/bash",
  2337. description: "",
  2338. signature: {
  2339. 0: 0x23, // #!/bin/bash
  2340. 1: 0x21,
  2341. 2: 0x2f,
  2342. 3: 0x62,
  2343. 4: 0x69,
  2344. 5: 0x6e,
  2345. 6: 0x2f,
  2346. 7: 0x62,
  2347. 8: 0x61,
  2348. 9: 0x73,
  2349. 10: 0x68,
  2350. },
  2351. extractor: null
  2352. },
  2353. {
  2354. name: "Shell",
  2355. extension: "sh",
  2356. mime: "application/sh",
  2357. description: "",
  2358. signature: {
  2359. 0: 0x23, // #!/bin/sh
  2360. 1: 0x21,
  2361. 2: 0x2f,
  2362. 3: 0x62,
  2363. 4: 0x69,
  2364. 5: 0x6e,
  2365. 6: 0x2f,
  2366. 7: 0x73,
  2367. 8: 0x68,
  2368. },
  2369. extractor: null
  2370. },
  2371. {
  2372. name: "Python",
  2373. extension: "py,pyc,pyd,pyo,pyw,pyz",
  2374. mime: "application/python",
  2375. description: "",
  2376. signature: {
  2377. 0: 0x23, // #!/usr/bin/python(2|3)
  2378. 1: 0x21,
  2379. 2: 0x2f,
  2380. 3: 0x75,
  2381. 4: 0x73,
  2382. 5: 0x72,
  2383. 6: 0x2f,
  2384. 7: 0x62,
  2385. 8: 0x69,
  2386. 9: 0x6e,
  2387. 10: 0x2f,
  2388. 11: 0x70,
  2389. 12: 0x79,
  2390. 13: 0x74,
  2391. 14: 0x68,
  2392. 15: 0x6f,
  2393. 16: 0x6e,
  2394. 17: [0x32, 0x33, 0xa, 0xd],
  2395. },
  2396. extractor: null
  2397. },
  2398. {
  2399. name: "Ruby",
  2400. extension: "rb",
  2401. mime: "application/ruby",
  2402. description: "",
  2403. signature: {
  2404. 0: 0x23, // #!/usr/bin/ruby
  2405. 1: 0x21,
  2406. 2: 0x2f,
  2407. 3: 0x75,
  2408. 4: 0x73,
  2409. 5: 0x72,
  2410. 6: 0x2f,
  2411. 7: 0x62,
  2412. 8: 0x69,
  2413. 9: 0x6e,
  2414. 10: 0x2f,
  2415. 11: 0x72,
  2416. 12: 0x75,
  2417. 13: 0x62,
  2418. 14: 0x79,
  2419. },
  2420. extractor: null
  2421. },
  2422. {
  2423. name: "perl",
  2424. extension: "pl,pm,t,pod",
  2425. mime: "application/perl",
  2426. description: "",
  2427. signature: {
  2428. 0: 0x23, // #!/usr/bin/perl
  2429. 1: 0x21,
  2430. 2: 0x2f,
  2431. 3: 0x75,
  2432. 4: 0x73,
  2433. 5: 0x72,
  2434. 6: 0x2f,
  2435. 7: 0x62,
  2436. 8: 0x69,
  2437. 9: 0x6e,
  2438. 10: 0x2f,
  2439. 11: 0x70,
  2440. 12: 0x65,
  2441. 13: 0x72,
  2442. 14: 0x6c,
  2443. },
  2444. extractor: null
  2445. },
  2446. {
  2447. name: "php",
  2448. extension: "php,phtml,php3,php4,php5,php7,phps,php-s,pht,phar",
  2449. mime: "application/php",
  2450. description: "",
  2451. signature: {
  2452. 0: 0x3c, // <?php
  2453. 1: 0x3f,
  2454. 2: 0x70,
  2455. 3: 0x68,
  2456. 4: 0x70,
  2457. },
  2458. extractor: null
  2459. }
  2460. ]
  2461. };
  2462. /**
  2463. * JPEG extractor.
  2464. *
  2465. * @param {Uint8Array} bytes
  2466. * @param {number} offset
  2467. * @returns {Uint8Array}
  2468. */
  2469. export function extractJPEG(bytes, offset) {
  2470. const stream = new Stream(bytes.slice(offset));
  2471. while (stream.hasMore()) {
  2472. const marker = stream.getBytes(2);
  2473. if (marker[0] !== 0xff) throw new Error(`Invalid marker while parsing JPEG at pos ${stream.position}: ${marker}`);
  2474. let segmentSize = 0;
  2475. switch (marker[1]) {
  2476. // No length
  2477. case 0xd8: // Start of Image
  2478. case 0x01: // For temporary use in arithmetic coding
  2479. break;
  2480. case 0xd9: // End found
  2481. return stream.carve();
  2482. // Variable size segment
  2483. case 0xc0: // Start of frame (Baseline DCT)
  2484. case 0xc1: // Start of frame (Extended sequential DCT)
  2485. case 0xc2: // Start of frame (Progressive DCT)
  2486. case 0xc3: // Start of frame (Lossless sequential)
  2487. case 0xc4: // Define Huffman Table
  2488. case 0xc5: // Start of frame (Differential sequential DCT)
  2489. case 0xc6: // Start of frame (Differential progressive DCT)
  2490. case 0xc7: // Start of frame (Differential lossless)
  2491. case 0xc8: // Reserved for JPEG extensions
  2492. case 0xc9: // Start of frame (Extended sequential DCT)
  2493. case 0xca: // Start of frame (Progressive DCT)
  2494. case 0xcb: // Start of frame (Lossless sequential)
  2495. case 0xcc: // Define arithmetic conditioning table
  2496. case 0xcd: // Start of frame (Differential sequential DCT)
  2497. case 0xce: // Start of frame (Differential progressive DCT)
  2498. case 0xcf: // Start of frame (Differential lossless)
  2499. case 0xdb: // Define Quantization Table
  2500. case 0xde: // Define hierarchical progression
  2501. case 0xe0: // Application-specific
  2502. case 0xe1: // Application-specific
  2503. case 0xe2: // Application-specific
  2504. case 0xe3: // Application-specific
  2505. case 0xe4: // Application-specific
  2506. case 0xe5: // Application-specific
  2507. case 0xe6: // Application-specific
  2508. case 0xe7: // Application-specific
  2509. case 0xe8: // Application-specific
  2510. case 0xe9: // Application-specific
  2511. case 0xea: // Application-specific
  2512. case 0xeb: // Application-specific
  2513. case 0xec: // Application-specific
  2514. case 0xed: // Application-specific
  2515. case 0xee: // Application-specific
  2516. case 0xef: // Application-specific
  2517. case 0xfe: // Comment
  2518. segmentSize = stream.readInt(2, "be");
  2519. stream.position += segmentSize - 2;
  2520. break;
  2521. // 1 byte
  2522. case 0xdf: // Expand reference image
  2523. stream.position++;
  2524. break;
  2525. // 2 bytes
  2526. case 0xdc: // Define number of lines
  2527. case 0xdd: // Define restart interval
  2528. stream.position += 2;
  2529. break;
  2530. // Start scan
  2531. case 0xda: // Start of scan
  2532. segmentSize = stream.readInt(2, "be");
  2533. stream.position += segmentSize - 2;
  2534. stream.continueUntil(0xff);
  2535. break;
  2536. // Continue through encoded data
  2537. case 0x00: // Byte stuffing
  2538. case 0xd0: // Restart
  2539. case 0xd1: // Restart
  2540. case 0xd2: // Restart
  2541. case 0xd3: // Restart
  2542. case 0xd4: // Restart
  2543. case 0xd5: // Restart
  2544. case 0xd6: // Restart
  2545. case 0xd7: // Restart
  2546. stream.continueUntil(0xff);
  2547. break;
  2548. default:
  2549. stream.continueUntil(0xff);
  2550. break;
  2551. }
  2552. }
  2553. throw new Error("Unable to parse JPEG successfully");
  2554. }
  2555. /**
  2556. * GIF extractor.
  2557. *
  2558. * @param {Uint8Array} bytes
  2559. * @param {Number} offset
  2560. * @returns {Uint8Array}
  2561. */
  2562. export function extractGIF(bytes, offset) {
  2563. const stream = new Stream(bytes.slice(offset));
  2564. //Move to application extension block.
  2565. stream.continueUntil([0x21, 0xff]);
  2566. //Move to Graphic Control Extension for frame #1.
  2567. stream.continueUntil([0x21, 0xf9]);
  2568. stream.moveForwardsBy(2);
  2569. while (stream.hasMore()) {
  2570. //Move to Image descriptor.
  2571. stream.moveForwardsBy(stream.getBytes(1)[0]+1);
  2572. //Move past Image descriptor to the image data.
  2573. stream.moveForwardsBy(11);
  2574. //Loop until next Graphic Control Extension.
  2575. while (stream.getBytes(2) !== [0x21, 0xf9]) {
  2576. stream.moveBackwardsBy(2);
  2577. stream.moveForwardsBy(stream.getBytes(1)[0]);
  2578. if (!stream.getBytes(1)[0])
  2579. break;
  2580. stream.moveBackwardsBy(1);
  2581. }
  2582. //When the end of the file is [0x00, 0x3b], end.
  2583. if (stream.getBytes(1)[0] === 0x3b)
  2584. break;
  2585. stream.moveForwardsBy(1);
  2586. }
  2587. return stream.carve();
  2588. }
  2589. /**
  2590. * Portable executable extractor.
  2591. * Assumes that the offset refers to an MZ header.
  2592. *
  2593. * @param {Uint8Array} bytes
  2594. * @param {number} offset
  2595. * @returns {Uint8Array}
  2596. */
  2597. export function extractMZPE(bytes, offset) {
  2598. const stream = new Stream(bytes.slice(offset));
  2599. // Read pointer to PE header
  2600. stream.moveTo(0x3c);
  2601. const peAddress = stream.readInt(4, "le");
  2602. // Move to PE header
  2603. stream.moveTo(peAddress);
  2604. // Get number of sections
  2605. stream.moveForwardsBy(6);
  2606. const numSections = stream.readInt(2, "le");
  2607. // Read Optional Header Magic to determine the state of the image file
  2608. // 0x10b = normal executable, 0x107 = ROM image, 0x20b = PE32+ executable
  2609. stream.moveForwardsBy(16);
  2610. const optionalMagic = stream.readInt(2, "le");
  2611. const pe32Plus = optionalMagic === 0x20b;
  2612. // Move to Data Directory
  2613. const dataDirectoryOffset = pe32Plus ? 112 : 96;
  2614. stream.moveForwardsBy(dataDirectoryOffset - 2);
  2615. // Read Certificate Table address and size (IMAGE_DIRECTORY_ENTRY_SECURITY)
  2616. stream.moveForwardsBy(32);
  2617. const certTableAddress = stream.readInt(4, "le");
  2618. const certTableSize = stream.readInt(4, "le");
  2619. // PE files can contain extra data appended to the end of the file called an "overlay".
  2620. // This data is not covered by the PE header and could be any arbitrary format, so its
  2621. // length cannot be determined without contextual information.
  2622. // However, the Attribute Certificate Table is stored in the overlay - usually right at
  2623. // the end. Therefore, if this table is defined, we can use its offset and size to carve
  2624. // out the entire PE file, including the overlay.
  2625. // If the Certificate Table is not defined, we continue to parse the PE file as best we
  2626. // can up to the end of the final section, not including any appended data in the overlay.
  2627. if (certTableAddress > 0) {
  2628. stream.moveTo(certTableAddress + certTableSize);
  2629. return stream.carve();
  2630. }
  2631. // Move past Optional Header to Section Header
  2632. stream.moveForwardsBy(88);
  2633. // Move to final section header
  2634. stream.moveForwardsBy((numSections - 1) * 0x28);
  2635. // Get raw data info
  2636. stream.moveForwardsBy(16);
  2637. const rawDataSize = stream.readInt(4, "le");
  2638. const rawDataAddress = stream.readInt(4, "le");
  2639. // Move to end of final section
  2640. stream.moveTo(rawDataAddress + rawDataSize);
  2641. return stream.carve();
  2642. }
  2643. /**
  2644. * PDF extractor.
  2645. *
  2646. * @param {Uint8Array} bytes
  2647. * @param {number} offset
  2648. * @returns {Uint8Array}
  2649. */
  2650. export function extractPDF(bytes, offset) {
  2651. const stream = new Stream(bytes.slice(offset));
  2652. // Find end-of-file marker (%%EOF)
  2653. stream.continueUntil([0x25, 0x25, 0x45, 0x4f, 0x46]);
  2654. stream.moveForwardsBy(5);
  2655. stream.consumeIf(0x0d);
  2656. stream.consumeIf(0x0a);
  2657. return stream.carve();
  2658. }
  2659. /**
  2660. * ZIP extractor.
  2661. *
  2662. * @param {Uint8Array} bytes
  2663. * @param {number} offset
  2664. * @returns {Uint8Array}
  2665. */
  2666. export function extractZIP(bytes, offset) {
  2667. const stream = new Stream(bytes.slice(offset));
  2668. // Find End of central directory record
  2669. stream.continueUntil([0x50, 0x4b, 0x05, 0x06]);
  2670. // Get comment length and consume
  2671. stream.moveForwardsBy(20);
  2672. const commentLength = stream.readInt(2, "le");
  2673. stream.moveForwardsBy(commentLength);
  2674. return stream.carve();
  2675. }
  2676. /**
  2677. * PNG extractor.
  2678. *
  2679. * @param {Uint8Array} bytes
  2680. * @param {number} offset
  2681. * @returns {Uint8Array}
  2682. */
  2683. export function extractPNG(bytes, offset) {
  2684. const stream = new Stream(bytes.slice(offset));
  2685. // Move past signature to first chunk
  2686. stream.moveForwardsBy(8);
  2687. let chunkSize = 0,
  2688. chunkType = "";
  2689. while (chunkType !== "IEND") {
  2690. chunkSize = stream.readInt(4, "be");
  2691. chunkType = stream.readString(4);
  2692. // Chunk data size + CRC checksum
  2693. stream.moveForwardsBy(chunkSize + 4);
  2694. }
  2695. return stream.carve();
  2696. }
  2697. /**
  2698. * BMP extractor.
  2699. *
  2700. * @param {Uint8Array} bytes
  2701. * @param {number} offset
  2702. * @returns {Uint8Array}
  2703. */
  2704. export function extractBMP(bytes, offset) {
  2705. const stream = new Stream(bytes.slice(offset));
  2706. // Move past header
  2707. stream.moveForwardsBy(2);
  2708. // Read full file size
  2709. const bmpSize = stream.readInt(4, "le");
  2710. // Move to end of file (file size minus header and size field)
  2711. stream.moveForwardsBy(bmpSize - 6);
  2712. return stream.carve();
  2713. }
  2714. /**
  2715. * WAV extractor.
  2716. *
  2717. * @param {Uint8Array} bytes
  2718. * @param {Number} offset
  2719. * @returns {Uint8Array}
  2720. */
  2721. export function extractWAV(bytes, offset) {
  2722. const stream = new Stream(bytes.slice(offset));
  2723. // Move to file size field.
  2724. stream.moveTo(4);
  2725. // Move to file size.
  2726. stream.moveTo(stream.readInt(4, "le")-4);
  2727. return stream.carve();
  2728. }
  2729. /**
  2730. * FLV extractor.
  2731. *
  2732. * @param {Uint8Array} bytes
  2733. * @param {number} offset
  2734. * @returns {Uint8Array}
  2735. */
  2736. export function extractFLV(bytes, offset) {
  2737. const stream = new Stream(bytes.slice(offset));
  2738. // Move past signature, version and flags
  2739. stream.moveForwardsBy(5);
  2740. // Read header size
  2741. const headerSize = stream.readInt(4, "be");
  2742. // Skip through the rest of the header
  2743. stream.moveForwardsBy(headerSize - 9);
  2744. let tagSize = -11; // Fake size of previous tag header
  2745. while (stream.hasMore()) {
  2746. const prevTagSize = stream.readInt(4, "be");
  2747. const tagType = stream.readInt(1);
  2748. if ([8, 9, 18].indexOf(tagType) < 0) {
  2749. // This tag is not valid
  2750. stream.moveBackwardsBy(1);
  2751. break;
  2752. }
  2753. if (prevTagSize !== (tagSize + 11)) {
  2754. // Previous tag was not valid, reverse back over this header
  2755. // and the previous tag body and header
  2756. stream.moveBackwardsBy(tagSize + 11 + 5);
  2757. break;
  2758. }
  2759. tagSize = stream.readInt(3, "be");
  2760. // Move past the rest of the tag header and payload
  2761. stream.moveForwardsBy(7 + tagSize);
  2762. }
  2763. return stream.carve();
  2764. }
  2765. /**
  2766. * RTF extractor.
  2767. *
  2768. * @param {Uint8Array} bytes
  2769. * @param {number} offset
  2770. * @returns {Uint8Array}
  2771. */
  2772. export function extractRTF(bytes, offset) {
  2773. const stream = new Stream(bytes.slice(offset));
  2774. let openTags = 0;
  2775. if (stream.readInt(1) !== 0x7b) { // {
  2776. throw new Error("Not a valid RTF file");
  2777. } else {
  2778. openTags++;
  2779. }
  2780. while (openTags > 0 && stream.hasMore()) {
  2781. switch (stream.readInt(1)) {
  2782. case 0x7b: // {
  2783. openTags++;
  2784. break;
  2785. case 0x7d: // }
  2786. openTags--;
  2787. break;
  2788. case 0x5c: // \
  2789. // Consume any more escapes and then skip over the next character
  2790. stream.consumeIf(0x5c);
  2791. stream.position++;
  2792. break;
  2793. default:
  2794. break;
  2795. }
  2796. }
  2797. return stream.carve();
  2798. }
  2799. /**
  2800. * SQLITE extractor.
  2801. *
  2802. * @param {Uint8Array} bytes
  2803. * @param {number} offset
  2804. * @returns {Uint8Array}
  2805. */
  2806. export function extractSQLITE(bytes, offset) {
  2807. const stream = new Stream(bytes.slice(offset));
  2808. stream.moveTo(16);
  2809. // Extract the size of the page.
  2810. const pageSize = stream.readInt(2);
  2811. stream.moveTo(28);
  2812. // Extract the number of pages.
  2813. const numPages = stream.readInt(4);
  2814. // Move to the end of all the pages.
  2815. stream.moveTo(pageSize*numPages);
  2816. return stream.carve();
  2817. }
  2818. /**
  2819. * PList (XML) extractor.
  2820. *
  2821. * @param {Uint8Array} bytes
  2822. * @param {number} offset
  2823. * @returns {Uint8Array}
  2824. */
  2825. export function extractPListXML(bytes, offset) {
  2826. const stream = new Stream(bytes.slice(offset));
  2827. // Find closing tag (</plist>)
  2828. stream.continueUntil([0x3c, 0x2f, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x3e]);
  2829. stream.moveForwardsBy(8);
  2830. stream.consumeIf(0x0a);
  2831. return stream.carve();
  2832. }
  2833. /**
  2834. * GZIP extractor.
  2835. *
  2836. * @param {Uint8Array} bytes
  2837. * @param {number} offset
  2838. * @returns {Uint8Array}
  2839. */
  2840. export function extractGZIP(bytes, offset) {
  2841. const stream = new Stream(bytes.slice(offset));
  2842. /* HEADER */
  2843. // Skip over signature and compression method
  2844. stream.moveForwardsBy(3);
  2845. // Read flags
  2846. const flags = stream.readInt(1);
  2847. // Skip over last modification time
  2848. stream.moveForwardsBy(4);
  2849. // Read compression flags
  2850. stream.readInt(1);
  2851. // Skip over OS
  2852. stream.moveForwardsBy(1);
  2853. /* OPTIONAL HEADERS */
  2854. // Extra fields
  2855. if (flags & 0x4) {
  2856. const extraFieldsSize = stream.readInt(2, "le");
  2857. stream.moveForwardsby(extraFieldsSize);
  2858. }
  2859. // Original filename
  2860. if (flags & 0x8) {
  2861. stream.continueUntil(0x00);
  2862. stream.moveForwardsBy(1);
  2863. }
  2864. // Comment
  2865. if (flags & 0x10) {
  2866. stream.continueUntil(0x00);
  2867. stream.moveForwardsBy(1);
  2868. }
  2869. // Checksum
  2870. if (flags & 0x2) {
  2871. stream.moveForwardsBy(2);
  2872. }
  2873. /* DEFLATE DATA */
  2874. parseDEFLATE(stream);
  2875. /* FOOTER */
  2876. // Skip over checksum and size of original uncompressed input
  2877. stream.moveForwardsBy(8);
  2878. return stream.carve();
  2879. }
  2880. /**
  2881. * BZIP2 extractor.
  2882. *
  2883. * @param {Uint8Array} bytes
  2884. * @param {Number} offset
  2885. * @returns {Uint8Array}
  2886. */
  2887. export function extractBZIP2(bytes, offset) {
  2888. const stream = new Stream(bytes.slice(offset));
  2889. //The EOFs shifted between all possible combinations.
  2890. const lookingfor = [
  2891. [0x77, 0x24, 0x53, 0x85, 0x09],
  2892. [0xee, 0x48, 0xa7, 0x0a, 0x12],
  2893. [0xdc, 0x91, 0x4e, 0x14, 0x24],
  2894. [0xb9, 0x22, 0x9c, 0x28, 0x48],
  2895. [0x72, 0x45, 0x38, 0x50, 0x90],
  2896. [0xbb, 0x92, 0x29, 0xc2, 0x84],
  2897. [0x5d, 0xc9, 0x14, 0xe1, 0x42],
  2898. [0x2e, 0xe4, 0x8a, 0x70, 0xa1],
  2899. [0x17, 0x72, 0x45, 0x38, 0x50]];
  2900. for (let i = 0; i < lookingfor.length; i++) {
  2901. //Continue until an EOF.
  2902. stream.continueUntil(lookingfor[i]);
  2903. if (stream.getBytes(5).join("") === lookingfor[i].join(""))
  2904. break;
  2905. //Jump back to the start if invalid EOF.
  2906. stream.moveTo(0);
  2907. }
  2908. stream.moveForwardsBy(4);
  2909. return stream.carve();
  2910. }
  2911. /**
  2912. * Zlib extractor.
  2913. *
  2914. * @param {Uint8Array} bytes
  2915. * @param {number} offset
  2916. * @returns {Uint8Array}
  2917. */
  2918. export function extractZlib(bytes, offset) {
  2919. const stream = new Stream(bytes.slice(offset));
  2920. // Skip over CMF
  2921. stream.moveForwardsBy(1);
  2922. // Read flags
  2923. const flags = stream.readInt(1);
  2924. // Skip over preset dictionary checksum
  2925. if (flags & 0x20) {
  2926. stream.moveForwardsBy(4);
  2927. }
  2928. // Parse DEFLATE stream
  2929. parseDEFLATE(stream);
  2930. // Skip over final checksum
  2931. stream.moveForwardsBy(4);
  2932. return stream.carve();
  2933. }
  2934. /**
  2935. * XZ extractor.
  2936. *
  2937. * @param {Uint8Array} bytes
  2938. * @param {Number} offset
  2939. * @returns {string}
  2940. */
  2941. export function extractXZ(bytes, offset) {
  2942. const stream = new Stream(bytes.slice(offset));
  2943. // Move forward to EOF marker
  2944. stream.continueUntil([0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a]);
  2945. // Move over EOF marker
  2946. stream.moveForwardsBy(7);
  2947. return stream.carve();
  2948. }
  2949. /**
  2950. * ELF extractor.
  2951. *
  2952. * @param {Uint8Array} bytes
  2953. * @param {number} offset
  2954. * @returns {Uint8Array}
  2955. */
  2956. export function extractELF(bytes, offset) {
  2957. const stream = new Stream(bytes.slice(offset));
  2958. // Skip over magic number
  2959. stream.moveForwardsBy(4);
  2960. // Read architecture (x86 == 1, x64 == 2)
  2961. const x86 = stream.readInt(1) === 1;
  2962. // Read endianness (1 == little, 2 == big)
  2963. const endian = stream.readInt(1) === 1 ? "le" : "be";
  2964. // Skip over header values
  2965. stream.moveForwardsBy(x86 ? 26 : 34);
  2966. // Read section header table offset
  2967. const shoff = x86 ? stream.readInt(4, endian) : stream.readInt(8, endian);
  2968. // Skip over flags, header size and program header size and entries
  2969. stream.moveForwardsBy(10);
  2970. // Read section header table entry size
  2971. const shentsize = stream.readInt(2, endian);
  2972. // Read number of entries in the section header table
  2973. const shnum = stream.readInt(2, endian);
  2974. // Jump to section header table
  2975. stream.moveTo(shoff);
  2976. // Move past each section header
  2977. stream.moveForwardsBy(shentsize * shnum);
  2978. return stream.carve();
  2979. }
  2980. // Construct required Huffman Tables
  2981. const fixedLiteralTableLengths = new Array(288);
  2982. for (let i = 0; i < fixedLiteralTableLengths.length; i++) {
  2983. fixedLiteralTableLengths[i] =
  2984. (i <= 143) ? 8 :
  2985. (i <= 255) ? 9 :
  2986. (i <= 279) ? 7 :
  2987. 8;
  2988. }
  2989. const fixedLiteralTable = buildHuffmanTable(fixedLiteralTableLengths);
  2990. const fixedDistanceTableLengths = new Array(30).fill(5);
  2991. const fixedDistanceTable = buildHuffmanTable(fixedDistanceTableLengths);
  2992. const huffmanOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  2993. /**
  2994. * Steps through a DEFLATE stream
  2995. *
  2996. * @param {Stream} stream
  2997. */
  2998. function parseDEFLATE(stream) {
  2999. // Parse DEFLATE data
  3000. let finalBlock = 0;
  3001. while (!finalBlock) {
  3002. // Read header
  3003. finalBlock = stream.readBits(1);
  3004. const blockType = stream.readBits(2);
  3005. if (blockType === 0) {
  3006. /* No compression */
  3007. // Consume the rest of the current byte
  3008. stream.moveForwardsBy(1);
  3009. // Read the block length value
  3010. const blockLength = stream.readInt(2, "le");
  3011. // Move to the end of this block
  3012. stream.moveForwardsBy(2 + blockLength);
  3013. } else if (blockType === 1) {
  3014. /* Fixed Huffman */
  3015. parseHuffmanBlock(stream, fixedLiteralTable, fixedDistanceTable);
  3016. } else if (blockType === 2) {
  3017. /* Dynamic Huffman */
  3018. // Read the number of liternal and length codes
  3019. const hlit = stream.readBits(5) + 257;
  3020. // Read the number of distance codes
  3021. const hdist = stream.readBits(5) + 1;
  3022. // Read the number of code lengths
  3023. const hclen = stream.readBits(4) + 4;
  3024. // Parse code lengths
  3025. const codeLengths = new Uint8Array(huffmanOrder.length);
  3026. for (let i = 0; i < hclen; i++) {
  3027. codeLengths[huffmanOrder[i]] = stream.readBits(3);
  3028. }
  3029. // Parse length table
  3030. const codeLengthsTable = buildHuffmanTable(codeLengths);
  3031. const lengthTable = new Uint8Array(hlit + hdist);
  3032. let code, repeat, prev;
  3033. for (let i = 0; i < hlit + hdist;) {
  3034. code = readHuffmanCode(stream, codeLengthsTable);
  3035. switch (code) {
  3036. case 16:
  3037. repeat = 3 + stream.readBits(2);
  3038. while (repeat--) lengthTable[i++] = prev;
  3039. break;
  3040. case 17:
  3041. repeat = 3 + stream.readBits(3);
  3042. while (repeat--) lengthTable[i++] = 0;
  3043. prev = 0;
  3044. break;
  3045. case 18:
  3046. repeat = 11 + stream.readBits(7);
  3047. while (repeat--) lengthTable[i++] = 0;
  3048. prev = 0;
  3049. break;
  3050. default:
  3051. lengthTable[i++] = code;
  3052. prev = code;
  3053. break;
  3054. }
  3055. }
  3056. const dynamicLiteralTable = buildHuffmanTable(lengthTable.subarray(0, hlit));
  3057. const dynamicDistanceTable = buildHuffmanTable(lengthTable.subarray(hlit));
  3058. parseHuffmanBlock(stream, dynamicLiteralTable, dynamicDistanceTable);
  3059. } else {
  3060. throw new Error(`Invalid block type while parsing DEFLATE stream at pos ${stream.position}`);
  3061. }
  3062. }
  3063. // Consume final byte if it has not been fully consumed yet
  3064. if (stream.bitPos > 0)
  3065. stream.moveForwardsBy(1);
  3066. }
  3067. // Static length tables
  3068. const lengthExtraTable = [
  3069. 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
  3070. ];
  3071. const distanceExtraTable = [
  3072. 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
  3073. ];
  3074. /**
  3075. * Parses a Huffman Block given the literal and distance tables
  3076. *
  3077. * @param {Stream} stream
  3078. * @param {Uint32Array} litTab
  3079. * @param {Uint32Array} distTab
  3080. */
  3081. function parseHuffmanBlock(stream, litTab, distTab) {
  3082. let code;
  3083. let loops = 0;
  3084. while ((code = readHuffmanCode(stream, litTab))) {
  3085. // console.log("Code: " + code + " (" + Utils.chr(code) + ") " + Utils.bin(code));
  3086. // End of block
  3087. if (code === 256) break;
  3088. // Detect probably infinite loops
  3089. if (++loops > 10000)
  3090. throw new Error("Caught in probable infinite loop while parsing Huffman Block");
  3091. // Literal
  3092. if (code < 256) continue;
  3093. // Length code
  3094. stream.readBits(lengthExtraTable[code - 257]);
  3095. // Dist code
  3096. code = readHuffmanCode(stream, distTab);
  3097. stream.readBits(distanceExtraTable[code]);
  3098. }
  3099. }
  3100. /**
  3101. * Builds a Huffman table given the relevant code lengths
  3102. *
  3103. * @param {Array} lengths
  3104. * @returns {Array} result
  3105. * @returns {Uint32Array} result.table
  3106. * @returns {number} result.maxCodeLength
  3107. * @returns {number} result.minCodeLength
  3108. */
  3109. function buildHuffmanTable(lengths) {
  3110. const maxCodeLength = Math.max.apply(Math, lengths);
  3111. const minCodeLength = Math.min.apply(Math, lengths);
  3112. const size = 1 << maxCodeLength;
  3113. const table = new Uint32Array(size);
  3114. for (let bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) {
  3115. for (let i = 0; i < lengths.length; i++) {
  3116. if (lengths[i] === bitLength) {
  3117. let reversed, rtemp, j;
  3118. for (reversed = 0, rtemp = code, j = 0; j < bitLength; j++) {
  3119. reversed = (reversed << 1) | (rtemp & 1);
  3120. rtemp >>= 1;
  3121. }
  3122. const value = (bitLength << 16) | i;
  3123. for (let j = reversed; j < size; j += skip) {
  3124. table[j] = value;
  3125. }
  3126. code++;
  3127. }
  3128. }
  3129. bitLength++;
  3130. code <<= 1;
  3131. skip <<= 1;
  3132. }
  3133. return [table, maxCodeLength, minCodeLength];
  3134. }
  3135. /**
  3136. * Reads the next Huffman code from the stream, given the relevant code table
  3137. *
  3138. * @param {Stream} stream
  3139. * @param {Uint32Array} table
  3140. * @returns {number}
  3141. */
  3142. function readHuffmanCode(stream, table) {
  3143. const [codeTable, maxCodeLength] = table;
  3144. // Read max length
  3145. const bitsBuf = stream.readBits(maxCodeLength);
  3146. const codeWithLength = codeTable[bitsBuf & ((1 << maxCodeLength) - 1)];
  3147. const codeLength = codeWithLength >>> 16;
  3148. if (codeLength > maxCodeLength) {
  3149. throw new Error(`Invalid Huffman Code length while parsing DEFLATE block at pos ${stream.position}: ${codeLength}`);
  3150. }
  3151. stream.moveBackwardsByBits(maxCodeLength - codeLength);
  3152. return codeWithLength & 0xffff;
  3153. }
  3154. /**
  3155. * EVTX extractor.
  3156. *
  3157. * @param {Uint8Array} bytes
  3158. * @param {Number} offset
  3159. * @returns {Uint8Array}
  3160. */
  3161. export function extractEVTX(bytes, offset) {
  3162. const stream = new Stream(bytes.slice(offset));
  3163. stream.moveTo(0x28);
  3164. // Move to first ELFCHNK.
  3165. const total = stream.readInt(4, "le") - 0x2c;
  3166. stream.moveForwardsBy(total);
  3167. while (stream.hasMore()) {
  3168. // Loop through ELFCHNKs.
  3169. if (stream.getBytes(7).join("") !== [0x45, 0x6c, 0x66, 0x43, 0x68, 0x6e, 0x6b].join(""))
  3170. break;
  3171. stream.moveForwardsBy(0xfff9);
  3172. }
  3173. stream.consumeWhile(0x00);
  3174. return stream.carve();
  3175. }
  3176. /**
  3177. * EVT extractor.
  3178. *
  3179. * @param {Uint8Array} bytes
  3180. * @param {Number} offset
  3181. * @returns {Uint8Array}
  3182. */
  3183. export function extractEVT(bytes, offset) {
  3184. const stream = new Stream(bytes.slice(offset));
  3185. stream.moveTo(0x14);
  3186. // Extract offset of EOF.
  3187. const eofoffset = stream.readInt(4, "le");
  3188. stream.moveTo(eofoffset);
  3189. // Extract the size of the EOF.
  3190. const eofsize = stream.readInt(4, "le");
  3191. // Move past EOF.
  3192. stream.moveForwardsBy(eofsize-4);
  3193. return stream.carve();
  3194. }