Skip to content

Commit

Permalink
Added OpenMSX on Windows support (incl. SSPI)
Browse files Browse the repository at this point in the history
  • Loading branch information
S0urceror committed Jul 30, 2020
1 parent 298a906 commit b562000
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 19 deletions.
115 changes: 98 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dezog",
"displayName": "DeZog",
"version": "1.3.4",
"version": "1.3.5",
"publisher": "S0urceror",
"description": "Visual Studio Code Debug Adapter for the Z80/ZX Spectrum.",
"author": {
Expand Down Expand Up @@ -42,12 +42,17 @@
},
"files": [],
"dependencies": {
"@types/debug": "^4.1.5",
"@types/http-errors": "^1.8.0",
"@types/node-fetch": "^2.5.7",
"await-notify": "1.0.1",
"binary-file": "^0.2.3",
"gif-writer": "^0.9.3",
"glob": "^7.1.6",
"jsonc-parser": "^2.3.0",
"mocha": "^7.2.0",
"network-byte-order": "^0.2.0",
"node-expose-sspi-strict": "^0.1.1",
"node-gzip": "^1.1.2",
"rng": "^0.2.2",
"ts-node": "^8.10.2",
Expand Down
99 changes: 98 additions & 1 deletion src/remotes/openmsx/openmsxremote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import {DecodeOpenMSXRegisters} from './decodeopenmsxdata';
import {Utility} from '../../misc/utility';
import {GenericWatchpoint, GenericBreakpoint} from '../../genericwatchpoint';
import {RemoteBase, RemoteBreakpoint, MemoryBank } from '../remotebase';
import {htonl,ntohl} from 'network-byte-order';

import * as NES from 'node-expose-sspi-strict';

let nes: typeof NES;
if (os.platform()=="win32") {
nes = require ('node-expose-sspi-strict');
}

export class OpenMSXRemote extends RemoteBase {
openmsx:net.Socket;
Expand Down Expand Up @@ -140,6 +148,91 @@ export class OpenMSXRemote extends RemoteBase {
});
});
}
async waitResponse () : Promise <ArrayBuffer> {
return new Promise <ArrayBuffer> ( async (resolve,reject) => {
this.openmsx.once ('readable', () => {
let buflen:Buffer;
while (null == (buflen = this.openmsx.read(4))) {};
let len:number = ntohl (buflen,0);
let chunk:Buffer;
while (null == (chunk = this.openmsx.read(len))) {};
if (len!=chunk.byteLength)
reject (new Error (`Not the expected length ${len}:${chunk.byteLength}`));
resolve (chunk.buffer.slice (chunk.byteOffset,chunk.byteOffset+chunk.byteLength));
});
})
}
async perform_auth () : Promise <boolean> {
return new Promise <boolean> ( async (resolve,reject) => {

const credInput = {
packageName: 'Negotiate',
credentialUse: 'SECPKG_CRED_OUTBOUND' as NES.CredentialUseFlag,
} as NES.AcquireCredHandleInput;

const clientCred = nes.sspi.AcquireCredentialsHandle(credInput);
const packageInfo = nes.sspi.QuerySecurityPackageInfo("Negotiate");

///////////////////////////////////////////////
// CHALLENGE
var input:NES.InitializeSecurityContextInput = {
credential: clientCred.credential,
targetName: "",
cbMaxToken: packageInfo.cbMaxToken
};
let clientSecurityContext = nes.sspi.InitializeSecurityContext(input);
if (clientSecurityContext.SECURITY_STATUS !== 'SEC_I_CONTINUE_NEEDED') {
throw new Error ("Authentication error");
}
let len:number = clientSecurityContext.SecBufferDesc.buffers[0].byteLength;
var blen:Uint8Array = new Uint8Array (4);
htonl (blen,0,len);
let buffer:Uint8Array = new Uint8Array (clientSecurityContext.SecBufferDesc.buffers[0]);

this.openmsx.write (blen);
this.openmsx.write (buffer);
let response:ArrayBuffer;
try {
response = await this.waitResponse ();
} catch (error) {
reject (error);
return;
}

////////////////////////////////////////////////
// RESPONSE
input = {
credential: clientCred.credential,
targetName: "",
serverSecurityContext: {
SecBufferDesc: {
ulVersion: 0,
buffers: [response],
},
},
cbMaxToken: packageInfo.cbMaxToken,
contextHandle: clientSecurityContext.contextHandle,
targetDataRep: 'SECURITY_NETWORK_DREP',
};
clientSecurityContext = nes.sspi.InitializeSecurityContext(input);

len = clientSecurityContext.SecBufferDesc.buffers[0].byteLength;
var blen:Uint8Array = new Uint8Array (4);
htonl (blen,0,len);
buffer = new Uint8Array (clientSecurityContext.SecBufferDesc.buffers[0]);

this.openmsx.write (blen);
this.openmsx.write (buffer);
try {
response = await this.waitResponse ();
} catch (error) {
reject (error);
return;
}

resolve (true);
});
}

/// Initializes the machine.
public async doInitialization(): Promise<void> {
Expand All @@ -165,10 +258,14 @@ export class OpenMSXRemote extends RemoteBase {
this.emit('log', "Closed the connection to OpenMSX");
})
this.openmsx.on ('data', data => {
console.log (data.toString());
//console.log (data.toString());
this.handleOpenMSXResponse (data);
});

if (os.platform()=="win32") {
await this.perform_auth ();
}

await this.perform_awake ("<openmsx-control>");
//await this.receive_response ();

Expand Down

0 comments on commit b562000

Please sign in to comment.