Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Decode Base64 to Windows executable file in ActiveX JavaScript

I'm trying to, with WSH JavaScript, decode a base64 string containing an executable file, and write the EXE to a file. This is the function I have for decoding:

decodeBase64 = function(s) {
    var e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;
    var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    for(i=0;i<64;i++){e[A.charAt(i)]=i;}
    for(x=0;x<L;x++){
        c=e[s.charAt(x)];b=(b<<6)+c;l+=6;
        while(l>=8){((a=(b>>>(l-=8))&0xff)||(x<(L-2)))&&(r+=w(a));}
    }
    return r;
};

It works for the decoding but when I try to write the decoded string to a file, I get an error saying "Invalid procedure call or argument". I suspect that's due to the encoding being wrong. Here's that code:

var FSO = new ActiveXObject("Scripting.FileSystemObject");
var f = FSO.CreateTextFile(Path, true, false);
f.Write(decodeBase64(data));
f.Close();

Now, I know you can make a ADODB.Stream with ISO-8859-1 encoding and read it out as Windows-1252 encoding, but I don't have that in the environment I'm in. Is it possible that there is another way to decode a Base64 string, containing an EXE in JavaScript, in the Windows ANSI encoding then save that to a file? Possibly a way to convert the encoding of the result of the decodeBase64 function to an encoding that I could write as a valid EXE?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!