hemisemidemipresent / NKsku

A multi-purpose library for decrypting Profile.save and other data, as well as making valid requests to NK's server
https://www.npmjs.com/package/nksku
13 stars 2 forks source link

Broken DGDATA hashing #2

Closed ghost closed 2 years ago

ghost commented 2 years ago

Issue is located at loc2 = data.charCodeAt(loc6);, meanwhile loc6 is always zero.

Proposed fix:

hash: function (data) {
      var loc2 = 0;
      var loc3 = 0;
      var loc7 = new Uint32Array(1);

      for (var loc6 = 0; loc6 < data.length; loc6++) {
          loc2 = data.charCodeAt(loc6);
          loc3 = (loc7[0] ^ loc2) & 255;
          loc7[0] = ((loc7[0] >> 8) & 16777215) ^ module.exports.secondHash(loc3);
      }
      if (loc7[0] < 0) {
          loc7[0] = 4294967295 + loc7[0] + 1;
      }
      var loc4 = loc7[0].toString(16);
      while (loc4.length < 8) {
          loc4 = '0' + loc4;
      }
      return loc4;
  }
hemisemidemipresent commented 2 years ago

in what situation does this come up?

ghost commented 2 years ago

For encoding SAS 4 (Steam) Profile.save. You could try to decode & encode again and see the hash is mismatched.

hemisemidemipresent commented 2 years ago

Thanks, if there's anything else feel free to re-open this issue or create a new one