start implementing in ts
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import "./shim.ts";
|
||||||
|
|
||||||
|
const str2byte = (s: string): number[] => {
|
||||||
|
return Array.from(s).map((_, i) => s.charCodeAt(i));
|
||||||
|
};
|
||||||
|
|
||||||
|
const SendUsrChk = (username: string, password: string): DataView => {
|
||||||
|
// type is char account[0x20]; char password[0x80];
|
||||||
|
let buf = new Uint8Array(0x20 + 0x80);
|
||||||
|
buf.fill(0);
|
||||||
|
let cmd_payload = new DataView(buf.buffer);
|
||||||
|
cmd_payload.writeByteArray(str2byte(username));
|
||||||
|
cmd_payload.add(0x20).writeByteArray(str2byte(password));
|
||||||
|
return cmd_payload;
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(SendUsrChk("admin", "admin"));
|
||||||
+24
-6
@@ -25,8 +25,13 @@ DataView.prototype.readU32 = function () {
|
|||||||
DataView.prototype.readU64 = function () {
|
DataView.prototype.readU64 = function () {
|
||||||
return this.getUint64(0);
|
return this.getUint64(0);
|
||||||
};
|
};
|
||||||
|
const isDataView = (x: DataView | number[]): x is DataView => {
|
||||||
|
return x instanceof DataView;
|
||||||
|
};
|
||||||
|
|
||||||
DataView.prototype.writeByteArray = function (arr) {
|
DataView.prototype.writeByteArray = function (arr) {
|
||||||
for (let i = 0; i < (arr.byteLength || arr.length); i++) {
|
const len = isDataView(arr) ? arr.byteLength : arr.length;
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
this.setUint8(i, arr[i]);
|
this.setUint8(i, arr[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -39,10 +44,23 @@ DataView.prototype.readByteArray = function (len) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Memory = {
|
const Memory = {
|
||||||
alloc: (len) => new DataView(new ArrayBuffer(len + 1)),
|
alloc: (len: number) => new DataView(new ArrayBuffer(len + 1)),
|
||||||
copy: (outbuf, inbuf, len) => outbuf.writeByteArray(inbuf.readByteArray(len)),
|
copy: (outbuf: DataView, inbuf: DataView, len: number) => outbuf.writeByteArray(inbuf.readByteArray(len)),
|
||||||
};
|
};
|
||||||
|
|
||||||
//module.exports = {
|
declare global {
|
||||||
// Memory,
|
interface DataView {
|
||||||
//};
|
add(offset: number): DataView;
|
||||||
|
readByteArray(len: number): DataView;
|
||||||
|
readU16(): undefined;
|
||||||
|
readU32(): undefined;
|
||||||
|
readU64(): undefined;
|
||||||
|
readU8(): undefined;
|
||||||
|
writeByteArray(arr: DataView | number[]): undefined;
|
||||||
|
writeU16(n: number): undefined;
|
||||||
|
writeU32(n: number): undefined;
|
||||||
|
writeU64(n: number): undefined;
|
||||||
|
writeU8(n: number): undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default global;
|
||||||
Reference in New Issue
Block a user