News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Really Bizarre Question

Started by Zen, July 13, 2013, 03:40:36 AM

Previous topic - Next topic

GoneFishing

#15
Zen,

First of all, I'd like to thank you for your encouraging words!
Now I want to show you some more results of my work ...

you wrote:
QuoteI was thinking that the NET Framework member functions could be used in much the same way as JAPHETH does with his COM interfaces COM and Assembly, essentially by addressing the COM Virtual Table, using simple addressing.

Here's the sequence of calls for obtaining the pointer to virtual functions table of _AppDomain interface which
exposes the public members of the System.AppDomain class to unmanaged code.
   invoke CLRCreateInstance,addr CLSID_CLRMetaHost,addr IID_ICLRMetaHost,addr  ppvICLRMetaHost
    ...
    ICLRMetaHost GetRuntime,pszVersion,addr IID_ICLRRuntimeInfo,addr  ppvICLRRuntimeInfo
    ...
    ICLRRuntimeInfo IsLoadable,addr fLoadable
    ...
    ICLRRuntimeInfo GetInterface, addr CLSID_CorRuntimeHost,addr IID_CorRuntimeHost , addr ppvICorRuntimeHost     
    ...
    ICorRuntimeHost Start
    ...
    ICorRuntimeHost GetDefaultDomain,addr  ppvIUnknown       
    ...
    IUnknown QueryInterface,addr IID_AppDomain ,addr  ppvIAppDomain



So now  we have a pointer to IAppDomain and we can use any of its functions( see dump of virtual functions table below ( to dump it yourself you should uncomment lines 39 and 80 of RuntimeHostV4Demo1.ASM , change MAKEIT.BAT to include symbolic info into the executable and  rebuild all)).
WinDbg's command window line:
dt -b  AsmHostCLR!vftAppDomain
and its output:
+0x000 QueryInterface   : (null)
   +0x004 AddRef           : (null)
   +0x008 Release          : (null)
   +0x00c GetTypeInfoCount : (null)
   +0x010 GetTypeInfo      : (null)
   +0x014 GetIDsOfNames    : (null)
   +0x018 renamed_Invoke   : (null)
   +0x01c get_ToString     : (null)
   +0x020 Equals           : (null)
   +0x024 GetHashCode      : (null)
   +0x028 GetType          : (null)
   +0x02c InitializeLifetimeService : (null)
   +0x030 GetLifetimeService : (null)
   +0x034 get_Evidence     : (null)
   +0x038 add_DomainUnload : (null)
   +0x03c remove_DomainUnload : (null)
   +0x040 add_AssemblyLoad : (null)
   +0x044 remove_AssemblyLoad : (null)
   +0x048 add_ProcessExit  : (null)
   +0x04c remove_ProcessExit : (null)
   +0x050 add_TypeResolve  : (null)
   +0x054 remove_TypeResolve : (null)
   +0x058 add_ResourceResolve : (null)
   +0x05c remove_ResourceResolve : (null)
   +0x060 add_AssemblyResolve : (null)
   +0x064 remove_AssemblyResolve : (null)
   +0x068 add_UnhandledException : (null)
   +0x06c remove_UnhandledException : (null)
   +0x070 DefineDynamicAssembly : (null)
   +0x074 DefineDynamicAssembly_2 : (null)
   +0x078 DefineDynamicAssembly_3 : (null)
   +0x07c DefineDynamicAssembly_4 : (null)
   +0x080 DefineDynamicAssembly_5 : (null)
   +0x084 DefineDynamicAssembly_6 : (null)
   +0x088 DefineDynamicAssembly_7 : (null)
   +0x08c DefineDynamicAssembly_8 : (null)
   +0x090 DefineDynamicAssembly_9 : (null)
   +0x094 CreateInstance   : (null)
   +0x098 CreateInstanceFrom : (null)
   +0x09c CreateInstance_2 : (null)
   +0x0a0 CreateInstanceFrom_2 : (null)
   +0x0a4 CreateInstance_3 : (null)
   +0x0a8 CreateInstanceFrom_3 : (null)
   +0x0ac Load             : (null)
   +0x0b0 Load_2           : (null)
   +0x0b4 Load_3           : (null)
   +0x0b8 Load_4           : (null)
   +0x0bc Load_5           : (null)
   +0x0c0 Load_6           : (null)
   +0x0c4 Load_7           : (null)
   +0x0c8 ExecuteAssembly  : (null)
   +0x0cc ExecuteAssembly_2 : (null)
   +0x0d0 ExecuteAssembly_3 : (null)
   +0x0d4 get_FriendlyName : (null)
   +0x0d8 get_BaseDirectory : (null)
   +0x0dc get_RelativeSearchPath : (null)
   +0x0e0 get_ShadowCopyFiles : (null)
   +0x0e4 GetAssemblies    : (null)
   +0x0e8 AppendPrivatePath : (null)
   +0x0ec ClearPrivatePath : (null)
   +0x0f0 SetShadowCopyPath : (null)
   +0x0f4 ClearShadowCopyPath : (null)
   +0x0f8 SetCachePath     : (null)
   +0x0fc SetData          : (null)
   +0x100 GetData          : (null)
   +0x104 SetAppDomainPolicy : (null)
   +0x108 SetThreadPrincipal : (null)
   +0x10c SetPrincipalPolicy : (null)
   +0x110 DoCallBack       : (null)
   +0x114 get_DynamicDirectory : (null)


