This commit is contained in:
Nithish Anand B 2026-05-23 18:46:11 +02:00 committed by GitHub
commit a571109aed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 64 additions and 3 deletions

View File

@ -12,7 +12,7 @@ export default class RawDecoder {
this._lines = 0; this._lines = 0;
} }
decodeRect(x, y, width, height, sock, display, depth) { decodeRect(x, y, width, height, sock, display, depth, pixelFormat) {
if ((width === 0) || (height === 0)) { if ((width === 0) || (height === 0)) {
return true; return true;
} }
@ -21,7 +21,7 @@ export default class RawDecoder {
this._lines = height; this._lines = height;
} }
const pixelSize = depth == 8 ? 1 : 4; const pixelSize = depth == 8 ? 1 : (depth == 16 ? 2 : 4); // Modifications
const bytesPerLine = width * pixelSize; const bytesPerLine = width * pixelSize;
while (this._lines > 0) { while (this._lines > 0) {
@ -43,6 +43,36 @@ export default class RawDecoder {
newdata[i * 4 + 3] = 255; newdata[i * 4 + 3] = 255;
} }
data = newdata; data = newdata;
} else if (depth == 16) { // Modifications: decode 16bpp raw
const fmt = pixelFormat || {};
const redMax = fmt.redMax !== undefined ? fmt.redMax : 31;
const greenMax = fmt.greenMax !== undefined ? fmt.greenMax : 63;
const blueMax = fmt.blueMax !== undefined ? fmt.blueMax : 31;
const redShift = fmt.redShift !== undefined ? fmt.redShift : 11;
const greenShift = fmt.greenShift !== undefined ? fmt.greenShift : 5;
const blueShift = fmt.blueShift !== undefined ? fmt.blueShift : 0;
const bigEndian = !!fmt.bigEndian;
const newdata = new Uint8Array(width * 4);
for (let i = 0; i < width; i++) {
const idx = i * 2;
let pixel;
if (bigEndian) {
pixel = (data[idx] << 8) | data[idx + 1];
} else {
pixel = data[idx] | (data[idx + 1] << 8);
}
const r = (pixel >> redShift) & redMax;
const g = (pixel >> greenShift) & greenMax;
const b = (pixel >> blueShift) & blueMax;
newdata[i * 4 + 0] = redMax ? (r * 255 / redMax) : 0;
newdata[i * 4 + 1] = greenMax ? (g * 255 / greenMax) : 0;
newdata[i * 4 + 2] = blueMax ? (b * 255 / blueMax) : 0;
newdata[i * 4 + 3] = 255;
}
data = newdata;
} }
// Max sure the image is fully opaque // Max sure the image is fully opaque

View File

@ -131,12 +131,15 @@ export default class RFB extends EventTargetMixin {
// Server capabilities // Server capabilities
this._rfbVersion = 0; this._rfbVersion = 0;
this._rfbMaxVersion = 3.8; this._rfbMaxVersion = 3.8;
this._rfbServerVersion = null;
this._rfbTightVNC = false; this._rfbTightVNC = false;
this._rfbVeNCryptState = 0; this._rfbVeNCryptState = 0;
this._rfbXvpVer = 0; this._rfbXvpVer = 0;
this._fbWidth = 0; this._fbWidth = 0;
this._fbHeight = 0; this._fbHeight = 0;
this._fbPixelFormat = null;
this._forceRawEncoding = false; // Modifications: 003.005 compat path
this._fbName = ""; this._fbName = "";
@ -1506,6 +1509,7 @@ export default class RFB extends EventTargetMixin {
} }
const sversion = this._sock.rQshiftStr(12).substr(4, 7); const sversion = this._sock.rQshiftStr(12).substr(4, 7);
this._rfbServerVersion = sversion;
Log.Info("Server ProtocolVersion: " + sversion); Log.Info("Server ProtocolVersion: " + sversion);
let isRepeater = 0; let isRepeater = 0;
switch (sversion) { switch (sversion) {
@ -1516,6 +1520,11 @@ export default class RFB extends EventTargetMixin {
case "003.006": // UltraVNC case "003.006": // UltraVNC
this._rfbVersion = 3.3; this._rfbVersion = 3.3;
break; break;
case "003.005": // non-standard (seen in impact.pcapng)
Log.Warn("Non-standard server version " + sversion + ", treating as RFB 3.3");
this._rfbVersion = 3.3;
this._forceRawEncoding = true; // Modifications: force raw/16bpp
break;
case "003.007": case "003.007":
this._rfbVersion = 3.7; this._rfbVersion = 3.7;
break; break;
@ -2164,6 +2173,18 @@ export default class RFB extends EventTargetMixin {
const greenShift = this._sock.rQshift8(); const greenShift = this._sock.rQshift8();
const blueShift = this._sock.rQshift8(); const blueShift = this._sock.rQshift8();
this._sock.rQskipBytes(3); // padding this._sock.rQskipBytes(3); // padding
this._fbPixelFormat = { // Modifications: store server pixel format
bpp: bpp,
depth: depth,
bigEndian: bigEndian,
trueColor: trueColor,
redMax: redMax,
greenMax: greenMax,
blueMax: blueMax,
redShift: redShift,
greenShift: greenShift,
blueShift: blueShift,
};
// NB(directxman12): we don't want to call any callbacks or print messages until // NB(directxman12): we don't want to call any callbacks or print messages until
// *after* we're past the point where we could backtrack // *after* we're past the point where we could backtrack
@ -2226,6 +2247,11 @@ export default class RFB extends EventTargetMixin {
Log.Warn("Intel AMT KVM only supports 8/16 bit depths. Using low color mode."); Log.Warn("Intel AMT KVM only supports 8/16 bit depths. Using low color mode.");
this._fbDepth = 8; this._fbDepth = 8;
} }
if (this._forceRawEncoding && this._fbPixelFormat &&
this._fbPixelFormat.depth === 16 && this._fbPixelFormat.trueColor) {
Log.Warn("Forcing 16bpp pixel format due to non-standard RFB version");
this._fbDepth = 16;
}
RFB.messages.pixelFormat(this._sock, this._fbDepth, true); RFB.messages.pixelFormat(this._sock, this._fbDepth, true);
this._sendEncodings(); this._sendEncodings();
@ -2240,6 +2266,11 @@ export default class RFB extends EventTargetMixin {
// In preference order // In preference order
encs.push(encodings.encodingCopyRect); encs.push(encodings.encodingCopyRect);
if (this._forceRawEncoding) { // Modifications: raw-only encodings
encs.push(encodings.encodingRaw);
RFB.messages.clientEncodings(this._sock, encs);
return;
}
// Only supported with full depth support // Only supported with full depth support
if (this._fbDepth == 24) { if (this._fbDepth == 24) {
if (supportsWebCodecsH264Decode) { if (supportsWebCodecsH264Decode) {
@ -3000,7 +3031,7 @@ export default class RFB extends EventTargetMixin {
return decoder.decodeRect(this._FBU.x, this._FBU.y, return decoder.decodeRect(this._FBU.x, this._FBU.y,
this._FBU.width, this._FBU.height, this._FBU.width, this._FBU.height,
this._sock, this._display, this._sock, this._display,
this._fbDepth); this._fbDepth, this._fbPixelFormat); // Modifications
} catch (err) { } catch (err) {
this._fail("Error decoding rect: " + err); this._fail("Error decoding rect: " + err);
return false; return false;