<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4112968733264573929</id><updated>2011-04-21T19:34:21.563-07:00</updated><category term='CLR'/><category term='Silverlight'/><title type='text'>techgeek</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://clrguru.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://clrguru.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Geek</name><uri>http://www.blogger.com/profile/07701267786710741438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4112968733264573929.post-1140138831115221605</id><published>2009-02-19T02:19:00.000-08:00</published><updated>2009-02-19T23:15:40.960-08:00</updated><title type='text'>Taming CoreClr - 3</title><content type='html'>Remember mscorlib.dll Assembly must be in same folder of coreclr.dll.&lt;br /&gt;Ok, Now CLR is up what Next!&lt;br /&gt;We have to create new Appdomain where we can execute our code.&lt;br /&gt;Signature for New Appdomain create method:&lt;br /&gt;&lt;font style="font-size:11px;" color='#5588aa'&gt;&lt;br /&gt;virtual HRESULT STDMETHODCALLTYPE InitializeAppdoamin(&lt;br /&gt;           /* [in] */ LPCWSTR pwzAppdomainname,&lt;br /&gt;           /* [in] */ DWORD pwzUnknown,&lt;br /&gt;           /* [in] */ LPCWSTR pwzManagerAssemblyName,LPCWSTR pwzMAppdomainmanagerName,&lt;br /&gt;   DWORD pwzUnknown2,&lt;br /&gt;           /* [in] */ LPCWSTR* appdomainSetup,LPCWSTR* activationData,&lt;br /&gt;           /* [out] */ DWORD *appDomainID) = 0;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;First parameter (pwzAppdomainname) can be any name you like.&lt;br /&gt;Second parameter (pwzUnknown) is unknown as I don't know its purpose but it should be 13 always to get work. Third parameter is Assembly name where Assembly manager class is defined. Remember if you want to use your own Assembly Manager compile the assembly as Silverlight assembly (Remove reference of mscorlib from project and add explicitly reference of mscorlib of Silverlight).pwzMAppdomainmanagerName is fourth parameter and should be name of manager class.pwzUnknown2 is again unknown but it should be 5 everytime. Sixth parameter (AppdomainSetup) is data to setup the Appdomain. ActivationData is data required by CLR to initialize and setup security policies etc, such as the manifest file name where list of files to be loaded by CLR is given etc. appDomainID will contain ID of new Appdomain.&lt;br /&gt;&lt;br /&gt;full example&lt;br /&gt;&lt;font style="font-size:11px;" color='#5588aa'&gt;&lt;br /&gt; LPCWSTR* appdomainSetup = new LPCWSTR[4];&lt;br /&gt; LPCWSTR* activationData = new LPCWSTR[4];&lt;br /&gt; appdomainSetup[0] = L"TRUSTEDPATH";&lt;br /&gt; appdomainSetup[1] = L"VERSIONING_MANIFEST_BASE";&lt;br /&gt; appdomainSetup[2] = L"MANIFEST_FILE_PATH";&lt;br /&gt; appdomainSetup[3] = L"LOADER_OPTIMIZATION";&lt;br /&gt; appdomainSetup[4] = L"LOCATION_URI";&lt;br /&gt; activationData[0] = L"..\\Debug";&lt;br /&gt; activationData[1] = L"default:\"..\\Debug\"";&lt;br /&gt; activationData[2] = L"..\\slr.dll.managed_manifest";&lt;br /&gt; activationData[3] = L"SingleDomain";&lt;br /&gt; activationData[4] = L"file://../Debug";&lt;br /&gt; a1 = pCLR-&gt;InitializeAppdoamin(L"AppDomain",13,&lt;br /&gt;                                        L"System.Windows.Browser, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",&lt;br /&gt;                                        L"System.Windows.Hosting.HostAppDomainManager",5, appdomainSetup,activationData,&lt;br /&gt;                                        &amp;appDomainID&lt;br /&gt;                                        );&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://cid-aa19c70bada7ee20.skydrive.live.com/self.aspx/public%20folder/ISilverlightCLRRuntimeHost.h"&gt;Here&lt;/a&gt; is link to get ISilverlightCLRRuntimeHost interface.&lt;br /&gt;Only few methods will work rest are not implemented in coreclr.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4112968733264573929-1140138831115221605?l=clrguru.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clrguru.blogspot.com/feeds/1140138831115221605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clrguru.blogspot.com/2009/02/taming-coreclr-concluding.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default/1140138831115221605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default/1140138831115221605'/><link rel='alternate' type='text/html' href='http://clrguru.blogspot.com/2009/02/taming-coreclr-concluding.html' title='Taming CoreClr - 3'/><author><name>Geek</name><uri>http://www.blogger.com/profile/07701267786710741438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4112968733264573929.post-7007378686747747299</id><published>2009-02-02T22:50:00.000-08:00</published><updated>2009-02-03T00:32:31.814-08:00</updated><title type='text'>Taming CoreClr Part-2</title><content type='html'>Hope you did not get bore with first blog of this series :)&lt;br /&gt;&lt;br /&gt;I will be more technical going forward with code samples.&lt;br /&gt;After successfully getting the Guid for CoreClr it was time to host CoreClr in custom host.&lt;br /&gt;here is the code for it..&lt;br /&gt;&lt;br /&gt;HMODULE clrmodule = LoadLibrary (TEXT ( "..//Coreclr.dll"));&lt;br /&gt;GetCLRRuntimeHost _clrMethod; &lt;br /&gt;_clrMethod = (GetCLRRuntimeHost)GetProcAddress( clrmodule , "GetCLRRuntimeHost" );&lt;br /&gt;&lt;br /&gt;You will be eager to know the signature of GetCLRRuntimeHost.&lt;br /&gt;&lt;br /&gt;typedef int (__stdcall *GetCLRRuntimeHost)(const IID  &amp;CLRGUID,PVOID* clrHost);&lt;br /&gt;&lt;br /&gt;We got the method handler(method pointer).&lt;br /&gt;Let us get the SilverlightCLR now:&lt;br /&gt;&lt;br /&gt;ISilverlightCLRRuntimeHost *pCLR = NULL;&lt;br /&gt;HRESULT a = _clrMethod(CLRGUID,(PVOID*) &amp;pCLR);&lt;br /&gt;&lt;br /&gt;One of the main question is still unanswered definition of ISilverlightCLRRuntimeHost?&lt;br /&gt;&lt;br /&gt;As told earlier initial thought was it should be similar to (or same) ICLRRuntimeHost.&lt;br /&gt;I used same interface and tried to call ExecuteApplication.&lt;br /&gt;boom!!!! it crashed.&lt;br /&gt;tried calling Start() again failed...with -2146234334 error code, HOST_E_INVALIDOPERATION.&lt;br /&gt;Tried other methods from ICLRRuntimeHost but none worked.&lt;br /&gt;So again i decided to debug Silverlight with IDA.&lt;br /&gt;After taking the CLRHOST interface pointer they are making a call to&lt;br /&gt;call    eax //ECX+38h&lt;br /&gt;&lt;br /&gt;where ECX is pointing to the vptr of coreclr object.&lt;br /&gt;Now if i calculate 38h it becomes 12th method of interface,&lt;br /&gt;here was a catch.. ICLRRuntimeHost only has 9 methods.&lt;br /&gt;So it clears that SilverlightCLRRuntime host interface is having additional methods.&lt;br /&gt;This method takes two parameters of int type &lt;br /&gt;&lt;br /&gt;pCLR-&gt;Magic(2483181568,29805167);&lt;br /&gt;&lt;br /&gt;I called this method Magic because the reason was not known for this call.&lt;br /&gt;After making this call again i tried pCLR-&gt;Start()&lt;br /&gt;&lt;br /&gt;bingo CLR was up :)&lt;br /&gt;&lt;br /&gt;to be concluded.......&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4112968733264573929-7007378686747747299?l=clrguru.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clrguru.blogspot.com/feeds/7007378686747747299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clrguru.blogspot.com/2009/02/taming-coreclr-part-2.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default/7007378686747747299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default/7007378686747747299'/><link rel='alternate' type='text/html' href='http://clrguru.blogspot.com/2009/02/taming-coreclr-part-2.html' title='Taming CoreClr Part-2'/><author><name>Geek</name><uri>http://www.blogger.com/profile/07701267786710741438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4112968733264573929.post-6169000080585584800</id><published>2009-01-27T21:03:00.000-08:00</published><updated>2009-01-27T22:19:36.102-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><category scheme='http://www.blogger.com/atom/ns#' term='CLR'/><title type='text'>Taming Coreclr Part-1</title><content type='html'>This is my life's first blog so kindly bear me for mistakes.&lt;br /&gt;CLR fascinates me since beginning. It is the virtual platform to execute managed code.&lt;br /&gt;When i saw the silverlight executing managed code inside the browser, it really thrilled me.&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb404713(VS.95).aspx"&gt;Silerlight &lt;/a&gt;is made up of three main components:&lt;br /&gt;1.AgCore.dll&lt;br /&gt;2.NpCtrl.dll &lt;br /&gt;3.Coreclr.dll&lt;br /&gt;&lt;br /&gt;NpCtrl is a NP plugin for browsers. So whenever browser loads a page having XAP refrences, NpCtrl is loaded. As per the my research this plugin then loads the AgCore which is the main Silverlight unmanaged execution engine. &lt;br /&gt;AgCore (Ag is symbol of silver in periodic table) is responsible for rendering the contents. if the xap has any Msil references or MSIL code, AgCore asks NpCtrl to load CoreClr. I am not sure about this indirection, as AgCore can itself load the CoreClr but it asks NpCtrl to load the CoreClr.&lt;br /&gt;&lt;br /&gt;Dissecting the CoreClr:&lt;br /&gt;CoreClr.dll is unmanaged COM library which is self contained and full CIL execution system(EE,GC etc). Microsoft has not released publicly interfaces and API's supported by CoreClr. So i took a side approach to reverse engineer the CoreClr.&lt;br /&gt;I opened the coreclr with PE explorer and here are the public exports:&lt;br /&gt;1. g_CLREngineMetrics&lt;br /&gt;2. GetCLRRuntimeHost&lt;br /&gt;&lt;br /&gt;As the name suggests second export should be used to get the CLRRuntimeHost handle. As its big brother(CLR) usage interface ICLRRuntimeHost for providing the hosting capabilities. To know more about Hosting CLR i recommend read &lt;a href="http://www.amazon.com/Customizing-Microsoft-Framework-Language-Runtime/dp/0735619883"&gt;Customizing the Microsoft .NET Framework Common Language Runtime by Steven Pratschner&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;GetCLRRuntimeHost expects two parameters, one is the GUID for CLRRuntimeHost and second is pointer to pointer to CLRHOST interface which i initial thought is ICLRRuntimeHost type (but it did not). So biggest challenge was to get the GUID for CLRHOST. I disassemble the coreclr using my old time friend &lt;a href="http://www.hex-rays.com/idapro/"&gt;IDA PRO&lt;/a&gt;. I used GuidFinder a plugin for IDA but it was not able to find any GUID. So i adopted another approach, I created a plugin for firefox a general purpose plugin for txt extensions. So what this plugin does, It loads coreclr explicitly and used &lt;a href="http://research.microsoft.com/en-us/projects/detours/"&gt;Detour&lt;/a&gt; to intercept calls made to GetCLRRuntimeHost. So i think you got how i managed to find GUID for CoreCLRHost.&lt;br /&gt;Here is CoreCLR guid&lt;br /&gt;&lt;br /&gt;EXTERN_GUID(CLRGUID,&lt;br /&gt;0x712AB73F, 0x2C22,0x4807, 0xAD, 0x7E, 0xF5, 0x01, 0xD7, 0xB7, 0x2C, 0x2D)&lt;br /&gt;&lt;br /&gt;I called it CLRGUID.&lt;br /&gt;&lt;br /&gt;Rest in next blog.. I will appreciate if you provide any feedback :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4112968733264573929-6169000080585584800?l=clrguru.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://clrguru.blogspot.com/feeds/6169000080585584800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://clrguru.blogspot.com/2009/01/taming-coreclr-part-1.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default/6169000080585584800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4112968733264573929/posts/default/6169000080585584800'/><link rel='alternate' type='text/html' href='http://clrguru.blogspot.com/2009/01/taming-coreclr-part-1.html' title='Taming Coreclr Part-1'/><author><name>Geek</name><uri>http://www.blogger.com/profile/07701267786710741438</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>
