Page MenuHomeSealhub

No OneTemporary

diff --git a/android/code/index.js b/android/code/index.js
index ddb9c87..c85d3c3 100644
--- a/android/code/index.js
+++ b/android/code/index.js
@@ -1,41 +1,50 @@
const net = require("net");
const child_process = require("child_process");
const fs = require("fs");
const server = net.createServer();
async function spawnPromise(program, args) {
return new Promise((resolve, reject) => {
const process = child_process.spawn(program, args);
process.on("close", (_) => {
resolve();
});
});
}
//maybe check output of child processe and send errors in some way
server.on("connection", (socket) => {
socket.on("data", async (dataBuf) => {
- data = dataBuf.toString();
+ data = dataBuf.toString();
if (data === "screenshot") {
socket.write("start");
await spawnPromise("bash", ["/conf/screenshot.sh"]);
socket.write(fs.readFileSync("/screenshot.png"));
socket.write("ENDOFMSG");
} else if (data.includes("touch")) {
dataSplit = data.split(" ");
await spawnPromise("bash", [
"/conf/touch.sh",
dataSplit[1],
dataSplit[2],
]);
- }
+ } else if (data === "back") {
+ await spawnPromise("bash", [
+ "/conf/back.sh",
+ ]);
+ } else if (data === "home") {
+ await spawnPromise("bash", [
+ "/conf/home.sh",
+ ]);
+ }
+
});
socket.on("close", (_) => {
socket.end();
});
});
server.listen(3000, () => {
console.log("listening on 3000");
});
diff --git a/android/conf/back.sh b/android/conf/back.sh
new file mode 100644
index 0000000..8bf7271
--- /dev/null
+++ b/android/conf/back.sh
@@ -0,0 +1 @@
+/opt/android-sdk-linux/platform-tools/adb shell input keyevent 4
\ No newline at end of file
diff --git a/android/conf/home.sh b/android/conf/home.sh
new file mode 100644
index 0000000..7fab581
--- /dev/null
+++ b/android/conf/home.sh
@@ -0,0 +1 @@
+/opt/android-sdk-linux/platform-tools/adb shell input keyevent 3
\ No newline at end of file
diff --git a/http_server/code/index.html b/http_server/code/index.html
index 584300d..12d17b2 100644
--- a/http_server/code/index.html
+++ b/http_server/code/index.html
@@ -1,112 +1,151 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Rentgen android</title>
<style>
main{
display: flex;
}
.log-section{
height: 600px;
width: 300px;
overflow-y: auto;
display: flex;
flex-direction: column;
margin-left: 20px;
}
.screen{
display: inline-block
}
+
+ .screen-buttons{
+ display: flex;
+ justify-content: space-around;
+ margin-top: 5px;
+ gap: 10px;
+ }
+
+ .screen-buttons button{
+ font-size: 1.1rem;
+ padding: 10px 20px;
+ width: 100%;
+ cursor: pointer;
+ background-color: transparent;
+ }
+
+ .screen-buttons button:hover{
+ background-color: aqua;
+ }
</style>
</head>
<body>
<main>
- <img id="screen" src="" class="screen"/>
+ <section class="screen-section">
+ <img id="screen" alt="android screen" src="" class="screen"/>
+ <div class="screen-buttons">
+ <button class="screen-buttons-home">home</button>
+ <button class="screen-buttons-back">back</button>
+ </div>
+ </section>
<p
id="clicks-log"
class="log-section"
></p>
<p
id="traffic-log"
class="log-section"
></p>
</main>
<script>
var screen = document.getElementById("screen");
var clicksLog = document.getElementById("clicks-log");
+ const homeButton = document.querySelector(".screen-buttons-home");
+ const backButton = document.querySelector(".screen-buttons-back");
+
let lastTouch = new Date().getTime();
const calculateElapsedTime = (last) => {
const currentTouch = new Date().getTime();
const elapsedTime = currentTouch - lastTouch;
const elapsedSec = Math.round(elapsedTime / 1000);
lastTouch = currentTouch;
return elapsedSec;
};
const waitToLog = (clickInfoText) => {
const clickInfo = document.createElement("span");
const waitInfo = document.createElement("span");
waitInfo.textContent = `await wait(${calculateElapsedTime(lastTouch)});`
clicksLog.appendChild(waitInfo);
clickInfo.textContent = clickInfoText;
clicksLog.appendChild(clickInfo);
}
+ const registerClick = ({path, logText}) =>{
+ const clicksLog = document.getElementById("clicks-log");
+ const span = document.createElement("span");
+
+ waitToLog(logText);
+
+ fetch(path, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ });
+ }
+
+ homeButton.addEventListener("click", () => registerClick({path: "home", logText: "await homeButton();"}));
+
+ backButton.addEventListener("click", () => registerClick({path: "back", logText: "await backButton();"}));
+
async function displayImage() {
try {
const response = await fetch("screen");
const blob = await response.blob();
screen.src = URL.createObjectURL(blob);
} catch (error) {
console.error("Error fetching image: ", error);
}
}
async function handleTouchEvent(event) {
- var phoneX = event.offsetX;
- var phoneY = event.offsetY;
- if (
- phoneX <= 320 &&
- phoneX >= 0 &&
- phoneY <= 640 &&
- phoneY >= 0
- ) {
- waitToLog(`await click(${phoneX}, ${phoneY});`);
-
- await fetch("touch", {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- },
- body: `x=${phoneX}&y=${phoneY}`,
- });
+ const phoneX = event.offsetX;
+ const phoneY = event.offsetY;
- }
+ waitToLog(`await click(${phoneX}, ${phoneY});`);
+
+ await fetch("touch", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: `x=${phoneX}&y=${phoneY}`,
+ });
}
async function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
async function screenshot_loop() {
var before;
while (true) {
before = performance.now();
await displayImage();
while (performance.now() - before < ___screenshotDelayMs___)
await sleep(50);
}
}
screen.addEventListener("click", handleTouchEvent);
screenshot_loop();
</script>
<script src="/trafficLog.js"></script>
</body>
</html>
diff --git a/http_server/code/index.mjs b/http_server/code/index.mjs
index b215049..7b9062f 100644
--- a/http_server/code/index.mjs
+++ b/http_server/code/index.mjs
@@ -1,114 +1,124 @@
import express from "express";
import net from "net";
import fs from "fs";
import { readFile } from "node:fs/promises";
const device_size_x = 320;
const device_size_y = 640;
const app = express();
app.use(express.urlencoded({ extended: false }));
const socket_client = net.createConnection({ port: 3000, host: "android" });
async function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
let doneWrite = 0;
let screenshotPromise = null;
async function screenshot() {
socket_client.write("screenshot");
while (!doneWrite) await sleep(15);
doneWrite = 0;
screenshotPromise = null;
}
async function guardedScreenshot() {
if (!screenshotPromise) {
screenshotPromise = screenshot();
}
return screenshotPromise;
}
async function waitFullBoot() {
var start = performance.now();
var counter = 0;
//will timeout after 10 min
while (performance.now() - start < 600 * 1000) {
var before = performance.now();
await screenshot();
var after = performance.now();
if (after - before < process.env.screenshotDelayMs) counter++;
else counter = 0;
if (counter === 10) return;
}
throw new Error("wait for screenshot time to be less than 0.5s timed out");
}
let fd;
socket_client.on("data", (dataBuf) => {
if (dataBuf.toString() === "start")
fd = fs.openSync("/code/screenshot.png", "w");
else {
if (dataBuf.toString().includes("ENDOFMSG")) {
fs.writeSync(fd, dataBuf);
fs.close(fd);
doneWrite = 1;
} else fs.writeSync(fd, dataBuf);
}
});
console.log("Waiting for full boot...");
await waitFullBoot();
console.log("Boot detected! activating endpoints");
app.get("/screen", async function (req, res) {
await guardedScreenshot();
res.sendFile("/code/screenshot.png");
});
app.get("/favicon.ico", function (req, res) {
res.sendFile("/code/favicon.ico");
});
app.get("/trafficLog.js", function (req, res) {
res.sendFile("/code/dist/trafficLog.js");
});
app.get("/trafficLog", async function (req, res) {
res.sendFile("/log/trafficLog");
});
app.post("/touch", function (req, res) {
const x = parseInt(req.body.x);
const y = parseInt(req.body.y);
if (isNaN(x) || isNaN(y) || x > device_size_x || y > device_size_y) {
res.send(
`the query params must be x <= ${device_size_x}, y <= ${device_size_y}\n`
);
} else {
socket_client.write(`touch ${x} ${y}`);
res.sendStatus(200);
}
});
app.get("/", async function (req, res) {
let fileData = (await readFile("/code/index.html")).toString();
fileData = fileData.replace(
"___screenshotDelayMs___",
process.env.screenshotDelayMs
);
res.setHeader("Content-Type", "text/html");
res.setHeader("Content-Disposition", "inline");
res.send(fileData);
});
+app.post("/back", function (req, res) {
+ socket_client.write(`back`);
+ res.sendStatus(200);
+});
+
+app.post("/home", function (req, res) {
+ socket_client.write(`home`);
+ res.sendStatus(200);
+});
+
app.listen(8080, () => console.log("Listening in port 8080"));

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 2, 19:45 (21 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1028823
Default Alt Text
(9 KB)

Event Timeline