Skip to content

Commit

Permalink
Basis for console stats. 0.0.5 build test.
Browse files Browse the repository at this point in the history
  • Loading branch information
PoneyClairDeLune committed Jul 3, 2022
1 parent b9db626 commit 2a7c86e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This is the documentation for Minuette. All APIs are available under the global
- [ ] Silent reading modification
- [ ] Silent measurement reject
- [ ] Silent measurement modification
* Console
- [x] Intercept
* Cookie
* Clipboard
- [ ] Intercept
Expand Down
14 changes: 7 additions & 7 deletions svc/agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";
import {ics} from "./ics.js";
ics.level = 3;
const map = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";

if (!self.agentActive) {
Expand Down Expand Up @@ -34,15 +33,14 @@ if (!self.agentActive) {
} else {
ics.debug("Received command: " + data);
let msg = JSON.parse(data);
switch (msg.event) {
switch (msg.e) {
};
};
};
// Attempt to connect to the extension backend
let connection, refreshConnection = function () {
connection = chrome.runtime.connect();
ics.debug(`Connection refreshed.`);
ics.debug(`%o`, connection);
connection.onMessage.addListener(receiver);
connection.onDisconnect.addListener(refreshConnection);
};
Expand All @@ -52,10 +50,12 @@ if (!self.agentActive) {
bridgeConnection.onmessage = function (msg) {
let data = msg.data;
if (data.noExt) {
console.info(data);
ics.debug(data);
} else {
msg.data.cid = extChannel;
connection.postMessage(JSON.stringify(msg.data));
data.c = connectionId;
data.p = pageId;
data.t = tabId;
connection.postMessage(JSON.stringify(data));
};
};
ics.debug(`Cross-context listening running on extension side: ${connectionId}`);
Expand All @@ -64,7 +64,7 @@ if (!self.agentActive) {
// Generic extension public message receiver
let pubReceiver = function (data) {
let msg = JSON.parse(data);
switch (msg.event) {
switch (msg.e) {
case "monitorDisconnect":
case "monitorConnect":
default: {
Expand Down
7 changes: 4 additions & 3 deletions svc/ics.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"use strict";

let ICS = function () {
const levels = ["error", "warn", "info", "debug"];
const levels = ["error", "warn", "info", "debug"],
realConsole = console;
let upThis = this;
this.level = levels.indexOf("info");
this.level = levels.indexOf("debug");
levels.forEach(function (e, i) {
upThis[e] = function () {
if (upThis.level >= i) {
console[e](...arguments);
realConsole[e](...arguments);
};
};
});
Expand Down
51 changes: 49 additions & 2 deletions svc/minuette.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
"use strict";
import {ics} from "./ics";
ics.level = 3;
{
console.info
// Constants
const selectorSkip = ["id", "class"],
EL = Symbol(), // Event listeners
ELs = {}, // Tracking overall event listeners
TSt = Symbol(), // The real toString
UID = Symbol(); // Unique ID for tracked objects
const fakeNativeCode = Function.toString().replace("function Function(", "function FuncName(");
// Namespace for Minuette
let Minuet = {};
// Allow hiding real code
let noToStr = function () {
return fakeNativeCode.replace("FuncName", this.name);
};
let hideCode = function (func) {
if (!func[TSt]) {
func[TSt] = func.toString;
func.toString = noToStr;
};
};
// Extension channel message
let extChannel = new BroadcastChannel("-ReplaceMeWithSomethingUnique-");
extChannel.onmessage = function (msg) {
switch (msg.e) {
case "apiExpose": {
self.Minuette = new Proxy(Minuet, {});
ics.debug("API exposed.");
break;
};
case "apiHide": {
delete self.Minuette;
ics.debug("API hidden.");
};
default: {
ics.debug(msg);
};
};
};
// Original API exposure
Minuet.console = console;
// Console hijack
{
self.console = {};
for (let name in Minuet.console) {
self.console[name] = function () {
extChannel.postMessage({e: "console", level: name});
Minuet.console[name](...arguments);
};
};
};
};
ics.debug("Minuette launched.");
2 changes: 1 addition & 1 deletion svc/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ browser.webNavigation.onCommitted.addListener(async function (data) {
inTabs[data.tabId] = new Set();
listeners.tabOpen(await browser.tabs.get(data.tabId));
} else {
ics.debug(`Ignore opened internal tab: %o`, data);
ics.debug(`Ignore opened internal tab ${data.tabId}(${data.url}).`);
};
});
listeners.tabOpen = async function (data) {
Expand Down

0 comments on commit 2a7c86e

Please sign in to comment.