Also many of the mscorelib classes exposed to unmanaged code can be used through IDispatch interface methods .Though I didn't try it yet .

Now a few words about the attachment.
I tried to translate to MASM this CPP project :C++ app hosts CLR 4 and invokes .NET assembly (CppHostCLR)
I used headinc utility (by ToutEnMasm) to partly translate metahost.h to include format. Also I use his <Interface> macro.
I've preserved almost all the CPP comments and included the original Documentation  folder into the attachment .
Once again:
NB: It requires  .NET Framework 4  to run / build it! .
It was tested under Windows 7 32 bit only.

Zen,
Thank you for the  good idea. I've been working on it almost all this month. In fact, sometimes it took me 2-3 days to figure out what's wrong in a single line of code .

Have fun!

P.S. I also like libraries   :t

EDIT: added AsmHostCLRv2  for .NET Framework  2.0.50727.
It contains only two demo out of three in AsmHostCLR  for .NET Framework 4.0.30319 because in-process side-by-side hosting is not supported in v2.




EDIT: attachments are temporary removed


dedndave

good job !   :t

we have all wondered about writing .NET code
i guess we were too lazy to figure it out - lol

i am running XP Media Center Edition 2005
it is not compatible with .NET 4.0
well - i can disable certain MCE features and make .NET 4.0 work ok
but - i haven't had the time to figure out if i can switch on the fly
so, my current build only has .NET 3.5 and below

GoneFishing

Thanks , Dave !

Try AsmHostCLRv2 . It runs on .NET 2.0

dedndave

yes - that one works fine   :t

qWord

nice, even if it is in its infancy  :t
MREAL macros - when you need floating point arithmetic while assembling!

Zen

VERTOGRAD,   
It's amazing that you were able to create an assembly language project that is able to determine whether the NET Framework is installed on the user's computer.
I've had a number of thoughts in the aftermath, and, I was wondering if you could clarify.

  • You supplied all the assembly code for the demo,...but, did you compile the executable with Visual Studio or MASM ???
  • I found this listing over at MSDN of all the useful utilities that are included with a NET Framework installation: Build, Deployment, and Configuration Tools (.NET Framework). As I recall from the days when the NET Framework was first released,...one of the principle objections from most programmers considering coding applications with the NET Framework instead of the existing Win32 APIs was that you could simply open the NET Framework assembly with Ildasm.exe (MSIL Disassembler),...and, you could read all the code as if it was the original source. Does the application you wrote open with Ildasm.exe ???
  • Reading the source code that you provided,...I got the distinct impression that you are a C# programmer,...is this correct ???
  • When I was originally learning how to write applications with the NET Framework,...Microsoft had just released version 1. The NET Framework was promoted as a huge improvement for language interoperability and for secure website development. However, the initial release was incomplete, and difficult for programnmers to learn (in terms of syntax). Do you think the latest version is adequate for the development of secure web sites ???

