12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545 |
- /**
- * File signatures and extractor functions
- *
- * @author n1474335 [n1474335@gmail.com]
- * @copyright Crown Copyright 2018
- * @license Apache-2.0
- *
- */
- import Stream from "./Stream.mjs";
- /**
- * A categorised table of file types, including signatures to identify them and functions
- * to extract them where possible.
- */
- export const FILE_SIGNATURES = {
- "Images": [
- {
- name: "Joint Photographic Experts Group image",
- extension: "jpg,jpeg,jpe,thm,mpo",
- mime: "image/jpeg",
- description: "",
- signature: {
- 0: 0xff,
- 1: 0xd8,
- 2: 0xff,
- 3: [0xc0, 0xc4, 0xdb, 0xdd, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe7, 0xe8, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xfe]
- },
- extractor: extractJPEG
- },
- {
- name: "Graphics Interchange Format image",
- extension: "gif",
- mime: "image/gif",
- description: "",
- signature: {
- 0: 0x47, // GIF
- 1: 0x49,
- 2: 0x46,
- 3: 0x38, // 8
- 4: [0x37, 0x39], // 7|9
- 5: 0x61 // a
- },
- extractor: extractGIF
- },
- {
- name: "Portable Network Graphics image",
- extension: "png",
- mime: "image/png",
- description: "",
- signature: {
- 0: 0x89,
- 1: 0x50, // PNG
- 2: 0x4e,
- 3: 0x47,
- 4: 0x0d,
- 5: 0x0a,
- 6: 0x1a,
- 7: 0x0a
- },
- extractor: extractPNG
- },
- {
- name: "WEBP Image",
- extension: "webp",
- mime: "image/webp",
- description: "",
- signature: {
- 8: 0x57,
- 9: 0x45,
- 10: 0x42,
- 11: 0x50
- },
- extractor: null
- },
- {
- name: "Camera Image File Format",
- extension: "crw",
- mime: "image/x-canon-crw",
- description: "",
- signature: {
- 6: 0x48, // HEAPCCDR
- 7: 0x45,
- 8: 0x41,
- 9: 0x50,
- 10: 0x43,
- 11: 0x43,
- 12: 0x44,
- 13: 0x52
- },
- extractor: null
- },
- { // Place before tiff check
- name: "Canon CR2 raw image",
- extension: "cr2",
- mime: "image/x-canon-cr2",
- description: "",
- signature: [
- {
- 0: 0x49,
- 1: 0x49,
- 2: 0x2a,
- 3: 0x0,
- 8: 0x43,
- 9: 0x52
- },
- {
- 0: 0x4d,
- 1: 0x4d,
- 2: 0x0,
- 3: 0x2a,
- 8: 0x43,
- 9: 0x52
- }
- ],
- extractor: null
- },
- {
- name: "Tagged Image File Format image",
- extension: "tif",
- mime: "image/tiff",
- description: "",
- signature: [
- {
- 0: 0x49,
- 1: 0x49,
- 2: 0x2a,
- 3: 0x0
- },
- {
- 0: 0x4d,
- 1: 0x4d,
- 2: 0x0,
- 3: 0x2a
- }
- ],
- extractor: null
- },
- {
- name: "Bitmap image",
- extension: "bmp",
- mime: "image/bmp",
- description: "",
- signature: {
- 0: 0x42,
- 1: 0x4d,
- 7: 0x0,
- 9: 0x0,
- 14: [0x0c, 0x28, 0x38, 0x40, 0x6c, 0x7c],
- 15: 0x0,
- 16: 0x0,
- 17: 0x0
- },
- extractor: extractBMP
- },
- {
- name: "JPEG Extended Range image",
- extension: "jxr",
- mime: "image/vnd.ms-photo",
- description: "",
- signature: {
- 0: 0x49,
- 1: 0x49,
- 2: 0xbc
- },
- extractor: null
- },
- {
- name: "Photoshop image",
- extension: "psd",
- mime: "image/vnd.adobe.photoshop",
- description: "",
- signature: {
- 0: 0x38, // 8BPS
- 1: 0x42,
- 2: 0x50,
- 3: 0x53,
- 4: 0x0,
- 5: 0x1,
- 6: 0x0,
- 7: 0x0,
- 8: 0x0,
- 9: 0x0,
- 10: 0x0,
- 11: 0x0
- },
- extractor: null
- },
- {
- name: "Photoshop Large Document",
- extension: "psb",
- mime: "application/x-photoshop",
- description: "",
- signature: {
- 0: 0x38, // 8BPS
- 1: 0x42,
- 2: 0x50,
- 3: 0x53,
- 4: 0x0,
- 5: 0x2,
- 6: 0x0,
- 7: 0x0,
- 8: 0x0,
- 9: 0x0,
- 10: 0x0,
- 11: 0x0,
- 12: 0x0
- },
- extractor: null
- },
- {
- name: "Paint Shop Pro image",
- extension: "psp",
- mime: "image/psp",
- description: "",
- signature: [
- {
- 0: 0x50, // Paint Shop Pro Im
- 1: 0x61,
- 2: 0x69,
- 3: 0x6e,
- 4: 0x74,
- 5: 0x20,
- 6: 0x53,
- 7: 0x68,
- 8: 0x6f,
- 9: 0x70,
- 10: 0x20,
- 11: 0x50,
- 12: 0x72,
- 13: 0x6f,
- 14: 0x20,
- 15: 0x49,
- 16: 0x6d
- },
- {
- 0: 0x7e,
- 1: 0x42,
- 2: 0x4b,
- 3: 0x0
- }
- ],
- extractor: null
- },
- {
- name: "The GIMP image",
- extension: "xcf",
- mime: "image/x-xcf",
- description: "",
- signature: {
- 0: 0x67, // gimp xcf
- 1: 0x69,
- 2: 0x6d,
- 3: 0x70,
- 4: 0x20,
- 5: 0x78,
- 6: 0x63,
- 7: 0x66,
- 8: 0x20,
- 9: [0x66, 0x76],
- 10: [0x69, 0x30],
- 11: [0x6c, 0x30],
- 12: [0x65, 0x31, 0x32, 0x33]
- },
- extractor: null
- },
- {
- name: "Icon image",
- extension: "ico",
- mime: "image/x-icon",
- description: "",
- signature: {
- 0: 0x0,
- 1: 0x0,
- 2: 0x1,
- 3: 0x0,
- 4: [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15],
- 5: 0x0,
- 6: [0x10, 0x20, 0x30, 0x40, 0x80],
- 7: [0x10, 0x20, 0x30, 0x40, 0x80],
- 9: 0x0,
- 10: [0x0, 0x1]
- },
- extractor: null
- },
- {
- name: "Radiance High Dynamic Range image",
- extension: "hdr",
- mime: "image/vnd.radiance",
- description: "",
- signature: {
- 0: 0x23, // #?RADIANCE
- 1: 0x3f,
- 2: 0x52,
- 3: 0x41,
- 4: 0x44,
- 5: 0x49,
- 6: 0x41,
- 7: 0x4e,
- 8: 0x43,
- 9: 0x45,
- 10: 0x0a
- },
- extractor: null
- },
- {
- name: "Sony ARW image",
- extension: "arw",
- mime: "image/x-raw",
- description: "",
- signature: {
- 0: 0x05,
- 1: 0x0,
- 2: 0x0,
- 3: 0x0,
- 4: 0x41,
- 5: 0x57,
- 6: 0x31,
- 7: 0x2e
- },
- extractor: null
- },
- {
- name: "Fujifilm Raw Image",
- extension: "raf",
- mime: "image/x-raw",
- description: "",
- signature: {
- 0: 0x46, // FUJIFILMCCD-RAW
- 1: 0x55,
- 2: 0x4a,
- 3: 0x49,
- 4: 0x46,
- 5: 0x49,
- 6: 0x4c,
- 7: 0x4d,
- 8: 0x43,
- 9: 0x43,
- 10: 0x44,
- 11: 0x2d,
- 12: 0x52,
- 13: 0x41,
- 14: 0x57
- },
- extractor: null
- },
- {
- name: "Minolta RAW image",
- extension: "mrw",
- mime: "image/x-raw",
- description: "",
- signature: {
- 0: 0x0,
- 1: 0x4d, // MRM
- 2: 0x52,
- 3: 0x4d
- },
- extractor: null
- },
- {
- name: "Adobe Bridge Thumbnail Cache",
- extension: "bct",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x6c,
- 1: 0x6e,
- 2: 0x62,
- 3: 0x74,
- 4: 0x02,
- 5: 0x0,
- 6: 0x0,
- 7: 0x0
- },
- extractor: null
- },
- {
- name: "Microsoft Document Imaging",
- extension: "mdi",
- mime: "image/vnd.ms-modi",
- description: "",
- signature: {
- 0: 0x45,
- 1: 0x50,
- 2: 0x2a,
- 3: 0x00
- },
- extractor: null
- },
- {
- name: "Joint Photographic Experts Group image (under Base64)",
- extension: "B64",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x2f,
- 1: 0x39,
- 2: 0x6a,
- 3: 0x2f,
- 4: 0x34
- },
- extractor: null
- },
- {
- name: "Portable Network Graphics image (under Base64)",
- extension: "B64",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x69,
- 1: 0x56,
- 2: 0x42,
- 3: 0x4f,
- 4: 0x52,
- 5: 0x77,
- 6: 0x30
- },
- extractor: null
- },
- {
- name: "AutoCAD Drawing",
- extension: "dwg,123d",
- mime: "application/acad",
- description: "",
- signature: {
- 0: 0x41,
- 1: 0x43,
- 2: 0x31,
- 3: 0x30,
- 4: [0x30, 0x31],
- 5: [0x30, 0x31, 0x32, 0x33, 0x34, 0x35],
- 6: 0x00
- },
- extractor: null
- },
- {
- name: "AutoCAD Drawing",
- extension: "dwg,dwt",
- mime: "application/acad",
- description: "",
- signature: [
- {
- 0: 0x41,
- 1: 0x43,
- 2: 0x31,
- 3: 0x30,
- 4: 0x31,
- 5: 0x38,
- 6: 0x00
- },
- {
- 0: 0x41,
- 1: 0x43,
- 2: 0x31,
- 3: 0x30,
- 4: 0x32,
- 5: 0x34,
- 6: 0x00
- },
- {
- 0: 0x41,
- 1: 0x43,
- 2: 0x31,
- 3: 0x30,
- 4: 0x32,
- 5: 0x37,
- 6: 0x00
- }
- ],
- extractor: null
- },
- ],
- "Video": [
- { // Place before webm
- name: "Matroska Multimedia Container",
- extension: "mkv",
- mime: "video/x-matroska",
- description: "",
- signature: {
- 31: 0x6d,
- 32: 0x61,
- 33: 0x74,
- 34: 0x72,
- 35: 0x6f,
- 36: 0x73,
- 37: 0x6b,
- 38: 0x61
- },
- extractor: null
- },
- {
- name: "WEBM video",
- extension: "webm",
- mime: "video/webm",
- description: "",
- signature: {
- 0: 0x1a,
- 1: 0x45,
- 2: 0xdf,
- 3: 0xa3
- },
- extractor: null
- },
- { // Place before MPEG-4
- name: "Flash MP4 video",
- extension: "f4v",
- mime: "video/mp4",
- description: "",
- signature: {
- 4: 0x66,
- 5: 0x74,
- 6: 0x79,
- 7: 0x70,
- 8: [0x66, 0x46],
- 9: 0x34,
- 10: [0x76, 0x56],
- 11: 0x20
- },
- extractor: null
- },
- {
- name: "MPEG-4 video",
- extension: "mp4",
- mime: "video/mp4",
- description: "",
- signature: [
- {
- 0: 0x0,
- 1: 0x0,
- 2: 0x0,
- 3: [0x18, 0x20],
- 4: 0x66,
- 5: 0x74,
- 6: 0x79,
- 7: 0x70
- },
- {
- 0: 0x33, // 3gp5
- 1: 0x67,
- 2: 0x70,
- 3: 0x35
- },
- {
- 0: 0x0,
- 1: 0x0,
- 2: 0x0,
- 3: 0x1c,
- 4: 0x66,
- 5: 0x74,
- 6: 0x79,
- 7: 0x70,
- 8: 0x6d,
- 9: 0x70,
- 10: 0x34,
- 11: 0x32,
- 16: 0x6d, // mp41mp42isom
- 17: 0x70,
- 18: 0x34,
- 19: 0x31,
- 20: 0x6d,
- 21: 0x70,
- 22: 0x34,
- 23: 0x32,
- 24: 0x69,
- 25: 0x73,
- 26: 0x6f,
- 27: 0x6d
- }
- ],
- extractor: null
- },
- {
- name: "M4V video",
- extension: "m4v",
- mime: "video/x-m4v",
- description: "",
- signature: {
- 0: 0x0,
- 1: 0x0,
- 2: 0x0,
- 3: 0x1c,
- 4: 0x66,
- 5: 0x74,
- 6: 0x79,
- 7: 0x70,
- 8: 0x4d,
- 9: 0x34,
- 10: 0x56
- },
- extractor: null
- },
- {
- name: "Quicktime video",
- extension: "mov",
- mime: "video/quicktime",
- description: "",
- signature: {
- 0: 0x0,
- 1: 0x0,
- 2: 0x0,
- 3: 0x14,
- 4: 0x66,
- 5: 0x74,
- 6: 0x79,
- 7: 0x70
- },
- extractor: null
- },
- {
- name: "Audio Video Interleave",
- extension: "avi",
- mime: "video/x-msvideo",
- description: "",
- signature: {
- 0: 0x52,
- 1: 0x49,
- 2: 0x46,
- 3: 0x46,
- 8: 0x41,
- 9: 0x56,
- 10: 0x49
- },
- extractor: null
- },
- {
- name: "Windows Media Video",
- extension: "wmv",
- mime: "video/x-ms-wmv",
- description: "",
- signature: {
- 0: 0x30,
- 1: 0x26,
- 2: 0xb2,
- 3: 0x75,
- 4: 0x8e,
- 5: 0x66,
- 6: 0xcf,
- 7: 0x11,
- 8: 0xa6,
- 9: 0xd9
- },
- extractor: null
- },
- {
- name: "MPEG video",
- extension: "mpg",
- mime: "video/mpeg",
- description: "",
- signature: {
- 0: 0x0,
- 1: 0x0,
- 2: 0x1,
- 3: 0xba
- },
- extractor: null
- },
- {
- name: "Flash Video",
- extension: "flv",
- mime: "video/x-flv",
- description: "",
- signature: {
- 0: 0x46,
- 1: 0x4c,
- 2: 0x56,
- 3: 0x1
- },
- extractor: extractFLV
- },
- {
- name: "OGG Video",
- extension: "ogv,ogm,opus,ogx",
- mime: "video/ogg",
- description: "",
- signature: [
- {
- 0: 0x4f, // OggS
- 1: 0x67,
- 2: 0x67,
- 3: 0x53,
- 4: 0x00,
- 5: 0x02,
- 28: 0x01,
- 29: 0x76, // video
- 30: 0x69,
- 31: 0x64,
- 32: 0x65,
- 33: 0x6f
- },
- {
- 0: 0x4f, // OggS
- 1: 0x67,
- 2: 0x67,
- 3: 0x53,
- 4: 0x00,
- 5: 0x02,
- 28: 0x80,
- 29: 0x74, // theora
- 30: 0x68,
- 31: 0x65,
- 32: 0x6f,
- 33: 0x72,
- 34: 0x61
- },
- {
- 0: 0x4f, // OggS
- 1: 0x67,
- 2: 0x67,
- 3: 0x53,
- 4: 0x00,
- 5: 0x02,
- 28: 0x66, // fishead
- 29: 0x69,
- 30: 0x73,
- 31: 0x68,
- 32: 0x65,
- 33: 0x61,
- 34: 0x64
- }
- ],
- extractor: null
- },
- ],
- "Audio": [
- {
- name: "Waveform Audio",
- extension: "wav",
- mime: "audio/x-wav",
- description: "",
- signature: {
- 0: 0x52,
- 1: 0x49,
- 2: 0x46,
- 3: 0x46,
- 8: 0x57,
- 9: 0x41,
- 10: 0x56,
- 11: 0x45
- },
- extractor: extractWAV
- },
- {
- name: "OGG audio",
- extension: "ogg",
- mime: "audio/ogg",
- description: "",
- signature: {
- 0: 0x4f,
- 1: 0x67,
- 2: 0x67,
- 3: 0x53
- },
- extractor: null
- },
- {
- name: "Musical Instrument Digital Interface audio",
- extension: "midi",
- mime: "audio/midi",
- description: "",
- signature: {
- 0: 0x4d,
- 1: 0x54,
- 2: 0x68,
- 3: 0x64
- },
- extractor: null
- },
- {
- name: "MPEG-3 audio",
- extension: "mp3",
- mime: "audio/mpeg",
- description: "",
- signature: [
- {
- 0: 0x49,
- 1: 0x44,
- 2: 0x33
- },
- {
- 0: 0xff,
- 1: 0xfb
- }
- ],
- extractor: null
- },
- {
- name: "MPEG-4 Part 14 audio",
- extension: "m4a",
- mime: "audio/m4a",
- description: "",
- signature: [
- {
- 4: 0x66,
- 5: 0x74,
- 6: 0x79,
- 7: 0x70,
- 8: 0x4d,
- 9: 0x34,
- 10: 0x41
- },
- {
- 0: 0x4d,
- 1: 0x34,
- 2: 0x41,
- 3: 0x20
- }
- ],
- extractor: null
- },
- {
- name: "Free Lossless Audio Codec",
- extension: "flac",
- mime: "audio/x-flac",
- description: "",
- signature: {
- 0: 0x66,
- 1: 0x4c,
- 2: 0x61,
- 3: 0x43
- },
- extractor: null
- },
- {
- name: "Adaptive Multi-Rate audio codec",
- extension: "amr",
- mime: "audio/amr",
- description: "",
- signature: {
- 0: 0x23,
- 1: 0x21,
- 2: 0x41,
- 3: 0x4d,
- 4: 0x52,
- 5: 0x0a
- },
- extractor: null
- },
- {
- name: "Audacity",
- extension: "au",
- mime: "audio/x-au",
- description: "",
- signature: {
- 0: 0x64, // dns.
- 1: 0x6e,
- 2: 0x73,
- 3: 0x2e,
- 24: 0x41, // AudacityBlockFile
- 25: 0x75,
- 26: 0x64,
- 27: 0x61,
- 28: 0x63,
- 29: 0x69,
- 30: 0x74,
- 31: 0x79,
- 32: 0x42,
- 33: 0x6c,
- 34: 0x6f,
- 35: 0x63,
- 36: 0x6b,
- 37: 0x46,
- 38: 0x69,
- 39: 0x6c,
- 40: 0x65
- },
- extractor: null
- },
- {
- name: "Audacity Block",
- extension: "auf",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x41, // AudacityBlockFile
- 1: 0x75,
- 2: 0x64,
- 3: 0x61,
- 4: 0x63,
- 5: 0x69,
- 6: 0x74,
- 7: 0x79,
- 8: 0x42,
- 9: 0x6c,
- 10: 0x6f,
- 11: 0x63,
- 12: 0x6b,
- 13: 0x46,
- 14: 0x69,
- 15: 0x6c,
- 16: 0x65
- },
- extractor: null
- },
- {
- name: "Audio Interchange File",
- extension: "aif",
- mime: "audio/x-aiff",
- description: "",
- signature: {
- 0: 0x46, // FORM
- 1: 0x4f,
- 2: 0x52,
- 3: 0x4d,
- 8: 0x41, // AIFF
- 9: 0x49,
- 10: 0x46,
- 11: 0x46
- },
- extractor: null
- },
- {
- name: "Audio Interchange File (compressed)",
- extension: "aifc",
- mime: "audio/x-aifc",
- description: "",
- signature: {
- 0: 0x46, // FORM
- 1: 0x4f,
- 2: 0x52,
- 3: 0x4d,
- 8: 0x41, // AIFC
- 9: 0x49,
- 10: 0x46,
- 11: 0x43
- },
- extractor: null
- }
- ],
- "Documents": [
- {
- name: "Portable Document Format",
- extension: "pdf",
- mime: "application/pdf",
- description: "",
- signature: {
- 0: 0x25,
- 1: 0x50,
- 2: 0x44,
- 3: 0x46
- },
- extractor: extractPDF
- },
- {
- name: "Portable Document Format (under Base64)",
- extension: "B64",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x41,
- 1: 0x4a,
- 2: 0x56,
- 3: 0x42,
- 4: 0x45,
- 5: 0x52,
- 6: 0x69
- },
- extractor: null
- },
- { // Place before PostScript
- name: "Adobe PostScript",
- extension: "ps,eps,ai,pfa",
- mime: "application/postscript",
- description: "",
- signature: {
- 0: 0x25,
- 1: 0x21,
- 2: 0x50,
- 3: 0x53,
- 4: 0x2d,
- 5: 0x41,
- 6: 0x64,
- 7: 0x6f,
- 8: 0x62,
- 9: 0x65
- },
- extractor: null
- },
- {
- name: "PostScript",
- extension: "ps",
- mime: "application/postscript",
- description: "",
- signature: {
- 0: 0x25,
- 1: 0x21
- },
- extractor: null
- },
- {
- name: "Encapsulated PostScript",
- extension: "eps,ai",
- mime: "application/eps",
- description: "",
- signature: {
- 0: 0xc5,
- 1: 0xd0,
- 2: 0xd3,
- 3: 0xc6
- },
- extractor: null
- },
- {
- name: "Rich Text Format",
- extension: "rtf",
- mime: "application/rtf",
- description: "",
- signature: {
- 0: 0x7b,
- 1: 0x5c,
- 2: 0x72,
- 3: 0x74,
- 4: 0x66
- },
- extractor: extractRTF
- },
- {
- name: "Microsoft Office document/OLE2",
- extension: "ole2,doc,xls,dot,ppt,xla,ppa,pps,pot,msi,sdw,db,vsd,msg",
- mime: "application/msword,application/vnd.ms-excel,application/vnd.ms-powerpoint",
- description: "Microsoft Office documents",
- signature: {
- 0: 0xd0,
- 1: 0xcf,
- 2: 0x11,
- 3: 0xe0,
- 4: 0xa1,
- 5: 0xb1,
- 6: 0x1a,
- 7: 0xe1
- },
- extractor: null
- },
- {
- name: "Microsoft Office document/OLE2 (under Base64)",
- extension: "B64",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x30,
- 1: 0x4d,
- 2: 0x38,
- 3: 0x52,
- 4: 0x34,
- 5: 0x4b,
- 6: 0x47,
- 7: 0x78
- },
- extractor: null
- },
- {
- name: "Microsoft Office 2007+ document",
- extension: "docx,xlsx,pptx",
- mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",
- description: "",
- signature: {
- 38: 0x5f, // _Types].xml
- 39: 0x54,
- 40: 0x79,
- 41: 0x70,
- 42: 0x65,
- 43: 0x73,
- 44: 0x5d,
- 45: 0x2e,
- 46: 0x78,
- 47: 0x6d,
- 48: 0x6c
- },
- extractor: extractZIP
- },
- {
- name: "Microsoft Access database",
- extension: "mdb,mda,mde,mdt,fdb,psa",
- mime: "application/msaccess",
- description: "",
- signature: {
- 0: 0x00,
- 1: 0x01,
- 2: 0x00,
- 3: 0x00,
- 4: 0x53, // Standard Jet
- 5: 0x74,
- 6: 0x61,
- 7: 0x6e,
- 8: 0x64,
- 9: 0x61,
- 10: 0x72,
- 11: 0x64,
- 12: 0x20,
- 13: 0x4a,
- 14: 0x65,
- 15: 0x74
- },
- extractor: null
- },
- {
- name: "Microsoft Access 2007+ database",
- extension: "accdb,accde,accda,accdu",
- mime: "application/msaccess",
- description: "",
- signature: {
- 0: 0x00,
- 1: 0x01,
- 2: 0x00,
- 3: 0x00,
- 4: 0x53, // Standard ACE DB
- 5: 0x74,
- 6: 0x61,
- 7: 0x6e,
- 8: 0x64,
- 9: 0x61,
- 10: 0x72,
- 11: 0x64,
- 12: 0x20,
- 13: 0x41,
- 14: 0x43,
- 15: 0x45,
- 16: 0x20
- },
- extractor: null
- },
- {
- name: "Microsoft OneNote document",
- extension: "one",
- mime: "application/onenote",
- description: "",
- signature: {
- 0: 0xe4,
- 1: 0x52,
- 2: 0x5c,
- 3: 0x7b,
- 4: 0x8c,
- 5: 0xd8,
- 6: 0xa7,
- 7: 0x4d,
- 8: 0xae,
- 9: 0xb1,
- 10: 0x53,
- 11: 0x78,
- 12: 0xd0,
- 13: 0x29,
- 14: 0x96,
- 15: 0xd3
- },
- extractor: null
- },
- {
- name: "Outlook Express database",
- extension: "dbx",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0xcf,
- 1: 0xad,
- 2: 0x12,
- 3: 0xfe,
- 4: [0x30, 0xc5, 0xc6, 0xc7],
- 11: 0x11
- },
- extractor: null
- },
- {
- name: "Personal Storage Table (Outlook)",
- extension: "pst,ost,fdb,pab",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x21, // !BDN
- 1: 0x42,
- 2: 0x44,
- 3: 0x4e
- },
- extractor: null
- },
- {
- name: "Microsoft Exchange Database",
- extension: "edb",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 4: 0xef,
- 5: 0xcd,
- 6: 0xab,
- 7: 0x89,
- 8: [0x20, 0x23],
- 9: 0x06,
- 10: 0x00,
- 11: 0x00,
- 12: [0x00, 0x01],
- 13: 0x00,
- 14: 0x00,
- 15: 0x00
- },
- extractor: null
- },
- {
- name: "WordPerfect document",
- extension: "wpd,wp,wp5,wp6,wpp,bk!,wcm",
- mime: "application/wordperfect",
- description: "",
- signature: {
- 0: 0xff,
- 1: 0x57,
- 2: 0x50,
- 3: 0x43,
- 7: [0x00, 0x01, 0x02],
- 8: 0x01,
- 9: 0x0a
- },
- extractor: null
- },
- {
- name: "EPUB e-book",
- extension: "epub",
- mime: "application/epub+zip",
- description: "",
- signature: {
- 0: 0x50,
- 1: 0x4b,
- 2: 0x3,
- 3: 0x4,
- 30: 0x6d, // mimetypeapplication/epub_zip
- 31: 0x69,
- 32: 0x6d,
- 33: 0x65,
- 34: 0x74,
- 35: 0x79,
- 36: 0x70,
- 37: 0x65,
- 38: 0x61,
- 39: 0x70,
- 40: 0x70,
- 41: 0x6c,
- 42: 0x69,
- 43: 0x63,
- 44: 0x61,
- 45: 0x74,
- 46: 0x69,
- 47: 0x6f,
- 48: 0x6e,
- 49: 0x2f,
- 50: 0x65,
- 51: 0x70,
- 52: 0x75,
- 53: 0x62,
- 54: 0x2b,
- 55: 0x7a,
- 56: 0x69,
- 57: 0x70
- },
- extractor: extractZIP
- },
- ],
- "Applications": [
- {
- name: "Windows Portable Executable",
- extension: "exe,dll,drv,vxd,sys,ocx,vbx,com,fon,scr",
- mime: "application/vnd.microsoft.portable-executable",
- description: "",
- signature: {
- 0: 0x4d,
- 1: 0x5a,
- 3: [0x0, 0x1, 0x2],
- 5: [0x0, 0x1, 0x2]
- },
- extractor: extractMZPE
- },
- {
- name: "Executable and Linkable Format",
- extension: "elf,bin,axf,o,prx,so",
- mime: "application/x-executable",
- description: "Executable and Linkable Format file. No standard file extension.",
- signature: {
- 0: 0x7f,
- 1: 0x45,
- 2: 0x4c,
- 3: 0x46
- },
- extractor: extractELF
- },
- {
- name: "MacOS Mach-O object",
- extension: "dylib",
- mime: "application/octet-stream",
- description: "",
- signature: [
- {
- 0: 0xca,
- 1: 0xfe,
- 2: 0xba,
- 3: 0xbe,
- 4: 0x00,
- 5: 0x00,
- 6: 0x00,
- 7: [0x01, 0x02, 0x03]
- },
- {
- 0: 0xce,
- 1: 0xfa,
- 2: 0xed,
- 3: 0xfe,
- 4: 0x07,
- 5: 0x00,
- 6: 0x00,
- 7: 0x00,
- 8: [0x01, 0x02, 0x03]
- }
- ],
- extractor: extractMACHO
- },
- {
- name: "MacOS Mach-O 64-bit object",
- extension: "dylib",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0xcf,
- 1: 0xfa,
- 2: 0xed,
- 3: 0xfe
- },
- extractor: extractMACHO
- },
- {
- name: "Adobe Flash",
- extension: "swf",
- mime: "application/x-shockwave-flash",
- description: "",
- signature: {
- 0: [0x43, 0x46],
- 1: 0x57,
- 2: 0x53,
- },
- extractor: null
- },
- {
- name: "Java Class",
- extension: "class",
- mime: "application/java-vm",
- description: "",
- signature: {
- 0: 0xca,
- 1: 0xfe,
- 2: 0xba,
- 3: 0xbe
- },
- extractor: null
- },
- {
- name: "Dalvik Executable",
- extension: "dex",
- mime: "application/octet-stream",
- description: "Dalvik Executable as used by Android",
- signature: {
- 0: 0x64,
- 1: 0x65,
- 2: 0x78,
- 3: 0x0a,
- 4: 0x30,
- 5: 0x33,
- 6: 0x35,
- 7: 0x0
- },
- extractor: null
- },
- {
- name: "Google Chrome Extension",
- extension: "crx",
- mime: "application/crx",
- description: "Google Chrome extension or packaged app",
- signature: {
- 0: 0x43,
- 1: 0x72,
- 2: 0x32,
- 3: 0x34
- },
- extractor: null
- },
- ],
- "Archives": [
- {
- name: "PKZIP archive",
- extension: "zip",
- mime: "application/zip",
- description: "",
- signature: {
- 0: 0x50,
- 1: 0x4b,
- 2: [0x3, 0x5, 0x7],
- 3: [0x4, 0x6, 0x8]
- },
- extractor: extractZIP
- },
- {
- name: "PKZIP archive (under Base64)",
- extension: "B64",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x55,
- 1: 0x45,
- 2: 0x73,
- 3: 0x44,
- 4: 0x42,
- 5: 0x42
- },
- extractor: null
- },
- {
- name: "TAR archive",
- extension: "tar",
- mime: "application/x-tar",
- description: "",
- signature: {
- 257: 0x75, // ustar
- 258: 0x73,
- 259: 0x74,
- 260: 0x61,
- 261: 0x72
- },
- extractor: extractTAR
- },
- {
- name: "Roshal Archive",
- extension: "rar",
- mime: "application/x-rar-compressed",
- description: "",
- signature: {
- 0: 0x52,
- 1: 0x61,
- 2: 0x72,
- 3: 0x21,
- 4: 0x1a,
- 5: 0x7,
- 6: [0x0, 0x1]
- },
- extractor: null
- },
- {
- name: "Gzip",
- extension: "gz",
- mime: "application/gzip",
- description: "",
- signature: {
- 0: 0x1f,
- 1: 0x8b,
- 2: 0x8
- },
- extractor: extractGZIP
- },
- {
- name: "Bzip2",
- extension: "bz2",
- mime: "application/x-bzip2",
- description: "",
- signature: {
- 0: 0x42,
- 1: 0x5a,
- 2: 0x68
- },
- extractor: extractBZIP2
- },
- {
- name: "7zip",
- extension: "7z",
- mime: "application/x-7z-compressed",
- description: "",
- signature: {
- 0: 0x37,
- 1: 0x7a,
- 2: 0xbc,
- 3: 0xaf,
- 4: 0x27,
- 5: 0x1c
- },
- extractor: null
- },
- {
- name: "Zlib Deflate",
- extension: "zlib",
- mime: "application/x-deflate",
- description: "",
- signature: {
- 0: 0x78,
- 1: [0x1, 0x9c, 0xda, 0x5e]
- },
- extractor: extractZlib
- },
- {
- name: "xz compression",
- extension: "xz",
- mime: "application/x-xz",
- description: "",
- signature: {
- 0: 0xfd,
- 1: 0x37,
- 2: 0x7a,
- 3: 0x58,
- 4: 0x5a,
- 5: 0x0
- },
- extractor: extractXZ
- },
- {
- name: "Tarball",
- extension: "tar.z",
- mime: "application/x-gtar",
- description: "",
- signature: {
- 0: 0x1f,
- 1: [0x9d, 0xa0]
- },
- extractor: null
- },
- {
- name: "ISO disk image",
- extension: "iso",
- mime: "application/octet-stream",
- description: "ISO 9660 CD/DVD image file",
- signature: [
- {
- 0x8001: 0x43,
- 0x8002: 0x44,
- 0x8003: 0x30,
- 0x8004: 0x30,
- 0x8005: 0x31
- },
- {
- 0x8801: 0x43,
- 0x8802: 0x44,
- 0x8803: 0x30,
- 0x8804: 0x30,
- 0x8805: 0x31
- },
- {
- 0x9001: 0x43,
- 0x9002: 0x44,
- 0x9003: 0x30,
- 0x9004: 0x30,
- 0x9005: 0x31
- }
- ],
- extractor: null
- },
- {
- name: "Virtual Machine Disk",
- extension: "vmdk",
- mime: "application/vmdk,application/x-virtualbox-vmdk",
- description: "",
- signature: {
- 0: 0x4b,
- 1: 0x44,
- 2: 0x4d,
- 3: 0x56,
- 5: 0x00,
- 6: 0x00,
- 7: 0x00
- },
- extractor: null
- },
- {
- name: "Virtual Hard Drive",
- extension: "vhd",
- mime: "application/x-vhd",
- description: "",
- signature: {
- 0: 0x63, // conectix
- 1: 0x6f,
- 2: 0x6e,
- 3: 0x65,
- 4: 0x63,
- 5: 0x74,
- 6: 0x69,
- 7: 0x78
- },
- extractor: null
- },
- {
- name: "Macintosh disk image",
- extension: "dmf,dmg",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x78,
- 1: 0x01,
- 2: 0x73,
- 3: 0x0d,
- 4: 0x62,
- 5: 0x62,
- 6: 0x60,
- 7: 0x60
- },
- extractor: null
- },
- {
- name: "ARJ Archive",
- extension: "arj",
- mime: "application/x-arj-compressed",
- description: "",
- signature: {
- 0: 0x60,
- 1: 0xea,
- 8: [0x0, 0x10, 0x14],
- 9: 0x0,
- 10: 0x2
- },
- extractor: null
- },
- {
- name: "WinAce Archive",
- extension: "ace",
- mime: "application/x-ace-compressed",
- description: "",
- signature: {
- 7: 0x2a, // **ACE**
- 8: 0x2a,
- 9: 0x41,
- 10: 0x43,
- 11: 0x45,
- 12: 0x2a,
- 13: 0x2a
- },
- extractor: null
- },
- {
- name: "Macintosh BinHex Encoded File",
- extension: "hqx",
- mime: "application/mac-binhex",
- description: "",
- signature: {
- 11: 0x6d, // must be converted with BinHex
- 12: 0x75,
- 13: 0x73,
- 14: 0x74,
- 15: 0x20,
- 16: 0x62,
- 17: 0x65,
- 18: 0x20,
- 19: 0x63,
- 20: 0x6f,
- 21: 0x6e,
- 22: 0x76,
- 23: 0x65,
- 24: 0x72,
- 25: 0x74,
- 26: 0x65,
- 27: 0x64,
- 28: 0x20,
- 29: 0x77,
- 30: 0x69,
- 31: 0x74,
- 32: 0x68,
- 33: 0x20,
- 34: 0x42,
- 35: 0x69,
- 36: 0x6e,
- 37: 0x48,
- 38: 0x65,
- 39: 0x78
- },
- extractor: null
- },
- {
- name: "ALZip Archive",
- extension: "alz",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x41, // ALZ
- 1: 0x4c,
- 2: 0x5a,
- 3: 0x01,
- 4: 0x0a,
- 5: 0x0,
- 6: 0x0,
- 7: 0x0
- },
- extractor: null
- },
- {
- name: "KGB Compressed Archive",
- extension: "kgb",
- mime: "application/x-kgb-compressed",
- description: "",
- signature: {
- 0: 0x4b, // KGB_arch -
- 1: 0x47,
- 2: 0x42,
- 3: 0x5f,
- 4: 0x61,
- 5: 0x72,
- 6: 0x63,
- 7: 0x68,
- 8: 0x20,
- 9: 0x2d
- },
- extractor: null
- },
- {
- name: "Microsoft Cabinet",
- extension: "cab",
- mime: "vnd.ms-cab-compressed",
- description: "",
- signature: {
- 0: 0x4d,
- 1: 0x53,
- 2: 0x43,
- 3: 0x46,
- 4: 0x00,
- 5: 0x00,
- 6: 0x00,
- 7: 0x00
- },
- extractor: null
- },
- {
- name: "Jar Archive",
- extension: "jar",
- mime: "application/java-archive",
- description: "",
- signature: {
- 0: 0x5f,
- 1: 0x27,
- 2: 0xa8,
- 3: 0x89
- },
- extractor: null
- },
- {
- name: "lzop compressed",
- extension: "lzop,lzo",
- mime: "application/x-lzop",
- description: "",
- signature: {
- 0: 0x89,
- 1: 0x4c, // LZO
- 2: 0x5a,
- 3: 0x4f,
- 4: 0x00,
- 5: 0x0d,
- 6: 0x0a,
- 7: 0x1a
- },
- extractor: null
- },
- ],
- "Miscellaneous": [
- {
- name: "UTF-8 text",
- extension: "txt",
- mime: "text/plain",
- description: "UTF-8 encoded Unicode byte order mark, commonly but not exclusively seen in text files.",
- signature: {
- 0: 0xef,
- 1: 0xbb,
- 2: 0xbf
- },
- extractor: null
- },
- { // Place before UTF-16 LE text
- name: "UTF-32 LE text",
- extension: "utf32le",
- mime: "charset/utf32le",
- description: "Little-endian UTF-32 encoded Unicode byte order mark.",
- signature: {
- 0: 0xff,
- 1: 0xfe,
- 2: 0x00,
- 3: 0x00
- },
- extractor: null
- },
- {
- name: "UTF-16 LE text",
- extension: "utf16le",
- mime: "charset/utf16le",
- description: "Little-endian UTF-16 encoded Unicode byte order mark.",
- signature: {
- 0: 0xff,
- 1: 0xfe
- },
- extractor: null
- },
- {
- name: "Web Open Font Format",
- extension: "woff",
- mime: "application/font-woff",
- description: "",
- signature: {
- 0: 0x77,
- 1: 0x4f,
- 2: 0x46,
- 3: 0x46,
- 4: 0x0,
- 5: 0x1,
- 6: 0x0,
- 7: 0x0
- },
- extractor: null
- },
- {
- name: "Web Open Font Format 2",
- extension: "woff2",
- mime: "application/font-woff",
- description: "",
- signature: {
- 0: 0x77,
- 1: 0x4f,
- 2: 0x46,
- 3: 0x32,
- 4: 0x0,
- 5: 0x1,
- 6: 0x0,
- 7: 0x0
- },
- extractor: null
- },
- {
- name: "Embedded OpenType font",
- extension: "eot",
- mime: "application/octet-stream",
- description: "",
- signature: [
- {
- 8: 0x2,
- 9: 0x0,
- 10: 0x1,
- 34: 0x4c,
- 35: 0x50
- },
- {
- 8: 0x1,
- 9: 0x0,
- 10: 0x0,
- 34: 0x4c,
- 35: 0x50
- },
- {
- 8: 0x2,
- 9: 0x0,
- 10: 0x2,
- 34: 0x4c,
- 35: 0x50
- },
- ],
- extractor: null
- },
- {
- name: "TrueType Font",
- extension: "ttf",
- mime: "application/font-sfnt",
- description: "",
- signature: {
- 0: 0x0,
- 1: 0x1,
- 2: 0x0,
- 3: 0x0,
- 4: 0x0
- },
- extractor: null
- },
- {
- name: "OpenType Font",
- extension: "otf",
- mime: "application/font-sfnt",
- description: "",
- signature: {
- 0: 0x4f,
- 1: 0x54,
- 2: 0x54,
- 3: 0x4f,
- 4: 0x0
- },
- extractor: null
- },
- {
- name: "SQLite",
- extension: "sqlite",
- mime: "application/x-sqlite3",
- description: "",
- signature: {
- 0: 0x53,
- 1: 0x51,
- 2: 0x4c,
- 3: 0x69
- },
- extractor: extractSQLITE
- },
- {
- name: "BitTorrent link",
- extension: "torrent",
- mime: "application/x-bittorrent",
- description: "",
- signature: [
- {
- 0: 0x64, // d8:announce##:
- 1: 0x38,
- 2: 0x3a,
- 3: 0x61,
- 4: 0x6e,
- 5: 0x6e,
- 6: 0x6f,
- 7: 0x75,
- 8: 0x6e,
- 9: 0x63,
- 10: 0x65,
- 11: 0x23,
- 12: 0x23,
- 13: 0x3a
- },
- {
- 0: 0x64, // d4:infod
- 1: 0x34,
- 2: 0x3a,
- 3: 0x69,
- 4: 0x6e,
- 5: 0x66,
- 6: 0x6f,
- 7: 0x64,
- 8: [0x34, 0x35, 0x36],
- 9: 0x3a
- }
- ],
- extractor: null
- },
- {
- name: "Cryptocurrency wallet",
- extension: "wallet",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x00,
- 1: 0x00,
- 2: 0x00,
- 3: 0x00,
- 4: 0x01,
- 5: 0x00,
- 6: 0x00,
- 7: 0x00,
- 8: 0x00,
- 9: 0x00,
- 10: 0x00,
- 11: 0x00,
- 12: 0x62,
- 13: 0x31,
- 14: 0x05,
- 15: 0x00
- },
- extractor: null
- },
- {
- name: "Registry fragment",
- extension: "hbin",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x68, // hbin
- 1: 0x62,
- 2: 0x69,
- 3: 0x6e,
- 4: 0x00
- },
- extractor: null
- },
- {
- name: "Registry script",
- extension: "rgs",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x48, // HKCR
- 1: 0x4b,
- 2: 0x43,
- 3: 0x52,
- 4: 0x0d,
- 5: 0x0a,
- 6: 0x5c,
- 7: 0x7b
- },
- extractor: null
- },
- {
- name: "WinNT Registry Hive",
- extension: "registry",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x72,
- 1: 0x65,
- 2: 0x67,
- 3: 0x66
- },
- extractor: null
- },
- {
- name: "Windows Event Log",
- extension: "evt",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x30,
- 1: 0x00,
- 2: 0x00,
- 3: 0x00,
- 4: 0x4c,
- 5: 0x66,
- 6: 0x4c,
- 7: 0x65
- },
- extractor: extractEVT
- },
- {
- name: "Windows Event Log",
- extension: "evtx",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x45, // ElfFile
- 1: 0x6c,
- 2: 0x66,
- 3: 0x46,
- 4: 0x69,
- 5: 0x6c,
- 6: 0x65
- },
- extractor: extractEVTX
- },
- {
- name: "Windows Pagedump",
- extension: "dmp",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x50, // PAGEDU(MP|64)
- 1: 0x41,
- 2: 0x47,
- 3: 0x45,
- 4: 0x44,
- 5: 0x55,
- 6: [0x4d, 0x36],
- 7: [0x50, 0x34]
- },
- extractor: null
- },
- {
- name: "Windows Prefetch",
- extension: "pf",
- mime: "application/x-pf",
- description: "",
- signature: {
- 0: [0x11, 0x17, 0x1a],
- 1: 0x0,
- 2: 0x0,
- 3: 0x0,
- 4: 0x53,
- 5: 0x43,
- 6: 0x43,
- 7: 0x41
- },
- extractor: null
- },
- {
- name: "Windows Prefetch (Win 10)",
- extension: "pf",
- mime: "application/x-pf",
- description: "",
- signature: {
- 0: 0x4d,
- 1: 0x41,
- 2: 0x4d,
- 3: 0x04,
- 7: 0x0
- },
- extractor: null
- },
- {
- name: "PList (XML)",
- extension: "plist",
- mime: "application/xml",
- description: "",
- signature: {
- 39: 0x3c, // <!DOCTYPE plist
- 40: 0x21,
- 41: 0x44,
- 42: 0x4f,
- 43: 0x43,
- 44: 0x54,
- 45: 0x59,
- 46: 0x50,
- 47: 0x45,
- 48: 0x20,
- 49: 0x70,
- 50: 0x6c,
- 51: 0x69,
- 52: 0x73,
- 53: 0x74
- },
- extractor: extractPListXML
- },
- {
- name: "PList (binary)",
- extension: "bplist,plist,ipmeta,abcdp,mdbackup,mdinfo,strings,nib,ichat,qtz,webbookmark,webhistory",
- mime: "application/x-plist",
- description: "",
- signature: {
- 0: 0x62, // bplist00
- 1: 0x70,
- 2: 0x6c,
- 3: 0x69,
- 4: 0x73,
- 5: 0x74,
- 6: 0x30,
- 7: 0x30
- },
- extractor: null
- },
- {
- name: "MacOS X Keychain",
- extension: "keychain",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0x6b, // keych
- 1: 0x79,
- 2: 0x63,
- 3: 0x68,
- 4: 0x00,
- 5: 0x01
- },
- extractor: null
- },
- {
- name: "TCP Packet",
- extension: "tcp",
- mime: "application/tcp",
- description: "",
- signature: {
- 12: 0x08,
- 13: 0x00,
- 14: 0x45,
- 15: 0x00,
- 21: 0x00,
- 22: b => b >= 0x01 && b <= 0x80,
- 23: 0x06
- },
- extractor: null
- },
- {
- name: "UDP Packet",
- extension: "udp",
- mime: "application/udp",
- description: "",
- signature: {
- 12: 0x08,
- 13: 0x00,
- 14: 0x45,
- 15: 0x00,
- 16: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05],
- 22: b => b >= 0x01 && b <= 0x80,
- 23: 0x11
- },
- extractor: null
- },
- {
- name: "Compiled HTML",
- extension: "chm,chw,chi",
- mime: "application/vnd.ms-htmlhelp",
- description: "",
- signature: {
- 0: 0x49, // ITSF
- 1: 0x54,
- 2: 0x53,
- 3: 0x46,
- 4: 0x03,
- 5: 0x00,
- 6: 0x00,
- 7: 0x00
- },
- extractor: null
- },
- {
- name: "Windows Password",
- extension: "pwl",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0xe3,
- 1: 0x82,
- 2: 0x85,
- 3: 0x96
- },
- extractor: null
- },
- {
- name: "Bitlocker recovery key",
- extension: "bitlocker",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: 0xff,
- 1: 0xfe,
- 2: 0x42,
- 3: 0x00,
- 4: 0x69,
- 5: 0x00,
- 6: 0x74,
- 7: 0x00,
- 8: 0x4c,
- 9: 0x00,
- 10: 0x6f,
- 11: 0x00,
- 12: 0x63,
- 13: 0x00,
- 14: 0x6b,
- 15: 0x00,
- 16: 0x65,
- 17: 0x00,
- 18: 0x72,
- 19: 0x00,
- 20: 0x20,
- 21: 0x00
- },
- extractor: null
- },
- {
- name: "Certificate",
- extension: "cer,cat,p7b,p7c,p7m,p7s,swz,rsa,crl,crt,der",
- mime: "application/pkix-cert",
- description: "",
- signature: {
- 0: 0x30,
- 1: 0x82,
- 4: [0x06, 0x0a, 0x30]
- },
- extractor: null
- },
- {
- name: "Certificate",
- extension: "cat,swz,p7m",
- mime: "application/vnd.ms-pki.seccat",
- description: "",
- signature: {
- 0: 0x30,
- 1: 0x83,
- 2: b => b !== 0x00,
- 5: 0x06,
- 6: 0x09
- },
- extractor: null
- },
- {
- name: "PGP pubring",
- extension: "pkr,gpg",
- mime: "application/pgp-keys",
- description: "",
- signature: {
- 0: 0x99,
- 1: 0x01,
- 2: [0x0d, 0xa2],
- 3: 0x04
- },
- extractor: null
- },
- {
- name: "PGP secring",
- extension: "skr",
- mime: "application/pgp-keys",
- description: "",
- signature: [
- {
- 0: 0x95,
- 1: 0x01,
- 2: 0xcf,
- 3: 0x04
- },
- {
- 0: 0x95,
- 1: 0x03,
- 2: 0xc6,
- 3: 0x04
- }
- ],
- extractor: null
- },
- {
- name: "PGP Safe",
- extension: "pgd",
- mime: "application/pgp-keys",
- description: "",
- signature: {
- 0: 0x50, // PGPdMAIN
- 1: 0x47,
- 2: 0x50,
- 3: 0x64,
- 4: 0x4d,
- 5: 0x41,
- 6: 0x49,
- 7: 0x4e,
- 8: 0x60,
- 9: 0x01,
- 10: 0x00
- },
- extractor: null
- },
- {
- name: "Task Scheduler",
- extension: "job",
- mime: "application/octet-stream",
- description: "",
- signature: {
- 0: [0x00, 0x01, 0x02, 0x03],
- 1: [0x05, 0x06],
- 2: 0x01,
- 3: 0x00,
- 20: 0x46,
- 21: 0x00
- },
- extractor: null
- },
- {
- name: "Windows Shortcut",
- extension: "lnk",
- mime: "application/x-ms-shortcut",
- description: "",
- signature: {
- 0: 0x4c,
- 1: 0x00,
- 2: 0x00,
- 3: 0x00,
- 4: 0x01,
- 5: 0x14,
- 6: 0x02,
- 7: 0x00,
- 8: 0x00,
- 9: 0x00,
- 10: 0x00,
- 11: 0x00,
- 12: 0xc0,
- 13: 0x00,
- 14: 0x00,
- 15: 0x00,
- 16: 0x00,
- 17: 0x00,
- 18: 0x00,
- 19: 0x46
- },
- extractor: null
- },
- {
- name: "Bash",
- extension: "bash",
- mime: "application/bash",
- description: "",
- signature: {
- 0: 0x23, // #!/bin/bash
- 1: 0x21,
- 2: 0x2f,
- 3: 0x62,
- 4: 0x69,
- 5: 0x6e,
- 6: 0x2f,
- 7: 0x62,
- 8: 0x61,
- 9: 0x73,
- 10: 0x68,
- },
- extractor: null
- },
- {
- name: "Shell",
- extension: "sh",
- mime: "application/sh",
- description: "",
- signature: {
- 0: 0x23, // #!/bin/sh
- 1: 0x21,
- 2: 0x2f,
- 3: 0x62,
- 4: 0x69,
- 5: 0x6e,
- 6: 0x2f,
- 7: 0x73,
- 8: 0x68,
- },
- extractor: null
- },
- {
- name: "Python",
- extension: "py,pyc,pyd,pyo,pyw,pyz",
- mime: "application/python",
- description: "",
- signature: {
- 0: 0x23, // #!/usr/bin/python(2|3)
- 1: 0x21,
- 2: 0x2f,
- 3: 0x75,
- 4: 0x73,
- 5: 0x72,
- 6: 0x2f,
- 7: 0x62,
- 8: 0x69,
- 9: 0x6e,
- 10: 0x2f,
- 11: 0x70,
- 12: 0x79,
- 13: 0x74,
- 14: 0x68,
- 15: 0x6f,
- 16: 0x6e,
- 17: [0x32, 0x33, 0xa, 0xd],
- },
- extractor: null
- },
- {
- name: "Ruby",
- extension: "rb",
- mime: "application/ruby",
- description: "",
- signature: {
- 0: 0x23, // #!/usr/bin/ruby
- 1: 0x21,
- 2: 0x2f,
- 3: 0x75,
- 4: 0x73,
- 5: 0x72,
- 6: 0x2f,
- 7: 0x62,
- 8: 0x69,
- 9: 0x6e,
- 10: 0x2f,
- 11: 0x72,
- 12: 0x75,
- 13: 0x62,
- 14: 0x79,
- },
- extractor: null
- },
- {
- name: "perl",
- extension: "pl,pm,t,pod",
- mime: "application/perl",
- description: "",
- signature: {
- 0: 0x23, // #!/usr/bin/perl
- 1: 0x21,
- 2: 0x2f,
- 3: 0x75,
- 4: 0x73,
- 5: 0x72,
- 6: 0x2f,
- 7: 0x62,
- 8: 0x69,
- 9: 0x6e,
- 10: 0x2f,
- 11: 0x70,
- 12: 0x65,
- 13: 0x72,
- 14: 0x6c,
- },
- extractor: null
- },
- {
- name: "php",
- extension: "php,phtml,php3,php4,php5,php7,phps,php-s,pht,phar",
- mime: "application/php",
- description: "",
- signature: {
- 0: 0x3c, // <?php
- 1: 0x3f,
- 2: 0x70,
- 3: 0x68,
- 4: 0x70,
- },
- extractor: null
- }
- ]
- };
- /**
- * JPEG extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractJPEG(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- while (stream.hasMore()) {
- const marker = stream.getBytes(2);
- if (marker[0] !== 0xff) throw new Error(`Invalid marker while parsing JPEG at pos ${stream.position}: ${marker}`);
- let segmentSize = 0;
- switch (marker[1]) {
- // No length
- case 0xd8: // Start of Image
- case 0x01: // For temporary use in arithmetic coding
- break;
- case 0xd9: // End found
- return stream.carve();
- // Variable size segment
- case 0xc0: // Start of frame (Baseline DCT)
- case 0xc1: // Start of frame (Extended sequential DCT)
- case 0xc2: // Start of frame (Progressive DCT)
- case 0xc3: // Start of frame (Lossless sequential)
- case 0xc4: // Define Huffman Table
- case 0xc5: // Start of frame (Differential sequential DCT)
- case 0xc6: // Start of frame (Differential progressive DCT)
- case 0xc7: // Start of frame (Differential lossless)
- case 0xc8: // Reserved for JPEG extensions
- case 0xc9: // Start of frame (Extended sequential DCT)
- case 0xca: // Start of frame (Progressive DCT)
- case 0xcb: // Start of frame (Lossless sequential)
- case 0xcc: // Define arithmetic conditioning table
- case 0xcd: // Start of frame (Differential sequential DCT)
- case 0xce: // Start of frame (Differential progressive DCT)
- case 0xcf: // Start of frame (Differential lossless)
- case 0xdb: // Define Quantization Table
- case 0xde: // Define hierarchical progression
- case 0xe0: // Application-specific
- case 0xe1: // Application-specific
- case 0xe2: // Application-specific
- case 0xe3: // Application-specific
- case 0xe4: // Application-specific
- case 0xe5: // Application-specific
- case 0xe6: // Application-specific
- case 0xe7: // Application-specific
- case 0xe8: // Application-specific
- case 0xe9: // Application-specific
- case 0xea: // Application-specific
- case 0xeb: // Application-specific
- case 0xec: // Application-specific
- case 0xed: // Application-specific
- case 0xee: // Application-specific
- case 0xef: // Application-specific
- case 0xfe: // Comment
- segmentSize = stream.readInt(2, "be");
- stream.position += segmentSize - 2;
- break;
- // 1 byte
- case 0xdf: // Expand reference image
- stream.position++;
- break;
- // 2 bytes
- case 0xdc: // Define number of lines
- case 0xdd: // Define restart interval
- stream.position += 2;
- break;
- // Start scan
- case 0xda: // Start of scan
- segmentSize = stream.readInt(2, "be");
- stream.position += segmentSize - 2;
- stream.continueUntil(0xff);
- break;
- // Continue through encoded data
- case 0x00: // Byte stuffing
- case 0xd0: // Restart
- case 0xd1: // Restart
- case 0xd2: // Restart
- case 0xd3: // Restart
- case 0xd4: // Restart
- case 0xd5: // Restart
- case 0xd6: // Restart
- case 0xd7: // Restart
- stream.continueUntil(0xff);
- break;
- default:
- stream.continueUntil(0xff);
- break;
- }
- }
- throw new Error("Unable to parse JPEG successfully");
- }
- /**
- * GIF extractor.
- *
- * @param {Uint8Array} bytes
- * @param {Number} offset
- * @returns {Uint8Array}
- */
- export function extractGIF(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move to application extension block.
- stream.continueUntil([0x21, 0xff]);
- // Move to Graphic Control Extension for frame #1.
- stream.continueUntil([0x21, 0xf9]);
- stream.moveForwardsBy(2);
- while (stream.hasMore()) {
- // Move to Image descriptor.
- stream.moveForwardsBy(stream.readInt(1) + 1);
- // Move past Image descriptor to the image data.
- stream.moveForwardsBy(11);
- // Loop until next Graphic Control Extension.
- while (stream.getBytes(2) !== [0x21, 0xf9]) {
- stream.moveBackwardsBy(2);
- stream.moveForwardsBy(stream.readInt(1));
- if (!stream.readInt(1))
- break;
- stream.moveBackwardsBy(1);
- }
- // When the end of the file is [0x00, 0x3b], end.
- if (stream.readInt(1) === 0x3b)
- break;
- stream.moveForwardsBy(1);
- }
- return stream.carve();
- }
- /**
- * Portable executable extractor.
- * Assumes that the offset refers to an MZ header.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractMZPE(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Read pointer to PE header
- stream.moveTo(0x3c);
- const peAddress = stream.readInt(4, "le");
- // Move to PE header
- stream.moveTo(peAddress);
- // Get number of sections
- stream.moveForwardsBy(6);
- const numSections = stream.readInt(2, "le");
- // Read Optional Header Magic to determine the state of the image file
- // 0x10b = normal executable, 0x107 = ROM image, 0x20b = PE32+ executable
- stream.moveForwardsBy(16);
- const optionalMagic = stream.readInt(2, "le");
- const pe32Plus = optionalMagic === 0x20b;
- // Move to Data Directory
- const dataDirectoryOffset = pe32Plus ? 112 : 96;
- stream.moveForwardsBy(dataDirectoryOffset - 2);
- // Read Certificate Table address and size (IMAGE_DIRECTORY_ENTRY_SECURITY)
- stream.moveForwardsBy(32);
- const certTableAddress = stream.readInt(4, "le");
- const certTableSize = stream.readInt(4, "le");
- // PE files can contain extra data appended to the end of the file called an "overlay".
- // This data is not covered by the PE header and could be any arbitrary format, so its
- // length cannot be determined without contextual information.
- // However, the Attribute Certificate Table is stored in the overlay - usually right at
- // the end. Therefore, if this table is defined, we can use its offset and size to carve
- // out the entire PE file, including the overlay.
- // If the Certificate Table is not defined, we continue to parse the PE file as best we
- // can up to the end of the final section, not including any appended data in the overlay.
- if (certTableAddress > 0) {
- stream.moveTo(certTableAddress + certTableSize);
- return stream.carve();
- }
- // Move past Optional Header to Section Header
- stream.moveForwardsBy(88);
- // Move to final section header
- stream.moveForwardsBy((numSections - 1) * 0x28);
- // Get raw data info
- stream.moveForwardsBy(16);
- const rawDataSize = stream.readInt(4, "le");
- const rawDataAddress = stream.readInt(4, "le");
- // Move to end of final section
- stream.moveTo(rawDataAddress + rawDataSize);
- return stream.carve();
- }
- /**
- * PDF extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractPDF(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Find end-of-file marker (%%EOF)
- stream.continueUntil([0x25, 0x25, 0x45, 0x4f, 0x46]);
- stream.moveForwardsBy(5);
- stream.consumeIf(0x0d);
- stream.consumeIf(0x0a);
- return stream.carve();
- }
- /**
- * ZIP extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractZIP(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Find End of central directory record
- stream.continueUntil([0x50, 0x4b, 0x05, 0x06]);
- // Get comment length and consume
- stream.moveForwardsBy(20);
- const commentLength = stream.readInt(2, "le");
- stream.moveForwardsBy(commentLength);
- return stream.carve();
- }
- /**
- * MACHO extractor
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractMACHO(bytes, offset) {
- // Magic bytes.
- const MHCIGAM64 = "207250237254";
- const MHMAGIC64 = "254237250207";
- const MHCIGAM = "206250237254";
- /**
- * Checks to see if the file is 64-bit.
- *
- * @param {string} magic
- * @returns {bool}
- */
- function isMagic64(magic) {
- return magic === MHCIGAM64 || magic === MHMAGIC64;
- }
- /**
- * Checks the endianness of the file.
- *
- * @param {string} magic
- * @returns {bool}
- */
- function shouldSwapBytes(magic) {
- return magic === MHCIGAM || magic === MHCIGAM64;
- }
- /**
- * Jumps through segment information and calculates the sum of the segement sizes.
- *
- * @param {Stream} stream
- * @param {number} offset
- * @param {string} isSwap
- * @param {number} ncmds
- * @returns {number}
- */
- function dumpSegmentCommands(stream, offset, isSwap, ncmds) {
- let total = 0;
- const LCSEGEMENT64 = 0x19;
- const LCSEGEMENT = 0x1;
- for (let i = 0; i < ncmds; i++) {
- // Move to start of segment.
- stream.moveTo(offset);
- const cmd = stream.readInt(4, isSwap);
- if (cmd === LCSEGEMENT64) {
- // Move to size of segment field.
- stream.moveTo(offset + 48);
- // Extract size of segement.
- total += stream.readInt(8, isSwap);
- stream.moveTo(offset + 4);
- // Move to offset of next segment.
- offset += stream.readInt(4, isSwap);
- } else if (cmd === LCSEGEMENT) {
- stream.moveTo(offset + 36);
- // Extract size of segement.
- total += stream.readInt(4, isSwap);
- stream.moveTo(offset + 4);
- offset += stream.readInt(4, isSwap);
- }
- }
- return total;
- }
- /**
- * Reads the number of command segments.
- *
- * @param {Stream} stream
- * @param {bool} is64
- * @param {string} isSwap
- * @returns {number}
- */
- function dumpMachHeader(stream, is64, isSwap) {
- let loadCommandsOffset = 28;
- if (is64)
- loadCommandsOffset += 4;
- // Move to number of commands field.
- stream.moveTo(16);
- const ncmds = stream.readInt(4, isSwap);
- return dumpSegmentCommands(stream, loadCommandsOffset, isSwap, ncmds);
- }
- const stream = new Stream(bytes.slice(offset));
- const magic = stream.getBytes(4).join("");
- // Move to the end of the final segment.
- stream.moveTo(dumpMachHeader(stream, isMagic64(magic), shouldSwapBytes(magic) ? "le" : "be"));
- return stream.carve();
- }
- /**
- * TAR extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractTAR(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- while (stream.hasMore()) {
- // Move to ustar identifier.
- stream.moveForwardsBy(0x101);
- if (stream.getBytes(5).join("") !== [0x75, 0x73, 0x74, 0x61, 0x72].join("")) {
- // Needed since if it were not here it relies on there being at least 0x106 padding of 0s at the end of the TAR.
- stream.moveBackwardsBy(0x106);
- break;
- }
- // Move back to file size field.
- stream.moveBackwardsBy(0x8a);
- let fsize = 0;
- // Read file size field.
- stream.getBytes(11).forEach((element, index) => {
- fsize += (element - 48).toString();
- });
- // Round number up from octet to nearest 512.
- fsize = (Math.ceil(parseInt(fsize, 8) / 512) * 512);
- // Move forwards to the end of that file.
- stream.moveForwardsBy(fsize + 0x179);
- }
- stream.consumeWhile(0x00);
- return stream.carve();
- }
- /**
- * PNG extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractPNG(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move past signature to first chunk
- stream.moveForwardsBy(8);
- let chunkSize = 0,
- chunkType = "";
- while (chunkType !== "IEND") {
- chunkSize = stream.readInt(4, "be");
- chunkType = stream.readString(4);
- // Chunk data size + CRC checksum
- stream.moveForwardsBy(chunkSize + 4);
- }
- return stream.carve();
- }
- /**
- * BMP extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractBMP(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move past header
- stream.moveForwardsBy(2);
- // Read full file size
- const bmpSize = stream.readInt(4, "le");
- // Move to end of file (file size minus header and size field)
- stream.moveForwardsBy(bmpSize - 6);
- return stream.carve();
- }
- /**
- * WAV extractor.
- *
- * @param {Uint8Array} bytes
- * @param {Number} offset
- * @returns {Uint8Array}
- */
- export function extractWAV(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move to file size field.
- stream.moveTo(4);
- // Move to file size.
- stream.moveTo(stream.readInt(4, "le") - 4);
- return stream.carve();
- }
- /**
- * FLV extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractFLV(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move past signature, version and flags
- stream.moveForwardsBy(5);
- // Read header size
- const headerSize = stream.readInt(4, "be");
- // Skip through the rest of the header
- stream.moveForwardsBy(headerSize - 9);
- let tagSize = -11; // Fake size of previous tag header
- while (stream.hasMore()) {
- const prevTagSize = stream.readInt(4, "be");
- const tagType = stream.readInt(1);
- if ([8, 9, 18].indexOf(tagType) < 0) {
- // This tag is not valid
- stream.moveBackwardsBy(1);
- break;
- }
- if (prevTagSize !== (tagSize + 11)) {
- // Previous tag was not valid, reverse back over this header
- // and the previous tag body and header
- stream.moveBackwardsBy(tagSize + 11 + 5);
- break;
- }
- tagSize = stream.readInt(3, "be");
- // Move past the rest of the tag header and payload
- stream.moveForwardsBy(7 + tagSize);
- }
- return stream.carve();
- }
- /**
- * RTF extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractRTF(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- let openTags = 0;
- if (stream.readInt(1) !== 0x7b) { // {
- throw new Error("Not a valid RTF file");
- } else {
- openTags++;
- }
- while (openTags > 0 && stream.hasMore()) {
- switch (stream.readInt(1)) {
- case 0x7b: // {
- openTags++;
- break;
- case 0x7d: // }
- openTags--;
- break;
- case 0x5c: // \
- // Consume any more escapes and then skip over the next character
- stream.consumeIf(0x5c);
- stream.position++;
- break;
- default:
- break;
- }
- }
- return stream.carve();
- }
- /**
- * SQLITE extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractSQLITE(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Extract the size of the page.
- stream.moveTo(16);
- const pageSize = stream.readInt(2);
- // Extract the number of pages.
- stream.moveTo(28);
- const numPages = stream.readInt(4);
- // Move to the end of all the pages.
- stream.moveTo(pageSize*numPages);
- return stream.carve();
- }
- /**
- * PList (XML) extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractPListXML(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Find closing tag (</plist>)
- stream.continueUntil([0x3c, 0x2f, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x3e]);
- stream.moveForwardsBy(8);
- stream.consumeIf(0x0a);
- return stream.carve();
- }
- /**
- * GZIP extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractGZIP(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- /* HEADER */
- // Skip over signature and compression method
- stream.moveForwardsBy(3);
- // Read flags
- const flags = stream.readInt(1);
- // Skip over last modification time
- stream.moveForwardsBy(4);
- // Read compression flags
- stream.readInt(1);
- // Skip over OS
- stream.moveForwardsBy(1);
- /* OPTIONAL HEADERS */
- // Extra fields
- if (flags & 0x4) {
- const extraFieldsSize = stream.readInt(2, "le");
- stream.moveForwardsby(extraFieldsSize);
- }
- // Original filename
- if (flags & 0x8) {
- stream.continueUntil(0x00);
- stream.moveForwardsBy(1);
- }
- // Comment
- if (flags & 0x10) {
- stream.continueUntil(0x00);
- stream.moveForwardsBy(1);
- }
- // Checksum
- if (flags & 0x2) {
- stream.moveForwardsBy(2);
- }
- /* DEFLATE DATA */
- parseDEFLATE(stream);
- /* FOOTER */
- // Skip over checksum and size of original uncompressed input
- stream.moveForwardsBy(8);
- return stream.carve();
- }
- /**
- * BZIP2 extractor.
- *
- * @param {Uint8Array} bytes
- * @param {Number} offset
- * @returns {Uint8Array}
- */
- export function extractBZIP2(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // The EOFs shifted between all possible combinations.
- const lookingfor = [
- [0x77, 0x24, 0x53, 0x85, 0x09],
- [0xee, 0x48, 0xa7, 0x0a, 0x12],
- [0xdc, 0x91, 0x4e, 0x14, 0x24],
- [0xb9, 0x22, 0x9c, 0x28, 0x48],
- [0x72, 0x45, 0x38, 0x50, 0x90],
- [0xbb, 0x92, 0x29, 0xc2, 0x84],
- [0x5d, 0xc9, 0x14, 0xe1, 0x42],
- [0x2e, 0xe4, 0x8a, 0x70, 0xa1],
- [0x17, 0x72, 0x45, 0x38, 0x50]
- ];
- for (let i = 0; i < lookingfor.length; i++) {
- // Continue until an EOF.
- stream.continueUntil(lookingfor[i]);
- if (stream.getBytes(5).join("") === lookingfor[i].join(""))
- break;
- // Jump back to the start if invalid EOF.
- stream.moveTo(0);
- }
- stream.moveForwardsBy(4);
- return stream.carve();
- }
- /**
- * Zlib extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractZlib(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Skip over CMF
- stream.moveForwardsBy(1);
- // Read flags
- const flags = stream.readInt(1);
- // Skip over preset dictionary checksum
- if (flags & 0x20) {
- stream.moveForwardsBy(4);
- }
- // Parse DEFLATE stream
- parseDEFLATE(stream);
- // Skip over final checksum
- stream.moveForwardsBy(4);
- return stream.carve();
- }
- /**
- * XZ extractor.
- *
- * @param {Uint8Array} bytes
- * @param {Number} offset
- * @returns {string}
- */
- export function extractXZ(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move forward to EOF marker
- stream.continueUntil([0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a]);
- // Move over EOF marker
- stream.moveForwardsBy(7);
- return stream.carve();
- }
- /**
- * ELF extractor.
- *
- * @param {Uint8Array} bytes
- * @param {number} offset
- * @returns {Uint8Array}
- */
- export function extractELF(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Skip over magic number
- stream.moveForwardsBy(4);
- // Read architecture (x86 == 1, x64 == 2)
- const x86 = stream.readInt(1) === 1;
- // Read endianness (1 == little, 2 == big)
- const endian = stream.readInt(1) === 1 ? "le" : "be";
- // Skip over header values
- stream.moveForwardsBy(x86 ? 26 : 34);
- // Read section header table offset
- const shoff = x86 ? stream.readInt(4, endian) : stream.readInt(8, endian);
- // Skip over flags, header size and program header size and entries
- stream.moveForwardsBy(10);
- // Read section header table entry size
- const shentsize = stream.readInt(2, endian);
- // Read number of entries in the section header table
- const shnum = stream.readInt(2, endian);
- // Jump to section header table
- stream.moveTo(shoff);
- // Move past each section header
- stream.moveForwardsBy(shentsize * shnum);
- return stream.carve();
- }
- // Construct required Huffman Tables
- const fixedLiteralTableLengths = new Array(288);
- for (let i = 0; i < fixedLiteralTableLengths.length; i++) {
- fixedLiteralTableLengths[i] =
- (i <= 143) ? 8 :
- (i <= 255) ? 9 :
- (i <= 279) ? 7 :
- 8;
- }
- const fixedLiteralTable = buildHuffmanTable(fixedLiteralTableLengths);
- const fixedDistanceTableLengths = new Array(30).fill(5);
- const fixedDistanceTable = buildHuffmanTable(fixedDistanceTableLengths);
- const huffmanOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
- /**
- * Steps through a DEFLATE stream
- *
- * @param {Stream} stream
- */
- function parseDEFLATE(stream) {
- // Parse DEFLATE data
- let finalBlock = 0;
- while (!finalBlock) {
- // Read header
- finalBlock = stream.readBits(1);
- const blockType = stream.readBits(2);
- if (blockType === 0) {
- /* No compression */
- // Consume the rest of the current byte
- stream.moveForwardsBy(1);
- // Read the block length value
- const blockLength = stream.readInt(2, "le");
- // Move to the end of this block
- stream.moveForwardsBy(2 + blockLength);
- } else if (blockType === 1) {
- /* Fixed Huffman */
- parseHuffmanBlock(stream, fixedLiteralTable, fixedDistanceTable);
- } else if (blockType === 2) {
- /* Dynamic Huffman */
- // Read the number of liternal and length codes
- const hlit = stream.readBits(5) + 257;
- // Read the number of distance codes
- const hdist = stream.readBits(5) + 1;
- // Read the number of code lengths
- const hclen = stream.readBits(4) + 4;
- // Parse code lengths
- const codeLengths = new Uint8Array(huffmanOrder.length);
- for (let i = 0; i < hclen; i++) {
- codeLengths[huffmanOrder[i]] = stream.readBits(3);
- }
- // Parse length table
- const codeLengthsTable = buildHuffmanTable(codeLengths);
- const lengthTable = new Uint8Array(hlit + hdist);
- let code, repeat, prev;
- for (let i = 0; i < hlit + hdist;) {
- code = readHuffmanCode(stream, codeLengthsTable);
- switch (code) {
- case 16:
- repeat = 3 + stream.readBits(2);
- while (repeat--) lengthTable[i++] = prev;
- break;
- case 17:
- repeat = 3 + stream.readBits(3);
- while (repeat--) lengthTable[i++] = 0;
- prev = 0;
- break;
- case 18:
- repeat = 11 + stream.readBits(7);
- while (repeat--) lengthTable[i++] = 0;
- prev = 0;
- break;
- default:
- lengthTable[i++] = code;
- prev = code;
- break;
- }
- }
- const dynamicLiteralTable = buildHuffmanTable(lengthTable.subarray(0, hlit));
- const dynamicDistanceTable = buildHuffmanTable(lengthTable.subarray(hlit));
- parseHuffmanBlock(stream, dynamicLiteralTable, dynamicDistanceTable);
- } else {
- throw new Error(`Invalid block type while parsing DEFLATE stream at pos ${stream.position}`);
- }
- }
- // Consume final byte if it has not been fully consumed yet
- if (stream.bitPos > 0)
- stream.moveForwardsBy(1);
- }
- // Static length tables
- const lengthExtraTable = [
- 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
- ];
- const distanceExtraTable = [
- 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
- ];
- /**
- * Parses a Huffman Block given the literal and distance tables
- *
- * @param {Stream} stream
- * @param {Uint32Array} litTab
- * @param {Uint32Array} distTab
- */
- function parseHuffmanBlock(stream, litTab, distTab) {
- let code;
- let loops = 0;
- while ((code = readHuffmanCode(stream, litTab))) {
- // console.log("Code: " + code + " (" + Utils.chr(code) + ") " + Utils.bin(code));
- // End of block
- if (code === 256) break;
- // Detect probably infinite loops
- if (++loops > 10000)
- throw new Error("Caught in probable infinite loop while parsing Huffman Block");
- // Literal
- if (code < 256) continue;
- // Length code
- stream.readBits(lengthExtraTable[code - 257]);
- // Dist code
- code = readHuffmanCode(stream, distTab);
- stream.readBits(distanceExtraTable[code]);
- }
- }
- /**
- * Builds a Huffman table given the relevant code lengths
- *
- * @param {Array} lengths
- * @returns {Array} result
- * @returns {Uint32Array} result.table
- * @returns {number} result.maxCodeLength
- * @returns {number} result.minCodeLength
- */
- function buildHuffmanTable(lengths) {
- const maxCodeLength = Math.max.apply(Math, lengths);
- const minCodeLength = Math.min.apply(Math, lengths);
- const size = 1 << maxCodeLength;
- const table = new Uint32Array(size);
- for (let bitLength = 1, code = 0, skip = 2; bitLength <= maxCodeLength;) {
- for (let i = 0; i < lengths.length; i++) {
- if (lengths[i] === bitLength) {
- let reversed, rtemp, j;
- for (reversed = 0, rtemp = code, j = 0; j < bitLength; j++) {
- reversed = (reversed << 1) | (rtemp & 1);
- rtemp >>= 1;
- }
- const value = (bitLength << 16) | i;
- for (let j = reversed; j < size; j += skip) {
- table[j] = value;
- }
- code++;
- }
- }
- bitLength++;
- code <<= 1;
- skip <<= 1;
- }
- return [table, maxCodeLength, minCodeLength];
- }
- /**
- * Reads the next Huffman code from the stream, given the relevant code table
- *
- * @param {Stream} stream
- * @param {Uint32Array} table
- * @returns {number}
- */
- function readHuffmanCode(stream, table) {
- const [codeTable, maxCodeLength] = table;
- // Read max length
- const bitsBuf = stream.readBits(maxCodeLength);
- const codeWithLength = codeTable[bitsBuf & ((1 << maxCodeLength) - 1)];
- const codeLength = codeWithLength >>> 16;
- if (codeLength > maxCodeLength) {
- throw new Error(`Invalid Huffman Code length while parsing DEFLATE block at pos ${stream.position}: ${codeLength}`);
- }
- stream.moveBackwardsByBits(maxCodeLength - codeLength);
- return codeWithLength & 0xffff;
- }
- /**
- * EVTX extractor.
- *
- * @param {Uint8Array} bytes
- * @param {Number} offset
- * @returns {Uint8Array}
- */
- export function extractEVTX(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Move to first ELFCHNK.
- stream.moveTo(0x28);
- const total = stream.readInt(4, "le") - 0x2c;
- stream.moveForwardsBy(total);
- while (stream.hasMore()) {
- // Loop through ELFCHNKs.
- if (stream.getBytes(7).join("") !== [0x45, 0x6c, 0x66, 0x43, 0x68, 0x6e, 0x6b].join(""))
- break;
- stream.moveForwardsBy(0xfff9);
- }
- stream.consumeWhile(0x00);
- return stream.carve();
- }
- /**
- * EVT extractor.
- *
- * @param {Uint8Array} bytes
- * @param {Number} offset
- * @returns {Uint8Array}
- */
- export function extractEVT(bytes, offset) {
- const stream = new Stream(bytes.slice(offset));
- // Extract offset of EOF.
- stream.moveTo(0x14);
- const eofOffset = stream.readInt(4, "le");
- stream.moveTo(eofOffset);
- // Extract the size of the EOF.
- const eofSize = stream.readInt(4, "le");
- // Move past EOF.
- stream.moveForwardsBy(eofSize-4);
- return stream.carve();
- }
|