flat assembler
Message board for the users of flat assembler.

Index > Windows > Calling Javascript From Assembly

Author
Thread Post new topic Reply to topic
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_
I've been trying to look into calling javascript from assembly, for example, say a .js file had a function "Hello()" i would like to call the Hello function from assembly, but I'm at a loss of where to start as I'm not sure what to search for, I've been looking on and off for a few days and found nothing.

I remember a long time ago (Not sure how long) i saw an example of calling vbscript from assembly on this forum, I've searched for it but could not find it. I figure it can't be much different to call javascript than vbscript, right?

Could someone point me in the right direction on what to search for please? A link to the MSDN or to the post i mentioned would be great, but even a keyword to search for would be good. Thanks in advance for any help.

Edit: I found the post after another search: http://board.flatassembler.net/topic.php?t=8320

Ill edit again in a while updating anything i find.
Post 22 Mar 2009, 12:52
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
You will need to work with the Windows Script Host. Probably implement a whole bunch of COM interfaces - a job well suited for C++, not asm.

It looks like the post you mentioned, and asmhack's example already does all that. As you can see he has lots of mundane lines of code that don't do much - let C++ do this for you. Save your asm excitement for a real purpose.
Post 22 Mar 2009, 22:41
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I'm curious, what your JavaScript code is for? Is JavaScript available outside of a browser scope?
Post 22 Mar 2009, 22:53
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Here I found something: http://www.codeproject.com/KB/COM/jscalls.aspx

But looks like you need to run it in the context of a web page, is that what are you looking for?
Post 22 Mar 2009, 23:04
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_
My interest is making scriptable events for my programs. My goal is to have a program which will act as a loader for any program and enable me to have a javascript file and functions in it such as "CreateWindowExA(...)" for example, so when the program calls CreateWindowExA, the function in the script will be called, and ill be able to modify parameters before returning back to the program. I'm familiar enough with hooking to do it, i just need to find a way to interact with a scripting language. If anyone uses Messenger Plus! scripting, they'll have an idea of the kind of thing im aiming for. I think you guys are right though, i should use C++ for this because of all the COM stuff would be such a pain to handle in ASM.

Offtopic:
LocoDelAssembly, Javascript is used out of a browser alot, try creating a .js file containing
Code:
WScript.Echo('Test');    
and run it (under windows of course). There are much more interesting things that can be done though, check this out: (it logs your windows xp product key)
Code:
var FSO = new ActiveXObject('Scripting.FileSystemObject');
var File = FSO.GetFile('Product Keys.txt').OpenAsTextStream(8, 0);
var Shell = new ActiveXObject('WScript.Shell');
var Env = Shell.Environment('PROCESS')
var Digits = [
 'B','C','D','F','G','H','J','K',
    'M','P','Q','R','T','V','W','X',
    'Y','2','3','4','6','7','8','9'
], Line = 0;

var DigitalProductId = new VBArray(Shell.RegRead('HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId'));
DigitalProductId = DigitalProductId.toArray();

var ProductId = new Array(15);
for (var i=52; i<=67; i++)
ProductId[i - 52] = DigitalProductId[i];

var dLen = 29, sLen = 15;
var KeyString = '', N, Value=0, HN;
for (i=dLen-1; i>=0; i--) {
  if (((i+1)%6)==0) {
            KeyString = '-' + KeyString;
      } else {
          HN = 0;
             for (N=sLen-1; N>=0; N--) {
                 Value = ((HN*256)|ProductId[N]);
                    ProductId[N] = Math.floor(Value/24);
                        HN = Value%24;
              }
              KeyString = Digits[HN] + KeyString;
 }
}

KeyString += ':' + new Date().toLocaleDateString();
KeyString += ':' + Env('COMPUTERNAME');
KeyString += ':' + Env('USERNAME');

File.Write(KeyString + '\r\n');
File.Close();
    

Note: I didn't originally write that algorithm, i found it in another language a fair while back, cant remember where or what language, and ported it to javascript because you may have noticed i like javascript Razz
Post 23 Mar 2009, 09:03
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Well, my Windows seems to be so screwed that I couldn't make it run. But, trying with the WinXP installed on a VirtualPC all worked great Very Happy

Thanks for the info!

[edit]I fixed the problem with the JS files by adding the "execute" option with "wscript.exe" to the JS extension.
Post 23 Mar 2009, 16:07
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_
No problem. If your anything like me and had a look of these three emoticons ShockedRazzCool mixed together on your face when you found out what javascript can do, maybe you'd be interested in HTML Applications (http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx).

"The power to build HTML Applications (HTAs) brings Microsoft Internet Explorer to the fore as a viable Microsoft Windows development platform. HTAs are full-fledged applications. These applications are trusted and display only the menus, icons, toolbars, and title information that the Web developer creates. In short, HTAs pack all the power of Internet Explorer—its object model, performance, rendering power and protocol support—without enforcing the strict security model and user interface of the browser."

Sorry for my rambling Razz I get a little over-enthusiastic about scripting sometimes (hence wanting to use it with asm Wink)

Oh and just to clarify, im going to try to implement the project i mentioned in a post above in c++ rather than assembly. Thanks.
Post 23 Mar 2009, 20:14
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

Oh and just to clarify, im going to try to implement the project i mentioned in a post above in c++ rather than assembly. Thanks.


If you manage to get a C++ program that calls a JavaScript function post it, I would like to port it to fasm just for fun.
Post 23 Mar 2009, 21:12
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_
Will do. Ill keep you posted.
Post 24 Mar 2009, 03:06
View user's profile Send private message Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
Just a side-note, but if you want to have scripts, why not LUA?
Post 24 Mar 2009, 06:57
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Pinecone_ wrote:
Oh and just to clarify, im going to try to implement the project i mentioned in a post above in c++ rather than assembly. Thanks.


If you're project is C++.. just use this. Smile
Post 01 Apr 2009, 06:12
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.