tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hooks.js (5642B)


      1 // This Source Code Form is subject to the terms of the Mozilla Public
      2 // License, v. 2.0. If a copy of the MPL was not distributed with this
      3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
      4 
      5 // --- asn1 ---
      6 
      7 if (DebugSymbol.findFunctionsNamed("SEC_ASN1DecodeItem_Util").length) {
      8  console.log("Attaching `SEC_ASN1DecodeItem_Util` interceptor...");
      9  Interceptor.attach(DebugSymbol.fromName("SEC_ASN1DecodeItem_Util").address, {
     10    onEnter: function (args) {
     11      const secItem = args[3]; // { type(8), data(8), len(4) }
     12 
     13      const len = secItem.add(8).add(8).readUInt();
     14      const buf = secItem.add(8).readByteArray(len);
     15 
     16      send({
     17        func: "SEC_ASN1DecodeItem_Util",
     18        data: new Uint8Array(buf),
     19      });
     20    },
     21  });
     22 }
     23 
     24 // --- certDN ---
     25 
     26 if (DebugSymbol.findFunctionsNamed("CERT_AsciiToName").length) {
     27  console.log("Attaching `CERT_AsciiToName` interceptor...");
     28  Interceptor.attach(DebugSymbol.fromName("CERT_AsciiToName").address, {
     29    onEnter: function (args) {
     30      send({
     31        func: "CERT_AsciiToName",
     32        data: args[0].readUtf8String(),
     33      });
     34    },
     35  });
     36 }
     37 
     38 // --- ech ---
     39 
     40 if (DebugSymbol.findFunctionsNamed("tls13_DecodeEchConfigs").length) {
     41  console.log("Attaching `tls13_DecodeEchConfigs` interceptor...");
     42  Interceptor.attach(DebugSymbol.fromName("tls13_DecodeEchConfigs").address, {
     43    onEnter: function (args) {
     44      const secItem = args[3]; // { type(8), data(8), len(4) }
     45 
     46      const len = secItem.add(8).add(8).readUInt();
     47      const buf = secItem.add(8).readByteArray(len);
     48 
     49      send({
     50        func: "tls13_DecodeEchConfigs",
     51        data: new Uint8Array(buf),
     52      });
     53    },
     54  });
     55 }
     56 
     57 // --- pkcs7 ---
     58 
     59 if (DebugSymbol.findFunctionsNamed("CERT_DecodeCertPackage").length) {
     60  console.log("Attaching `CERT_DecodeCertPackage` interceptor...");
     61  Interceptor.attach(DebugSymbol.fromName("CERT_DecodeCertPackage").address, {
     62    onEnter: function (args) {
     63      const len = args[1].toInt32();
     64      const buf = args[0].readByteArray(len);
     65 
     66      send({
     67        func: "CERT_DecodeCertPackage",
     68        data: new Uint8Array(buf),
     69      });
     70    },
     71  });
     72 }
     73 
     74 // --- pkcs8 ---
     75 
     76 if (
     77  DebugSymbol.findFunctionsNamed("PK11_ImportDERPrivateKeyInfoAndReturnKey")
     78    .length
     79 ) {
     80  console.log(
     81    "Attaching `PK11_ImportDERPrivateKeyInfoAndReturnKey` interceptor...",
     82  );
     83  Interceptor.attach(
     84    DebugSymbol.fromName("PK11_ImportDERPrivateKeyInfoAndReturnKey").address,
     85    {
     86      onEnter: function (args) {
     87        const secItem = args[3]; // { type(8), data(8), len(4) }
     88 
     89        const len = secItem.add(8).add(8).readUInt();
     90        const buf = secItem.add(8).readByteArray(len);
     91 
     92        send({
     93          func: "PK11_ImportDERPrivateKeyInfoAndReturnKey",
     94          data: new Uint8Array(buf),
     95        });
     96      },
     97    },
     98  );
     99 }
    100 
    101 // --- pkcs12 ---
    102 
    103 if (DebugSymbol.findFunctionsNamed("SEC_PKCS12DecoderUpdate").length) {
    104  console.log("Attaching `SEC_PKCS12DecoderUpdate` interceptor...");
    105  Interceptor.attach(DebugSymbol.fromName("SEC_PKCS12DecoderUpdate").address, {
    106    onEnter: function (args) {
    107      const len = args[2].toInt32();
    108      const buf = args[1].readByteArray(len);
    109 
    110      send({ func: "SEC_PKCS12DecoderUpdate", data: new Uint8Array(buf) });
    111    },
    112  });
    113 }
    114 
    115 // --- quickder ---
    116 
    117 if (DebugSymbol.findFunctionsNamed("SEC_QuickDERDecodeItem_Util").length) {
    118  console.log("Attaching `SEC_QuickDERDecodeItem_Util` interceptor...");
    119  Interceptor.attach(
    120    DebugSymbol.fromName("SEC_QuickDERDecodeItem_Util").address,
    121    {
    122      onEnter: function (args) {
    123        const secItem = args[3]; // { type(8), data(8), len(4) }
    124 
    125        const len = secItem.add(8).add(8).readUInt();
    126        const buf = secItem.add(8).readByteArray(len);
    127 
    128        send({
    129          func: "SEC_QuickDERDecodeItem_Util",
    130          data: new Uint8Array(buf),
    131        });
    132      },
    133    },
    134  );
    135 }
    136 
    137 // -- smime --
    138 
    139 if (DebugSymbol.findFunctionsNamed("NSS_CMSDecoder_Update").length) {
    140  console.log("Attaching `NSS_CMSDecoder_Update` interceptor...");
    141  Interceptor.attach(DebugSymbol.fromName("NSS_CMSDecoder_Update").address, {
    142    onEnter: function (args) {
    143      const len = args[2].toInt32();
    144      const buf = args[1].readByteArray(len);
    145 
    146      send({ func: "NSS_CMSDecoder_Update", data: new Uint8Array(buf) });
    147    },
    148  });
    149 }
    150 
    151 // --- TLS ---
    152 
    153 if (DebugSymbol.findFunctionsNamed("ssl_DefClose").length) {
    154  console.log("Attaching `ssl_DefClose` interceptor...");
    155  Interceptor.attach(DebugSymbol.fromName("ssl_DefClose").address, {
    156    onEnter: function (args) {
    157      send({ func: "ssl_DefClose", ss: args[0] });
    158    },
    159  });
    160 }
    161 
    162 if (DebugSymbol.findFunctionsNamed("ssl_DefRecv").length) {
    163  console.log("Attaching `ssl_DefRecv` interceptor...");
    164  Interceptor.attach(DebugSymbol.fromName("ssl_DefRecv").address, {
    165    onEnter: function (args) {
    166      this.ss = args[0];
    167      this.buf = args[1];
    168      this.len = args[2].toInt32();
    169    },
    170    onLeave: function (_retVal) {
    171      const buf = this.buf.readByteArray(this.len);
    172 
    173      send({
    174        func: "ssl_DefRecv",
    175        ss: this.ss,
    176        data: new Uint8Array(buf),
    177      });
    178    },
    179  });
    180 }
    181 
    182 if (DebugSymbol.findFunctionsNamed("ssl_DefRead").length) {
    183  console.log("Attaching `ssl_DefRead` interceptor...");
    184  Interceptor.attach(DebugSymbol.fromName("ssl_DefRead").address, {
    185    onEnter: function (args) {
    186      this.ss = args[0];
    187      this.buf = args[1];
    188      this.len = args[2].toInt32();
    189    },
    190    onLeave: function (_retVal) {
    191      const buf = this.buf.readByteArray(this.len);
    192 
    193      send({
    194        func: "ssl_DefRead",
    195        ss: this.ss,
    196        data: new Uint8Array(buf),
    197      });
    198    },
    199  });
    200 }