miijs
Version:
The most complete and easy to use Mii library available.
3 lines (2 loc) • 3.94 kB
JavaScript
import{i as m,j as A,n as u}from"./chunk-AD7HDZ5R.js";import{e as s,f as F,g as h,h as p}from"./chunk-C7XDOTG6.js";import{g as d}from"./chunk-VMLSR5BU.js";d();function D(e){return s.Buffer.isBuffer(e)||e instanceof Uint8Array||e instanceof ArrayBuffer||e instanceof SharedArrayBuffer?s.Buffer.from(e):!1}var l=520;function C(e){let c=s.Buffer.alloc(64);return e.slice(41,43).copy(c,0),c.fill(0,2,16),e.slice(468,476).copy(c,16),e.slice(468,476).copy(c,24),e.slice(488,520).copy(c,32),c}function K(e,c,r,i,o){let t=s.Buffer.alloc(480),x=0,a=e.indexOf(0),f=a>=0?a+1:14;e.slice(0,f).copy(t,x),x+=f;let n=16-r;o.slice(0,n).copy(t,x),x+=n,c.slice(0,r).copy(t,x),x+=r,o.slice(16,32).copy(t,x),x+=16;for(let y=0;y<32;y++)t[x+y]=o[32+y]^i[y];return x+=32,t.slice(0,x)}function g(e,c,r){let i=s.Buffer.alloc(r),o=0,t=0;for(;o<r;){let x=s.Buffer.alloc(2+c.length);x[0]=t>>8&255,x[1]=t&255,c.copy(x,2);let a=p("sha256",e);a.update(x);let f=a.digest(),n=Math.min(32,r-o);f.copy(i,o,0,n),o+=n,t++}return i}function B(e,c,r,i,o,t){let x=K(e,c,r,i,t),a=g(o,x,48);return{aesKey:a.slice(0,16),aesIV:a.slice(16,32),hmacKey:a.slice(32,48)}}function E(e){if(e=D(e),!e)throw new Error("Tag is not a valid Buffer type");let c=s.Buffer.alloc(l);e.slice(8,16).copy(c,0),e.slice(128,160).copy(c,8),e.slice(16,52).copy(c,40),e.slice(160,520).copy(c,76),e.slice(52,84).copy(c,436),e.slice(0,8).copy(c,468),e.slice(84,128).copy(c,476);let r=C(c),i=B(s.Buffer.from("756E666978656420696E666F7300","hex"),s.Buffer.from("DB4B9E3F45278F397EFF9B4FB9930000","hex"),14,s.Buffer.from("044917DC76B49640D6F83939960FAED4EF392FAAB21428AA21FB54E545054766","hex"),s.Buffer.from("1D164B375B72A55728B91D64B6A3C205","hex"),r),o=B(s.Buffer.from("6C6F636B65642073656372657400","hex"),s.Buffer.from("FDC8A07694B89E4C47D37DE8CE5C74C1","hex"),16,s.Buffer.from("044917DC76B49640D6F83939960FAED4EF392FAAB21428AA21FB54E545054766","hex"),s.Buffer.from("7F752D2873A20017FEF85C0575904B6D","hex"),r),t=s.Buffer.alloc(l),x=h("aes-128-ctr",i.aesKey,i.aesIV);x.setAutoPadding(!1),x.update(c.slice(44,436)).copy(t,44),c.slice(0,8).copy(t,0),c.slice(40,44).copy(t,40),c.slice(468,520).copy(t,468);let f=p("sha256",o.hmacKey);f.update(t.slice(468,520)),f.digest().copy(t,436);let y=p("sha256",i.hmacKey);return y.update(t.slice(41,520)),y.digest().copy(t,8),t}function H(e){if(e=D(e),!e)throw new Error("Tag is not a valid Buffer type");let c=C(e),r=B(s.Buffer.from("756E666978656420696E666F7300","hex"),s.Buffer.from("DB4B9E3F45278F397EFF9B4FB9930000","hex"),14,s.Buffer.from("044917DC76B49640D6F83939960FAED4EF392FAAB21428AA21FB54E545054766","hex"),s.Buffer.from("1D164B375B72A55728B91D64B6A3C205","hex"),c),i=B(s.Buffer.from("6C6F636B65642073656372657400","hex"),s.Buffer.from("FDC8A07694B89E4C47D37DE8CE5C74C1","hex"),16,s.Buffer.from("044917DC76B49640D6F83939960FAED4EF392FAAB21428AA21FB54E545054766","hex"),s.Buffer.from("7F752D2873A20017FEF85C0575904B6D","hex"),c),o=s.Buffer.alloc(l),t=p("sha256",i.hmacKey);t.update(e.slice(468,520)),t.digest().copy(o,436);let x=p("sha256",r.hmacKey);x.update(e.slice(41,436)),x.update(o.slice(436,468)),x.update(e.slice(468,520)),x.digest().copy(o,8);let a=F("aes-128-ctr",r.aesKey,r.aesIV);a.setAutoPadding(!1),a.update(e.slice(44,436)).copy(o,44),e.slice(0,8).copy(o,0),e.slice(40,44).copy(o,40),e.slice(468,520).copy(o,468);let n=s.Buffer.alloc(l);return o.slice(0,8).copy(n,8),o.slice(8,40).copy(n,128),o.slice(40,76).copy(n,16),o.slice(76,436).copy(n,160),o.slice(436,468).copy(n,52),o.slice(468,476).copy(n,0),o.slice(476,520).copy(n,84),n}function V(e){let c=e.slice(0,l),i=E(c).slice(76,172);return s.Buffer.from(i)}function T(e,c){if(e=D(e),!e)throw new Error("Dump is not a valid Buffer type");c=m(c);let r=A(c,u.FFSD),i=E(e.slice(0,l));r.copy(i,76);let o=H(i),t=s.Buffer.alloc(e.length);return o.copy(t,0),e.length>l&&e.slice(l).copy(t,l),t}export{V as extractMiiFromAmiibo,T as insertMiiIntoAmiibo};
//# sourceMappingURL=amiiboHandler-DJRKB37R.js.map