'node base64 decode incorrect in windows10
Exec the code use nodejs v16 or v18 in windows10(10.0.19044)
const content = 'c21hcnQgc2l6aW5nOmk6MQ1hZG1pbmlzdHJhdGl2ZSBzZXNzaW9uOmk6MA1zY3JlZW4gbW9kZSBpZDppOjENZGVza3RvcHdpZHRoOmk6MjE5NA1kZXNrdG9waGVpZ2h0Omk6MTIzNA1mdWxsIGFkZHJlc3M6czoxMjcuMC4wLjE6OTQ3Nw1yZWRpcmVjdGNsaXBib2FyZDppOjANYXV0b3JlY29ubmVjdGlvbiBlbmFibGVkOmk6MQ1kcml2ZXN0b3JlZGlyZWN0OnM6RHluYW1pY0RyaXZlcw1jb25uZWN0aW9uIHR5cGU6aToxDWF1dGhlbnRpY2F0aW9uIGxldmVsOmk6MA1hbGxvdyBmb250IHNtb290aGluZzppOjE='
console.log(
Buffer.from(content).toString()
)
// output: allow font smoothing:i:1icDrives
But the correct result should be:
window.atob('c21hcnQgc2l6aW5nOmk6MQ1hZG1pbmlzdHJhdGl2ZSBzZXNzaW9uOmk6MA1zY3JlZW4gbW9kZSBpZDppOjENZGVza3RvcHdpZHRoOmk6MjE5NA1kZXNrdG9waGVpZ2h0Omk6MTIzNA1mdWxsIGFkZHJlc3M6czoxMjcuMC4wLjE6OTQ3Nw1yZWRpcmVjdGNsaXBib2FyZDppOjANYXV0b3JlY29ubmVjdGlvbiBlbmFibGVkOmk6MQ1kcml2ZXN0b3JlZGlyZWN0OnM6RHluYW1pY0RyaXZlcw1jb25uZWN0aW9uIHR5cGU6aToxDWF1dGhlbnRpY2F0aW9uIGxldmVsOmk6MA1hbGxvdyBmb250IHNtb290aGluZzppOjE=')
// output: smart sizing:i:1\radministrative session:i:0\rscreen mode id:i:1\rdesktopwidth:i:2194\rdesktopheight:i:1234\rfull address:s:127.0.0.1:9477\rredirectclipboard:i:0\rautoreconnection enabled:i:1\rdrivestoredirect:s:DynamicDrives\rconnection type:i:1\rauthentication level:i:0\rallow font smoothing:i:1
Solution 1:[1]
The string is decoding correctly, if you assign the value to a variable and inspect it you can see your expected output. The issue here is what is being displayed in the console, this is being caused by the string having special characters which are being parsed.
The problem is \r - this is the sequence for a Carriage Return
You would need to escape the values for the string to fully display as you expect, there's a couple of different ways you can do this:
Using JSON.stringify as a quick way to escape the full string:
const content = "c21hcnQgc2l6aW5nOmk6MQ1hZG1pbmlzdHJhdGl2ZSBzZXNzaW9uOmk6MA1zY3JlZW4gbW9kZSBpZDppOjENZGVza3RvcHdpZHRoOmk6MjE5NA1kZXNrdG9waGVpZ2h0Omk6MTIzNA1mdWxsIGFkZHJlc3M6czoxMjcuMC4wLjE6OTQ3Nw1yZWRpcmVjdGNsaXBib2FyZDppOjANYXV0b3JlY29ubmVjdGlvbiBlbmFibGVkOmk6MQ1kcml2ZXN0b3JlZGlyZWN0OnM6RHluYW1pY0RyaXZlcw1jb25uZWN0aW9uIHR5cGU6aToxDWF1dGhlbnRpY2F0aW9uIGxldmVsOmk6MA1hbGxvdyBmb250IHNtb290aGluZzppOjE="
console.log(JSON.stringify(Buffer.from(content, 'base64').toString()))
//output: "smart sizing:i:1\radministrative session:i:0\rscreen mode id:i:1\rdesktopwidth:i:2194\rdesktopheight:i:1234\rfull address:s:127.0.0.1:9477\rredirectclipboard:i:0\rautoreconnection enabled:i:1\rdrivestoredirect:s:DynamicDrives\rconnection type:i:1\rauthentication level:i:0\rallow font smoothing:i:1"
Or, replacing the special characters using String.prototype.replaceAll():
const content = "c21hcnQgc2l6aW5nOmk6MQ1hZG1pbmlzdHJhdGl2ZSBzZXNzaW9uOmk6MA1zY3JlZW4gbW9kZSBpZDppOjENZGVza3RvcHdpZHRoOmk6MjE5NA1kZXNrdG9waGVpZ2h0Omk6MTIzNA1mdWxsIGFkZHJlc3M6czoxMjcuMC4wLjE6OTQ3Nw1yZWRpcmVjdGNsaXBib2FyZDppOjANYXV0b3JlY29ubmVjdGlvbiBlbmFibGVkOmk6MQ1kcml2ZXN0b3JlZGlyZWN0OnM6RHluYW1pY0RyaXZlcw1jb25uZWN0aW9uIHR5cGU6aToxDWF1dGhlbnRpY2F0aW9uIGxldmVsOmk6MA1hbGxvdyBmb250IHNtb290aGluZzppOjE="
console.log(Buffer.from(content, 'base64').toString().replaceAll('\r','\\r'))
//output: smart sizing:i:1\radministrative session:i:0\rscreen mode id:i:1\rdesktopwidth:i:2194\rdesktopheight:i:1234\rfull address:s:127.0.0.1:9477\rredirectclipboard:i:0\rautoreconnection enabled:i:1\rdrivestoredirect:s:DynamicDrives\rconnection type:i:1\rauthentication level:i:0\rallow font smoothing:i:1
Same as above but using RegEx:
const content = "c21hcnQgc2l6aW5nOmk6MQ1hZG1pbmlzdHJhdGl2ZSBzZXNzaW9uOmk6MA1zY3JlZW4gbW9kZSBpZDppOjENZGVza3RvcHdpZHRoOmk6MjE5NA1kZXNrdG9waGVpZ2h0Omk6MTIzNA1mdWxsIGFkZHJlc3M6czoxMjcuMC4wLjE6OTQ3Nw1yZWRpcmVjdGNsaXBib2FyZDppOjANYXV0b3JlY29ubmVjdGlvbiBlbmFibGVkOmk6MQ1kcml2ZXN0b3JlZGlyZWN0OnM6RHluYW1pY0RyaXZlcw1jb25uZWN0aW9uIHR5cGU6aToxDWF1dGhlbnRpY2F0aW9uIGxldmVsOmk6MA1hbGxvdyBmb250IHNtb290aGluZzppOjE="
console.log(Buffer.from(content, 'base64').toString().replace(/[\n\r]/g, '\\r'))
//output: smart sizing:i:1\radministrative session:i:0\rscreen mode id:i:1\rdesktopwidth:i:2194\rdesktopheight:i:1234\rfull address:s:127.0.0.1:9477\rredirectclipboard:i:0\rautoreconnection enabled:i:1\rdrivestoredirect:s:DynamicDrives\rconnection type:i:1\rauthentication level:i:0\rallow font smoothing:i:1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
