Skip to content

Instantly share code, notes, and snippets.

@deejayy
Last active February 29, 2020 14:03
Show Gist options
  • Save deejayy/047bdd1cd18714474a7f to your computer and use it in GitHub Desktop.
Save deejayy/047bdd1cd18714474a7f to your computer and use it in GitHub Desktop.
decode something
function hldsDecrypt()
{
this.decode_table = [
0x5A180000,
0x1A001040,
0x00104000,
0x12401040,
0x40105040,
0x10504000,
0x52401000,
0x40100000,
0x10081000,
0x0A181040,
0x1A184040,
0x18485000,
0x4A500040,
0x50005040,
0x00585000,
0x5A581000
];
}
hldsDecrypt.prototype = {
packet: function(input) {
if (input.length > 0x2A) {
var output = new Buffer(input.length - 0x2A, 'ascii');
input.copy(output, 0, 0x2A, input.length);
return output;
} else {
return (new Buffer(intput.length));
}
},
clean: function (input) {
var output = new Buffer(input.length, 'ascii');
output.fill('\x00');
var c = 0;
var xorbase = input.readUInt8(0);
for (var i = 0; i < input.length; i++) {
c = input.readUInt8(i);
if (i >= 8) {
if (i % 4 == 0 || i % 4 == 3) {
c ^= xorbase;
}
output.writeUInt8(c, i - 8);
}
}
console.log(output);
return output.slice(0, output.length - 8);
},
unclean: function (input, keyin, keyout) {
var output = new Buffer(input.length + 8, 'ascii');
output.fill('\x00');
output.writeUInt32LE(keyout, 0);
output.writeUInt32LE(keyin, 4);
var c = 0;
var xorbase = keyout;
for (var i = 0; i < input.length; i++) {
c = input.readUInt8(i);
if (i % 4 == 0 || i % 4 == 3) {
c ^= xorbase;
}
output.writeUInt8(c & 0xff, i+8);
}
console.log(output);
return output;
},
decode: function (input) {
var output = new Buffer(input.length, 'ascii');
output.fill('\x00');
var dw;
for (var i = 0; i < Math.floor(input.length)/4; i++) {
if (i * 4 + 4 <= input.length) {
dw = input.readUInt32BE(i * 4);
dw ^= this.decode_table[i % this.decode_table.length];
output.writeInt32LE(dw, i * 4);
} else {
console.log('gond lehet');
}
}
console.log(output);
return output;
},
encode: function (input) {
var output = new Buffer(input.length, 'ascii');
output.fill('\x00');
var dw;
for (var i = 0; i < Math.floor(input.length)/4; i++) {
if (i * 4 + 4 <= input.length) {
dw = input.readUInt32LE(i * 4);
dw ^= this.decode_table[i % this.decode_table.length];
output.writeInt32BE(dw, i * 4);
} else {
console.log('gond lehet');
}
}
console.log(output);
return output;
},
};
exports.hldsDecrypt = hldsDecrypt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment