I also found out how to read unicode, the -1 is for unicode
var openkeys=fso.openTextFile("testtext.txt",1,false,-1);
If I use charCodeAt(0) for a file that starts with hex 41 42 (text for AB)
I get an answer of 16961 = 42 41 (text for BA)
So it kind of pairs them in reverse, so some bit shifting have to be done of if I want to get the bytes.
But if you want to read pure raw data you have to use read(number of bytes/2)
instead of readall()
Example that reads the notepad.exe file in rawdata mode and
shows the hex value of 16 bytes starting on offset 132.
Rename to .hta
Code:
<html>
<head>
<title>Show hex value of data in file</title>
<script>
function Readfile() {
var fso=new ActiveXObject("Scripting.FileSystemObject");
var openkeys=fso.openTextFile("C:\\WINDOWS/NOTEPAD.EXE",1,false,-1);
var buf = openkeys.read(66); // read first 132 bytes
var buf = openkeys.read(8); // read the 16 bytes we want.
var hD='0123456789ABCDEF';
for (var i=0; i<8; i++)
{
var d= buf.charCodeAt(i) & 255; // get the fist 8 bits
if (d<16){document.write('0')};
var h = hD.substr(d&15,1);
while (d>15) {
d>>=4;
h=hD.substr(d&15,1)+h;
}
document.write(h + ' ');
var d= buf.charCodeAt(i)>>8; // get the top 8 bits
if (d<16){document.write('0')};
var h = hD.substr(d&15,1);
while (d>15) {
d>>=4;
h=hD.substr(d&15,1)+h;
}
document.write(h + ' ');
}
openkeys.close()
}
</script>
</head>
<body onLoad="Readfile()">
</body>
</html>