fix view chunksize being too big causing pixelation

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Feb 5, 2025 at 11:44 UTC 854d6c00d2f7b27f2139a6c1e4ed986d2f1ea612
2 files changed +12 -4
public/scripts/agent-desktop-0.0.2-min.js
+6 -2
@@ -221,12 +221,16 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
221 if ((cmd == 3) || (cmd == 4) || (cmd == 7)) { X = (view[4] << 8) + view[5]; Y = (view[6] << 8) + view[7]; }
222 if (obj.debugmode > 2) { console.log('CMD', cmd, cmdsize, X, Y); }
223
224 + // Fix for view being too large for String.fromCharCode.apply()
225 + var chunkSize = 10000;
226 + let result = '';
227 + for (let i = 0; i < view.length; i += chunkSize) { result += String.fromCharCode.apply(null, view.slice(i, i + chunkSize)); }
228 // Record the command if needed
229 if (obj.recordedData != null) {
230 if (cmdsize > 65000) {
227 - obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdsize) + obj.shortToStr(cmd) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + String.fromCharCode.apply(null, view)));
231 + obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdsize) + obj.shortToStr(cmd) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + result));
232 } else {
229 - obj.recordedData.push(recordingEntry(2, 1, String.fromCharCode.apply(null, view)));
233 + obj.recordedData.push(recordingEntry(2, 1, result));
234 }
235 }
236
public/scripts/agent-desktop-0.0.2.js
+6 -2
@@ -221,12 +221,16 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
221 if ((cmd == 3) || (cmd == 4) || (cmd == 7)) { X = (view[4] << 8) + view[5]; Y = (view[6] << 8) + view[7]; }
222 if (obj.debugmode > 2) { console.log('CMD', cmd, cmdsize, X, Y); }
223
224 + // Fix for view being too large for String.fromCharCode.apply()
225 + var chunkSize = 10000;
226 + let result = '';
227 + for (let i = 0; i < view.length; i += chunkSize) { result += String.fromCharCode.apply(null, view.slice(i, i + chunkSize)); }
228 // Record the command if needed
229 if (obj.recordedData != null) {
230 if (cmdsize > 65000) {
227 - obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdsize) + obj.shortToStr(cmd) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + String.fromCharCode.apply(null, view)));
231 + obj.recordedData.push(recordingEntry(2, 1, obj.shortToStr(27) + obj.shortToStr(8) + obj.intToStr(cmdsize) + obj.shortToStr(cmd) + obj.shortToStr(0) + obj.shortToStr(0) + obj.shortToStr(0) + result));
232 } else {
229 - obj.recordedData.push(recordingEntry(2, 1, String.fromCharCode.apply(null, view)));
233 + obj.recordedData.push(recordingEntry(2, 1, result));
234 }
235 }
236