Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic code execution on WinRT in Windows 8 (either C++ or .NET/C#)?

Does WinRT under windows 8 metro allow you to dynamically load and execute code? For example, is it possible to download a dll into memory or to isolated storage and run code from it? Could code that JIT compiles a scripting language to native assembly language (e.g. third party browsers) be able to do the same in WinRT, or is it prohibited as an "unsafe" operation?

Is the answer to this question different for "managed" code running in WinRT? For example, in managed code, could you download an assembly from the internet and have it be discoverable in MEF or otherwise be able to load it at runtime? Can you use Reflection.Emit in some form? In C++, can you run assembly code generated at runtime by your application, or dynamically load a DLL at runtime (presumably some form of WinRT DLL)?

like image 210
Jeremy Bell Avatar asked Sep 19 '11 15:09

Jeremy Bell


People also ask

What is C# WinRT?

C#/WinRT is a NuGet-packaged toolkit that provides Windows Runtime (WinRT) projection support for the C# language. A projection assembly is an interop assembly, which enables programming WinRT APIs in a natural and familiar way for the target language.

What is WinRT?

Windows Runtime (WinRT) is a platform-agnostic component and application architecture first introduced in Windows 8 and Windows Server 2012 in 2012.

What are WinRT apps?

WinRT applications are applications that use Windows Runtime framework. More specifically, these are Windows Store and Universal Windows Platform (UWP) applications. Note that dotTrace is unable to profile a UWP application if it uses . NET native tool chain.


3 Answers

You question is a bit unclear... so some general pointers:

  • .NET app using among other things WinRT (but NOT the new UI model!)
    In this case everything is possible that you today (perhaps not OLEDB) but Reflection etc.

  • .NET app built for Metro UI
    AFAIK this is not possible (see http://blogs.microsoft.co.il/blogs/sasha/archive/2011/09/17/metro-net-framework-profile-windows-tailored.aspx and http://tirania.org/blog/) at least as long as you want to sell via Windows Store... outside of this scope (Windows Store) there might some tricks to circumvent that restriction as already demonstrated by some... but I wouldn't count on that... MAYBE you can use some JavaScript (eval etc.) to do something dynamic but I am not sure currently

like image 72
Yahia Avatar answered Sep 23 '22 18:09

Yahia


Windows 10 adds the codeGeneration capability for this purpose. This allows the functions VirtualAllocFromApp and VirtualProtectFromApp to be used in WinRT apps as VirtualAlloc and VirtualProtect would be used in Win32.

like image 36
user5391644 Avatar answered Sep 25 '22 18:09

user5391644


In general, you cannot load and execute new code in a Metro style app. What you can access is what you ship with the app.

LoadLibrary and GetProcAddress are missing so C++ can't dynamically load code.
Likewise, C# cannot because there is no Assembly.Load.
JavaScript can, but only in the web container and not in the fuller trust portions of the code.

The reason for all this is that the store's security/malware protection would be moot if an app could just load and run arbitrary code.

like image 27
Steve Rowe Avatar answered Sep 25 '22 18:09

Steve Rowe