FileSignatures.mjs 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545
  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. {
  1285. 0: 0xca,
  1286. 1: 0xfe,
  1287. 2: 0xba,
  1288. 3: 0xbe,
  1289. 4: 0x00,
  1290. 5: 0x00,
  1291. 6: 0x00,
  1292. 7: [0x01, 0x02, 0x03]
  1293. },
  1294. {
  1295. 0: 0xce,
  1296. 1: 0xfa,
  1297. 2: 0xed,
  1298. 3: 0xfe,
  1299. 4: 0x07,
  1300. 5: 0x00,
  1301. 6: 0x00,
  1302. 7: 0x00,
  1303. 8: [0x01, 0x02, 0x03]
  1304. }
  1305. ],
  1306. extractor: extractMACHO
  1307. },
  1308. {
  1309. name: "MacOS Mach-O 64-bit object",
  1310. extension: "dylib",
  1311. mime: "application/octet-stream",
  1312. description: "",
  1313. signature: {
  1314. 0: 0xcf,
  1315. 1: 0xfa,
  1316. 2: 0xed,
  1317. 3: 0xfe
  1318. },
  1319. extractor: extractMACHO
  1320. },
  1321. {
  1322. name: "Adobe Flash",
  1323. extension: "swf",
  1324. mime: "application/x-shockwave-flash",
  1325. description: "",
  1326. signature: {
  1327. 0: [0x43, 0x46],
  1328. 1: 0x57,
  1329. 2: 0x53,
  1330. },
  1331. extractor: null
  1332. },
  1333. {
  1334. name: "Java Class",
  1335. extension: "class",
  1336. mime: "application/java-vm",
  1337. description: "",
  1338. signature: {
  1339. 0: 0xca,
  1340. 1: 0xfe,
  1341. 2: 0xba,
  1342. 3: 0xbe
  1343. },
  1344. extractor: null
  1345. },
  1346. {
  1347. name: "Dalvik Executable",
  1348. extension: "dex",
  1349. mime: "application/octet-stream",
  1350. description: "Dalvik Executable as used by Android",
  1351. signature: {
  1352. 0: 0x64,
  1353. 1: 0x65,
  1354. 2: 0x78,
  1355. 3: 0x0a,
  1356. 4: 0x30,
  1357. 5: 0x33,
  1358. 6: 0x35,
  1359. 7: 0x0
  1360. },
  1361. extractor: null
  1362. },
  1363. {
  1364. name: "Google Chrome Extension",
  1365. extension: "crx",
  1366. mime: "application/crx",
  1367. description: "Google Chrome extension or packaged app",
  1368. signature: {
  1369. 0: 0x43,
  1370. 1: 0x72,
  1371. 2: 0x32,
  1372. 3: 0x34
  1373. },
  1374. extractor: null
  1375. },
  1376. ],
  1377. "Archives": [
  1378. {
  1379. name: "PKZIP archive",
  1380. extension: "zip",
  1381. mime: "application/zip",
  1382. description: "",
  1383. signature: {
  1384. 0: 0x50,
  1385. 1: 0x4b,
  1386. 2: [0x3, 0x5, 0x7],
  1387. 3: [0x4, 0x6, 0x8]
  1388. },
  1389. extractor: extractZIP
  1390. },
  1391. {
  1392. name: "PKZIP archive (under Base64)",
  1393. extension: "B64",
  1394. mime: "application/octet-stream",
  1395. description: "",
  1396. signature: {
  1397. 0: 0x55,
  1398. 1: 0x45,
  1399. 2: 0x73,
  1400. 3: 0x44,
  1401. 4: 0x42,
  1402. 5: 0x42
  1403. },
  1404. extractor: null
  1405. },
  1406. {
  1407. name: "TAR archive",
  1408. extension: "tar",
  1409. mime: "application/x-tar",
  1410. description: "",
  1411. signature: {
  1412. 257: 0x75, // ustar
  1413. 258: 0x73,
  1414. 259: 0x74,
  1415. 260: 0x61,
  1416. 261: 0x72
  1417. },
  1418. extractor: extractTAR
  1419. },
  1420. {
  1421. name: "Roshal Archive",
  1422. extension: "rar",
  1423. mime: "application/x-rar-compressed",
  1424. description: "",
  1425. signature: {
  1426. 0: 0x52,
  1427. 1: 0x61,
  1428. 2: 0x72,
  1429. 3: 0x21,
  1430. 4: 0x1a,
  1431. 5: 0x7,
  1432. 6: [0x0, 0x1]
  1433. },
  1434. extractor: null
  1435. },
  1436. {
  1437. name: "Gzip",
  1438. extension: "gz",
  1439. mime: "application/gzip",
  1440. description: "",
  1441. signature: {
  1442. 0: 0x1f,
  1443. 1: 0x8b,
  1444. 2: 0x8
  1445. },
  1446. extractor: extractGZIP
  1447. },
  1448. {
  1449. name: "Bzip2",
  1450. extension: "bz2",
  1451. mime: "application/x-bzip2",
  1452. description: "",
  1453. signature: {
  1454. 0: 0x42,
  1455. 1: 0x5a,
  1456. 2: 0x68
  1457. },
  1458. extractor: extractBZIP2
  1459. },
  1460. {
  1461. name: "7zip",
  1462. extension: "7z",
  1463. mime: "application/x-7z-compressed",
  1464. description: "",
  1465. signature: {
  1466. 0: 0x37,
  1467. 1: 0x7a,
  1468. 2: 0xbc,
  1469. 3: 0xaf,
  1470. 4: 0x27,
  1471. 5: 0x1c
  1472. },
  1473. extractor: null
  1474. },
  1475. {
  1476. name: "Zlib Deflate",
  1477. extension: "zlib",
  1478. mime: "application/x-deflate",
  1479. description: "",
  1480. signature: {
  1481. 0: 0x78,
  1482. 1: [0x1, 0x9c, 0xda, 0x5e]
  1483. },
  1484. extractor: extractZlib
  1485. },
  1486. {
  1487. name: "xz compression",
  1488. extension: "xz",
  1489. mime: "application/x-xz",
  1490. description: "",
  1491. signature: {
  1492. 0: 0xfd,
  1493. 1: 0x37,
  1494. 2: 0x7a,
  1495. 3: 0x58,
  1496. 4: 0x5a,
  1497. 5: 0x0
  1498. },
  1499. extractor: extractXZ
  1500. },
  1501. {
  1502. name: "Tarball",
  1503. extension: "tar.z",
  1504. mime: "application/x-gtar",
  1505. description: "",
  1506. signature: {
  1507. 0: 0x1f,
  1508. 1: [0x9d, 0xa0]
  1509. },
  1510. extractor: null
  1511. },
  1512. {
  1513. name: "ISO disk image",
  1514. extension: "iso",
  1515. mime: "application/octet-stream",
  1516. description: "ISO 9660 CD/DVD image file",
  1517. signature: [
  1518. {
  1519. 0x8001: 0x43,
  1520. 0x8002: 0x44,
  1521. 0x8003: 0x30,
  1522. 0x8004: 0x30,
  1523. 0x8005: 0x31
  1524. },
  1525. {
  1526. 0x8801: 0x43,
  1527. 0x8802: 0x44,
  1528. 0x8803: 0x30,
  1529. 0x8804: 0x30,
  1530. 0x8805: 0x31
  1531. },
  1532. {
  1533. 0x9001: 0x43,
  1534. 0x9002: 0x44,
  1535. 0x9003: 0x30,
  1536. 0x9004: 0x30,
  1537. 0x9005: 0x31
  1538. }
  1539. ],
  1540. extractor: null
  1541. },
  1542. {
  1543. name: "Virtual Machine Disk",
  1544. extension: "vmdk",
  1545. mime: "application/vmdk,application/x-virtualbox-vmdk",
  1546. description: "",
  1547. signature: {
  1548. 0: 0x4b,
  1549. 1: 0x44,
  1550. 2: 0x4d,
  1551. 3: 0x56,
  1552. 5: 0x00,
  1553. 6: 0x00,
  1554. 7: 0x00
  1555. },
  1556. extractor: null
  1557. },
  1558. {
  1559. name: "Virtual Hard Drive",
  1560. extension: "vhd",
  1561. mime: "application/x-vhd",
  1562. description: "",
  1563. signature: {
  1564. 0: 0x63, // conectix
  1565. 1: 0x6f,
  1566. 2: 0x6e,
  1567. 3: 0x65,
  1568. 4: 0x63,
  1569. 5: 0x74,
  1570. 6: 0x69,
  1571. 7: 0x78
  1572. },
  1573. extractor: null
  1574. },
  1575. {
  1576. name: "Macintosh disk image",
  1577. extension: "dmf,dmg",
  1578. mime: "application/octet-stream",
  1579. description: "",
  1580. signature: {
  1581. 0: 0x78,
  1582. 1: 0x01,
  1583. 2: 0x73,
  1584. 3: 0x0d,
  1585. 4: 0x62,
  1586. 5: 0x62,
  1587. 6: 0x60,
  1588. 7: 0x60
  1589. },
  1590. extractor: null
  1591. },
  1592. {
  1593. name: "ARJ Archive",
  1594. extension: "arj",
  1595. mime: "application/x-arj-compressed",
  1596. description: "",
  1597. signature: {
  1598. 0: 0x60,
  1599. 1: 0xea,
  1600. 8: [0x0, 0x10, 0x14],
  1601. 9: 0x0,
  1602. 10: 0x2
  1603. },
  1604. extractor: null
  1605. },
  1606. {
  1607. name: "WinAce Archive",
  1608. extension: "ace",
  1609. mime: "application/x-ace-compressed",
  1610. description: "",
  1611. signature: {
  1612. 7: 0x2a, // **ACE**
  1613. 8: 0x2a,
  1614. 9: 0x41,
  1615. 10: 0x43,
  1616. 11: 0x45,
  1617. 12: 0x2a,
  1618. 13: 0x2a
  1619. },
  1620. extractor: null
  1621. },
  1622. {
  1623. name: "Macintosh BinHex Encoded File",
  1624. extension: "hqx",
  1625. mime: "application/mac-binhex",
  1626. description: "",
  1627. signature: {
  1628. 11: 0x6d, // must be converted with BinHex
  1629. 12: 0x75,
  1630. 13: 0x73,
  1631. 14: 0x74,
  1632. 15: 0x20,
  1633. 16: 0x62,
  1634. 17: 0x65,
  1635. 18: 0x20,
  1636. 19: 0x63,
  1637. 20: 0x6f,
  1638. 21: 0x6e,
  1639. 22: 0x76,
  1640. 23: 0x65,
  1641. 24: 0x72,
  1642. 25: 0x74,
  1643. 26: 0x65,
  1644. 27: 0x64,
  1645. 28: 0x20,
  1646. 29: 0x77,
  1647. 30: 0x69,
  1648. 31: 0x74,
  1649. 32: 0x68,
  1650. 33: 0x20,
  1651. 34: 0x42,
  1652. 35: 0x69,
  1653. 36: 0x6e,
  1654. 37: 0x48,
  1655. 38: 0x65,
  1656. 39: 0x78
  1657. },
  1658. extractor: null
  1659. },
  1660. {
  1661. name: "ALZip Archive",
  1662. extension: "alz",
  1663. mime: "application/octet-stream",
  1664. description: "",
  1665. signature: {
  1666. 0: 0x41, // ALZ
  1667. 1: 0x4c,
  1668. 2: 0x5a,
  1669. 3: 0x01,
  1670. 4: 0x0a,
  1671. 5: 0x0,
  1672. 6: 0x0,
  1673. 7: 0x0
  1674. },
  1675. extractor: null
  1676. },
  1677. {
  1678. name: "KGB Compressed Archive",
  1679. extension: "kgb",
  1680. mime: "application/x-kgb-compressed",
  1681. description: "",
  1682. signature: {
  1683. 0: 0x4b, // KGB_arch -
  1684. 1: 0x47,
  1685. 2: 0x42,
  1686. 3: 0x5f,
  1687. 4: 0x61,
  1688. 5: 0x72,
  1689. 6: 0x63,
  1690. 7: 0x68,
  1691. 8: 0x20,
  1692. 9: 0x2d
  1693. },
  1694. extractor: null
  1695. },
  1696. {
  1697. name: "Microsoft Cabinet",
  1698. extension: "cab",
  1699. mime: "vnd.ms-cab-compressed",
  1700. description: "",
  1701. signature: {
  1702. 0: 0x4d,
  1703. 1: 0x53,
  1704. 2: 0x43,
  1705. 3: 0x46,
  1706. 4: 0x00,
  1707. 5: 0x00,
  1708. 6: 0x00,
  1709. 7: 0x00
  1710. },
  1711. extractor: null
  1712. },
  1713. {
  1714. name: "Jar Archive",
  1715. extension: "jar",
  1716. mime: "application/java-archive",
  1717. description: "",
  1718. signature: {
  1719. 0: 0x5f,
  1720. 1: 0x27,
  1721. 2: 0xa8,
  1722. 3: 0x89
  1723. },
  1724. extractor: null
  1725. },
  1726. {
  1727. name: "lzop compressed",
  1728. extension: "lzop,lzo",
  1729. mime: "application/x-lzop",
  1730. description: "",
  1731. signature: {
  1732. 0: 0x89,
  1733. 1: 0x4c, // LZO
  1734. 2: 0x5a,
  1735. 3: 0x4f,
  1736. 4: 0x00,
  1737. 5: 0x0d,
  1738. 6: 0x0a,
  1739. 7: 0x1a
  1740. },
  1741. extractor: null
  1742. },
  1743. ],
  1744. "Miscellaneous": [
  1745. {
  1746. name: "UTF-8 text",
  1747. extension: "txt",
  1748. mime: "text/plain",
  1749. description: "UTF-8 encoded Unicode byte order mark, commonly but not exclusively seen in text files.",
  1750. signature: {
  1751. 0: 0xef,
  1752. 1: 0xbb,
  1753. 2: 0xbf
  1754. },
  1755. extractor: null
  1756. },
  1757. { // Place before UTF-16 LE text
  1758. name: "UTF-32 LE text",
  1759. extension: "utf32le",
  1760. mime: "charset/utf32le",
  1761. description: "Little-endian UTF-32 encoded Unicode byte order mark.",
  1762. signature: {
  1763. 0: 0xff,
  1764. 1: 0xfe,
  1765. 2: 0x00,
  1766. 3: 0x00
  1767. },
  1768. extractor: null
  1769. },
  1770. {
  1771. name: "UTF-16 LE text",
  1772. extension: "utf16le",
  1773. mime: "charset/utf16le",
  1774. description: "Little-endian UTF-16 encoded Unicode byte order mark.",
  1775. signature: {
  1776. 0: 0xff,
  1777. 1: 0xfe
  1778. },
  1779. extractor: null
  1780. },
  1781. {
  1782. name: "Web Open Font Format",
  1783. extension: "woff",
  1784. mime: "application/font-woff",
  1785. description: "",
  1786. signature: {
  1787. 0: 0x77,
  1788. 1: 0x4f,
  1789. 2: 0x46,
  1790. 3: 0x46,
  1791. 4: 0x0,
  1792. 5: 0x1,
  1793. 6: 0x0,
  1794. 7: 0x0
  1795. },
  1796. extractor: null
  1797. },
  1798. {
  1799. name: "Web Open Font Format 2",
  1800. extension: "woff2",
  1801. mime: "application/font-woff",
  1802. description: "",
  1803. signature: {
  1804. 0: 0x77,
  1805. 1: 0x4f,
  1806. 2: 0x46,
  1807. 3: 0x32,
  1808. 4: 0x0,
  1809. 5: 0x1,
  1810. 6: 0x0,
  1811. 7: 0x0
  1812. },
  1813. extractor: null
  1814. },
  1815. {
  1816. name: "Embedded OpenType font",
  1817. extension: "eot",
  1818. mime: "application/octet-stream",
  1819. description: "",
  1820. signature: [
  1821. {
  1822. 8: 0x2,
  1823. 9: 0x0,
  1824. 10: 0x1,
  1825. 34: 0x4c,
  1826. 35: 0x50
  1827. },
  1828. {
  1829. 8: 0x1,
  1830. 9: 0x0,
  1831. 10: 0x0,
  1832. 34: 0x4c,
  1833. 35: 0x50
  1834. },
  1835. {
  1836. 8: 0x2,
  1837. 9: 0x0,
  1838. 10: 0x2,
  1839. 34: 0x4c,
  1840. 35: 0x50
  1841. },
  1842. ],
  1843. extractor: null
  1844. },
  1845. {
  1846. name: "TrueType Font",
  1847. extension: "ttf",
  1848. mime: "application/font-sfnt",
  1849. description: "",
  1850. signature: {
  1851. 0: 0x0,
  1852. 1: 0x1,
  1853. 2: 0x0,
  1854. 3: 0x0,
  1855. 4: 0x0
  1856. },
  1857. extractor: null
  1858. },
  1859. {
  1860. name: "OpenType Font",
  1861. extension: "otf",
  1862. mime: "application/font-sfnt",
  1863. description: "",
  1864. signature: {
  1865. 0: 0x4f,
  1866. 1: 0x54,
  1867. 2: 0x54,
  1868. 3: 0x4f,
  1869. 4: 0x0
  1870. },
  1871. extractor: null
  1872. },
  1873. {
  1874. name: "SQLite",
  1875. extension: "sqlite",
  1876. mime: "application/x-sqlite3",
  1877. description: "",
  1878. signature: {
  1879. 0: 0x53,
  1880. 1: 0x51,
  1881. 2: 0x4c,
  1882. 3: 0x69
  1883. },
  1884. extractor: extractSQLITE
  1885. },
  1886. {
  1887. name: "BitTorrent link",
  1888. extension: "torrent",
  1889. mime: "application/x-bittorrent",
  1890. description: "",
  1891. signature: [
  1892. {
  1893. 0: 0x64, // d8:announce##:
  1894. 1: 0x38,
  1895. 2: 0x3a,
  1896. 3: 0x61,
  1897. 4: 0x6e,
  1898. 5: 0x6e,
  1899. 6: 0x6f,
  1900. 7: 0x75,
  1901. 8: 0x6e,
  1902. 9: 0x63,
  1903. 10: 0x65,
  1904. 11: 0x23,
  1905. 12: 0x23,
  1906. 13: 0x3a
  1907. },
  1908. {
  1909. 0: 0x64, // d4:infod
  1910. 1: 0x34,
  1911. 2: 0x3a,
  1912. 3: 0x69,
  1913. 4: 0x6e,
  1914. 5: 0x66,
  1915. 6: 0x6f,
  1916. 7: 0x64,
  1917. 8: [0x34, 0x35, 0x36],
  1918. 9: 0x3a
  1919. }
  1920. ],
  1921. extractor: null
  1922. },
  1923. {
  1924. name: "Cryptocurrency wallet",
  1925. extension: "wallet",
  1926. mime: "application/octet-stream",
  1927. description: "",
  1928. signature: {
  1929. 0: 0x00,
  1930. 1: 0x00,
  1931. 2: 0x00,
  1932. 3: 0x00,
  1933. 4: 0x01,
  1934. 5: 0x00,
  1935. 6: 0x00,
  1936. 7: 0x00,
  1937. 8: 0x00,
  1938. 9: 0x00,
  1939. 10: 0x00,
  1940. 11: 0x00,
  1941. 12: 0x62,
  1942. 13: 0x31,
  1943. 14: 0x05,
  1944. 15: 0x00
  1945. },
  1946. extractor: null
  1947. },
  1948. {
  1949. name: "Registry fragment",
  1950. extension: "hbin",
  1951. mime: "application/octet-stream",
  1952. description: "",
  1953. signature: {
  1954. 0: 0x68, // hbin
  1955. 1: 0x62,
  1956. 2: 0x69,
  1957. 3: 0x6e,
  1958. 4: 0x00
  1959. },
  1960. extractor: null
  1961. },
  1962. {
  1963. name: "Registry script",
  1964. extension: "rgs",
  1965. mime: "application/octet-stream",
  1966. description: "",
  1967. signature: {
  1968. 0: 0x48, // HKCR
  1969. 1: 0x4b,
  1970. 2: 0x43,
  1971. 3: 0x52,
  1972. 4: 0x0d,
  1973. 5: 0x0a,
  1974. 6: 0x5c,
  1975. 7: 0x7b
  1976. },
  1977. extractor: null
  1978. },
  1979. {
  1980. name: "WinNT Registry Hive",
  1981. extension: "registry",
  1982. mime: "application/octet-stream",
  1983. description: "",
  1984. signature: {
  1985. 0: 0x72,
  1986. 1: 0x65,
  1987. 2: 0x67,
  1988. 3: 0x66
  1989. },
  1990. extractor: null
  1991. },
  1992. {
  1993. name: "Windows Event Log",
  1994. extension: "evt",
  1995. mime: "application/octet-stream",
  1996. description: "",
  1997. signature: {
  1998. 0: 0x30,
  1999. 1: 0x00,
  2000. 2: 0x00,
  2001. 3: 0x00,
  2002. 4: 0x4c,
  2003. 5: 0x66,
  2004. 6: 0x4c,
  2005. 7: 0x65
  2006. },
  2007. extractor: extractEVT
  2008. },
  2009. {
  2010. name: "Windows Event Log",
  2011. extension: "evtx",
  2012. mime: "application/octet-stream",
  2013. description: "",
  2014. signature: {
  2015. 0: 0x45, // ElfFile
  2016. 1: 0x6c,
  2017. 2: 0x66,
  2018. 3: 0x46,
  2019. 4: 0x69,
  2020. 5: 0x6c,
  2021. 6: 0x65
  2022. },
  2023. extractor: extractEVTX
  2024. },
  2025. {
  2026. name: "Windows Pagedump",
  2027. extension: "dmp",
  2028. mime: "application/octet-stream",
  2029. description: "",
  2030. signature: {
  2031. 0: 0x50, // PAGEDU(MP|64)
  2032. 1: 0x41,
  2033. 2: 0x47,
  2034. 3: 0x45,
  2035. 4: 0x44,
  2036. 5: 0x55,
  2037. 6: [0x4d, 0x36],
  2038. 7: [0x50, 0x34]
  2039. },
  2040. extractor: null
  2041. },
  2042. {
  2043. name: "Windows Prefetch",
  2044. extension: "pf",
  2045. mime: "application/x-pf",
  2046. description: "",
  2047. signature: {
  2048. 0: [0x11, 0x17, 0x1a],
  2049. 1: 0x0,
  2050. 2: 0x0,
  2051. 3: 0x0,
  2052. 4: 0x53,
  2053. 5: 0x43,
  2054. 6: 0x43,
  2055. 7: 0x41
  2056. },
  2057. extractor: null
  2058. },
  2059. {
  2060. name: "Windows Prefetch (Win 10)",
  2061. extension: "pf",
  2062. mime: "application/x-pf",
  2063. description: "",
  2064. signature: {
  2065. 0: 0x4d,
  2066. 1: 0x41,
  2067. 2: 0x4d,
  2068. 3: 0x04,
  2069. 7: 0x0
  2070. },
  2071. extractor: null
  2072. },
  2073. {
  2074. name: "PList (XML)",
  2075. extension: "plist",
  2076. mime: "application/xml",
  2077. description: "",
  2078. signature: {
  2079. 39: 0x3c, // <!DOCTYPE plist
  2080. 40: 0x21,
  2081. 41: 0x44,
  2082. 42: 0x4f,
  2083. 43: 0x43,
  2084. 44: 0x54,
  2085. 45: 0x59,
  2086. 46: 0x50,
  2087. 47: 0x45,
  2088. 48: 0x20,
  2089. 49: 0x70,
  2090. 50: 0x6c,
  2091. 51: 0x69,
  2092. 52: 0x73,
  2093. 53: 0x74
  2094. },
  2095. extractor: extractPListXML
  2096. },
  2097. {
  2098. name: "PList (binary)",
  2099. extension: "bplist,plist,ipmeta,abcdp,mdbackup,mdinfo,strings,nib,ichat,qtz,webbookmark,webhistory",
  2100. mime: "application/x-plist",
  2101. description: "",
  2102. signature: {
  2103. 0: 0x62, // bplist00
  2104. 1: 0x70,
  2105. 2: 0x6c,
  2106. 3: 0x69,
  2107. 4: 0x73,
  2108. 5: 0x74,
  2109. 6: 0x30,
  2110. 7: 0x30
  2111. },
  2112. extractor: null
  2113. },
  2114. {
  2115. name: "MacOS X Keychain",
  2116. extension: "keychain",
  2117. mime: "application/octet-stream",
  2118. description: "",
  2119. signature: {
  2120. 0: 0x6b, // keych
  2121. 1: 0x79,
  2122. 2: 0x63,
  2123. 3: 0x68,
  2124. 4: 0x00,
  2125. 5: 0x01
  2126. },
  2127. extractor: null
  2128. },
  2129. {
  2130. name: "TCP Packet",
  2131. extension: "tcp",
  2132. mime: "application/tcp",
  2133. description: "",
  2134. signature: {
  2135. 12: 0x08,
  2136. 13: 0x00,
  2137. 14: 0x45,
  2138. 15: 0x00,
  2139. 21: 0x00,
  2140. 22: b => b >= 0x01 && b <= 0x80,
  2141. 23: 0x06
  2142. },
  2143. extractor: null
  2144. },
  2145. {
  2146. name: "UDP Packet",
  2147. extension: "udp",
  2148. mime: "application/udp",
  2149. description: "",
  2150. signature: {
  2151. 12: 0x08,
  2152. 13: 0x00,
  2153. 14: 0x45,
  2154. 15: 0x00,
  2155. 16: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05],
  2156. 22: b => b >= 0x01 && b <= 0x80,
  2157. 23: 0x11
  2158. },
  2159. extractor: null
  2160. },
  2161. {
  2162. name: "Compiled HTML",
  2163. extension: "chm,chw,chi",
  2164. mime: "application/vnd.ms-htmlhelp",
  2165. description: "",
  2166. signature: {
  2167. 0: 0x49, // ITSF
  2168. 1: 0x54,
  2169. 2: 0x53,
  2170. 3: 0x46,
  2171. 4: 0x03,
  2172. 5: 0x00,
  2173. 6: 0x00,
  2174. 7: 0x00
  2175. },
  2176. extractor: null
  2177. },
  2178. {
  2179. name: "Windows Password",
  2180. extension: "pwl",
  2181. mime: "application/octet-stream",
  2182. description: "",
  2183. signature: {
  2184. 0: 0xe3,
  2185. 1: 0x82,
  2186. 2: 0x85,
  2187. 3: 0x96
  2188. },
  2189. extractor: null
  2190. },
  2191. {
  2192. name: "Bitlocker recovery key",
  2193. extension: "bitlocker",
  2194. mime: "application/octet-stream",
  2195. description: "",
  2196. signature: {
  2197. 0: 0xff,
  2198. 1: 0xfe,
  2199. 2: 0x42,
  2200. 3: 0x00,
  2201. 4: 0x69,
  2202. 5: 0x00,
  2203. 6: 0x74,
  2204. 7: 0x00,
  2205. 8: 0x4c,
  2206. 9: 0x00,
  2207. 10: 0x6f,
  2208. 11: 0x00,
  2209. 12: 0x63,
  2210. 13: 0x00,
  2211. 14: 0x6b,
  2212. 15: 0x00,
  2213. 16: 0x65,
  2214. 17: 0x00,
  2215. 18: 0x72,
  2216. 19: 0x00,
  2217. 20: 0x20,
  2218. 21: 0x00
  2219. },
  2220. extractor: null
  2221. },
  2222. {
  2223. name: "Certificate",
  2224. extension: "cer,cat,p7b,p7c,p7m,p7s,swz,rsa,crl,crt,der",
  2225. mime: "application/pkix-cert",
  2226. description: "",
  2227. signature: {
  2228. 0: 0x30,
  2229. 1: 0x82,
  2230. 4: [0x06, 0x0a, 0x30]
  2231. },
  2232. extractor: null
  2233. },
  2234. {
  2235. name: "Certificate",
  2236. extension: "cat,swz,p7m",
  2237. mime: "application/vnd.ms-pki.seccat",
  2238. description: "",
  2239. signature: {
  2240. 0: 0x30,
  2241. 1: 0x83,
  2242. 2: b => b !== 0x00,
  2243. 5: 0x06,
  2244. 6: 0x09
  2245. },
  2246. extractor: null
  2247. },
  2248. {
  2249. name: "PGP pubring",
  2250. extension: "pkr,gpg",
  2251. mime: "application/pgp-keys",
  2252. description: "",
  2253. signature: {
  2254. 0: 0x99,
  2255. 1: 0x01,
  2256. 2: [0x0d, 0xa2],
  2257. 3: 0x04
  2258. },
  2259. extractor: null
  2260. },
  2261. {
  2262. name: "PGP secring",
  2263. extension: "skr",
  2264. mime: "application/pgp-keys",
  2265. description: "",
  2266. signature: [
  2267. {
  2268. 0: 0x95,
  2269. 1: 0x01,
  2270. 2: 0xcf,
  2271. 3: 0x04
  2272. },
  2273. {
  2274. 0: 0x95,
  2275. 1: 0x03,
  2276. 2: 0xc6,
  2277. 3: 0x04
  2278. }
  2279. ],
  2280. extractor: null
  2281. },
  2282. {
  2283. name: "PGP Safe",
  2284. extension: "pgd",
  2285. mime: "application/pgp-keys",
  2286. description: "",
  2287. signature: {
  2288. 0: 0x50, // PGPdMAIN
  2289. 1: 0x47,
  2290. 2: 0x50,
  2291. 3: 0x64,
  2292. 4: 0x4d,
  2293. 5: 0x41,
  2294. 6: 0x49,
  2295. 7: 0x4e,
  2296. 8: 0x60,
  2297. 9: 0x01,
  2298. 10: 0x00
  2299. },
  2300. extractor: null
  2301. },
  2302. {
  2303. name: "Task Scheduler",
  2304. extension: "job",
  2305. mime: "application/octet-stream",
  2306. description: "",
  2307. signature: {
  2308. 0: [0x00, 0x01, 0x02, 0x03],
  2309. 1: [0x05, 0x06],
  2310. 2: 0x01,
  2311. 3: 0x00,
  2312. 20: 0x46,
  2313. 21: 0x00
  2314. },
  2315. extractor: null
  2316. },
  2317. {
  2318. name: "Windows Shortcut",
  2319. extension: "lnk",
  2320. mime: "application/x-ms-shortcut",
  2321. description: "",
  2322. signature: {
  2323. 0: 0x4c,
  2324. 1: 0x00,
  2325. 2: 0x00,
  2326. 3: 0x00,
  2327. 4: 0x01,
  2328. 5: 0x14,
  2329. 6: 0x02,
  2330. 7: 0x00,
  2331. 8: 0x00,
  2332. 9: 0x00,
  2333. 10: 0x00,
  2334. 11: 0x00,
  2335. 12: 0xc0,
  2336. 13: 0x00,
  2337. 14: 0x00,
  2338. 15: 0x00,
  2339. 16: 0x00,
  2340. 17: 0x00,
  2341. 18: 0x00,
  2342. 19: 0x46
  2343. },
  2344. extractor: null
  2345. },
  2346. {
  2347. name: "Bash",
  2348. extension: "bash",
  2349. mime: "application/bash",
  2350. description: "",
  2351. signature: {
  2352. 0: 0x23, // #!/bin/bash
  2353. 1: 0x21,
  2354. 2: 0x2f,
  2355. 3: 0x62,
  2356. 4: 0x69,
  2357. 5: 0x6e,
  2358. 6: 0x2f,
  2359. 7: 0x62,
  2360. 8: 0x61,
  2361. 9: 0x73,
  2362. 10: 0x68,
  2363. },
  2364. extractor: null
  2365. },
  2366. {
  2367. name: "Shell",
  2368. extension: "sh",
  2369. mime: "application/sh",
  2370. description: "",
  2371. signature: {
  2372. 0: 0x23, // #!/bin/sh
  2373. 1: 0x21,
  2374. 2: 0x2f,
  2375. 3: 0x62,
  2376. 4: 0x69,
  2377. 5: 0x6e,
  2378. 6: 0x2f,
  2379. 7: 0x73,
  2380. 8: 0x68,
  2381. },
  2382. extractor: null
  2383. },
  2384. {
  2385. name: "Python",
  2386. extension: "py,pyc,pyd,pyo,pyw,pyz",
  2387. mime: "application/python",
  2388. description: "",
  2389. signature: {
  2390. 0: 0x23, // #!/usr/bin/python(2|3)
  2391. 1: 0x21,
  2392. 2: 0x2f,
  2393. 3: 0x75,
  2394. 4: 0x73,
  2395. 5: 0x72,
  2396. 6: 0x2f,
  2397. 7: 0x62,
  2398. 8: 0x69,
  2399. 9: 0x6e,
  2400. 10: 0x2f,
  2401. 11: 0x70,
  2402. 12: 0x79,
  2403. 13: 0x74,
  2404. 14: 0x68,
  2405. 15: 0x6f,
  2406. 16: 0x6e,
  2407. 17: [0x32, 0x33, 0xa, 0xd],
  2408. },
  2409. extractor: null
  2410. },
  2411. {
  2412. name: "Ruby",
  2413. extension: "rb",
  2414. mime: "application/ruby",
  2415. description: "",
  2416. signature: {
  2417. 0: 0x23, // #!/usr/bin/ruby
  2418. 1: 0x21,
  2419. 2: 0x2f,
  2420. 3: 0x75,
  2421. 4: 0x73,
  2422. 5: 0x72,
  2423. 6: 0x2f,
  2424. 7: 0x62,
  2425. 8: 0x69,
  2426. 9: 0x6e,
  2427. 10: 0x2f,
  2428. 11: 0x72,
  2429. 12: 0x75,
  2430. 13: 0x62,
  2431. 14: 0x79,
  2432. },
  2433. extractor: null
  2434. },
  2435. {
  2436. name: "perl",
  2437. extension: "pl,pm,t,pod",
  2438. mime: "application/perl",
  2439. description: "",
  2440. signature: {
  2441. 0: 0x23, // #!/usr/bin/perl
  2442. 1: 0x21,
  2443. 2: 0x2f,
  2444. 3: 0x75,
  2445. 4: 0x73,
  2446. 5: 0x72,
  2447. 6: 0x2f,
  2448. 7: 0x62,
  2449. 8: 0x69,
  2450. 9: 0x6e,
  2451. 10: 0x2f,
  2452. 11: 0x70,
  2453. 12: 0x65,
  2454. 13: 0x72,
  2455. 14: 0x6c,
  2456. },
  2457. extractor: null
  2458. },
  2459. {
  2460. name: "php",
  2461. extension: "php,phtml,php3,php4,php5,php7,phps,php-s,pht,phar",
  2462. mime: "application/php",
  2463. description: "",
  2464. signature: {
  2465. 0: 0x3c, // <?php
  2466. 1: 0x3f,
  2467. 2: 0x70,
  2468. 3: 0x68,
  2469. 4: 0x70,
  2470. },
  2471. extractor: null
  2472. }
  2473. ]
  2474. };
  2475. /**
  2476. * JPEG extractor.
  2477. *
  2478. * @param {Uint8Array} bytes
  2479. * @param {number} offset
  2480. * @returns {Uint8Array}
  2481. */
  2482. export function extractJPEG(bytes, offset) {
  2483. const stream = new Stream(bytes.slice(offset));
  2484. while (stream.hasMore()) {
  2485. const marker = stream.getBytes(2);
  2486. if (marker[0] !== 0xff) throw new Error(`Invalid marker while parsing JPEG at pos ${stream.position}: ${marker}`);
  2487. let segmentSize = 0;
  2488. switch (marker[1]) {
  2489. // No length
  2490. case 0xd8: // Start of Image
  2491. case 0x01: // For temporary use in arithmetic coding
  2492. break;
  2493. case 0xd9: // End found
  2494. return stream.carve();
  2495. // Variable size segment
  2496. case 0xc0: // Start of frame (Baseline DCT)
  2497. case 0xc1: // Start of frame (Extended sequential DCT)
  2498. case 0xc2: // Start of frame (Progressive DCT)
  2499. case 0xc3: // Start of frame (Lossless sequential)
  2500. case 0xc4: // Define Huffman Table
  2501. case 0xc5: // Start of frame (Differential sequential DCT)
  2502. case 0xc6: // Start of frame (Differential progressive DCT)
  2503. case 0xc7: // Start of frame (Differential lossless)
  2504. case 0xc8: // Reserved for JPEG extensions
  2505. case 0xc9: // Start of frame (Extended sequential DCT)
  2506. case 0xca: // Start of frame (Progressive DCT)
  2507. case 0xcb: // Start of frame (Lossless sequential)
  2508. case 0xcc: // Define arithmetic conditioning table
  2509. case 0xcd: // Start of frame (Differential sequential DCT)
  2510. case 0xce: // Start of frame (Differential progressive DCT)
  2511. case 0xcf: // Start of frame (Differential lossless)
  2512. case 0xdb: // Define Quantization Table
  2513. case 0xde: // Define hierarchical progression
  2514. case 0xe0: // Application-specific
  2515. case 0xe1: // Application-specific
  2516. case 0xe2: // Application-specific
  2517. case 0xe3: // Application-specific
  2518. case 0xe4: // Application-specific
  2519. case 0xe5: // Application-specific
  2520. case 0xe6: // Application-specific
  2521. case 0xe7: // Application-specific
  2522. case 0xe8: // Application-specific
  2523. case 0xe9: // Application-specific
  2524. case 0xea: // Application-specific
  2525. case 0xeb: // Application-specific
  2526. case 0xec: // Application-specific
  2527. case 0xed: // Application-specific
  2528. case 0xee: // Application-specific
  2529. case 0xef: // Application-specific
  2530. case 0xfe: // Comment
  2531. segmentSize = stream.readInt(2, "be");
  2532. stream.position += segmentSize - 2;
  2533. break;
  2534. // 1 byte
  2535. case 0xdf: // Expand reference image
  2536. stream.position++;
  2537. break;
  2538. // 2 bytes
  2539. case 0xdc: // Define number of lines
  2540. case 0xdd: // Define restart interval
  2541. stream.position += 2;
  2542. break;
  2543. // Start scan
  2544. case 0xda: // Start of scan
  2545. segmentSize = stream.readInt(2, "be");
  2546. stream.position += segmentSize - 2;
  2547. stream.continueUntil(0xff);
  2548. break;
  2549. // Continue through encoded data
  2550. case 0x00: // Byte stuffing
  2551. case 0xd0: // Restart
  2552. case 0xd1: // Restart
  2553. case 0xd2: // Restart
  2554. case 0xd3: // Restart
  2555. case 0xd4: // Restart
  2556. case 0xd5: // Restart
  2557. case 0xd6: // Restart
  2558. case 0xd7: // Restart
  2559. stream.continueUntil(0xff);
  2560. break;
  2561. default:
  2562. stream.continueUntil(0xff);
  2563. break;
  2564. }
  2565. }
  2566. throw new Error("Unable to parse JPEG successfully");
  2567. }
  2568. /**
  2569. * GIF extractor.
  2570. *
  2571. * @param {Uint8Array} bytes
  2572. * @param {Number} offset
  2573. * @returns {Uint8Array}
  2574. */
  2575. export function extractGIF(bytes, offset) {
  2576. const stream = new Stream(bytes.slice(offset));
  2577. // Move to application extension block.
  2578. stream.continueUntil([0x21, 0xff]);
  2579. // Move to Graphic Control Extension for frame #1.
  2580. stream.continueUntil([0x21, 0xf9]);
  2581. stream.moveForwardsBy(2);
  2582. while (stream.hasMore()) {
  2583. // Move to Image descriptor.
  2584. stream.moveForwardsBy(stream.readInt(1) + 1);
  2585. // Move past Image descriptor to the image data.
  2586. stream.moveForwardsBy(11);
  2587. // Loop until next Graphic Control Extension.
  2588. while (stream.getBytes(2) !== [0x21, 0xf9]) {
  2589. stream.moveBackwardsBy(2);
  2590. stream.moveForwardsBy(stream.readInt(1));
  2591. if (!stream.readInt(1))
  2592. break;
  2593. stream.moveBackwardsBy(1);
  2594. }
  2595. // When the end of the file is [0x00, 0x3b], end.
  2596. if (stream.readInt(1) === 0x3b)
  2597. break;
  2598. stream.moveForwardsBy(1);
  2599. }
  2600. return stream.carve();
  2601. }
  2602. /**
  2603. * Portable executable extractor.
  2604. * Assumes that the offset refers to an MZ header.
  2605. *
  2606. * @param {Uint8Array} bytes
  2607. * @param {number} offset
  2608. * @returns {Uint8Array}
  2609. */
  2610. export function extractMZPE(bytes, offset) {
  2611. const stream = new Stream(bytes.slice(offset));
  2612. // Read pointer to PE header
  2613. stream.moveTo(0x3c);
  2614. const peAddress = stream.readInt(4, "le");
  2615. // Move to PE header
  2616. stream.moveTo(peAddress);
  2617. // Get number of sections
  2618. stream.moveForwardsBy(6);
  2619. const numSections = stream.readInt(2, "le");
  2620. // Read Optional Header Magic to determine the state of the image file
  2621. // 0x10b = normal executable, 0x107 = ROM image, 0x20b = PE32+ executable
  2622. stream.moveForwardsBy(16);
  2623. const optionalMagic = stream.readInt(2, "le");
  2624. const pe32Plus = optionalMagic === 0x20b;
  2625. // Move to Data Directory
  2626. const dataDirectoryOffset = pe32Plus ? 112 : 96;
  2627. stream.moveForwardsBy(dataDirectoryOffset - 2);
  2628. // Read Certificate Table address and size (IMAGE_DIRECTORY_ENTRY_SECURITY)
  2629. stream.moveForwardsBy(32);
  2630. const certTableAddress = stream.readInt(4, "le");
  2631. const certTableSize = stream.readInt(4, "le");
  2632. // PE files can contain extra data appended to the end of the file called an "overlay".
  2633. // This data is not covered by the PE header and could be any arbitrary format, so its
  2634. // length cannot be determined without contextual information.
  2635. // However, the Attribute Certificate Table is stored in the overlay - usually right at
  2636. // the end. Therefore, if this table is defined, we can use its offset and size to carve
  2637. // out the entire PE file, including the overlay.
  2638. // If the Certificate Table is not defined, we continue to parse the PE file as best we
  2639. // can up to the end of the final section, not including any appended data in the overlay.
  2640. if (certTableAddress > 0) {
  2641. stream.moveTo(certTableAddress + certTableSize);
  2642. return stream.carve();
  2643. }
  2644. // Move past Optional Header to Section Header
  2645. stream.moveForwardsBy(88);
  2646. // Move to final section header
  2647. stream.moveForwardsBy((numSections - 1) * 0x28);
  2648. // Get raw data info
  2649. stream.moveForwardsBy(16);
  2650. const rawDataSize = stream.readInt(4, "le");
  2651. const rawDataAddress = stream.readInt(4, "le");
  2652. // Move to end of final section
  2653. stream.moveTo(rawDataAddress + rawDataSize);
  2654. return stream.carve();
  2655. }
  2656. /**
  2657. * PDF extractor.
  2658. *
  2659. * @param {Uint8Array} bytes
  2660. * @param {number} offset
  2661. * @returns {Uint8Array}
  2662. */
  2663. export function extractPDF(bytes, offset) {
  2664. const stream = new Stream(bytes.slice(offset));
  2665. // Find end-of-file marker (%%EOF)
  2666. stream.continueUntil([0x25, 0x25, 0x45, 0x4f, 0x46]);
  2667. stream.moveForwardsBy(5);
  2668. stream.consumeIf(0x0d);
  2669. stream.consumeIf(0x0a);
  2670. return stream.carve();
  2671. }
  2672. /**
  2673. * ZIP extractor.
  2674. *
  2675. * @param {Uint8Array} bytes
  2676. * @param {number} offset
  2677. * @returns {Uint8Array}
  2678. */
  2679. export function extractZIP(bytes, offset) {
  2680. const stream = new Stream(bytes.slice(offset));
  2681. // Find End of central directory record
  2682. stream.continueUntil([0x50, 0x4b, 0x05, 0x06]);
  2683. // Get comment length and consume
  2684. stream.moveForwardsBy(20);
  2685. const commentLength = stream.readInt(2, "le");
  2686. stream.moveForwardsBy(commentLength);
  2687. return stream.carve();
  2688. }
  2689. /**
  2690. * MACHO extractor
  2691. *
  2692. * @param {Uint8Array} bytes
  2693. * @param {number} offset
  2694. * @returns {Uint8Array}
  2695. */
  2696. export function extractMACHO(bytes, offset) {
  2697. // Magic bytes.
  2698. const MHCIGAM64 = "207250237254";
  2699. const MHMAGIC64 = "254237250207";
  2700. const MHCIGAM = "206250237254";
  2701. /**
  2702. * Checks to see if the file is 64-bit.
  2703. *
  2704. * @param {string} magic
  2705. * @returns {bool}
  2706. */
  2707. function isMagic64(magic) {
  2708. return magic === MHCIGAM64 || magic === MHMAGIC64;
  2709. }
  2710. /**
  2711. * Checks the endianness of the file.
  2712. *
  2713. * @param {string} magic
  2714. * @returns {bool}
  2715. */
  2716. function shouldSwapBytes(magic) {
  2717. return magic === MHCIGAM || magic === MHCIGAM64;
  2718. }
  2719. /**
  2720. * Jumps through segment information and calculates the sum of the segement sizes.
  2721. *
  2722. * @param {Stream} stream
  2723. * @param {number} offset
  2724. * @param {string} isSwap
  2725. * @param {number} ncmds
  2726. * @returns {number}
  2727. */
  2728. function dumpSegmentCommands(stream, offset, isSwap, ncmds) {
  2729. let total = 0;
  2730. const LCSEGEMENT64 = 0x19;
  2731. const LCSEGEMENT = 0x1;
  2732. for (let i = 0; i < ncmds; i++) {
  2733. // Move to start of segment.
  2734. stream.moveTo(offset);
  2735. const cmd = stream.readInt(4, isSwap);
  2736. if (cmd === LCSEGEMENT64) {
  2737. // Move to size of segment field.
  2738. stream.moveTo(offset + 48);
  2739. // Extract size of segement.
  2740. total += stream.readInt(8, isSwap);
  2741. stream.moveTo(offset + 4);
  2742. // Move to offset of next segment.
  2743. offset += stream.readInt(4, isSwap);
  2744. } else if (cmd === LCSEGEMENT) {
  2745. stream.moveTo(offset + 36);
  2746. // Extract size of segement.
  2747. total += stream.readInt(4, isSwap);
  2748. stream.moveTo(offset + 4);
  2749. offset += stream.readInt(4, isSwap);
  2750. }
  2751. }
  2752. return total;
  2753. }
  2754. /**
  2755. * Reads the number of command segments.
  2756. *
  2757. * @param {Stream} stream
  2758. * @param {bool} is64
  2759. * @param {string} isSwap
  2760. * @returns {number}
  2761. */
  2762. function dumpMachHeader(stream, is64, isSwap) {
  2763. let loadCommandsOffset = 28;
  2764. if (is64)
  2765. loadCommandsOffset += 4;
  2766. // Move to number of commands field.
  2767. stream.moveTo(16);
  2768. const ncmds = stream.readInt(4, isSwap);
  2769. return dumpSegmentCommands(stream, loadCommandsOffset, isSwap, ncmds);
  2770. }
  2771. const stream = new Stream(bytes.slice(offset));
  2772. const magic = stream.getBytes(4).join("");
  2773. // Move to the end of the final segment.
  2774. stream.moveTo(dumpMachHeader(stream, isMagic64(magic), shouldSwapBytes(magic) ? "le" : "be"));
  2775. return stream.carve();
  2776. }
  2777. /**
  2778. * TAR extractor.
  2779. *
  2780. * @param {Uint8Array} bytes
  2781. * @param {number} offset
  2782. * @returns {Uint8Array}
  2783. */
  2784. export function extractTAR(bytes, offset) {
  2785. const stream = new Stream(bytes.slice(offset));
  2786. while (stream.hasMore()) {
  2787. // Move to ustar identifier.
  2788. stream.moveForwardsBy(0x101);
  2789. if (stream.getBytes(5).join("") !== [0x75, 0x73, 0x74, 0x61, 0x72].join("")) {
  2790. // Needed since if it were not here it relies on there being at least 0x106 padding of 0s at the end of the TAR.
  2791. stream.moveBackwardsBy(0x106);
  2792. break;
  2793. }
  2794. // Move back to file size field.
  2795. stream.moveBackwardsBy(0x8a);
  2796. let fsize = 0;
  2797. // Read file size field.
  2798. stream.getBytes(11).forEach((element, index) => {
  2799. fsize += (element - 48).toString();
  2800. });
  2801. // Round number up from octet to nearest 512.
  2802. fsize = (Math.ceil(parseInt(fsize, 8) / 512) * 512);
  2803. // Move forwards to the end of that file.
  2804. stream.moveForwardsBy(fsize + 0x179);
  2805. }
  2806. stream.consumeWhile(0x00);
  2807. return stream.carve();
  2808. }
  2809. /**
  2810. * PNG extractor.
  2811. *
  2812. * @param {Uint8Array} bytes
  2813. * @param {number} offset
  2814. * @returns {Uint8Array}
  2815. */
  2816. export function extractPNG(bytes, offset) {
  2817. const stream = new Stream(bytes.slice(offset));
  2818. // Move past signature to first chunk
  2819. stream.moveForwardsBy(8);
  2820. let chunkSize = 0,
  2821. chunkType = "";
  2822. while (chunkType !== "IEND") {
  2823. chunkSize = stream.readInt(4, "be");
  2824. chunkType = stream.readString(4);
  2825. // Chunk data size + CRC checksum
  2826. stream.moveForwardsBy(chunkSize + 4);
  2827. }
  2828. return stream.carve();
  2829. }
  2830. /**
  2831. * BMP extractor.
  2832. *
  2833. * @param {Uint8Array} bytes
  2834. * @param {number} offset
  2835. * @returns {Uint8Array}
  2836. */
  2837. export function extractBMP(bytes, offset) {
  2838. const stream = new Stream(bytes.slice(offset));
  2839. // Move past header
  2840. stream.moveForwardsBy(2);
  2841. // Read full file size
  2842. const bmpSize = stream.readInt(4, "le");
  2843. // Move to end of file (file size minus header and size field)
  2844. stream.moveForwardsBy(bmpSize - 6);
  2845. return stream.carve();
  2846. }
  2847. /**
  2848. * WAV extractor.
  2849. *
  2850. * @param {Uint8Array} bytes
  2851. * @param {Number} offset
  2852. * @returns {Uint8Array}
  2853. */
  2854. export function extractWAV(bytes, offset) {
  2855. const stream = new Stream(bytes.slice(offset));
  2856. // Move to file size field.
  2857. stream.moveTo(4);
  2858. // Move to file size.
  2859. stream.moveTo(stream.readInt(4, "le") - 4);
  2860. return stream.carve();
  2861. }
  2862. /**
  2863. * FLV extractor.
  2864. *
  2865. * @param {Uint8Array} bytes
  2866. * @param {number} offset
  2867. * @returns {Uint8Array}
  2868. */
  2869. export function extractFLV(bytes, offset) {
  2870. const stream = new Stream(bytes.slice(offset));
  2871. // Move past signature, version and flags
  2872. stream.moveForwardsBy(5);
  2873. // Read header size
  2874. const headerSize = stream.readInt(4, "be");
  2875. // Skip through the rest of the header
  2876. stream.moveForwardsBy(headerSize - 9);
  2877. let tagSize = -11; // Fake size of previous tag header
  2878. while (stream.hasMore()) {
  2879. const prevTagSize = stream.readInt(4, "be");
  2880. const tagType = stream.readInt(1);
  2881. if ([8, 9, 18].indexOf(tagType) < 0) {
  2882. // This tag is not valid
  2883. stream.moveBackwardsBy(1);
  2884. break;
  2885. }
  2886. if (prevTagSize !== (tagSize + 11)) {
  2887. // Previous tag was not valid, reverse back over this header
  2888. // and the previous tag body and header
  2889. stream.moveBackwardsBy(tagSize + 11 + 5);
  2890. break;
  2891. }
  2892. tagSize = stream.readInt(3, "be");
  2893. // Move past the rest of the tag header and payload
  2894. stream.moveForwardsBy(7 + tagSize);
  2895. }
  2896. return stream.carve();
  2897. }
  2898. /**
  2899. * RTF extractor.
  2900. *
  2901. * @param {Uint8Array} bytes
  2902. * @param {number} offset
  2903. * @returns {Uint8Array}
  2904. */
  2905. export function extractRTF(bytes, offset) {
  2906. const stream = new Stream(bytes.slice(offset));
  2907. let openTags = 0;
  2908. if (stream.readInt(1) !== 0x7b) { // {
  2909. throw new Error("Not a valid RTF file");
  2910. } else {
  2911. openTags++;
  2912. }
  2913. while (openTags > 0 && stream.hasMore()) {
  2914. switch (stream.readInt(1)) {
  2915. case 0x7b: // {
  2916. openTags++;
  2917. break;
  2918. case 0x7d: // }
  2919. openTags--;
  2920. break;
  2921. case 0x5c: // \
  2922. // Consume any more escapes and then skip over the next character
  2923. stream.consumeIf(0x5c);
  2924. stream.position++;
  2925. break;
  2926. default:
  2927. break;
  2928. }
  2929. }
  2930. return stream.carve();
  2931. }
  2932. /**
  2933. * SQLITE extractor.
  2934. *
  2935. * @param {Uint8Array} bytes
  2936. * @param {number} offset
  2937. * @returns {Uint8Array}
  2938. */
  2939. export function extractSQLITE(bytes, offset) {
  2940. const stream = new Stream(bytes.slice(offset));
  2941. // Extract the size of the page.
  2942. stream.moveTo(16);
  2943. const pageSize = stream.readInt(2);
  2944. // Extract the number of pages.
  2945. stream.moveTo(28);
  2946. const numPages = stream.readInt(4);
  2947. // Move to the end of all the pages.
  2948. stream.moveTo(pageSize*numPages);
  2949. return stream.carve();
  2950. }
  2951. /**
  2952. * PList (XML) extractor.
  2953. *
  2954. * @param {Uint8Array} bytes
  2955. * @param {number} offset
  2956. * @returns {Uint8Array}
  2957. */
  2958. export function extractPListXML(bytes, offset) {
  2959. const stream = new Stream(bytes.slice(offset));
  2960. // Find closing tag (</plist>)
  2961. stream.continueUntil([0x3c, 0x2f, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x3e]);
  2962. stream.moveForwardsBy(8);
  2963. stream.consumeIf(0x0a);
  2964. return stream.carve();
  2965. }
  2966. /**
  2967. * GZIP extractor.
  2968. *
  2969. * @param {Uint8Array} bytes
  2970. * @param {number} offset
  2971. * @returns {Uint8Array}
  2972. */
  2973. export function extractGZIP(bytes, offset) {
  2974. const stream = new Stream(bytes.slice(offset));
  2975. /* HEADER */
  2976. // Skip over signature and compression method
  2977. stream.moveForwardsBy(3);
  2978. // Read flags
  2979. const flags = stream.readInt(1);
  2980. // Skip over last modification time
  2981. stream.moveForwardsBy(4);
  2982. // Read compression flags
  2983. stream.readInt(1);
  2984. // Skip over OS
  2985. stream.moveForwardsBy(1);
  2986. /* OPTIONAL HEADERS */
  2987. // Extra fields
  2988. if (flags & 0x4) {
  2989. const extraFieldsSize = stream.readInt(2, "le");
  2990. stream.moveForwardsby(extraFieldsSize);
  2991. }
  2992. // Original filename
  2993. if (flags & 0x8) {
  2994. stream.continueUntil(0x00);
  2995. stream.moveForwardsBy(1);
  2996. }
  2997. // Comment
  2998. if (flags & 0x10) {
  2999. stream.continueUntil(0x00);
  3000. stream.moveForwardsBy(1);
  3001. }
  3002. // Checksum
  3003. if (flags & 0x2) {
  3004. stream.moveForwardsBy(2);
  3005. }
  3006. /* DEFLATE DATA */
  3007. parseDEFLATE(stream);
  3008. /* FOOTER */
  3009. // Skip over checksum and size of original uncompressed input
  3010. stream.moveForwardsBy(8);
  3011. return stream.carve();
  3012. }
  3013. /**
  3014. * BZIP2 extractor.
  3015. *
  3016. * @param {Uint8Array} bytes
  3017. * @param {Number} offset
  3018. * @returns {Uint8Array}
  3019. */
  3020. export function extractBZIP2(bytes, offset) {
  3021. const stream = new Stream(bytes.slice(offset));
  3022. // The EOFs shifted between all possible combinations.
  3023. const lookingfor = [
  3024. [0x77, 0x24, 0x53, 0x85, 0x09],
  3025. [0xee, 0x48, 0xa7, 0x0a, 0x12],
  3026. [0xdc, 0x91, 0x4e, 0x14, 0x24],
  3027. [0xb9, 0x22, 0x9c, 0x28, 0x48],
  3028. [0x72, 0x45, 0x38, 0x50, 0x90],
  3029. [0xbb, 0x92, 0x29, 0xc2, 0x84],
  3030. [0x5d, 0xc9, 0x14, 0xe1, 0x42],
  3031. [0x2e, 0xe4, 0x8a, 0x70, 0xa1],
  3032. [0x17, 0x72, 0x45, 0x38, 0x50]
  3033. ];
  3034. for (let i = 0; i < lookingfor.length; i++) {
  3035. // Continue until an EOF.
  3036. stream.continueUntil(lookingfor[i]);
  3037. if (stream.getBytes(5).join("") === lookingfor[i].join(""))
  3038. break;
  3039. // Jump back to the start if invalid EOF.
  3040. stream.moveTo(0);
  3041. }
  3042. stream.moveForwardsBy(4);
  3043. return stream.carve();
  3044. }
  3045. /**
  3046. * Zlib extractor.
  3047. *
  3048. * @param {Uint8Array} bytes
  3049. * @param {number} offset
  3050. * @returns {Uint8Array}
  3051. */
  3052. export function extractZlib(bytes, offset) {
  3053. const stream = new Stream(bytes.slice(offset));
  3054. // Skip over CMF
  3055. stream.moveForwardsBy(1);
  3056. // Read flags
  3057. const flags = stream.readInt(1);
  3058. // Skip over preset dictionary checksum
  3059. if (flags & 0x20) {
  3060. stream.moveForwardsBy(4);
  3061. }
  3062. // Parse DEFLATE stream
  3063. parseDEFLATE(stream);
  3064. // Skip over final checksum
  3065. stream.moveForwardsBy(4);
  3066. return stream.carve();
  3067. }
  3068. /**
  3069. * XZ extractor.
  3070. *
  3071. * @param {Uint8Array} bytes
  3072. * @param {Number} offset
  3073. * @returns {string}
  3074. */
  3075. export function extractXZ(bytes, offset) {
  3076. const stream = new Stream(bytes.slice(offset));
  3077. // Move forward to EOF marker
  3078. stream.continueUntil([0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a]);
  3079. // Move over EOF marker
  3080. stream.moveForwardsBy(7);
  3081. return stream.carve();
  3082. }
  3083. /**
  3084. * ELF extractor.
  3085. *
  3086. * @param {Uint8Array} bytes
  3087. * @param {number} offset
  3088. * @returns {Uint8Array}
  3089. */
  3090. export function extractELF(bytes, offset) {
  3091. const stream = new Stream(bytes.slice(offset));
  3092. // Skip over magic number
  3093. stream.moveForwardsBy(4);
  3094. // Read architecture (x86 == 1, x64 == 2)
  3095. const x86 = stream.readInt(1) === 1;
  3096. // Read endianness (1 == little, 2 == big)
  3097. const endian = stream.readInt(1) === 1 ? "le" : "be";
  3098. // Skip over header values
  3099. stream.moveForwardsBy(x86 ? 26 : 34);
  3100. // Read section header table offset
  3101. const shoff = x86 ? stream.readInt(4, endian) : stream.readInt(8, endian);
  3102. // Skip over flags, header size and program header size and entries
  3103. stream.moveForwardsBy(10);
  3104. // Read section header table entry size
  3105. const shentsize = stream.readInt(2, endian);
  3106. // Read number of entries in the section header table
  3107. const shnum = stream.readInt(2, endian);
  3108. // Jump to section header table
  3109. stream.moveTo(shoff);
  3110. // Move past each section header
  3111. stream.moveForwardsBy(shentsize * shnum);
  3112. return stream.carve();
  3113. }
  3114. // Construct required Huffman Tables
  3115. const fixedLiteralTableLengths = new Array(288);
  3116. for (let i = 0; i < fixedLiteralTableLengths.length; i++) {
  3117. fixedLiteralTableLengths[i] =
  3118. (i <= 143) ? 8 :
  3119. (i <= 255) ? 9 :
  3120. (i <= 279) ? 7 :
  3121. 8;
  3122. }
  3123. const fixedLiteralTable = buildHuffmanTable(fixedLiteralTableLengths);
  3124. const fixedDistanceTableLengths = new Array(30).fill(5);
  3125. const fixedDistanceTable = buildHuffmanTable(fixedDistanceTableLengths);
  3126. const huffmanOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  3127. /**
  3128. * Steps through a DEFLATE stream
  3129. *
  3130. * @param {Stream} stream
  3131. */
  3132. function parseDEFLATE(stream) {
  3133. // Parse DEFLATE data
  3134. let finalBlock = 0;
  3135. while (!finalBlock) {
  3136. // Read header
  3137. finalBlock = stream.readBits(1);
  3138. const blockType = stream.readBits(2);
  3139. if (blockType === 0) {
  3140. /* No compression */
  3141. // Consume the rest of the current byte
  3142. stream.moveForwardsBy(1);
  3143. // Read the block length value
  3144. const blockLength = stream.readInt(2, "le");
  3145. // Move to the end of this block
  3146. stream.moveForwardsBy(2 + blockLength);
  3147. } else if (blockType === 1) {
  3148. /* Fixed Huffman */
  3149. parseHuffmanBlock(stream, fixedLiteralTable, fixedDistanceTable);
  3150. } else if (blockType === 2) {
  3151. /* Dynamic Huffman */
  3152. // Read the number of liternal and length codes
  3153. const hlit = stream.readBits(5) + 257;
  3154. // Read the number of distance codes
  3155. const hdist = stream.readBits(5) + 1;
  3156. // Read the number of code lengths
  3157. const hclen = stream.readBits(4) + 4;
  3158. // Parse code lengths
  3159. const codeLengths = new Uint8Array(huffmanOrder.length);
  3160. for (let i = 0; i < hclen; i++) {
  3161. codeLengths[huffmanOrder[i]] = stream.readBits(3);
  3162. }
  3163. // Parse length table
  3164. const codeLengthsTable = buildHuffmanTable(codeLengths);
  3165. const lengthTable = new Uint8Array(hlit + hdist);
  3166. let code, repeat, prev;
  3167. for (let i = 0; i < hlit + hdist;) {
  3168. code = readHuffmanCode(stream, codeLengthsTable);
  3169. switch (code) {
  3170. case 16:
  3171. repeat = 3 + stream.readBits(2);
  3172. while (repeat--) lengthTable[i++] = prev;
  3173. break;
  3174. case 17:
  3175. repeat = 3 + stream.readBits(3);
  3176. while (repeat--) lengthTable[i++] = 0;
  3177. prev = 0;
  3178. break;
  3179. case 18:
  3180. repeat = 11 + stream.readBits(7);
  3181. while (repeat--) lengthTable[i++] = 0;
  3182. prev = 0;
  3183. break;
  3184. default:
  3185. lengthTable[i++] = code;
  3186. prev = code;
  3187. break;
  3188. }
  3189. }
  3190. const dynamicLiteralTable = buildHuffmanTable(lengthTable.subarray(0, hlit));
  3191. const dynamicDistanceTable = buildHuffmanTable(lengthTable.subarray(hlit));
  3192. parseHuffmanBlock(stream, dynamicLiteralTable, dynamicDistanceTable);
  3193. } else {
  3194. throw new Error(`Invalid block type while parsing DEFLATE stream at pos ${stream.position}`);
  3195. }
  3196. }
  3197. // Consume final byte if it has not been fully consumed yet
  3198. if (stream.bitPos > 0)
  3199. stream.moveForwardsBy(1);
  3200. }
  3201. // Static length tables
  3202. const lengthExtraTable = [
  3203. 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
  3204. ];
  3205. const distanceExtraTable = [
  3206. 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
  3207. ];
  3208. /**
  3209. * Parses a Huffman Block given the literal and distance tables
  3210. *
  3211. * @param {Stream} stream
  3212. * @param {Uint32Array} litTab
  3213. * @param {Uint32Array} distTab
  3214. */
  3215. function parseHuffmanBlock(stream, litTab, distTab) {
  3216. let code;
  3217. let loops = 0;
  3218. while ((code = readHuffmanCode(stream, litTab))) {
  3219. // console.log("Code: " + code + " (" + Utils.chr(code) + ") " + Utils.bin(code));
  3220. // End of block
  3221. if (code === 256) break;
  3222. // Detect probably infinite loops
  3223. if (++loops > 10000)
  3224. throw new Error("Caught in probable infinite loop while parsing Huffman Block");
  3225. // Literal
  3226. if (code < 256) continue;
  3227. // Length code
  3228. stream.readBits(lengthExtraTable[code - 257]);
  3229. // Dist code
  3230. code = readHuffmanCode(stream, distTab);
  3231. stream.readBits(distanceExtraTable[code]);
  3232. }
  3233. }
  3234. /**
  3235. * Builds a Huffman table given the relevant code lengths
  3236. *
  3237. * @param {Array} lengths
  3238. * @returns {Array} result
  3239. * @returns {Uint32Array} result.table
  3240. * @returns {number} result.maxCodeLength
  3241. * @returns {number} result.minCodeLength
  3242. */
  3243. function buildHuffmanTable(lengths) {
  3244. const maxCodeLength = Math.max.apply(Math, lengths);
  3245. const minCodeLength = Math.min.apply(Math, lengths);
  3246. const size = 1 << maxCodeLength;
  3247. const table = new Uint32Array(size);
  3248. for (let bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) {
  3249. for (let i = 0; i < lengths.length; i++) {
  3250. if (lengths[i] === bitLength) {
  3251. let reversed, rtemp, j;
  3252. for (reversed = 0, rtemp = code, j = 0; j < bitLength; j++) {
  3253. reversed = (reversed << 1) | (rtemp & 1);
  3254. rtemp >>= 1;
  3255. }
  3256. const value = (bitLength << 16) | i;
  3257. for (let j = reversed; j < size; j += skip) {
  3258. table[j] = value;
  3259. }
  3260. code++;
  3261. }
  3262. }
  3263. bitLength++;
  3264. code <<= 1;
  3265. skip <<= 1;
  3266. }
  3267. return [table, maxCodeLength, minCodeLength];
  3268. }
  3269. /**
  3270. * Reads the next Huffman code from the stream, given the relevant code table
  3271. *
  3272. * @param {Stream} stream
  3273. * @param {Uint32Array} table
  3274. * @returns {number}
  3275. */
  3276. function readHuffmanCode(stream, table) {
  3277. const [codeTable, maxCodeLength] = table;
  3278. // Read max length
  3279. const bitsBuf = stream.readBits(maxCodeLength);
  3280. const codeWithLength = codeTable[bitsBuf & ((1 << maxCodeLength) - 1)];
  3281. const codeLength = codeWithLength >>> 16;
  3282. if (codeLength > maxCodeLength) {
  3283. throw new Error(`Invalid Huffman Code length while parsing DEFLATE block at pos ${stream.position}: ${codeLength}`);
  3284. }
  3285. stream.moveBackwardsByBits(maxCodeLength - codeLength);
  3286. return codeWithLength & 0xffff;
  3287. }
  3288. /**
  3289. * EVTX extractor.
  3290. *
  3291. * @param {Uint8Array} bytes
  3292. * @param {Number} offset
  3293. * @returns {Uint8Array}
  3294. */
  3295. export function extractEVTX(bytes, offset) {
  3296. const stream = new Stream(bytes.slice(offset));
  3297. // Move to first ELFCHNK.
  3298. stream.moveTo(0x28);
  3299. const total = stream.readInt(4, "le") - 0x2c;
  3300. stream.moveForwardsBy(total);
  3301. while (stream.hasMore()) {
  3302. // Loop through ELFCHNKs.
  3303. if (stream.getBytes(7).join("") !== [0x45, 0x6c, 0x66, 0x43, 0x68, 0x6e, 0x6b].join(""))
  3304. break;
  3305. stream.moveForwardsBy(0xfff9);
  3306. }
  3307. stream.consumeWhile(0x00);
  3308. return stream.carve();
  3309. }
  3310. /**
  3311. * EVT extractor.
  3312. *
  3313. * @param {Uint8Array} bytes
  3314. * @param {Number} offset
  3315. * @returns {Uint8Array}
  3316. */
  3317. export function extractEVT(bytes, offset) {
  3318. const stream = new Stream(bytes.slice(offset));
  3319. // Extract offset of EOF.
  3320. stream.moveTo(0x14);
  3321. const eofOffset = stream.readInt(4, "le");
  3322. stream.moveTo(eofOffset);
  3323. // Extract the size of the EOF.
  3324. const eofSize = stream.readInt(4, "le");
  3325. // Move past EOF.
  3326. stream.moveForwardsBy(eofSize-4);
  3327. return stream.carve();
  3328. }