...And, finally,...do you think we should have a HUGE, WILD PARTY,...to celebrate your accomplishment ???   :dazzled:
Zen

GoneFishing

#21
Zen,

I'll try to answer all your questions:

  • I compiled those executables with  ML.EXE 6.14 from MASM32 package. Please, see MAKEIT.BAT for  command lines .
  • As you can see on the picture this executable cannot be opened with .NET disassembler ILDASM. EnumRuntimes is written in native APIs and calls CLR  internally
  • if you're speaking about  C# source code of managed class libraries from :C++ app hosts CLR 4 and invokes .NET assembly (CppHostCLR) project ... I didn't change a single byte in them. Really, I'm not  a  C# programmer ... I'm not a programmer at all . It's my hobby to write a few lines of asm code for fun and self-improvement.
  • QuoteDo you think the latest version is adequate for the development of secure web sites ???
    This is the question that I leave unanswered  because of lack of knowledge and experience in that field.


Recently I've read online a book of Steven Pratschner "Customizing the Microsoft® .NET Framework Common Language Runtime".
From Foreword:
QuoteIn October 1999, someone I knew at Microsoft asked me if I would do some consulting work on the Microsoft .NET Framework team. At that time, I knew very little about the .NET Framework, but what I did know impressed me quite a bit, and I immediately joined the team.

At that time, the .NET Framework was internally called COM+ 2.0. But Microsoft knew that this new way of programming deserved a better name than that. Before its first release, the .NET Framework had many other names. One code name was "Lightning."
Did you notice an icon of ILDASM on the picture?   ;)


Quote...And, finally,...do you think we should have a HUGE, WILD PARTY,...to celebrate your accomplishment ???

That sounds good ... but I'm afraid I know nothing about parties    (except one called "A Mad Tea Party")

I'm currently working on ASP.NET part of your initial question. 
It may take me some time to post an example of hosting ASP.NET runtime .


dedndave


GoneFishing

#23
Later I'll figure out what I was doing wrong    ;)
I'll think about it tomorrow  :biggrin:

Dave:
        How did you manage to get a picture of me?  :biggrin:

EDIT: That's it


dedndave

i hope that's a $1.00 bill - can't afford $100   :lol:
i also hope she plans on washing that towel when she's done

Zen

VERTOGRAD, 
Hey, thanks for taking the time to answer those questions. So, it really is an unmanaged code application.   
Seeing as how you have accomplished the near-impossible,...I have alot more complex stuff bouncing around in my mind,...
BUT,...I'm NOT going to ask, because, you are fearless,...you will try to code a demo,...and, we'll never hear from you again !!!  :bgrin:

By the way, AsmHostCLRv2  for .NET Framework  2.0.50727 works correctly on the public terminal in a public library (somewhere in California).

You've opened the door, though,...we know it's possible (even if it is insanely complex),...and, other assembly programmers will go where no assembly programmer has gone before.
Zen

Farabi

Quote from: dedndave on August 22, 2013, 05:16:59 AM
i hope that's a $1.00 bill - can't afford $100   :lol:
i also hope she plans on washing that towel when she's done

Ahem, dave. That is mean I will stick to my new wife for a long time. :greensml:
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Paulo

Quote from: dedndave on August 22, 2013, 05:16:59 AM
i also hope she plans on washing that towel when she's done

Judging by the look on her face, I suspect there was a lot of flux residue on the towel.  :biggrin:

Apologies to all for hijacking the thread.

Zen

PAULO,   
Quote from: PAULOApologies to all for hijacking the thread.
No problem,...we all hijack DAVE's threads all the time.  :icon_redface:
Zen