tyranid / dotnettojscript Goto Github PK
View Code? Open in Web Editor NEWA tool to create a JScript file which loads a .NET v2 assembly from memory.
License: GNU General Public License v3.0
A tool to create a JScript file which loads a .NET v2 assembly from memory.
License: GNU General Public License v3.0
This file is part of DotNetToJScript - A tool to generate a JScript which bootstraps an arbitrary .NET Assembly and class. Copyright (C) James Forshaw 2017 DotNetToJScript is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. DotNetToJScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DotNetToJScript. If not, see <http://www.gnu.org/licenses/>. Usage Notes: This only works from full trust JScript(obviously), so should work in scriptlets etc. By default it will only works if v2/v3/v3.5 is installed. However if you specify the '-ver auto' switch when building the output it will also work on v4+ only, however that will introduce a dependency on WScript.Shell which you might not want. To use this you'll need to create an assembly which targets .NET 2 (though in most cases you can also use 3.5 as you don't tend to see .NET 2 installed in isolation. In the assembly implement a class called TestClass which does something you want to do in the public, parameterless constructor. public class TestClass { public TestClass() { /* Start notepad */ Process.Start("notepad.exe"); } } Ensure it's public. Then pass to this tool the path to the .NET assembly. If you annotate the class with the ComVisible attribute you can even interact with the object after it's created. e.g. [ComVisible(true)] public class TestClass { public void DoSomething(string arg) { } } You can change the name of the entry class by using the -c switch and adding the name. You can also get the tool to add additional code to interact with the object by specifying the -s parameter with the path to a text file containing the additional JScript. The created object is named 'o', so for example if you wanted to call the DoSomething method load a file containing: o.DoSomething("SomeArg"); The default mode is to output a JScript file which can be executed in Windows Scripting Host. However if you want a scriptlet pass either -m (for a scriptlet which can be used from a scriptlet moniker) or -u (for a scriptlet which can be used from regsvr32). You can also specify the '-l vba' switch to output a VBA file which should work in Office Macros or '-l vbscript' for VBScript. Finally by default the tool will output to stdout, you can output direct to a file using the -o switch.
.
I wonder how you found the overridden function's real name like GetByteCount_2 for System.Text.ASCIIEncoding.
I'm stuck with this question for years... Can you be my teacher with this question. Thank you sincerely
Hi,
Thanks to your explanations I've managed to get a v4 assembly to get executed through the DotNetToJscript technique.
However, with the exact same assembly (.dll), the JScript version, running in wscript.exe, works perfectly, but the VBA version fails with an unspecified error which I would translate in english to "an exception was raised by the target of a call".
The assembly DLL is compiled this way:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:library /out:dbc2_agent.dll *.cs
This works:
DotNetToJScript.exe --ver=auto -l JScript -c dropboxc2.C2_Agent dbc2_agent.dll > dbc2_agent.js
This fails, using the VBA code in Excel (32 bits if it makes any difference...):
DotNetToJScript.exe --ver=auto -l VBA -c dropboxc2.C2_Agent dbc2_agent.dll > dbc2_agent.vb
Any idea would be helpful.
Thanks !
Hi,
Thank you for sharing this excellent tool and method.
This is not an issue but rather a Request For Information.
Could you please elaborate on why is it required to create an assembly which targets .NET2 and not let's say .NET4 ?
Actually if you have a paper or something explaining the nifty details of how all this works could you point me to it ?
Thanks,
Arno
hi
testing this amazing tool with Vb .net assembly
it loads in memory then the wscipt close directly :/
Not sure if you just didn't get into detail onto why .NET 2 is required, or are still looking into options. Here is some info on how to setup a registration-free .NET 4 COM component with a manifest file.
http://stackoverflow.com/questions/2382927/can-i-use-a-net-4-0-library-in-a-net-2-0-application
Hello! I want to load third party class libraries.?
when pulling from github and loading DotNetToJScript in visual studio and compiling I get the error.
PS C:\Users\misthios\codeplay\pen300\book\chapter4> ./DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=auto -o demo.js
This tool should only be run on v2 of the CLR
my specifications
PS C:\Users\misthios\codeplay\pen300\book\chapter4> $PSVersionTable
>>
Name Value
---- -----
PSVersion 5.1.19041.1682
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1682
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
The error want me to run v2 that is understandable, however there is no immediate resources how to remedy this. Tried installing .NET 3.5 manually that did not work.
However getting the files from release and running it opens up system dialog to install net 3.5. Shouldn't this be the ideal behaviour?
Not able to run DotNetToJScript.exe and create Jscript. I've install .NET v2.0:
PS> $PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.9151
BuildVersion 6.1.7600.16385
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
PS > .\DotNetToJScript.exe
This tool should only be run on v2 of the CLR
OS Version: 10.0.18363 N/A Build 18363
When i build JS from my selected VB.net it doesn't show any error but in the same time it wont work but 33 months ago all was good it's weird.
With larger target binaries (1200KB) observe the above error.
By removing the line splits on the base64 serialized object it is fine - all that string concatenation is bad for cscripts health.
TestClass
put the cs file path as argument or dll file assembled by cs ?
Hello I am attempting to use DotNetToJScript for a project but I am having an issue with getting the ExampleAssembly to actually run calc.exe. I am running DotNetToJScript.exe -o test.js ..\..\..\ExampleAssembly\bin\Debug/ExampleAssembly.dll
and then using wscript test.js
. All of which works without any errors being thrown or any other issue. However calc.exe is never actually run. I ensured that I have DOTNet 3.5 framework selected, and that I have added the NDesk.dll to the references. Any guidance would be much appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.