Vito Plantamura's Blog - VPC Technologies SRL http://www.vitoplantamura.com/blog/ en-us Vito Plantamura Thu, 18 Mar 2010 16:59:30 GMT newtelligence dasBlog 2.3.9074.18820 planta@vitoplantamura.com planta@vitoplantamura.com http://www.vitoplantamura.com/blog/Trackback.aspx?guid=d0e0224b-8917-409d-aaf7-c0bed8b7aa8e http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,d0e0224b-8917-409d-aaf7-c0bed8b7aa8e.aspx http://www.vitoplantamura.com/blog/CommentView,guid,d0e0224b-8917-409d-aaf7-c0bed8b7aa8e.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=d0e0224b-8917-409d-aaf7-c0bed8b7aa8e 1
SmartRM.com is an venture capital-backed service (founded by italian people in the USA) that allows to protect user documents and videos, letting the user to store locally a copy of the encrypted document for easy and secure distribution via email, USB keys etc.

In order to view the original document, the user needs to login into SmartRM and then use a proprietary viewer to open the encrypted PDF, in our test case.

The problem is that the viewer can be easily hacked in order to obtain a copy of the original document, starting from an encrypted version of the document itself.
This is pretty obvious and easy to accomplish, in any case.

The promises of the service are listed in their homepage, and sum up the nature of the application:
  • Alice cannot read the document before tomorrow morning
  • Bob can watch the video only once
  • Everyone can listen to my song for a week
  • Everyone can ask me the permission to open my file
Although the first and the last statements remain allegedly true, a simple viewer hack makes the second and third statements misleading and exposes the user’s sensitive data to an high risk of leakage.

There are 2 “solutions” to this problem:
  • “Security through obscurity”, ie by using “tricks” to complicate the work of an hacker, as Windows Media Player does, for example. But “security through obscurity” is not security, as someone has said, and is a “solution” doomed to failure in the short-term.
  • Completely redesign the security and application model, considering, for example, the idea of storing the user data on a central server, and then serving the content as images or in a streaming way (as SmartRM's competitors do). But in this case there are a lot of other security problems and considerations that need to be taken into consideration… Out of the scope of this demonstration.
This video demonstrates the simple hack:



Technically speaking, the hack proposed in this post is pretty simple: it required only 3 hours to be discovered and developed.

The SmartRM viewer is implemented as a FireFox extension: any time you need to open a document (currently only PDF files are supported by SmartRM), the extension decrypts locally the document, calls a third party PDF library (Quick PDF Library - www.quickpdflibrary.com) passing the original unencrypted version of the document and then the file is showed to the user as a series of images, that the user can only view or, eventually, print, if given the appropriate permission. The PDF rendering job is done by the Quick PDF Library (QuickPDFDLL0717.dll).

The hack, and then the “concept flaw” of the whole idea is simple: it is enough to “intercept” the call from the SmartRM extension to the Quick PDF Library dll to obtain an original, unencrypted version of the PDF.

As said before and considering that having the user's encrypted files stored locally is the main competitive advantage of the service against its competitors, the only remedy to this problem is employing some form of “security through obscurity”, that, as you probably know, is a very short-term solution to the problem and, for a company involved in protecting sensitive data for its clients, is simply a credibility suicide.

As a computer user, some years ago, I remember the case of the live streaming of RealMedia video files (rtsp protocol). The premise of that technology was to allow an internet user to gain access to a video file only through live streaming, without the ability to download and then potentially share the content with other (non-paying) internet users. The response of the internet community was a very smart tool (Streambox VCR) which allowed to “record” a rtsp live stream into a file saved into the user’s hard drive. The response of Real.com was a lawsuit to discontinue the support and distribution of Streambox, making it one of the most famous “underground” tools of that time: people started to reverse engineer Streambox in order to make it up-to-date with the changes in the rtsp protocol… A lawsuit was the only option in this case for RealMedia and this is the point of the whole discussion.

Another (in)famous case was that of the “Sony Rootkit”, intended for copy protection, discovered by Mark Russinovich (search Google for more info).

Windows Media Player, for example, in a typical spirit of “security through obscurity”, doesn’t allow to play DRM-protected files if a debugger is attached to the player’s Windows process… This should stop only the very inexperienced hacker !

As it should be clear, it is impossible to guarantee protection of sensitive data from technological premises like these.

How the hack works (and the Proxy Dll hooking trick)

As said before, the SmartRM extension calls into the QuickPDFDLL0717.dll through its exported functions in order to render a PDF page into a GDI Device Context. The relevant flow of calls into QuickPDFDLL0717.dll is as follow:

QuickPDFCreateLibrary : initializes the library.
QuickPDFUnlockKey : unlocks the library.
QuickPDFCreateBuffer : creates a “buffer”.
QuickPDFAddToBuffer : copies the unencrypted PDF bytes into the buffer.
QuickPDFRenderPageToDC : renders the PDF to a Device Context.


So, simply by intercepting the call to QuickPDFAddToBuffer is enough to get an unencrypted version of the PDF.

As you may already know, there are a lot of systems and tricks to intercept an API call (take a look at my site). The case in question is the most simple: a DLL calling into an other DLL through an exported reference… The most simple interception system is to build a “proxy dll”, ie a module with the same name of the one we want to monitor and, above all, with the exact same exports of the original image (in this case QuickPDFDLL0717.dll), respecting the same calling convention, function names, number and order of parameters, type of each parameter and return value of the original module.

So I downloaded the Quick PDF Library (which includes a C++ SDK) and found 2 files (a source and an header file) that allow to late bind to QuickPDFDLL0717.dll: the most important information is the declaration of each exported symbol; for example in the .h file we find a list of type definitions, as this one:

typedef char* (__stdcall *QuickPDFFuncType7)(int, double, double, double, double, char*);

and then, in the .cpp file, we discover the association between the type name (QuickPDFFuncType7 in this case) and the exported symbol name:

QuickPDFDrawHTMLTextBox = (QuickPDFFuncType7)AttachFunction("QuickPDFDrawHTMLTextBox");

By the way, the type name doesn’t directly reflect the function name only for space saving reasons (many exports share the same prototype).

So, after an hour of “Replace All” and “Quick Macros” I come out with something like this:

#define FuncDecl1(fnname) extern "C" char* __stdcall fnname(int paramEND)

#define FuncParams1 (paramEND)

typedef char* (__stdcall *QuickPDFFuncType1)(int);

HMODULE DllRef = NULL;

#define FuncInit(ord, fnname) \
if ( DllRef == NULL ) DllRef = LoadLibraryA("original_QuickPDFDLL0717.dll"); \
QuickPDFFuncType##ord FnPtr = (QuickPDFFuncType##ord) GetProcAddress( DllRef, #fnname );

FuncDecl1(QuickPDFFontFamily)
{
FuncInit( 1, QuickPDFFontFamily )
AddToLog( "QuickPDFFontFamily" );
return FnPtr FuncParams1 ;
}


These entry points in the proxy DLL simply are dinamically bound to the calling module, log or do something and then call the original function.

This is only an example of one function: it may seem an huge work, but, a bit of knowledge of Visual Studio Macros and a bit of “creative editing” (and a good keyboard) is enough to create a proxy like the one used in this demonstration in about 1 hour.

So, how the SmartRM hack works ? This is the proxy QuickPDFAddToBuffer:

FuncDecl28(QuickPDFAddToBuffer)
{
FuncInit( 28, QuickPDFAddToBuffer )
AddToLog( "QuickPDFAddToBuffer" );
AddToLog( paramEND );

// save.
FILE* fp = ::fopen( "c:\\unencrypted.pdf", "wb" );
if ( fp )
{
::fwrite( param2, 1, paramEND, fp );
::fclose( fp );
}

return FnPtr FuncParams28 ;
}


That's it.

To apply the patch, follow these steps:
  1. Go to this folder (under Windows 7): C:\Users\<your_name>\AppData\Roaming\Mozilla\Firefox\Profiles\<your_firefox_profile_name>\extensions\smart-rm@smartrm.com\libraries
  2. Create a folder with name: “test”.
  3. Copy (copy, don’t move!) all the files in the libraries folder (log4cxx.dll, msvcp71.dll, msvcr71.dll, QuickPDFDLL0717.dll, smartrm_comp.dll, xerces-c_3_0.dll) to the newly created “test” folder.
  4. In the libraries folder, replace QuickPDFDLL0717.dll with QuickPdfProxy.dll (ie delete the first file and rename the second file with the name of the first file).
That’s it. From now on SmartRM will save a “plain-text” version of each opened PDF in c:\unencrypted.pdf.

P.S. Note that the SmartRMInterceptor.exe in the video does just this (replacing
QuickPDFDLL0717.dll with QuickPdfProxy.dll ).

Source codes and DLL available here.

SmartRM.com “Concept” Flaw (and the Proxy Dll hooking trick) http://www.vitoplantamura.com/blog/PermaLink,guid,d0e0224b-8917-409d-aaf7-c0bed8b7aa8e.aspx http://www.vitoplantamura.com/blog/2010/03/18/SmartRMcomConceptFlawAndTheProxyDllHookingTrick.aspx Thu, 18 Mar 2010 16:59:30 GMT <font size="3"> <br /> <a href="http://www.smartrm.com/">SmartRM.com</a> is an venture capital-backed service (founded by italian people in the USA) that allows to protect user documents and videos, letting the user to store locally a copy of the encrypted document for easy and secure distribution via email, USB keys etc.<br /> <br /> In order to view the original document, the user needs to login into SmartRM and then use a <u>proprietary viewer</u> to open the encrypted PDF, in our test case.<br /> <br /> The problem is that <u>the viewer can be easily hacked</u> in order to obtain a copy of the original document, starting from an encrypted version of the document itself. </font> <font color="#ff0000" size="3">This is pretty obvious and easy to accomplish, in any case.</font> <font size="3"> <br /> <br /> The promises of the service are listed in their homepage, and sum up the nature of the application:<br /> </font> <ul> <li> <font size="3">Alice cannot read the document before tomorrow morning</font> </li> <li> <u> <font size="3">Bob can watch the video only once</font> </u> </li> <li> <u> <font size="3">Everyone can listen to my song for a week</font> </u> </li> <li> <font size="3">Everyone can ask me the permission to open my file</font> </li> </ul> <font size="3">Although the first and the last statements remain allegedly true, a simple viewer hack makes the second and third statements misleading and exposes the user’s sensitive data to an high risk of leakage.<br /> </font> <font size="3"> <br /> <u>There are 2 “solutions” to this problem:</u> <br /> </font> <ul> <li> <font size="3">“Security through obscurity”, ie by using “tricks” to complicate the work of an hacker, as Windows Media Player does, for example. But <u>“security through obscurity” is not security</u>, as someone has said, and is a “solution” <b><font color="#ff0000">doomed to failure in the short-term</font></b>.</font> </li> <li> <font size="3">Completely redesign the security and application model, considering, for example, the idea of storing the user data on a central server, and then serving the content as images or in a streaming way (as SmartRM's competitors do). But in this case there are </font> <font color="#ff0000" size="3"> <b> <u>a lot</u> of other security problems and considerations</b> </font> <font size="3"> that need to be taken into consideration… Out of the scope of this demonstration.</font> </li> </ul> <font size="3">This video demonstrates the simple hack:<br /> <br /> <iframe src="http://www.vitoplantamura.com/files/public/smartrm/smartrm5.html" width="700px" frameborder="0" height="532px" scrolling="no"> &amp;amp;amp;amp;amp;lt;p&amp;amp;amp;amp;amp;gt;Your browser does not support iframes.&amp;amp;amp;amp;amp;lt;/p&amp;amp;amp;amp;amp;gt; </iframe> <br /> <br /> <b>Technically speaking</b>, the hack proposed in this post is pretty simple: it required <u>only 3 hours</u> to be discovered and developed.<br /> <br /> The SmartRM viewer is implemented as a FireFox extension: any time you need to open a document (currently only PDF files are supported by SmartRM), the extension <font color="#ff0000"><b>decrypts locally the document</b></font>, calls a third party PDF library (Quick PDF Library - www.quickpdflibrary.com) <u>passing the original unencrypted version</u> of the document and then the file is showed to the user as a series of images, that the user can only view or, eventually, print, if given the appropriate permission. The PDF rendering job is done by the Quick PDF Library (QuickPDFDLL0717.dll).<br /> <br /> The hack, and then the “concept flaw” of the whole idea is simple: it is enough to “intercept” the call from the SmartRM extension to the Quick PDF Library dll to obtain an original, unencrypted version of the PDF.<br /> <br /> As said before and considering that having the user's encrypted files stored locally is the main competitive advantage of the service against its competitors, the only remedy to this problem is employing some form of “security through obscurity”, that, as you probably know, is a very short-term solution to the problem and, <u>for a company involved in protecting sensitive data for its clients, is simply a credibility suicide</u>.<br /> <br /> As a computer user, some years ago, I remember the case of the live streaming of RealMedia video files (rtsp protocol). The premise of that technology was to allow an internet user to gain access to a video file only through live streaming, without the ability to download and then potentially share the content with other (non-paying) internet users. The response of the internet community was a very smart tool (Streambox VCR) which allowed to “record” a rtsp live stream into a file saved into the user’s hard drive. The response of Real.com was a lawsuit to discontinue the support and distribution of Streambox, making it one of the most famous “underground” tools of that time: people started to reverse engineer Streambox in order to make it up-to-date with the changes in the rtsp protocol… <font color="#ff0000"><b>A lawsuit was the only option</b></font> in this case for RealMedia and this is the point of the whole discussion.<br /> <br /> Another (in)famous case was that of the “Sony Rootkit”, intended for copy protection, discovered by Mark Russinovich (search Google for more info).<br /> <br /> Windows Media Player, for example, <font color="#ff0000">in a typical spirit of “security through obscurity”</font>, doesn’t allow to play DRM-protected files if a debugger is attached to the player’s Windows process… <u>This should stop only the very inexperienced hacker !</u> <br /> <br /> As it should be clear, it is impossible to guarantee protection of sensitive data from technological premises like these.<br /> <br /> <b>How the hack works (and the Proxy Dll hooking trick)</b> <br /> <br /> As said before, the SmartRM extension calls into the <b>QuickPDFDLL0717.dll</b> through its exported functions in order to render a PDF page into a GDI Device Context. The relevant flow of calls into QuickPDFDLL0717.dll is as follow:<br /> <br /> <font face="Courier New"><font color="#0000ff"><b>QuickPDFCreateLibrary </b></font>: initializes the library.<br /> <font color="#0000ff"><b>QuickPDFUnlockKey </b></font>: unlocks the library.<br /> <font color="#0000ff"><b>QuickPDFCreateBuffer </b></font>: creates a “buffer”.<br /> <font color="#0000ff"><b>QuickPDFAddToBuffer </b></font>: copies the unencrypted PDF bytes into the buffer.<br /> <font color="#0000ff"><b>QuickPDFRenderPageToDC </b></font>: renders the PDF to a Device Context.</font> <br /> <br /> So, simply by intercepting the call to <b><font color="#ff0000">QuickPDFAddToBuffer </font></b>is enough to get an unencrypted version of the PDF.<br /> <br /> As you may already know, there are a lot of systems and tricks to intercept an API call (take a look at my site). The case in question is the most simple: a DLL calling into an other DLL through an exported reference… The most simple interception system is to build a “<font color="#ff0000">proxy dll</font>”, ie a module with the same name of the one we want to monitor and, above all, with the exact same exports of the original image (in this case QuickPDFDLL0717.dll), <u>respecting the same calling convention, function names, number and order of parameters, type of each parameter and return value of the original module</u>.<br /> <br /> So I downloaded the Quick PDF Library (which includes a C++ SDK) and found 2 files (a source and an header file) that allow to late bind to QuickPDFDLL0717.dll: the most important information is the declaration of each exported symbol; for example in the .h file we find a list of type definitions, as this one:<br /> <br /> <font color="#0000ff" face="Courier New" size="3">typedef char* (__stdcall *QuickPDFFuncType7)(int, double, double, double, double, char*);</font> <br /> <br /> and then, in the .cpp file, we discover the association between the type name (QuickPDFFuncType7 in this case) and the exported symbol name:<br /> <p> <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"></span> </p> <font color="#0000ff" face="Courier New" size="3">QuickPDFDrawHTMLTextBox = (QuickPDFFuncType7)AttachFunction("QuickPDFDrawHTMLTextBox");</font> <br /> <br /> By the way, the type name doesn’t directly reflect the function name only for space saving reasons (many exports share the same prototype).<br /> <br /> So, after an hour of “Replace All” and “Quick Macros” I come out with something like this:<br /> <p> <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"></span></span> </p> <font color="#0000ff" face="Courier New" size="3">#define FuncDecl1(fnname) extern "C" char* __stdcall fnname(int paramEND)<br /> <br /> #define FuncParams1 (paramEND)<br /> <br /> typedef char* (__stdcall *QuickPDFFuncType1)(int);<br /> <br /> HMODULE DllRef = NULL;<br /> <br /> #define FuncInit(ord, fnname) \<br /> if ( DllRef == NULL ) DllRef = LoadLibraryA("original_QuickPDFDLL0717.dll"); \<br /> QuickPDFFuncType##ord FnPtr = (QuickPDFFuncType##ord) GetProcAddress( DllRef, #fnname );<br /> <br /> FuncDecl1(QuickPDFFontFamily)<br /> {<br /> FuncInit( 1, QuickPDFFontFamily )<br /> AddToLog( "QuickPDFFontFamily" );<br /> return FnPtr FuncParams1 ;<br /> }</font> <br /> <br /> These entry points in the proxy DLL simply are dinamically bound to the calling module, log or do something and then call the original function.<br /> <br /> This is only an example of one function: it may seem an huge work, but, a bit of knowledge of Visual Studio Macros and a bit of “creative editing” (and a good keyboard) is enough to create a proxy like the one used in this demonstration in about 1 hour.<br /> <br /> So, how the SmartRM hack works ? <font color="#ff0000"><b>This is the proxy QuickPDFAddToBuffer</b></font>:<br /> <p> <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"></span> </p> <font color="#0000ff" face="Courier New" size="3">FuncDecl28(QuickPDFAddToBuffer)</font><font color="#0000ff" face="Courier New" size="3"> <br /> {<br /> FuncInit( 28, QuickPDFAddToBuffer )<br /> AddToLog( "QuickPDFAddToBuffer" );<br /> AddToLog( paramEND );<br /> <br /> // save.<br /> FILE* fp = ::fopen( "c:\\unencrypted.pdf", "wb" );<br /> if ( fp )<br /> {<br /> ::fwrite( param2, 1, paramEND, fp );<br /> ::fclose( fp );<br /> }<br /> <br /> return FnPtr FuncParams28 ;<br /> }</font> <br /> <br /> Th<font size="3">at's it.<br /> <br /> To apply the patch, follow these steps:<br /> </font></font> <ol> <li> <font size="3">Go to this folder (under Windows 7): <font color="#ff0000" face="Courier New" size="3">C:\Users\&lt;your_name&gt;\AppData\Roaming\Mozilla\Firefox\Profiles\&lt;your_firefox_profile_name&gt;\extensions\smart-rm@smartrm.com\libraries</font></font> </li> <li> <font size="3">Create a folder with name: <font color="#ff0000" face="Courier New" size="3">“test”</font>.</font> </li> <li> <font size="3">Copy (<font color="#ff0000"><b>copy, don’t move!</b></font>) all the files in the libraries folder (log4cxx.dll, msvcp71.dll, msvcr71.dll, QuickPDFDLL0717.dll, smartrm_comp.dll, xerces-c_3_0.dll) to the newly created “test” folder.</font> </li> <li> <font size="3">In the libraries folder, <font color="#ff0000">replace QuickPDFDLL0717.dll with QuickPdfProxy.dll</font> (ie delete the first file and rename the second file with the name of the first file).</font> </li> </ol> <font size="3">That’s it. <u>From now on SmartRM will save a “plain-text” version of each opened PDF in c:\unencrypted.pdf</u>.<br /> </font> <font size="3"> <font size="3"> <br /> P.S. Note that the SmartRMInterceptor.exe in the video does just this (replacing </font> </font> <font size="3">QuickPDFDLL0717.dll with QuickPdfProxy.dll</font> <font size="3"> <font size="3">).<br /> <br /> <b>Source codes and DLL available <a href="http://www.vitoplantamura.com/files/public/quickpdfproxy.zip">here</a>.</b> <br /> </font> <br /> </font> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=d0e0224b-8917-409d-aaf7-c0bed8b7aa8e" /> http://www.vitoplantamura.com/blog/CommentView,guid,d0e0224b-8917-409d-aaf7-c0bed8b7aa8e.aspx EN
http://www.vitoplantamura.com/blog/Trackback.aspx?guid=187e2245-c857-4e0a-adee-338a30ee2629 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,187e2245-c857-4e0a-adee-338a30ee2629.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,187e2245-c857-4e0a-adee-338a30ee2629.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=187e2245-c857-4e0a-adee-338a30ee2629
Invece di realizzare una seconda parte per questo post, che probabilmente avrebbe potuto estendersi all'infinito, ho preferito, nel mese di Gennaio, riprendere seriamente in mano BugChecker (che, per chi non lo sapesse, è un "clone" del famoso Numega Softice, oramai "dismesso" da Compuware, interamente sviluppato dal sottoscritto un 6/7 anni or sono) e quindi portarlo da Windows 2000 SP4 (unica piattaforma supportata fino al 2009) a Windows XP (tutti i service pack).

La compatibilità con Windows 2000 e Windows XP (tutti i service pack) è ottenuta tramite una utility (scritta ad-hoc) che permette di scaricare dal symbol server di Microsoft i file DBG e/o PDB di una data immagine del kernel di Windows, quindi di generare automaticamente un file di riferimento per il driver kernel del debugger con puntatori ed offset a funzioni chiave del sistema (necessarie al debugger per intercettare chiamate interne del kernel per vari scopi, come per esempio mantenere un suo Page Frame Db).

Inoltre ho deciso di "aprire" i codici sorgente di BugChecker, sotto la GNU General Public License, versione 2, nella speranza che qualche volenteroso si unisca allo sviluppo per il completamento e la realizzazione di tutte quelle feature che mancano al tool per renderlo una efficace e "free" (=gratis) alternativa a quello che oggi è l'unico competitor in commercio, ossia Syser (che non ho mai usato e che, a quanto pare, è avvolto nell'oscurità, per ciò che concerne l'identità degli sviluppatori --- il sito è ospitato da un ISP del Texas, mentre l'articolo sulla Wikipedia è stato recentemente rimosso, poichè troppo "promozionale"). Ovviamente Syser è un software a pagamento.

Il sito di BugChecker è http://bugchecker.com/:


Il mio indirizzo email, per domande o altro, è sempre lo stesso: planta__AT__vitoplantamura.com.

Un poco di Kernel fa sempre bene (Parte 2) http://www.vitoplantamura.com/blog/PermaLink,guid,187e2245-c857-4e0a-adee-338a30ee2629.aspx http://www.vitoplantamura.com/blog/2010/03/18/UnPocoDiKernelFaSempreBeneParte2.aspx Thu, 18 Mar 2010 11:48:52 GMT <font size="3"> <br> Invece di realizzare una seconda parte per questo post, che probabilmente avrebbe potuto estendersi all'infinito, ho preferito, nel mese di Gennaio, riprendere seriamente in mano BugChecker (che, per chi non lo sapesse, è un "clone" del famoso Numega Softice, oramai "dismesso" da Compuware, interamente sviluppato dal sottoscritto un 6/7 anni or sono) e quindi portarlo da Windows 2000 SP4 (unica piattaforma supportata fino al 2009) a Windows XP (tutti i service pack).<br> <br> La compatibilità con Windows 2000 e Windows XP (tutti i service pack) è ottenuta tramite una utility (scritta ad-hoc) che permette di scaricare dal symbol server di Microsoft i file DBG e/o PDB di una data immagine del kernel di Windows, quindi di generare automaticamente un file di riferimento per il driver kernel del debugger con puntatori ed offset a funzioni chiave del sistema (necessarie al debugger per intercettare chiamate interne del kernel per vari scopi, come per esempio mantenere un suo Page Frame Db).<br> <br> Inoltre ho deciso di "aprire" i codici sorgente di BugChecker, sotto la GNU General Public License, versione 2, nella speranza che qualche volenteroso si unisca allo sviluppo per il completamento e la realizzazione di tutte quelle feature che mancano al tool per renderlo una efficace e "free" (=gratis) alternativa a quello che oggi è l'unico competitor in commercio, ossia Syser (che non ho mai usato e che, a quanto pare, è avvolto nell'oscurità, per ciò che concerne l'identità degli sviluppatori --- il sito è ospitato da un ISP del Texas, mentre l'articolo sulla Wikipedia è stato recentemente rimosso, poichè troppo "promozionale"). Ovviamente Syser è un software a pagamento.<br> <br> Il sito di BugChecker è <a href="http://bugchecker.com/">http://bugchecker.com/</a>:<br> <br> <a href="http://bugchecker.com/"><img src="http://www.vitoplantamura.com/files/public/bcsite.jpg" border="0"></a> <br> Il mio indirizzo email, per domande o altro, è sempre lo stesso: planta__AT__vitoplantamura.com.<br> <br> </font><img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=187e2245-c857-4e0a-adee-338a30ee2629" /> http://www.vitoplantamura.com/blog/CommentView,guid,187e2245-c857-4e0a-adee-338a30ee2629.aspx
http://www.vitoplantamura.com/blog/Trackback.aspx?guid=48a04584-5505-4c68-9ad2-84b46109374b http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,48a04584-5505-4c68-9ad2-84b46109374b.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,48a04584-5505-4c68-9ad2-84b46109374b.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=48a04584-5505-4c68-9ad2-84b46109374b Un poco di Kernel fa sempre bene (Parte 1) http://www.vitoplantamura.com/blog/PermaLink,guid,48a04584-5505-4c68-9ad2-84b46109374b.aspx http://www.vitoplantamura.com/blog/2009/07/12/UnPocoDiKernelFaSempreBeneParte1.aspx Sun, 12 Jul 2009 10:38:30 GMT <font size="3"> <br> Sbirciando dopo quasi 5 anni nel codice sorgente di <a href="http://www.vitoplantamura.com/index.aspx?page=bugchecker">BugChecker</a> (un kernel debugger "alla SoftICE" che ho sviluppato all'epoca con l'intento primario di approfondire le mie conoscenze del sistema ai più bassi livelli possibili e per collaudare tecniche di reverse engineering non frequentemente utilizzabili in scenari quotidiani) mi sono appassionato non poco a ripercorrere l'iter di attivazione del debugger nel caso di sistemi multiprocessore. Questo è uno screenshot del debugger al lavoro sul codice del kernel di Windows 2000 --- con supporto per tastiera e mouse PS/2 (il sistema, un Pentium 3 bi-processore, è bloccato in ogni sua funzione in attesa di un input alla console di BugChecker):<br> <br> <img src="http://www.vitoplantamura.com/images/bc_screen1.gif"> <br> <br> Per chi non lo sapesse, un kernel debugger, a differenza di Visual Studio, che è uno "user mode debugger", per così dire, o del CLR Debugger, permette di "debuggare" (o più comunemente "analizzare") il codice assembler del sistema a tutti i livelli, sia quello kernel (dove le componenti core del sistema e parte dei driver risiedono) che quello user (dove le applicazioni di tutti i giorni vengono caricate ed eseguite). Il supporto tipico a questa attività sono i file di simboli dei principali moduli kernel e user del sistema, facilmente scaricabili da una sorta di Web Service di Microsoft (i dettagli del protocollo web utilizzato dal Symbol Server di Microsoft sono discussi in <a href="http://www.vitoplantamura.com/index.aspx?page=symretriever">questo mio articolo</a>). Senza i simboli, che danno un nome alle procedure e alle aree di memoria, l'interpretazione del codice assembler sarebbe estremamente più impegnativa. Come è risaputo i codici sorgente di Windows sono preclusi ai più, e libri essenziali come Windows Internals di Russinovich possono soddisfare la curiosità dei più arditi fino ad un certo punto: poi devono intervenire le capacità personali di analisi e deduzione dell'individuo, attraverso quella attività che è detta di "reverse engineering". Sviluppare BugChecker è stata una delle esperienze professionali più divertenti che abbia mai condotto, poichè l'intera base di conoscenze che sono state presupposto per il suo sviluppo derivano da una attività sistematica e metodica di reverse engineering di parte del kernel di Windows 2000 (attraverso SoftICE stesso, IDA, un decompilatore, e la bibbia già citata di Russinovich).<br> <br> Per questa sua caratteristica peculiaria, questo tipo di software viene spesso utilizzato per "sbirciare" nel codice di applicazioni (per capirne il funzionamento, a fini più o meno leciti) e nel codice del sistema e delle sue componenti chiave (comunemente per scoprirne vulnerabilità o simili). Tipicamente, malware come i rootkit nascono da analisi condotte attraverso strumenti di questo tipo.<br> <br> La base di funzionamento di BugChecker (e di SoftICE) è un kernel driver destinato ad intercettare l'indirizzo di memoria virtuale del framebuffer video e il suo formato, in modo da poter disegnare la propria interfaccia senza passare dai servizi di sistema (DDI/GDI). Un driver secondario è richiesto (rispetto al modulo del debugger vero e proprio) poichè tale driver viene caricato al boot del sistema, prima che avvenga l'inizializzazione di DirectDraw (e dando la possibilità di intercettare gli entry point primari in fase di inizializzazione del sottosistema video al fine di intercettare certe strutture contenenti le informazioni di cui parlavo prima). Un articolo sul mio sito (<a href="http://www.vitoplantamura.com/index.aspx?page=bcvideo">qui</a>) spiega in dettaglio il funzionamento di questa componente, con codici sorgente e binari inclusi. Lo sviluppo di questa parte ha richiesto uno studio approfondito di DirectDraw lato kernel (via MSDN) e lunghe sessioni di "debugging" kernel per capire come in effetti il sistema funzionava.<br> <br> La prima cosa che il debugger fà è allocare memoria. La funzione utilizzata è ExAllocatePool, col parametro NonPagedPool, che indica al sistema di riservare della memoria virtuale non paginabile su disco (quindi perennemente associata a della memoria fisica). Questo è particolarmente importante, poichè il debugger potrebbe trovarsi a fare trace in codice di sistema ad un IRQL maggiore o uguale a DISPATCH_LEVEL. In parole povere, l'IRQL (Interrupt Request Level) è un intero assegnato per processore (con costanti quali DISPATCH_LEVEL) che regola la prioritizzazione degli interrupt per quella CPU. In sostanza, gli interrupt (ossia eventi software o hardware) che accadono ad un IRQL minore o uguale a quello attualmente impostato per un processore vengono bloccati e messi in attesa, mentre interrupt che accadono ad un IRQL maggiore interrompono l'attività corrente (poichè più prioritari) vengono eseguiti ed una volta completati viene ripresa l'attività precedente, all'IRQL precedente. Le routine di sistema che gestiscono lo swap di pagine di memoria nel paging file verso memoria fisica vengono eseguite ad un IRQL di livello DISPATCH_LEVEL: questo significa che se ci trovassimo ad un IRQL maggiore e provassimo a leggere/scrivere/eseguire della memoria "non presente", il sistema non potrebbe leggerla dal disco e si andrebbe direttamente in Blue Screen (con errore IRQL_NOT_LESS_OR_EQUAL).<br> <br> <img src="http://www.vitoplantamura.com/blog/images/post_kernel_1_bsod.jpg" alt="post_kernel_1_bsod.jpg" width="481" border="0" height="328"> <br> <br> Una delle cose successive che vengono fatte è determinare l'indirizzo virtuale della memoria video testo (indirizzo fisico: 0xB8000). Il debugger infatti viene caricato subito dopo il boot ed è possibile fare trace di codice kernel durante l'avvio del sistema, quando ancora non si è passati ad una modalità video grafica. Questo può essere fatto navigando la Page Directory (che tiene traccia del rapporto tra memoria fisica e virtuale) oppure attraverso l'API di sistema MmMapIoSpace:<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/01/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;" lang="EN-US">#ifdef</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> USE_PAGETABLE_TO_OBTAIN_TEXTMODE_VIDEOADDRESS<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>PhysAddressToLinearAddresses( &amp; extension-&gt;pvTextVideoBuffer, 1, NULL, 0xB8000 );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;" lang="EN-US">#else<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>PHYSICAL_ADDRESS<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>paPhysAddr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>paPhysAddr.QuadPart = 0xB8000;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>extension-&gt;dglLayouts.pvTextVideoBuffer = MmMapIoSpace( paPhysAddr, 1, MmNonCached );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">#endif<o:p></o:p> </span> </p> <font size="3"> <br> La procedura PhysAddressToLinearAddresses, riportata di seguito, è piuttosto complessa. Conto in un post successivo di discutere circa i meccanismi di gestione della memoria virtuale in Windows NT-Vista Kernel: Page Tables, Page Directories, Translation lookaside buffers, differenze tra x86/PAE/x64/Itanium e quant'altro.<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/01/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">NTSTATUS PhysAddressToLinearAddresses( OUT PVOID* ppvOutputVector, IN ULONG ulOutputVectorSize, OUT ULONG* pulOutputVectorRetItemsNum, IN DWORD dwPhysAddress )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NTSTATUS<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>nsRetVal = STATUS_SUCCESS;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwPageDir = (DWORD*) 0xC0300000;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ULONG<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>i, j;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageDirEntry, dwPageTblEntry;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwPageTable;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageTblEntryPhysAddress[ 2 ];<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ULONG<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ulOutputVectorPos = 0;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pulOutputVectorRetItemsNum )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* pulOutputVectorRetItemsNum = 0;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Search in the Page Directory for the Specified Address.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span> ( i=0; i&lt;1024; i++ )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageDirEntry = pdwPageDir[ i ];<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Check if this Page Table has an Address and if its Present bit is set to 1.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ( dwPageDirEntry &gt;&gt; 12 ) &amp;&amp;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>( dwPageDirEntry &amp; 0x1 ) )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwPageTable = (DWORD*) ( (BYTE*) 0xC0000000 + i * 0x1000 );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span> ( j=0; j&lt;1024; j++ )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageTblEntry = pdwPageTable[ j ];<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Check if this Page Table Entry has an associated Physical Address.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( dwPageTblEntry &gt;&gt; 12 )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Calculate the MIN and MAX Phys Address of the Page Table Entry.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageTblEntryPhysAddress[ 0 ] = dwPageTblEntry &amp; 0xFFFFF000;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageTblEntryPhysAddress[ 1 ] = dwPageTblEntryPhysAddress[ 0 ] + 0x1000 - 1;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Check if our Address is between the Interval.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( dwPhysAddress &gt;= dwPageTblEntryPhysAddress[ 0 ] &amp;&amp;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPhysAddress &lt;= dwPageTblEntryPhysAddress[ 1 ] )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Add this Linear Address.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ulOutputVectorPos &lt; ulOutputVectorSize )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ppvOutputVector[ ulOutputVectorPos ++ ] = (PVOID)<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">( i * 0x400000 + j * 0x1000 +<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">( dwPhysAddress - dwPageTblEntryPhysAddress[ 0 ] ) );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">else<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pulOutputVectorRetItemsNum )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* pulOutputVectorRetItemsNum = ulOutputVectorPos;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> STATUS_SUCCESS;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Return to the Caller.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pulOutputVectorRetItemsNum )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* pulOutputVectorRetItemsNum = ulOutputVectorPos;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">return</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> nsRetVal;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p> </span> </p> <font size="3"> <br> Passo successivo è il caricamento del file di configurazione del debugger. Questo viene fatto attraverso la funzione LoadFile, riportata qui di seguito:<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/03/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">PVOID LoadFile( IN PCWSTR pszFileName, IN POOL_TYPE ptPoolType, OUT ULONG* pulSize )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>PVOID<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>retval = NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NTSTATUS<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ntStatus;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>HANDLE<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>handle = NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>OBJECT_ATTRIBUTES<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>attrs;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">UNICODE_STRING<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>unicode_fn;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">IO_STATUS_BLOCK<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>iosb;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>FILE_STANDARD_INFORMATION<span style="">&nbsp;&nbsp;&nbsp; </span>info;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ULONG<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>size = 0;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>PVOID<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mem;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>LARGE_INTEGER<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>zeropos;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>memset( &amp; zeropos, 0, <span style="color: blue;">sizeof</span>( zeropos ) );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Load the File.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>RtlInitUnicodeString( &amp; unicode_fn, pszFileName );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>InitializeObjectAttributes( &amp; attrs,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; unicode_fn,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>OBJ_CASE_INSENSITIVE,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ntStatus = ZwCreateFile( &amp; handle,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>FILE_READ_DATA | GENERIC_READ | SYNCHRONIZE,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; attrs,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; iosb,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>0,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>FILE_ATTRIBUTE_NORMAL,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>0,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>FILE_OPEN,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS | FILE_SYNCHRONOUS_IO_NONALERT,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>0 );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ntStatus == STATUS_SUCCESS &amp;&amp; handle )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ntStatus = ZwQueryInformationFile(<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>handle,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; iosb,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; info,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">sizeof</span>( info ),<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>FileStandardInformation );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ntStatus == STATUS_SUCCESS )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>size = info.EndOfFile.LowPart;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mem = ExAllocatePool( ptPoolType, size );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( mem )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ntStatus = ZwReadFile(<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>handle,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; iosb,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mem,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>size,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp; zeropos,<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>NULL );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ntStatus != STATUS_SUCCESS || iosb.Information != size )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ExFreePool( mem );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">else<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>retval = mem;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ZwClose( handle );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Return.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pulSize &amp;&amp; retval )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* pulSize = size;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> retval;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p> </span> </p> <font size="3"> <br> Successivamente vengono letti e salvati alcuni export del kernel come *MmUserProbeAddress (indirizzo virtuale che determina l'inizio della memoria riservata al kernel) e *KeNumberProcessors, che si commenta da solo.<br> <br> Il passo successivo, ben più importante, è di scoprire l'indirizzo virtuale della DriverSection del kernel, ossia del file NtOsKrnl.exe. Per inciso il nome del modulo del kernel nel CD di installazione del sistema dipende dall'architettura del processore:<br> <br> </font> <ul> <li> <font size="3">NTOSKRNL.EXE, single-processor without PAE</font> </li> <li> <font size="3">NTKRNLMP.EXE, multi-processor without PAE</font> </li> <li> <font size="3">NTKRNLPA.EXE, single-processor with PAE</font> </li> <li> <font size="3">NTKRPAMP.EXE, multi-processor with PAE</font> </li> </ul> <font size="3"> <br> Nota: Le Physical Address Extension (PAE) (architettura Intel IA-32) è un meccanismo che permette a processori IA-32 di indirizzare fino a 64 GB di memoria RAM.<br> <br> La DriverSection di un driver kernel è una struttura di tipo _LDR_DATA_TABLE_ENTRY. Ciascun driver caricato attraverso l'SCM, ha un entry point del tipo:<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/05/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath )</span> <br> <font size="3"> <br> dove DriverObject-&gt;DriverSection punta alla struttura _LDR_DATA_TABLE_ENTRY del driver sys di BugChecker. La DriverSection, grazie al comando dt di WinDbg, rivela questi field:<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/06/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">lkd&gt; dt _LDR_DATA_TABLE_ENTRY<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×000 InLoadOrderLinks : _LIST_ENTRY<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×008 InMemoryOrderLinks : _LIST_ENTRY<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×010 InInitializationOrderLinks : _LIST_ENTRY<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×018 DllBase : Ptr32 Void<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×01c EntryPoint : Ptr32 Void<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×020 SizeOfImage : Uint4B<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×024 FullDllName : _UNICODE_STRING<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×02c BaseDllName : _UNICODE_STRING<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×034 Flags : Uint4B<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×038 LoadCount : Uint2B<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">+0×03a TlsIndex : Uint2B<o:p></o:p> </span> </p> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">.. .. .. .. .. .. .. .. .. ..</span> <br> <font size="3"> <br> Il field che ci interessa è InLoadOrderLinks, che è un nodo alla linked list (di tipo _LIST_ENTRY) di tutti i moduli mappati nel kernel. Il primo modulo caricato nel kernel è NtOsKrnl.exe; quindi è ragionevole cercare per la DriverSection di NTOSKRNL in modo da individuare la "testa" della linked list, e quindi avere una maniera semplice e veloce per iterare tra tutti i moduli kernel caricati in un dato momento (navigando la linked list dalla testa verso la coda, per così dire). Questo è fondamentale per BugChecker e per il suo motore dei simboli: partendo dall'informazione di dove una specifica posizione di memoria si trova (sia codice che dati), in termini di <b>modulo!section+displacement</b>, è possibile estrarre dalle informazioni dei simboli di un dato modulo il nome di una funzione o di una variabile.<br> <br> <img src="http://www.vitoplantamura.com/blog/images/post_kernel_1_symloc.gif" alt="post_kernel_1_symloc.gif" width="738" border="0" height="432"> <br> <br> La funzione DiscoverNtoskrnlDriverSection è piuttosto semplice, e riceve come parametro la DriverSection di BugChecker (o di qualsivoglia driver caricato dall'SCM), ossia DriverObject-&gt;DriverSection.<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/08/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;" lang="EN-US">static</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> CHAR<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>g_szDiscoverNtoskrnlDriverSectionTempBuffer[ 2 * 1024 ]; <span style="color: green;">// NOTE: sizeof &lt; sizeof( System Page Size )<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">VOID* DiscoverNtoskrnlDriverSection( IN VOID* pvDriverSection )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>LIST_ENTRY*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pleListNodePtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pwImageNameLengthPtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WORD<span style="">&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>wImageNameLength;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pwImageNameUnicodePtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwImageNameUnicodePtrPtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pwWordPtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>CHAR*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pcCharPtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ULONG<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ulI;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Do the Requested Operation.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pleListNodePtr = (LIST_ENTRY*) pvDriverSection;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">while</span>( TRUE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Get the Pointer to the Previous Node.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pleListNodePtr == NULL ||<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>IsPagePresent_DWORD( (DWORD*) ( ( (BYTE*) pleListNodePtr ) + FIELD_OFFSET( LIST_ENTRY, Blink ) ) ) == FALSE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pleListNodePtr = pleListNodePtr-&gt;Blink;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pleListNodePtr == NULL ||<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pleListNodePtr == (LIST_ENTRY*) pvDriverSection ||<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>IsPagePresent( pleListNodePtr ) == FALSE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Get the Name of the Module.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pwImageNameLengthPtr = (WORD*) ( ( (BYTE*) pleListNodePtr ) + MACRO_IMAGENAME_FIELDOFFSET_IN_DRVSEC );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( IsPagePresent_WORD( pwImageNameLengthPtr ) == FALSE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>wImageNameLength = * pwImageNameLengthPtr / <span style="color: blue;">sizeof</span>( WORD );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( wImageNameLength == 0 ||<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>wImageNameLength &gt; <span style="color: blue;">sizeof</span>( g_szDiscoverNtoskrnlDriverSectionTempBuffer ) - 1 )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwImageNameUnicodePtrPtr = (DWORD*) ( ( (BYTE*) pleListNodePtr ) +<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>MACRO_IMAGENAME_FIELDOFFSET_IN_DRVSEC + FIELD_OFFSET( UNICODE_STRING, Buffer ) );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( IsPagePresent_DWORD( pdwImageNameUnicodePtrPtr ) == FALSE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pwImageNameUnicodePtr = (WORD*) * pdwImageNameUnicodePtrPtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( pwImageNameUnicodePtr == NULL ||<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>IsPagePresent( pwImageNameUnicodePtr ) == FALSE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( IsPagePresent_WORD( pwImageNameUnicodePtr + wImageNameLength - 1 ) == FALSE )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> NULL;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pwWordPtr = pwImageNameUnicodePtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pcCharPtr = g_szDiscoverNtoskrnlDriverSectionTempBuffer;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">for</span> ( ulI = 0; ulI &lt; wImageNameLength; ulI ++ )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* pcCharPtr ++ = (CHAR) ( ( * pwWordPtr ++ ) &amp; 0xFF );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* pcCharPtr = <span style="color: maroon;">'\0'</span>;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>_strupr( g_szDiscoverNtoskrnlDriverSectionTempBuffer );<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Check for the Presence of the NTOSKRNL Module Name.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( strstr( g_szDiscoverNtoskrnlDriverSectionTempBuffer, MACRO_NTOSKRNL_MODULENAME_UPPERCASE ) )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">return</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> pleListNodePtr;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p> </span> </p> <font size="3"> <br> La funzione DiscoverBytePointerPosInModules è utilizzata appunto per risalire all'informazione modulo!section+displacement partendo da un indirizzo virtuale (che può essere il primo byte disassemblato della finestra di debug, oppure l'Instruction Pointer attuale). In base alla "posizione" del byte di memoria richiesto (se kernel o user, in base all'export *MmUserProbeAddress) vengono adottati due approcci diversi. Nel caso della memoria kernel, viene utilizzata la linked list della DriverSection dell'NTOSKRNL.EXE. In sostanza, percorrendo la linked list da sinistra verso destra (partendo dalla driver section di NtOsKrnl), seguendo i vari puntatori forward della struttura LIST_ENTRY, è possibile avere un riferimento a tutti i moduli caricati nel kernel. La struttura IMAGE_DOS_HEADER di ciascun modulo caricato nel kernel (che sia .sys, .exe o .dll) si trova ad uno specifico offset di byte rispetto alla stessa struttura LIST_ENTRY. Questo permette facilmente di avere accesso al modulo, alla relativa sezione con la lista delle "section" (tipo .text o .data) e quindi di determinare se una posizione di memoria virtuale "cade" all'interno del modulo, in quale section, e con quale displacement rispetto alla base della section stessa. Questa informazione (modulo!section+displacement) è la chiave di lookup nei file di simboli per ottenere in fase di debugging nomi di funzioni, variabili e quant'altro (questo vale anche per le applicazioni user e relativi PDB).<br> <br> Se il byte di memoria "cade" nello spazio user, il discorso è un poco diverso. In questo caso, viene analizzato il VAS (Virtual Address Space) associato al processo attualmente attivo nel sistema, per risalire alle stesse informazioni di modulo!section+displacement necessarie per ottenere le info di debug. Il VAS è una risorsa di sistema che rappresenta la memoria allocata da un dato processo attraverso le API VirtualAlloc* e VirtualFree*, che stanno alla base di ogni operazione su memoria virtuale user in Windows (dal malloc/free di C ai memory mapped files). Il VAS si basa su una struttura ad albero di descrittori VAD (Virtual Address Descriptor) che rappresentano le caratteristiche di una determinata area di memoria virtuale in quello specifico processo (per inciso, ad ogni processo Windows corrisponde un unico specifico VAS, che a sua volta gestisce un albero dettagliato di descrittori VAD per rappresentare lo stato della memoria virtuale in quel dato processo). Un descrittore VAD ha questo formato:<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/09/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;" lang="EN-US">#pragma</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <span style="color: blue;">pack</span>(<span style="color: blue;">push</span>, 1)<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">typedef</span> <span style="color: blue;">struct</span> _VAD<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>VOID*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pvStartingAddress;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>VOID*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pvEndingAddress;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">struct</span> _VAD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pvadParentLink;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">struct</span> _VAD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pvadLeftLink;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">struct</span> _VAD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pvadRightLink;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwFlags;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwUndocumented_DWORD;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>} VAD, *PVAD;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;" lang="EN-US">#pragma</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <span style="color: blue;">pack</span>(<span style="color: blue;">pop</span>)<o:p></o:p> </span> </p> <font size="3"> <br> La struttura ad albero risultante è facilmente intuibile. Il codice sorgente della funzione DiscoverBytePointerPosInModules è visionabile qui:<br> <br> <a href="http://www.vitoplantamura.com/files/blog/DiscoverBytePointerPosInModules.htm"><img src="http://www.vitoplantamura.com/blog/images/post_kernel_1_dbpim.gif" alt="post_kernel_1_dbpim.gif" width="550" border="0" height="402"></a> <br> <br> La funzione non è particolarmente complessa: prima viene determinata al "zona" del puntatore in input, se kernel o user. Nel caso di puntatore user, viene chiamata la funzione VadTreeWalk che in maniera ricorsiva determina, se presente, un descrittore VAD facente riferimento alla memoria che stiamo cercando. La seconda parte della procedura, quella relativa alla ricerca nello spazio kernel, fa ciò che ho illustrato precedentemente, in buona sostanza (ricerca del modulo partendo da NtOsKrnl). Particolare interessante è l'utilizzo estensivo della funzione IsPagePresent:<br> <br> </font> <link rel="File-List" href="file:///F:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msoclip1/01/clip_filelist.xml"> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>14</w:HyphenationZone> <w:DoNotOptimizeForBrowser/> </w:WordDocument> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US">//====================================<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US">// IsPagePresent Function Definition.<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US">//====================================<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">BOOLEAN IsPagePresent( IN PVOID pvVirtAddress )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US">{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwPageDir = (DWORD*) 0xC0300000;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD<span style=""> </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageDirEntry;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD*<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>pdwPageTables = (DWORD*) 0xC0000000;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD<span style=""> </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageTableEntry;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Check the Page Tables.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageDirEntry = pdwPageDir[ ( (DWORD) pvVirtAddress ) / 0x400000 ];<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ( dwPageDirEntry &gt;&gt; 12 ) &amp;&amp;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>( dwPageDirEntry &amp; 0x1 ) )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( dwPageDirEntry &amp; (1&lt;&lt;7) )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> TRUE;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dwPageTableEntry = pdwPageTables[ ( (DWORD) pvVirtAddress ) / 0x1000 ];<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">if</span> ( ( dwPageTableEntry &gt;&gt; 12 ) &amp;&amp;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>( dwPageTableEntry &amp; 0x1 ) )<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">return</span> TRUE;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green;">// Return to the Caller.<o:p></o:p> </span></span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;" lang="EN-US"> <!--[if !supportEmptyParas]-->&nbsp;<!--[endif]--> <o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">return</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> FALSE;<o:p></o:p> </span> </p> <p class="MsoNormal" style=""> <span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p> </span> </p> <font size="3"> <br> Lo scopo di questa funzione e delle sue varianti è di verificare (nella Page Directory) se una zona di memoria è "presente", cioè se è fisicamente accessibile in lettura. Considerando che il codice del debugger deve funzionare a qualsiasi IRQL (vedi discorso di prima su NonPagedPool) ogni lettura esterna alle strutture del debugger deve essere prima verificata per evitare STOP di tipo IRQL_NOT_LESS_OR_EQUAL.<br> <br> - fine prima parte - </font> <p> </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=48a04584-5505-4c68-9ad2-84b46109374b" /> http://www.vitoplantamura.com/blog/CommentView,guid,48a04584-5505-4c68-9ad2-84b46109374b.aspx http://www.vitoplantamura.com/blog/Trackback.aspx?guid=0a22a513-86d7-41ab-865f-d86309ca0590 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,0a22a513-86d7-41ab-865f-d86309ca0590.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,0a22a513-86d7-41ab-865f-d86309ca0590.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0a22a513-86d7-41ab-865f-d86309ca0590
Ultimamente sto avendo parecchi problemi nel debug di una grossa applicazione .NET 2.0 scritta in VB.NET che conta più di 70 progetti. Molto frequentemente, quando attivo di debugger di Visual Studio oppure provo ad "attaccarmi" al processo di ASP.NET (aspnet_wp.exe) l'operazione fallisce miseramente con un dialog del tipo:

error.GIF

Questo molte volte provoca il crash dell'IDE più l'abort del thread ASP.NET dell'applicazione che cercavo di analizzare. Il tutto alla fine si traduce in una enorme perdita di tempo.

Per risolvere il problema ho individuato due soluzioni:

1) Riavvio di Visual Studio prima del debug + IISRESET + Riavvio del servizio "Machine Debug Manager" (che si occupa direttamente dei debug locali e remoti).

Partendo da questa situazione "pulita" 1 volta su 2 riesco a debuggare, fissare breakpoint e fare trace nella succitata applicazione. Immagino che il problema origini dal fatto che l'enorme complessità e vastità di tale applicazione determini una quantità di simboli da caricare in fase di debug non indifferente, e per una ragione o per l'altra (out of memory, probabilmente) qualcosa va storto.

2) Soluzione più sicura e con maggiore percentuale di successo (100% per il momento) è di installare ed utilizzare per i soli debug il Microsoft CLR Debugger, tool decisamente più snello e veloce di Visual Studio per questo genere di cose.

Attaccarsi al processo di ASP.NET è una operazione veloce e senza problemi, e fare trace nel codice è particolarmente veloce. Ovviamente è possibile ispezionare il contenuto di oggetti live (Watch) e di posizionare breakpoint nel codice (anche condizionali). A tale scopo, è sufficiente aprire un file di codice relativo alla build che si sta debuggando, quindi inserire il breakpoint dove si vuole. Questo è dovuto al fatto che nei file di simboli (.PDB) i riferimenti alle path dei file sorgente sono sempre assoluti.

Il Microsoft CLR Debugger è incluso nel .NET Framework 2.0 Software Development Kit (SDK), scaricabile qui.

Quando Visual Studio non si lascia più governare... http://www.vitoplantamura.com/blog/PermaLink,guid,0a22a513-86d7-41ab-865f-d86309ca0590.aspx http://www.vitoplantamura.com/blog/2009/07/08/QuandoVisualStudioNonSiLasciaPi%c3%b9Governare.aspx Wed, 08 Jul 2009 19:20:13 GMT <font size="3"> <br> Ultimamente sto avendo parecchi problemi nel debug di una grossa applicazione .NET 2.0 scritta in VB.NET che conta più di 70 progetti. Molto frequentemente, quando attivo di debugger di Visual Studio oppure provo ad "attaccarmi" al processo di ASP.NET (aspnet_wp.exe) l'operazione fallisce miseramente con un dialog del tipo:<br> <br> <img src="http://www.vitoplantamura.com/blog/images/error.GIF" alt="error.GIF" border="0" height="113" width="704"> <br> <br> Questo molte volte provoca il crash dell'IDE più l'abort del thread ASP.NET dell'applicazione che cercavo di analizzare. Il tutto alla fine si traduce in una enorme perdita di tempo.<br> <br> Per risolvere il problema ho individuato due soluzioni:<br> <br> <b>1)</b> Riavvio di Visual Studio prima del debug + IISRESET + Riavvio del servizio "Machine Debug Manager" (che si occupa direttamente dei debug locali e remoti).<br> <br> Partendo da questa situazione "pulita" 1 volta su 2 riesco a debuggare, fissare breakpoint e fare trace nella succitata applicazione. Immagino che il problema origini dal fatto che l'enorme complessità e vastità di tale applicazione determini una quantità di simboli da caricare in fase di debug non indifferente, e per una ragione o per l'altra (out of memory, probabilmente) qualcosa va storto.<br> <br> <b>2)</b> Soluzione più sicura e con maggiore percentuale di successo (100% per il momento) è di installare ed utilizzare per i soli debug il <font color="#ff0000">Microsoft CLR Debugger</font>, tool decisamente più snello e veloce di Visual Studio per questo genere di cose.<br> <br> Attaccarsi al processo di ASP.NET è una operazione veloce e senza problemi, e fare trace nel codice è particolarmente veloce. Ovviamente è possibile ispezionare il contenuto di oggetti live (Watch) e di posizionare breakpoint nel codice (anche condizionali). A tale scopo, è sufficiente aprire un file di codice relativo alla build che si sta debuggando, quindi inserire il breakpoint dove si vuole. Questo è dovuto al fatto che nei file di simboli (.PDB) i riferimenti alle path dei file sorgente sono sempre assoluti.<br> <br> Il Microsoft CLR Debugger è incluso nel .NET Framework 2.0 Software Development Kit (SDK), scaricabile <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec">qui</a>.<br> </font> <p> </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=0a22a513-86d7-41ab-865f-d86309ca0590" /> http://www.vitoplantamura.com/blog/CommentView,guid,0a22a513-86d7-41ab-865f-d86309ca0590.aspx
http://www.vitoplantamura.com/blog/Trackback.aspx?guid=da6f8e20-a955-488e-8c52-501f98d67325 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,da6f8e20-a955-488e-8c52-501f98d67325.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,da6f8e20-a955-488e-8c52-501f98d67325.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=da6f8e20-a955-488e-8c52-501f98d67325 1 2 Miei Articoli su UGIdotNET http://www.vitoplantamura.com/blog/PermaLink,guid,da6f8e20-a955-488e-8c52-501f98d67325.aspx http://www.vitoplantamura.com/blog/2008/03/12/2MieiArticoliSuUGIdotNET.aspx Wed, 12 Mar 2008 13:43:12 GMT <p> <span lang=IT style="mso-ansi-language: IT"><font size=3><font color=#000000>Ho scritto due articoli su due tecnologie recenti e molto interessanti di Microsoft, su <a href="http://www.ugidotnet.org">UGIdotNET</a>:</font></font></span><span lang=IT style="mso-ansi-language: IT"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <o:p> <font color=#000000 size=3>&nbsp;</font> </o:p> </span> </p> <ol> <li> <div class=MsoNormal style="MARGIN: 0in 0in 0pt"><span lang=IT style="mso-ansi-language: IT"> <o:p></o:p> </span><font color=#000000 size=3><a href="https://www.ugidotnet.org/autore/11435/Vito-Plantamura">Microsoft Software Licensing and Protection Services</a></font> </div> <li> <div class=MsoNormal style="MARGIN: 0in 0in 0pt"><font color=#000000 size=3><a href="https://www.ugidotnet.org/autore/11435/Vito-Plantamura">Windows CardSpace e ASP.NET 2.0</a></font> </div> </li> </ol> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span lang=IT style="mso-ansi-language: IT"><font size=3><font color=#000000>E’ necessario registrarsi al sito prima di poter accedere ai contenuti all’interno.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span lang=IT style="mso-ansi-language: IT"><font color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span lang=IT style="mso-ansi-language: IT"><font color=#000000 size=3>Buona Lettura !</font></span> </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=da6f8e20-a955-488e-8c52-501f98d67325" /> http://www.vitoplantamura.com/blog/CommentView,guid,da6f8e20-a955-488e-8c52-501f98d67325.aspx http://www.vitoplantamura.com/blog/Trackback.aspx?guid=445654cb-f99f-4361-9dd6-e20ea2545e27 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,445654cb-f99f-4361-9dd6-e20ea2545e27.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,445654cb-f99f-4361-9dd6-e20ea2545e27.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=445654cb-f99f-4361-9dd6-e20ea2545e27 Una classe per fare Inter-Process Communication tra processi Win32 (C++) http://www.vitoplantamura.com/blog/PermaLink,guid,445654cb-f99f-4361-9dd6-e20ea2545e27.aspx http://www.vitoplantamura.com/blog/2008/02/17/UnaClassePerFareInterProcessCommunicationTraProcessiWin32C.aspx Sun, 17 Feb 2008 15:12:38 GMT <p> <font size=3>Per poter fare Inter-Process Communication tra processi Win32, storicamente, sono disponibili i seguenti strumenti:</font> </p> <ul> <li> <font size=3>Clipboard </font> <li> <font size=3>COM</font> <li> <font size=3>Data Copy </font> <li> <font size=3>DDE </font> <li> <font size=3>File Mapping </font> <li> <font size=3>Mailslots </font> <li> <font size=3>Pipes</font> <li> <font size=3>RPC </font> <li> <font size=3>Windows Sockets</font> </li> </ul> <p> <font size=3>Ognuno di essi ha dei pro, dei contro e delle applicazioni specifiche:</font> </p> <p> <strong><font size=3>Clipboard</font></strong> </p> <p> <font size=3>Probabilmente si tratta del meccanismo meno idoneo per scambiare dati tra processi. La clipboard è condivisa da tutta la sessione Windows corrente e soprattutto l'utente nè ha accesso trasparente quando fà copia ed incolla da un semplice textbox, per esempio.</font> </p> <p> <font size=3>Inoltre manca la possibilità di specificare criteri di sicurezza associati al canale e/o ai dati trasferiti.</font> </p> <p> <strong><font size=3>COM</font></strong> </p> <p> <font size=3>OLE (basato su COM) supporta i "compound documents", dove è possibile edittare parti di documenti provenienti e associati ad applicazioni (processi) Win32 differenti.</font> </p> <p> <strong><font size=3>DCOM</font></strong> </p> <p> <font size=3>DCOM permette di avere client e server distribuiti su processi Win32/64 diversi, ed anche su macchine diverse.</font> </p> <p> <font size=3>Il vantaggio (trasparente) del Marshalling di parametri tra processi diversi rispetto al COM tradizionale permette di oltrepassare i "limiti" del processo corrente.</font> </p> <p> <font size=3>Inoltre, il sofisticato modello di sicurezza implementato permette che solamente parti autorizzate possano connettersi ad un server DCOM.</font> </p> <p> <strong><font size=3>Data Copy </font></strong> </p> <p> <font size=3>Si tratta di un sistema di comunicazione basato sul messaggio Windows "<u>WM_COPYDATA</u>".</font> </p> <p> <font size=3>Il problema principale con questo sistema è la sicurezza: non è possibile (in modo semplice) determinare l'identità di chi sta tendando di inviare messaggi ad un recipient WM_COPYDATA.</font> </p> <p> <font size=3>Un mio articolo (in inglese) su una classe che implementa questo meccanismo di IPC è reperibile qui:</font> </p> <p> <a href="http://www.vitoplantamura.com/index.aspx?page=wmcopydata"><font size=3>http://www.vitoplantamura.com/index.aspx?page=wmcopydata</font></a> </p> <p> <font size=3><strong>DDE</strong> </font> </p> <p> <font size=3>DDE è di solito utilizzato per supportare vecchie applicazioni legacy che possono farne uso.</font> </p> <p> <font size=3>In soluzioni di nuova implementazione si preferisce usare uno degli altri meccanismi di IPC disponibili.</font> </p> <p> <strong><font size=3>Mailslots</font></strong> </p> <p> <font size=3>Nella mia esperienza di sviluppatore, ho avuto (veramente) poco a che fare con le Mailslot.</font> </p> <p> <font size=3>Solitamente vengono utilizzate per fare "broadcast" di piccoli messaggi tra computer nel contesto di un dominio di rete.</font> </p> <p> <font size=3><strong>Pipes</strong> </font> </p> <p> <font size=3>Tra gli strumenti ed il software Microsoft (per Windows NT e superiori), le Named Pipe sono il secondo meccanismo di elezione per realizzare infrastrutture di Interprocess Communication tra processi Win32/64 (dopo i File Mapping, come detto sopra).</font> </p> <p> <font size=3>Una mia classe (e relativo articoletto in inglese) che utilizza le Named Pipe per fare Interprocess Communication è presente negli Archivi del mio sito qui:</font> </p> <p> <a href="http://www.vitoplantamura.com/index.aspx?page=namedpipes"><font size=3>http://www.vitoplantamura.com/index.aspx?page=namedpipes</font></a> </p> <p> <font size=3><strong>RPC</strong> </font> </p> <p> <font size=3>RPC permette di chiamare funzioni remote, in maniera estremamente performante (in un altro processo sullo stesso computer o anche in un'altra macchina nella rete locale)</font> </p> <p> <font size=3>Per queste caratteristiche di velocità, l'RPC è utilizzato estensivamente a livello di sistema su piattaforma Windows NT e superiori.</font> </p> <p> <strong><font size=3>Windows Sockets</font></strong> </p> <p> <font size=3>I Windows Sockets sono lo strumento di elezione per l'IPC tra computer in una stessa rete (LAN, WAN o Internet), ma raramente sono utilizzati come meccanismo unico di comunicazione tra 2 o più processi sulla stessa macchina.</font> </p> <p> <strong><font size=3>File Mapping, e la classe C++ qui presentata:</font></strong> </p> <p> <font size=3>Il File Mapping è uno dei meccanismi più utilizzati per scambiare dati tra processi sulla stessa macchina, e, sicuramente, uno dei preferiti nelle stesse applicazioni sviluppate da Microsoft.</font> </p> <p> <font size=3>In sostanza, il File Mapping permette di trattare un file come se fosse una regione di memoria virtuale mappata nello spazio di indirizzamento del processo corrente. L'opportunità di IPC si presenta quando un secondo processo apre un oggetto di File Mapping oppure quando lo eredita dal processo padre, come accade nella classe associata a questo post.</font> </p> <p> <font size=3>Windows, internamente, mappa la regione di memoria virtuale associata al File Mapping nel primo processo alla stessa memoria fisica (o posizione nel Paging File) anche nel secondo processo: il risultato è che quando si scrive o legge da tale memoria (sia nel primo che nel secondo processo) internamente si sta accedendo alla stessa memoria fisica della macchina.</font> </p> <p> <font size=3>E' possibile associare delle informazioni di sicurezza all'oggetto di File Mapping tramite la struttura <u>SECURITY_ATTRIBUTES</u>, così come accade quando si crea un file, per esempio.</font> </p> <p> <font size=3>Nel caso specifico della classe qui presentata, l'handle all'oggetto di File Mapping viene passato al secondo processo tramite command line dal primo processo (ossia il processo "padre", tramite una chiamata a <u>CreateProcess</u>). Per rendere ciò possibile è necessario specificare esplicitamente che gli oggetti kernel che si stanno creando (nel primo processo) possono essere ereditati da tutti i processi "figli". Questo impostando un bit nella struttura <u>SECURITY_ATTRIBUTES</u>, passata poi alle funzioni "<u>CreateFileMapping</u>" e "<u>CreateEvent</u>":</font> </p> <font size=3> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span><font color=#0000ff>SECURITY_ATTRIBUTES</font><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> sa;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>::memset( &amp; sa, 0, </font><span style="COLOR: blue">sizeof</span><font color=#000000>( sa ) );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>sa.bInheritHandle = TRUE;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000>&nbsp;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>m_hDataAvailEvent = ::<font color=#0000ff>CreateEvent</font>( &amp; sa, FALSE, FALSE, NULL );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>m_hDataReceivedEvent = ::<font color=#0000ff>CreateEvent</font>( &amp; sa, FALSE, FALSE, NULL );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>m_hFileMapping = ::<font color=#0000ff>CreateFileMapping</font>( INVALID_HANDLE_VALUE, &amp; sa, PAGE_READWRITE, 0, m_dwFileMappingDim, NULL );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <span lang=EN-GB style="mso-ansi-language: EN-GB"><font color=#000000><font face="Times New Roman"> <o:p></o:p> </font></font></span> </p> <p> </font><font size=3>La classe ha due costruttori, a seconda se si è nel primo o nel secondo processo:</font>> <font size=3> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>CSharedMemoryChannel( <font color=#0000ff>DWORD</font> dwFileMappingDim )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000>&nbsp;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span>CSharedMemoryChannel( <font color=#0000ff>charstring&amp;</font> csInitParams )<o:p></o:p> </font></span> </p> <p> </font><font size=3>Il primo processo chiama il primo costruttore, specificando semplicemente la dimensione della Shared Section da creare.</font>> <p> <font size=3>Il secondo processo, invece, passa una stringa (eventualmente estratta dalla propria Command Line) con un formato di questo tipo:</font> </p> <font color=#000000 size=3> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp; <font color=#0000ff>handle al File Mapping</font> [PIPE] <font color=#0000ff>dimensione del File Mapping</font> [PIPE] <font color=#0000ff>handle al primo Evento (DataAvailEvent)</font> [PIPE] <font color=#0000ff>handle al secondo Evento (DataReceivedEvent)</font></span> </p> </font> <p> <font size=3>L'applicazione può chiamare il metodo "<u>GetSharedMemoryDataString</u>" per ottenere in automatico questa stringa.</font> </p> <p> <font size=3>Come per le altre classi di IPC simili presenti nella sezione Archivi del mio sito, due tipi di puntatore a funzione sono definiti per permettere al consumer della mia classe di ricevere notifica quando nuovi dati sono presenti oppure quando l'altra parte si è "disconnessa":</font> </p> <font size=3> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><span style="mso-spacerun: yes"><font color=#000000>&nbsp; </font></span><span style="COLOR: blue">typedef</span><font color=#000000> VOID ( </font><span style="COLOR: blue">__cdecl</span><font color=#000000> * PFNSMCRECV )( IN DWORD dwParam, IN LPVOID pvBuffer, IN LONG lBufferSize );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <span lang=EN-GB style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-GB"><span style="mso-spacerun: yes"><font color=#000000>&nbsp; </font></span><span style="COLOR: blue">typedef</span><font color=#000000> VOID ( </font><span style="COLOR: blue">__cdecl</span><font color=#000000> * PFNSMCDISCONNECT )( IN DWORD dwParam );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> </font><font size=3></font>&nbsp;> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <font size=3>Tali puntatori vengono specificati chiamando l'API "<u>SetRecvFunction</u>":</font> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"> <font size=3></font>&nbsp; </p> <font size=3> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span><font color=#0000ff>BOOL</font> SetRecvFunction ( <font color=#0000ff>PFNSMCRECV</font> pfnRecv, <font color=#0000ff>PFNSMCDISCONNECT</font> pfnDisconnect, <font color=#0000ff>DWORD</font> dwRecvParam )</font></span> </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> </font><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><font face=Verdana color=#000000 size=3>La classe è scaricabile qui: </font></span><a href="http://www.vitoplantamura.com/blog/content/binary/SharedMemoryChannel.h"><font size=3>SharedMemoryChannel.h (10,19 KB)</font></a>.> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> &nbsp; </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=445654cb-f99f-4361-9dd6-e20ea2545e27" /> http://www.vitoplantamura.com/blog/CommentView,guid,445654cb-f99f-4361-9dd6-e20ea2545e27.aspx http://www.vitoplantamura.com/blog/Trackback.aspx?guid=82b5a323-9b33-4a49-9e34-2432e8c87204 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,82b5a323-9b33-4a49-9e34-2432e8c87204.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,82b5a323-9b33-4a49-9e34-2432e8c87204.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=82b5a323-9b33-4a49-9e34-2432e8c87204 Un controllino di “Auto-Completion” semplice semplice http://www.vitoplantamura.com/blog/PermaLink,guid,82b5a323-9b33-4a49-9e34-2432e8c87204.aspx http://www.vitoplantamura.com/blog/2008/01/31/UnControllinoDiAutoCompletionSempliceSemplice.aspx Thu, 31 Jan 2008 16:04:11 GMT <p> <font size=3>Nel tentativo di aggiornare questo blog quanto più frequentemente possibile, mi piacerebbe postare qui del codice che ho scritto qualche tempo fà allo scopo di implementare qualcosa di simile all’effetto di menù a tendina fatto conoscere al grande pubblico (se non sbaglio) da </font><a href="http://www.google.com/webhp?complete=1&amp;hl=en"><font size=3>Google Suggest</font></a><font size=3> qualche anno orsono:</font> </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/1.gif" border=0> </p> <p> <font size=3>Dunque, immagino che su internet si possano trovare decine di esempi simili (anche su </font><a href="http://www.codeproject.com/"><font size=3>CodeProject</font></a><font size=3>, probabilmente) ma ritengo che la bellezza della mia soluzione consista nel fatto che:</font> </p> <ul> <li> <font size=3>L’intera implementazione è veramente esigua. Questo significa che è possibile, per chi si sta avvicinando adesso ad AJAX, di capire un poco di più di che cosa si tratti, da un punto di vista molto di “basso livello”, se così si può dire. Nella mia esperienza di consulente e formatore, noto sempre più spesso la carenza di competenze Javascript (anche nei più abili programmatori ASP.NET !!) e contemporaneamente come tali competenze siano sempre più richieste dal mercato (vedi ad esempio la miriade di siti, anche italiani, recentemente usciti o rifatti, dove popup e menù a tendina come quello in oggetto sono ovunque). </font> <li> <font size=3>In virtù del punto precedente, eventuali “customizzazioni” al mio lavoro risultano estremamente semplici da implementare: in altri controlli simili al mio che ho visto in giro (anche blasonati), tale semplicità si perde molto spesso in una miriade di eventi client o server nei quali il programmatore medio (e non) tende ad affogare (senza alla fine raggiungere il risultato desiderato).</font> </li> </ul> <p> <font size=3>Di contro però, c’è da dire che il codice che segue è stato espressamente scritto per Internet Explorer (quindi ideale per una applicazione di tipo intranet dove i requisiti dei client sono prefissati e conosciuti). Comunque, adeguare questo codice affinchè funzioni anche con altri browser è cosa assai semplice.</font> </p> <p> <font size=3>Per cominciare c’è la parte HTML. Questo markup permette di renderizzare un editbox predisposto a visualizzare il menù di Auto-Completion quando si preme un tasto, per esempio:</font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;</span><span style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">div</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> </font><span style="COLOR: red">style</span><span style="COLOR: blue"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />="position: relative;"&gt;<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">&lt;</span><span style="COLOR: #a31515">input</span><font color=#000000> </font><span style="COLOR: red">name</span><span style="COLOR: blue">="ctrlAcSearchBox"</span><font color=#000000> </font><span style="COLOR: red">id</span><span style="COLOR: blue">="ctrlAcSearchBox"</span><font color=#000000> </font><span style="COLOR: red">type</span><span style="COLOR: blue">="text"</span><font color=#000000> </font><span style="COLOR: red">autocomplete</span><span style="COLOR: blue">="off"</span><font color=#000000> </font><span style="COLOR: red">Style</span><span style="COLOR: blue">="width: 250px;"<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: red">onkeydown</span><span style="COLOR: blue">='</span><font color=#000000><span style="BACKGROUND: yellow; mso-highlight: yellow">&lt;%</span>= "AutoCompletion_onEditBoxKey(\"" + "ctrlAcSearchBox" + "\", event.keyCode);" <span style="BACKGROUND: yellow; mso-highlight: yellow">%&gt;</span></font><span style="COLOR: blue">'<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: red">onkeyup</span><span style="COLOR: blue">='</span><font color=#000000><span style="BACKGROUND: yellow; mso-highlight: yellow">&lt;%</span>= "AutoCompletion_onEditBoxKeyChange(\"http://localhost/folder/AutoCompletionInterface.aspx\", \"" + "ctrlAcSearchBox" + "\", event.keyCode);" <span style="BACKGROUND: yellow; mso-highlight: yellow">%&gt;</span></font><span style="COLOR: blue">'<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: red">ondeactivate</span><span style="COLOR: blue">='</span><font color=#000000><span style="BACKGROUND: yellow; mso-highlight: yellow">&lt;%</span>= "document.getElementById( \"" + "ctrlAcSearchBox" + "\" + \"div\" ).style.display = \"none\";" <span style="BACKGROUND: yellow; mso-highlight: yellow">%&gt;</span></font><span style="COLOR: blue">'</span><font color=#000000> </font><span style="COLOR: blue">/&gt;<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">&lt;</span><span style="COLOR: #a31515">div</span><font color=#000000> </font><span style="COLOR: red">id</span><span style="COLOR: blue">='</span><font color=#000000><span style="BACKGROUND: yellow; mso-highlight: yellow">&lt;%</span>= "ctrlAcSearchBox" + "div" <span style="BACKGROUND: yellow; mso-highlight: yellow">%&gt;</span></font><span style="COLOR: blue">'</span><font color=#000000> </font><span style="COLOR: red">style</span><span style="COLOR: blue">="position: absolute; top: 23px;<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>left: 0px; width: 250px; display: none;"&gt;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">&lt;/</span><span style="COLOR: #a31515">div</span><span style="COLOR: blue">&gt;<o:p></o:p> </span></span> </p> <p> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">&lt;/</span><span style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">div</span><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">&gt;</span> </p> <p> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><font face=Verdana color=#000000><font size=3>La presenza qui delle due DIV è fondamentale: infatti la seconda DIV (ossia quella innestata), con l’attributo di stile “position: absolute” permette di visualizzare il box di Auto-Completion esattamente sotto l’editbox: infatti la direttiva “absolute”, che normalmente renderizzerebbe il contenuto della DIV rispetto all’angolo superiore-sinistro della fine<font color=#000000>stra di browsing, qui viene invece riferita alla posizione della prima DIV, che possiede un attributo di stile di tipo “position: relative”. Togliendo infatti la prima DIV, si ottiene l’effetto di vedere il box di Auto-Completion nell’angolo superiore-sinistro della finestra, confermando quindi questa regola dell’HTML.</font></font></font></span> </p> <p> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><font face=Verdana color=#000000 size=3>Il controllo INPUT TYPE=”TEXT” gestisce una serie di eventi che permettono al box di Auto-Completion di apparire e scomparire all’occorrenza (onkeydown, onkeyup, ondeactivate). Ricordo che da Code-Behind è possibile leggere il valore inserito nell’editbox scrivendo del codice come questo:</font></span> </p> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><font color=#0000ff>Request</font>.Form[“<font color=#ff0000>ctrlAcSearchBox</font>”]</font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><font face=Verdana size=3>Inoltre in una posizione idonea della pagina è necessario includere il file .js che di fatto implementa il box di Auto-Completion lato-client:</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000></font></span>&nbsp; </p> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&lt;</span><span style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">script</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> </font><span style="COLOR: red">type</span><span style="COLOR: blue">="text/javascript"</span><font color=#000000> </font><span style="COLOR: red">src</span><span style="COLOR: blue">="http://localhost/folder/AutoCompletion.js"&gt;&lt;/</span><span style="COLOR: #a31515">script</span><span style="COLOR: blue">&gt;</span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="COLOR: blue"></span></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="COLOR: blue"><font face=Verdana color=#000000><font size=3>E’ possibile scaricare tale file da questo indirizzo: </font><a href="http://www.vitoplantamura.com/blog/content/binary/AutoCompletion.js"><font size=3>AutoCompletion.js (3,43 KB)</font></a><font size=3>. In ogni caso, di seguito, è riportato integralmente:</font></font></span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="COLOR: blue"><font face=Verdana color=#000000></font></span></span>&nbsp; </p> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="COLOR: blue"> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_getSelection (n, def)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">for</span><font color=#000000>( i=0; i&lt;10; i ++ )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> tr = document.getElementById( n + </font><span style="COLOR: #a31515">"tr"</span><font color=#000000> + i );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( tr == </font><span style="COLOR: blue">null</span><font color=#000000> )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000> def;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">else</span><font color=#000000> </font><span style="COLOR: blue">if</span><font color=#000000> ( tr.style.color == </font><span style="COLOR: #a31515">"#ffffff"</span><font color=#000000> )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000> i;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span> <o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000> def;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_putSelection (n, s)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">for</span><font color=#000000>( i=0; i&lt;10; i ++ )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> tr = document.getElementById( n + </font><span style="COLOR: #a31515">"tr"</span><font color=#000000> + i );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( tr == </font><span style="COLOR: blue">null</span><font color=#000000> )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font><span style="COLOR: blue">return</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( s == i )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>tr.style.backgroundColor = </font><span style="COLOR: #a31515">"#0040D0"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>tr.style.color = </font><span style="COLOR: #a31515">"#ffffff"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">else<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>tr.style.backgroundColor = </font><span style="COLOR: #a31515">"#ffffff"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>tr.style.color = </font><span style="COLOR: #a31515">"#000000"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_getNum (n)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> i;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">for</span><font color=#000000>( i=0; i&lt;10; i ++ )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> tr = document.getElementById( n + </font><span style="COLOR: #a31515">"tr"</span><font color=#000000> + i );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( tr == </font><span style="COLOR: blue">null</span><font color=#000000> )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000> i;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000> i;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_processResponse (n)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> req = document.getElementById( n + </font><span style="COLOR: #a31515">"div"</span><font color=#000000> ).req;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( req.readyState == 4 &amp;&amp; req.status == 200 )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>document.getElementById( n + </font><span style="COLOR: #a31515">"div"</span><font color=#000000> ).style.display = </font><span style="COLOR: #a31515">"block"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>document.getElementById( n + </font><span style="COLOR: #a31515">"div"</span><font color=#000000> ).innerHTML = req.responseText;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_setEditText (n)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> sel = AutoCompletion_getSelection (n);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( sel == </font><span style="COLOR: blue">null</span><font color=#000000> )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>document.getElementById( n ).value = document.getElementById( n + </font><span style="COLOR: #a31515">"span"</span><font color=#000000> + sel ).innerHTML;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>document.getElementById( n + </font><span style="COLOR: #a31515">"div"</span><font color=#000000> ).style.display = </font><span style="COLOR: #a31515">"none"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>document.getElementById( n ).focus ();<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_onEditBoxKey (n, key)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( key == 27 ) </font><span style="COLOR: green">// esc.<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>document.getElementById( n + </font><span style="COLOR: #a31515">"div"</span><font color=#000000> ).style.display = </font><span style="COLOR: #a31515">"none"</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">event</span><font color=#000000>.returnValue = </font><span style="COLOR: blue">false</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span> <o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( key == 38 ) </font><span style="COLOR: green">// up.<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> s = AutoCompletion_getSelection (n, 0) - 1;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( s &lt; 0 )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>s = AutoCompletion_getNum(n) - 1;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>AutoCompletion_putSelection( n, s );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">event</span><font color=#000000>.returnValue = </font><span style="COLOR: blue">false</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">else</span><font color=#000000> </font><span style="COLOR: blue">if</span><font color=#000000> ( key == 40 ) </font><span style="COLOR: green">// down.<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> s = AutoCompletion_getSelection (n, AutoCompletion_getNum(n)-1) + 1;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp; </span><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font><span style="COLOR: blue">if</span><font color=#000000> ( s &gt;= AutoCompletion_getNum (n) )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>s = 0;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>AutoCompletion_putSelection( n, s );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">event</span><font color=#000000>.returnValue = </font><span style="COLOR: blue">false</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">else</span><font color=#000000> </font><span style="COLOR: blue">if</span><font color=#000000> ( key == 13 ) </font><span style="COLOR: green">// enter.<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>AutoCompletion_setEditText (n);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">event</span><font color=#000000>.returnValue = </font><span style="COLOR: blue">false</span><font color=#000000>;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> encodeHtml ( s )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>s = escape(s);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>s = s.replace(/\</font><span style="COLOR: green">//g,"%2F");<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>s = s.replace(/\?/g,</font><span style="COLOR: #a31515">"%3F"</span><font color=#000000>);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>s = s.replace(/=/g,</font><span style="COLOR: #a31515">"%3D"</span><font color=#000000>);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>s = s.replace(/&amp;/g,</font><span style="COLOR: #a31515">"%26"</span><font color=#000000>);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>s = s.replace(/@/g,</font><span style="COLOR: #a31515">"%40"</span><font color=#000000>);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">return</span><font color=#000000> s;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>} <o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <o:p> <font color=#000000>&nbsp;</font> </o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">function</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000> AutoCompletion_onEditBoxKeyChange (base, n, key)<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">if</span><font color=#000000> ( key == 8 || (key &gt;= 32 &amp;&amp; key != 38 &amp;&amp; key != 40) )<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> url = base + </font><span style="COLOR: #a31515">"?str="</span><font color=#000000> + encodeHtml( document.getElementById( n ).value ) + </font><span style="COLOR: #a31515">"&amp;rnd="</span><font color=#000000> + Math.floor(Math.random()*1000000000) + </font><span style="COLOR: #a31515">"&amp;n="</span><font color=#000000> + n;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span> <o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">var</span><font color=#000000> req = </font><span style="COLOR: blue">new</span><font color=#000000> ActiveXObject(</font><span style="COLOR: #a31515">"Microsoft.XMLHTTP"</span><font color=#000000>);<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>document.getElementById( n + </font><span style="COLOR: #a31515">"div"</span><font color=#000000> ).req = req;<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>req.onreadystatechange = </font><span style="COLOR: blue">new</span><font color=#000000> Function ( </font><span style="COLOR: #a31515">"AutoCompletion_processResponse('"</span><font color=#000000> + n + </font><span style="COLOR: #a31515">"');"</span><font color=#000000> );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>req.open ( </font><span style="COLOR: #a31515">"GET"</span><font color=#000000>, url, </font><span style="COLOR: blue">true</span><font color=#000000> );<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>req.send ();<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000>}</font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3>Di <font color=#000000>seguito è riportata una descrizione di ciascuna funzione JS:</font></font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_getSelection</strong>: semplicemente ritorna l’indice dell’elemento attualmente selezionato nel box.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_putSelection</strong>: seleziona un elemento nel box.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_getNum</strong>: restituisce la dimensione del box, come numero di item attualmente visualizzati.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_setEditText</strong>: in base alla selezione corrente nel box, popola l’editbox opportunamente.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_onEditBoxKey</strong> (associata all’evento “onkeydown” dell’editbox): gestisce la pressione dei tasti quando il focus appartiene all’editbox (tasti: esc, su, giù, enter).</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_onEditBoxKeyChange</strong> (associata all’evento “onkeyup” dell’editbox): scatena una richiesta GET al server (attraverso l’oggetto "Microsoft.XMLHTTP") alla pressione di un tasto nell’editbox. Come specificato nell’evento “onreadystatechange”, la gestione della risposta da parte del server è demandata alla funzione JS con nome “AutoCompletion_processResponse”.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3><strong>AutoCompletion_processResponse</strong>: questa funzione riceve la risposta del server. In questo caso, il server restituisce HTML (direttamente il contenuto del box di Auto-Completion). In altri casi è frequente trovare l’oggetto "Microsoft.XMLHTTP” coinvolto nello scambio di markup XML tra server e client (questo argomento, però, esula dagli obiettivi di questo post).</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3>Dietro le quinte, una pagina ASPX si occupa di restituire il markup HTML che costituisce il box di Auto-Completion visualizzato. L’URL di tale pagina ASPX è fornito alla funzione “AutoCompletion_onEditBoxKeyChange” nel gestore dell’evento “onkeyup” del nostro INPUT TYPE=”TEXT” (ossia dell’editbox).</font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000><font size=3>Il codice di questa pagina è scaricabile qui (</font><a href="http://www.vitoplantamura.com/blog/content/binary/AutoCompletionInterface.aspx.txt"><font size=3>AutoCompletionInterface.aspx (0,45 KB)</font></a><font size=3>&nbsp;+ </font><a href="http://www.vitoplantamura.com/blog/content/binary/AutoCompletionInterface.aspx.cs.txt"><font size=3>AutoCompletionInterface.aspx.cs (2,4 KB)</font></a><font size=3>). Il markup della pagina ASPX è trascurabile. La struttura del file di Code-Behind, invece, è molto intuitiva: nel gestore della Page_Load, viene generato dell’HTML secondo la stringa di ricerca passata (ossia ciò che l’utente ha inserito nell’editbox) quindi il markup risultante viene restituito come risposta alla GET della parte JS.</font></font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3></font></span>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font face=Verdana color=#000000 size=3>Tale markup verrà quindi visualizzato nella seconda DIV di cui sopra, mostrando il box di Auto-Completion:</font></span> </span></span>> <p> </span></span><img src="http://www.vitoplantamura.com/blog/content/binary/2.gif" border=0>> <p> <font color=#000000 size=3>Nel file di Code-Behind di esempio, viene chiamata una Stored Procedure che potrebbe essere qualcosa del genere:</font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-tab-count: 1"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">SELECT</span><font color=#000000> </font><span style="COLOR: blue">TOP</span><font color=#000000> 10<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><font color=#000000><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>u</font><span style="COLOR: gray">.</span><font color=#000000>nome_cognome<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">FROM</span><font color=#000000> Utenti u<o:p></o:p> </font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="COLOR: blue">WHERE</span><font color=#000000> u</font><span style="COLOR: gray">.</span><font color=#000000>nome_cognome </font><span style="COLOR: gray">like</span><font color=#000000> @Nome_Cognome </font><span style="COLOR: gray">+</span><font color=#000000> </font><span style="COLOR: red">'%'<o:p></o:p> </span></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes"><font color=#000000>&nbsp; </font></span><span style="COLOR: blue">ORDER</span><font color=#000000> </font><span style="COLOR: blue">BY</span><font color=#000000> u</font><span style="COLOR: gray">.</span><font color=#000000>nome_cognome</font></span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"></span>&nbsp; </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=82b5a323-9b33-4a49-9e34-2432e8c87204" /> http://www.vitoplantamura.com/blog/CommentView,guid,82b5a323-9b33-4a49-9e34-2432e8c87204.aspx http://www.vitoplantamura.com/blog/Trackback.aspx?guid=28c85b7f-9966-4e22-ab43-e99dc56f575e http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,28c85b7f-9966-4e22-ab43-e99dc56f575e.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,28c85b7f-9966-4e22-ab43-e99dc56f575e.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=28c85b7f-9966-4e22-ab43-e99dc56f575e File di Style Sheet specificati al runtime. http://www.vitoplantamura.com/blog/PermaLink,guid,28c85b7f-9966-4e22-ab43-e99dc56f575e.aspx http://www.vitoplantamura.com/blog/2007/12/15/FileDiStyleSheetSpecificatiAlRuntime.aspx Sat, 15 Dec 2007 14:23:42 GMT <p> <font size=3><font color=#000000>G</font><font color=#000000>iusto un piccolo update al Blog, in modo da poter dimostrare di essere ancora vivo ed "attivo"... :-)</font></font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3>Dunque un pò di tempo fà mi sono imbattuto nella necessità di dover aggiungere al run-time un file di Style Sheet (tipicamente con estensione ".css") ad una pagina ".aspx" (ASP.NET 2.0). Tipicamente le direttive al browser circa quali file css caricare vengono specificate nella sezione "&lt;head&gt;" di una pagina html: poichè il contesto nel quale mi trovavo era una webpart per DotNetNuke (ossia un controllo ".ascx") e poichè il file ".css" da tirare sù dipendeva da diverse variabili che potevo conoscere solo al run-time, ho dovuto trovare una soluzione al problema, forse un poco fuori dagli schemi.</font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000><font size=3><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />&nbsp;<o:p></o:p> </font></font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3>Dunque, il codice è il seguente:</font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3></font>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000></font>&nbsp; </p> <font face="Times New Roman" color=#000000 size=3> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;Control page = <span style="COLOR: blue">null</span>;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;Control c = Parent;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;while</span><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US"> (c != <span style="COLOR: blue">null</span>)<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;{<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;&nbsp;page = c;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;&nbsp;c = c.Parent;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;}<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;HtmlLink stylesheet = <span style="COLOR: blue">new</span> HtmlLink();<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;stylesheet.Href = <span style="COLOR: maroon">"http://www.someserver.com/stylesheet.css"</span>;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;stylesheet.Attributes[<span style="COLOR: maroon">"rel"</span>] = <span style="COLOR: maroon">"stylesheet"</span>;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;stylesheet.Attributes[<span style="COLOR: maroon">"text"</span>] = <span style="COLOR: maroon">"text/css"</span>;<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> <span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">&nbsp;&nbsp;&nbsp;((System.Web.UI.Page)page).Header.Controls.Add(stylesheet);<o:p></o:p> </span> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> &nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> </font>&nbsp;> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3>In sostanza, nella prima parte viene ottenuta una reference alla pagina principale (.ASPX), mentre nella seconda si procede alla specificazione del file .CSS da caricare sul client.</font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3></font>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3>L'esigenza di fare una cosa del genere potrebbe sembrare piuttosto remota, ma, al contrario, se si pensa per esempio alla necessità di incorporare un controllo di terze parti in una webpart per DotNetNuke (come nel mio caso) che magari sia closed-source e che magari richieda un particolare foglio di stile per funzionare correttamente, il codice sopra potrebbe essere di fondamentale aiuto...</font> </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3></font>&nbsp; </p> <p class=MsoNormal style="MARGIN: 0in 0in 0pt"> <font color=#000000 size=3>Se qualcuno dovesse conoscere una soluzione più semplice per ottenere lo stesso risultato, si senta libero di postarla qui come risposta.</font> </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=28c85b7f-9966-4e22-ab43-e99dc56f575e" /> http://www.vitoplantamura.com/blog/CommentView,guid,28c85b7f-9966-4e22-ab43-e99dc56f575e.aspx http://www.vitoplantamura.com/blog/Trackback.aspx?guid=b5b64f9e-ee07-4ed3-a7dd-91fed524df48 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,b5b64f9e-ee07-4ed3-a7dd-91fed524df48.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,b5b64f9e-ee07-4ed3-a7dd-91fed524df48.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=b5b64f9e-ee07-4ed3-a7dd-91fed524df48 4

Per un mio grosso cliente di Milano, sto dirigendo tecnologicamente lo sviluppo di un portale basato su ASP.NET 2.0, dove, funzionalmente, è richiesta l'integrazione di certe logiche di workflowing nella gestione dei loro processi aziendali.

A tale scopo ho proposto l'utilizzo di Windows Workflow Foundation, in modo da poter testare sul campo (aldilà di semplici applicazioni di prova), nel contesto dello sviluppo di un grosso progetto di classe enterprise questa nuova interessante tecnologia di Microsoft.

Dopo qualche ora di ricerca sono riuscito ad accumulare abbastanza conoscenza per mettere sù un proof of concept al fine di collaudare le idee ed ipotesi che avevo maturato. Allegata a questo post, c'è una applicazione ASP.NET di esempio derivata da quel mio primo prototipo.

La Web Application di Esempio

E' possibile scaricare l'applicazione di esempio qui: WwfExample.rar (386,08 KB).

L'applicazione (la solution) consta di due progetti: la Web Application ed il progetto Workflows, che racchiude tutto il codice specifico che consuma i servizi di Workflow Foundation (WF).

Prima di poter utilizzare l'applicazione in questione, è necessario "attaccare" il file di database fornito alla istanza di SQL Server 2005 Express presente sulla macchina di sviluppo.

L'applicazione utilizza tre tabelle per mantenere il suo stato:

La tabella Users mantiene una lista di tutti gli utenti abilitati ad utilizzare l'applicazione, con relativi ruoli separati da virgola. La tabella WorkflowsList mantiene una lista di tutti i workflow che l'applicazione è abilitata a far partire, con, annesse, informazioni circa quali utenti e quali gruppi hanno tale privilegio e, soprattutto, indicazioni circa il tipo .NET e l'assembly dal quale recuperare la definizione della classe di Workflow. La tabella UserActivities mantiene uno stato della applicazione "parallelo" a quello del Workflow ed è la tebella che viene consultata dal sistema per capire in quale stato si trova l'intera applicazione. I record in questa tabella vengono aggiunti direttamente dalle Activity del Workflow ed essa è una prima ma importante forma di comunicazione tra codice ASP.NET e codice di Workflow Foundation.

Sono inoltre presenti anche queste due tabelle:

In particolare, la tabella InstanceState viene utilizzata da Workflow Foundation (specificatamente dal servizio SqlWorkflowPersistenceService) per persistere lo stato di un determinato Workflow: il Workflow viene serializzato attraverso il BinaryFormatter, poi compresso, quindi depositato nel campo blob state di questa tabella. Per creare queste due tabelle, e relative stored procedure, è necessario recuperare ed eseguire gli script presenti tipicamente qui:

C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\SqlPersistenceService_Schema.sql

C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\SqlPersistenceService_Logic.sql

NOTA: nel file di db incluso in questo esempio, le tabelle e le stored procedure di WF sono già presenti.

Fatta partire, l'applicazione mostra una semplice mascherina di login:

Dove viene appurato il nome dell'utente e, soprattutto, i ruoli a lui assegnati (tramite lookup su db). Verificata la veridicità delle credenziali, viene creato un FormsAuthenticationTicket contenente le informazioni di interesse applicativo sull'utente.

Immediatamente dopo si accede alla form principale dell'applicazione di esempio:

Questa form permette di avviare un dato workflow (se si dispone delle autorizzazioni necessarie per poterlo fare) e di gestire attività pendenti (sempre se si è autorizzati a farlo). La griglia delle attività pendenti (la seconda) viene popolata attraverso la tabella UserActivities su database, che a sua volta viene popolata dal codice del Workflow avviato e gestito dall'applicazione ASP.NET, con nome WorkflowExample.cs:

Questo semplice workflow sequenziale definisce una serie di form ASP.NET da visualizzare una dopo l'altra. A ciascuna form sono associati diritti a livello di utente e ruolo, in modo che soltanto gli utenti abilitati abbiano modo di accedervi. E' naturalmente possibile definire workflow di una complessità molto superiore rispetto a quella del workflow qui rappresentato. Nella fattispecie, è possibile inserire qualsiasi tipo di Activity nel flusso di esecuzione del workflow: se necessario, è possibile definire uno stato privato al workflow aggiungendo proprietà (eventualmente bindabili) nel file WorkflowExample.cs. La proprietà bindabile DataSet nella classe Workflows.UserActivity, come spiegato sotto, può essere utilizzata per scambiare dati tra il workflow e l'applicazione ASP.NET.

Da interfaccia utente, in Visual Studio (ossia dal Workflow Designer) è possibile, per ciascuna form, definire proprietà salienti, tra le quali quelle di autorizzazione appena descritte:

La proprietà DataSet (quando bindata) permette di passare informazioni da una Activity ad un'altra, passando dal codice ASP.NET, nel nostro caso specifico: il sistema, infatti, serializza di volta in volta il contenuto di questa proprietà della Activity nel campo DetailsXml della tabella UserActivities; questo permette al codice della pagina web di modificare il dataset, che poi, trasparentemente, viene ripassato alla Activity del Workflow, in modo che lo stato della proprietà bindabile sia aggiornato opportunamente.

Cliccando su una attività pendente, si accede ad una form di gestione:

Il link Complete Activity scatena il codice che realizza l'interoperabilità con Workflow Foundation: in questo caso e per il nostro Workflow di esempio, l'attività "Form2" viene chiusa e si passa all'attività "Form3", che è giusto la successiva nel nostro workflow sequenziale.

Il funzionamento dell'intera applicazione è piuttosto semplice, se si intendono i meccanismi di intercomunicazione di WF (vedi code di item, o WorkflowQueue). Questo schema dovrebbe riassumere a grandi linee ciò che accade:

La discussione seguente è un poco più complessa, poichè tratta specificatamente dei problemi di interoperabilità tra ASP.NET e WF e delle soluzioni che ho ricercato e deciso di adottare caso per caso.

Threading

Normalmente, Workflow Foundation utilizza le caratteristiche del servizio DefaultWorkflowSchedulerService per creare e coordinare i thread responsabili dell’esecuzione di tutti i workflow associati ad uno stesso runtime (WorkflowRuntime). Nella fattispecie, questo implica l’esecuzione asincrona delle istanze di workflow gestite da un runtime, che vengono opportunamente e trasparentemente messe nella coda di esecuzione del thread pool .NET associato all’applicazione host.

Nel contesto di una applicazione ASP.NET, questo, generalmente, non è desiderabile. Infatti, il DefaultWorkflowSchedulerService, quando utilizzato in una applicazione web, và ad impegnare un thread aggiuntivo per ciascuna richiesta HTTP che il server di IIS, in un dato momento, sta processando e che richiede le funzionalità di Workflow Foundation. Per indirizzare questo problema, è necessario specificare il servizio ManualWorkflowSchedulerService, quando si inizializza una istanza del WorkflowRuntime:

Runtime =new WorkflowRuntime();

[...]

Runtime.AddService(new ManualWorkflowSchedulerService(true));

[...]

Questo permette di controllare l’esecuzione di un dato workflow, di coordinarla rispetto al thread che sta servendo la richiesta HTTP e di disimpegnare un thread dal thread pool dell’applicazione host, poichè WF và ad eseguire le nostre activity nel contesto dello stesso thread che sta eseguendo la pagina ASP.NET.

Quanto detto è possibile evincerlo empiricamente andando a sbirciare nel call stack .NET durante l’esecuzione dell’applicazione di esempio allegata a questo post:

UserActivity.Execute è il nostro codice applicativo che implementa la nostra Activity (il primo contesto evidenziato in blu). API.CompleteActivity (il secondo contesto in blu) è un nostro metodo chiamato direttamente da un gestore eventi di un pulsante di una webform, che chiama l’API ManualWorkflowSchedulerService.RunWorkflow, che provoca l’esecuzione immediata del workflow il cui ID passiamo come parametro. Come anticipato, sia il codice della pagina web che quello del workflow vengono eseguiti nel contesto dello stesso thread.

Transazionalità e Persistenza

La classe TransactionScope (System.Transactions) permette di definire contesti transazionali in codice .NET 2.0 e 3.0 in maniera semplice ed immediata. Specialmente se si utilizza SQL Server 2005, l’uso della classe TransactionScope diviene ancora più semplice, poichè si viene liberati del tutto da tutte quelle considerazioni di cui tener conto circa eventuali, inutili e costosi coinvolgimenti del MSDTC per transazioni puramente locali, importanti invece quando si lavora, per esempio, con SQL Server 2000. Sorvolando sulle specifiche caratteristiche della classe TransactionScope (fuori dagli obiettivi di questo post), nell’esempio fornito viene usata questa nuova funzionalità di .NET 2.0 per la scrittura di codice transazionale che scrive su SQL Server.

Uno dei requisiti principali per realizzare una consistente interoperabilità tra WF e ASP.NET è la corretta gestione della persistenza dei workflow su database. Per comunicare a Workflow Foundation di persistere tutti i workflow relativi ad uno stesso WorkflowRuntime su database, è necessario registrare il servizio SqlWorkflowPersistenceService all’atto della inizializzazione dell’istanza del WorkflowRuntime:

Runtime =new WorkflowRuntime();

[...]

NameValueCollection parameters =new NameValueCollection();
parameters.Add("ConnectionString", connectionString);
parameters.Add("UnloadOnIdle", "false");
Runtime.AddService(new SqlWorkflowPersistenceService(parameters));

[...]

Come parametri, specifichiamo la stringa di connessione al database ed indichiamo al servizio di NON persistere un workflow su database quando questo è inattivo (parametro UnloadOnIdle): infatti, per un maggiore controllo e per ragioni di consistenza transazionale che vedremo tra poco, ci preoccupiamo noi di chiamare il metodo WorkflowInstance.Unload quando intendiamo persistere una istanza di Workflow su db.

Infatti uno dei maggiori problemi quando si intende integrare della logica che accede ad un db in una istanza di Workflow con della logica dello stesso tipo eseguita esternamente nel contesto dell’applicazione host (in questo caso ASP.NET) è che WF, per ragioni di design, impedisce alla transazione ambientale associata al thread di esecuzione nel momento in cui si esegue il workflow (ManualWorkflowSchedulerService.RunWorkflow) di propagarsi fino al contesto di esecuzione nel quale vengono eseguite le Activity del workflow. Questo è possibile evincerlo empiricamente, per esempio, debuggando l’applicazione di esempio di questo post: prima di chiamare l’API ManualWorkflowSchedulerService.RunWorkflow, la proprietà statica System.Transactions.Transaction.Current è correttamente valorizzata, poichè siamo in uno scope transazionale definito da un costrutto TransactionScope. Al contrario, all’interno del metodo UserActivity.Execute (che implementa la nostra activity) tale proprietà statica ha valore nullo, benchè la chiamata al metodo UserActivity.Execute sia originata a partire da del codice configurato per essere transazionale.

Volendo approfondire la questione ed i motivi di tale comportamento, è necessario ritornare al call stack rappresentato all’inizio di questo post: nella fattispecie, in una delle 9 chiamate che separano il codice host dal codice della Activity, WF ha intenzionalmente “soppresso” la nostra transazione ambientale. Alla fine, come risultato, questo ci impedisce di associare del codice che accede al db in una Activity di un Workflow ad una transazione iniziata dall’host.

Volendo scendere nel merito, magari utilizzando l’ottimo .NET Reflector di Roeder e spulciando rapidamente in quei 9 metodi di cui sopra, è possibile trovare la spiegazione di questo comportamento nel metodo System.Workflow.Runtime.WorkflowExecutor.RunSome, che, decompilato, appare così:

internal void RunSome(object ignored)
{
   [...]

   using (TransactionScope scope =new TransactionScope(TransactionScopeOption.Suppress))
   {
      try
      {
         this.FireWorkflowExecutionEvent(this, WorkflowEventInternal.Executing);
         this.RunScheduler();
      }
      catch (Exception exception)
      {

         [...]

      }
      finally
      {
         this.FireWorkflowExecutionEvent(this, WorkflowEventInternal.NotExecuting);
      }

      scope.Complete();
   }

   [...]
}

Questo ci obbliga a trovare nuove soluzioni per scrivere sul database in maniera consistente.

La soluzione che ho ricercato ed adottato sfrutta i meccanismi di serializzazione di .NET, per mettere “in coda” una o più operazioni che è necessario associare ad una transazione controllata dal codice host (ossia da noi). Per ottenere l’effetto desiderato, bisogna, per prima cosa, creare una coda di Workflow dove andare ad aggiungere istanze di un nostro tipo custom (con nome DbAccessCallDetails), che rappresenta una chiamata ad un metodo di qualsiasi tipo che interagisce col db. L’idea di base è di registrare semplicemente l’operazione di interazione col db in questa coda (quando si è all’interno di una Activity), quindi, andare a chiamare il metodo che implementa tale operazione in un secondo momento, per esempio all’atto della serializzazione del Workflow su database. Considerando che la coda di Workflow (WorkflowQueue) è un oggetto che appartiene al Workflow e che le nostre istanze di DbAccessCallDetails si trovano depositate in tale coda, quando il servizio SqlWorkflowPersistenceService, tramite il BinaryFormatter, andrà a serializzare, quindi comprimere e persistere su db il nostro Workflow, noi avremo l’occasione che aspettiamo per svuotare la nostra coda e quindi eseguire quei metodi di cui avevamo procrastinato l’esecuzione.

La classe DbAccessCallDetails si presenta semplicemente così:

[Serializable()]
publicclass DbAccessCallDetails : ISerializable
{
   // constructor(s).
   public DbAccessCallDetails(Delegate fnParam, object[] psParam)
   {
      fn = fnParam;
      ps = psParam;
   }
   public DbAccessCallDetails(SerializationInfo info, StreamingContext context)
   {
   }

   // data.
   public Delegate fn =null;
   publicobject[] ps =null;

   // ISerializable stuff.
   void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
   {
      // call the method.
      if (fn !=null)
         fn.DynamicInvoke(ps);
   }
}

In breve, quando si cerca di serializzare una istanza di questa classe, viene chiamato il metodo ISerializable.GetObjectData, che semplicemente invoca il metodo ad essa associato. Questo metodo inserisce dei record su db, nel caso del mio esempio (tabella UserActivities).

Come detto precedentemente, la serializzazione del Workflow avviene all’atto della chiamata al metodo WorkflowInstance.Unload. Come emerge da vari documenti e testimonianze su internet, e come può essere approfondito direttamente attraverso Reflector, questo metodo (intenzionalmente) è l’unico pezzo di codice di WF che non sopprime attivamente la transazione ambientale del thread che lo sta chiamando. Questo significa che è possibile associare ad una stessa transazione ambientale gestita dall’host sia la persistenza dell’istanza del Workflow su database, sia il codice rappresentato dalle varie istanze di DbAccessCallDetails eventualmente presenti nella coda del Workflow. Questo “trucco” ci permette di avere sul database uno stato dei dati di interoperabilità tra la nostra applicazione e Workflow Foundation sempre consistenti:

public static void CompleteActivity(Guid workflowGuid, Guid activityGuid, DataSet activityData, System.Web.HttpRequest Request, System.Web.HttpResponse resp)
{
   // notify the completion to the wf.
   WorkflowInstance wi = Runtime.GetWorkflow(workflowGuid);
   wi.EnqueueItem(
      activityGuid.ToString(),
      new ActivityCompletedEventArgs(activityData),
      null, null);

   // tell the workflow to progress.
   string redirectUrl =null;
   using (TransactionScope scope =new TransactionScope())
   {
      // complete on the db.
      using (Workflows.DataTableAdapters.UserActivitiesTableAdapter ta =new Workflows.DataTableAdapters.UserActivitiesTableAdapter())
      {
         // complete on the db.
         ta.CompleteActivity(activityGuid.ToString());

         // get the redirect page url.
         redirectUrl = (string)ta.GetDataByActivityGuid(activityGuid.ToString()).Rows[0]["ReturnPageUrl"];
         redirectUrl ="/"+ (Request.ApplicationPath +"/"+ redirectUrl).Trim('/');
      }

      // call the workflow.
      Runtime.GetService<ManualWorkflowSchedulerService>().RunWorkflow(workflowGuid);

      // persist the workflow on the db.
      wi.Unload();

      // commit.
      scope.Complete();
   }

   // redirect.
   resp.Redirect(redirectUrl);
}

Il metodo CompleteActivity permette di chiudere l’Activity attualmente aperta, di avanzare nell’esecuzione del Workflow (quindi eseguendo le Activity successive) e soprattutto di aggiornare lo stato sul db. Questo avviene all’atto della chiamata al metodo wi.Unload(), che, secondo quanto detto in precedenza, persiste il workflow su db ed esegue le varie istanze di DbAccessCallDetails, tutto quanto associato alla stessa System.Transactions.Transaction (TransactionScope).

Windows Workflow Foundation e ASP.NET 2.0 http://www.vitoplantamura.com/blog/PermaLink,guid,b5b64f9e-ee07-4ed3-a7dd-91fed524df48.aspx http://www.vitoplantamura.com/blog/2007/08/27/WindowsWorkflowFoundationEASPNET20.aspx Mon, 27 Aug 2007 00:08:22 GMT <p> Per un mio grosso cliente di Milano, sto dirigendo tecnologicamente lo sviluppo di un portale basato su ASP.NET 2.0, dove, funzionalmente, è richiesta l'integrazione di certe logiche di workflowing nella gestione dei loro processi aziendali. </p> <p> A tale scopo ho proposto l'utilizzo di <strong>Windows Workflow Foundation</strong>, in modo da poter testare sul campo (aldilà di semplici applicazioni di prova), nel contesto dello sviluppo di un grosso progetto di classe enterprise questa nuova interessante tecnologia di Microsoft. </p> <p> Dopo qualche ora di ricerca sono riuscito ad accumulare abbastanza conoscenza per mettere sù un proof of concept al fine di collaudare le idee ed ipotesi che avevo maturato. Allegata a questo post, c'è una applicazione ASP.NET di esempio derivata da quel mio primo prototipo. </p> <p> <strong><font size=4>La Web Application di Esempio</font></strong> </p> <p> E' possibile scaricare l'applicazione di esempio qui: <a href="http://www.vitoplantamura.com/blog/content/binary/WwfExample.rar">WwfExample.rar (386,08 KB)</a>. </p> <p> L'applicazione (la solution) consta di due progetti: la <strong>Web Application</strong> ed il progetto <strong>Workflows</strong>, che racchiude tutto il codice specifico che consuma i servizi di Workflow Foundation (WF). </p> <p> Prima di poter utilizzare l'applicazione in questione, è necessario "attaccare" il file di database fornito alla istanza di SQL Server 2005 Express presente sulla macchina di sviluppo. </p> <p> L'applicazione utilizza tre tabelle per mantenere il suo stato: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_db_1.gif" border=0> </p> <p> La tabella <strong>Users</strong> mantiene una lista di tutti gli utenti abilitati ad utilizzare l'applicazione, con relativi ruoli separati da virgola. La tabella <strong>WorkflowsList</strong> mantiene una lista di tutti i workflow che l'applicazione è abilitata a far partire, con, annesse, informazioni circa quali utenti e quali gruppi hanno tale privilegio e, soprattutto, indicazioni circa il tipo .NET e l'assembly dal quale recuperare la definizione della classe di Workflow. La tabella <strong>UserActivities</strong> mantiene uno stato della applicazione "parallelo" a quello del Workflow ed è la tebella che viene consultata dal sistema per capire in quale stato si trova l'intera applicazione. I record in questa tabella vengono aggiunti direttamente dalle <font face="Courier New" color=#ff0000>Activity</font> del Workflow ed essa è una prima ma importante forma di comunicazione tra codice ASP.NET e codice di Workflow Foundation. </p> <p> Sono inoltre presenti anche queste due tabelle: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_db_2.gif" border=0> </p> <p> In particolare, la tabella <strong>InstanceState</strong> viene utilizzata da Workflow Foundation (specificatamente dal servizio <font face="Courier New" color=#ff0000>SqlWorkflowPersistenceService</font>) per persistere lo stato di un determinato Workflow: il Workflow viene serializzato attraverso il <font face="Courier New" color=#ff0000>BinaryFormatter</font>, poi compresso, quindi depositato nel campo blob <strong>state</strong> di questa tabella. Per creare queste due tabelle, e relative stored procedure, è necessario recuperare ed eseguire gli script presenti tipicamente qui: </p> <p> <strong>C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\SqlPersistenceService_Schema.sql</strong> </p> <p> <strong>C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\SqlPersistenceService_Logic.sql</strong> </p> <p> <u>NOTA</u>: nel file di db incluso in questo esempio, le tabelle e le stored procedure di WF sono già presenti. </p> <p> Fatta partire, l'applicazione mostra una semplice mascherina di login: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_form_1.gif" border=0> </p> <p> Dove viene appurato il nome dell'utente e, soprattutto, i ruoli a lui assegnati (tramite lookup su db). Verificata la veridicità delle credenziali, viene creato un <font face="Courier New" color=#ff0000>FormsAuthenticationTicket</font> contenente le informazioni di interesse applicativo sull'utente. </p> <p> Immediatamente dopo si accede alla form principale dell'applicazione di esempio: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_form_2.gif" border=0> </p> <p> Questa form permette di avviare un dato workflow (se si dispone delle autorizzazioni necessarie per poterlo fare) e di gestire attività pendenti (sempre se si è autorizzati a farlo). La griglia delle attività pendenti (la seconda) viene popolata attraverso la tabella <strong>UserActivities</strong> su database, che a sua volta viene popolata dal codice del Workflow avviato e gestito dall'applicazione ASP.NET, con nome <strong>WorkflowExample.cs</strong>: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_wf.gif" border=0> </p> <p> Questo semplice workflow sequenziale definisce una serie di form ASP.NET da visualizzare una dopo l'altra. A ciascuna form sono associati diritti a livello di utente e ruolo, in modo che soltanto gli utenti abilitati abbiano modo di accedervi. E' naturalmente possibile definire workflow di una complessità molto superiore rispetto a quella del workflow qui rappresentato. Nella fattispecie, è possibile inserire qualsiasi tipo di <font face="Courier New" color=#ff0000>Activity</font> nel flusso di esecuzione del workflow: se necessario, è possibile definire uno stato privato al workflow aggiungendo proprietà (eventualmente bindabili) nel file <strong>WorkflowExample.cs</strong>. La proprietà bindabile <font face="Courier New" color=#ff0000>DataSet</font> nella classe <font face="Courier New" color=#ff0000>Workflows.UserActivity</font>, come spiegato sotto, può essere utilizzata per scambiare dati tra il workflow e l'applicazione ASP.NET. </p> <p> Da interfaccia utente, in Visual Studio (ossia dal <strong>Workflow Designer</strong>) è possibile, per ciascuna form, definire proprietà salienti, tra le quali quelle di autorizzazione appena descritte: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_props.gif" border=0> </p> <p> La proprietà <font face="Courier New" color=#ff0000>DataSet</font> (quando bindata) permette di passare informazioni da una <font face="Courier New" color=#ff0000>Activity</font> ad un'altra, passando dal codice ASP.NET, nel nostro caso specifico: il sistema, infatti, serializza di volta in volta il contenuto di questa proprietà della Activity nel campo <strong>DetailsXml</strong> della tabella <strong>UserActivities</strong>; questo permette al codice della pagina web di modificare il dataset, che poi, trasparentemente, viene ripassato alla Activity del Workflow, in modo che lo stato della proprietà bindabile sia aggiornato opportunamente. </p> <p> Cliccando su una attività pendente, si accede ad una form di gestione: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_form_3.gif" border=0> </p> <p> Il link <strong>Complete Activity</strong> scatena il codice che realizza l'interoperabilità con Workflow Foundation: in questo caso e per il nostro Workflow di esempio, l'attività "<strong>Form2</strong>" viene chiusa e si passa all'attività "<strong>Form3</strong>", che è giusto la successiva nel nostro workflow sequenziale. </p> <p> Il funzionamento dell'intera applicazione è piuttosto semplice, se si intendono i meccanismi di intercomunicazione di WF (vedi code di item, o <font face="Courier New" color=#ff0000>WorkflowQueue</font>). Questo schema dovrebbe riassumere a grandi linee ciò che accade: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_schema.gif" border=0> </p> <p> La discussione seguente è un poco più complessa, poichè tratta specificatamente dei problemi di interoperabilità tra ASP.NET e WF e delle soluzioni che ho ricercato e deciso di adottare caso per caso. </p> <p> <strong><font color=#000000 size=4>Threading</font></strong> </p> <p> Normalmente, Workflow Foundation utilizza le caratteristiche del servizio <font face="Courier New" color=#ff0000>DefaultWorkflowSchedulerService</font> per creare e coordinare i thread responsabili dell’esecuzione di tutti i workflow associati ad uno stesso runtime (<font face="Courier New" color=#ff0000>WorkflowRuntime</font>). Nella fattispecie, questo implica l’esecuzione asincrona delle istanze di workflow gestite da un runtime, che vengono opportunamente e trasparentemente messe nella coda di esecuzione del thread pool .NET associato all’applicazione host. </p> <p> Nel contesto di una applicazione ASP.NET, questo, generalmente, non è desiderabile. Infatti, il <font face="Courier New" color=#ff0000>DefaultWorkflowSchedulerService</font>, quando utilizzato in una applicazione web, và ad impegnare un thread aggiuntivo per ciascuna richiesta HTTP che il server di IIS, in un dato momento, sta processando e che richiede le funzionalità di Workflow Foundation. Per indirizzare questo problema, è necessario specificare il servizio <font face="Courier New" color=#ff0000>ManualWorkflowSchedulerService</font>, quando si inizializza una istanza del <font face="Courier New" color=#ff0000>WorkflowRuntime</font>: </p> <p> <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Runtime <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> WorkflowRuntime();<br> <br> <font color=#deb887 size=4><strong>[...]</strong></font> <br> <br> Runtime.AddService(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ManualWorkflowSchedulerService(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>));<br> <br> <font color=#deb887 size=4><strong>[...]</strong></font> <br> <br> </span> </p> <p> Questo permette di controllare l’esecuzione di un dato workflow, di coordinarla rispetto al thread che sta servendo la richiesta HTTP e di disimpegnare un thread dal thread pool dell’applicazione host, poichè WF và ad eseguire le nostre activity nel contesto dello stesso thread che sta eseguendo la pagina ASP.NET. </p> <p> Quanto detto è possibile evincerlo empiricamente andando a sbirciare nel call stack .NET durante l’esecuzione dell’applicazione di esempio allegata a questo post: </p> <p> <img src="http://www.vitoplantamura.com/blog/content/binary/img_callstack.gif" border=0> </p> <p> <font face="Courier New" color=#ff0000>UserActivity.Execute</font> è il nostro codice applicativo che implementa la nostra Activity (il primo contesto evidenziato in blu). <font face="Courier New" color=#ff0000>API.CompleteActivity</font> (il secondo contesto in blu) è un nostro metodo chiamato direttamente da un gestore eventi di un pulsante di una webform, che chiama l’API <font face="Courier New" color=#ff0000>ManualWorkflowSchedulerService.RunWorkflow</font>, che provoca l’esecuzione immediata del workflow il cui ID passiamo come parametro. Come anticipato, sia il codice della pagina web che quello del workflow vengono eseguiti nel contesto dello stesso thread. </p> <p> <strong><font size=4>Transazionalità e Persistenza</font></strong> </p> <p> La classe <font face="Courier New" color=#ff0000>TransactionScope</font> (<font face="Courier New" color=#ff0000>System.Transactions</font>) permette di definire contesti transazionali in codice .NET 2.0 e 3.0 in maniera semplice ed immediata. Specialmente se si utilizza SQL Server 2005, l’uso della classe <font face="Courier New" color=#ff0000>TransactionScope</font> diviene ancora più semplice, poichè si viene liberati del tutto da tutte quelle considerazioni di cui tener conto circa eventuali, inutili e costosi coinvolgimenti del MSDTC per transazioni puramente locali, importanti invece quando si lavora, per esempio, con SQL Server 2000. Sorvolando sulle specifiche caratteristiche della classe <font face="Courier New" color=#ff0000>TransactionScope</font> (fuori dagli obiettivi di questo post), nell’esempio fornito viene usata questa nuova funzionalità di .NET 2.0 per la scrittura di codice transazionale che scrive su SQL Server. </p> <p> Uno dei requisiti principali per realizzare una consistente interoperabilità tra WF e ASP.NET è la corretta gestione della persistenza dei workflow su database. Per comunicare a Workflow Foundation di persistere tutti i workflow relativi ad uno stesso <font face="Courier New" color=#ff0000>WorkflowRuntime</font> su database, è necessario registrare il servizio <font face="Courier New" color=#ff0000>SqlWorkflowPersistenceService</font> all’atto della inizializzazione dell’istanza del <font face="Courier New" color=#ff0000>WorkflowRuntime</font>: </p> <p> <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Runtime <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> WorkflowRuntime();<br> <br> <strong><font color=#deb887 size=4>[...]</font></strong> <br> <br> NameValueCollection parameters <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> NameValueCollection();<br> parameters.Add(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ConnectionString"</span>, connectionString);<br> parameters.Add(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"UnloadOnIdle"</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"false"</span>);<br> Runtime.AddService(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> SqlWorkflowPersistenceService(parameters));<br> <br> <strong><font color=#deb887 size=4>[...]</font></strong> <br> </span> </p> <p> Come parametri, specifichiamo la stringa di connessione al database ed indichiamo al servizio di NON persistere un workflow su database quando questo è inattivo (parametro <font face="Courier New" color=#ff0000>UnloadOnIdle</font>): infatti, per un maggiore controllo e per ragioni di consistenza transazionale che vedremo tra poco, ci preoccupiamo noi di chiamare il metodo <font face="Courier New" color=#ff0000>WorkflowInstance.Unload</font> quando intendiamo persistere una istanza di Workflow su db. </p> <p> Infatti uno dei maggiori problemi quando si intende integrare della logica che accede ad un db in una istanza di Workflow con della logica dello stesso tipo eseguita esternamente nel contesto dell’applicazione host (in questo caso ASP.NET) è che WF, per ragioni di design, impedisce alla transazione ambientale associata al thread di esecuzione nel momento in cui si esegue il workflow (<font face="Courier New" color=#ff0000>ManualWorkflowSchedulerService.RunWorkflow</font>) di propagarsi fino al contesto di esecuzione nel quale vengono eseguite le Activity del workflow. Questo è possibile evincerlo empiricamente, per esempio, debuggando l’applicazione di esempio di questo post: prima di chiamare l’API <font face="Courier New" color=#ff0000>ManualWorkflowSchedulerService.RunWorkflow</font>, la proprietà statica <font face="Courier New" color=#ff0000>System.Transactions.Transaction.Current</font> è correttamente valorizzata, poichè siamo in uno scope transazionale definito da un costrutto <font face="Courier New" color=#ff0000>TransactionScope</font>. Al contrario, all’interno del metodo <font face="Courier New" color=#ff0000>UserActivity.Execute</font> (che implementa la nostra activity) tale proprietà statica ha valore nullo, benchè la chiamata al metodo <font face="Courier New" color=#ff0000>UserActivity.Execute</font> sia originata a partire da del codice configurato per essere transazionale. </p> <p> Volendo approfondire la questione ed i motivi di tale comportamento, è necessario ritornare al call stack rappresentato all’inizio di questo post: nella fattispecie, in una delle 9 chiamate che separano il codice host dal codice della Activity, WF ha intenzionalmente “soppresso” la nostra transazione ambientale. Alla fine, come risultato, questo ci impedisce di associare del codice che accede al db in una Activity di un Workflow ad una transazione iniziata dall’host. </p> <p> Volendo scendere nel merito, magari utilizzando l’ottimo <strong>.NET Reflector di Roeder</strong> e spulciando rapidamente in quei 9 metodi di cui sopra, è possibile trovare la spiegazione di questo comportamento nel metodo <font face="Courier New" color=#ff0000>System.Workflow.Runtime.WorkflowExecutor.RunSome</font>, che, decompilato, appare così: </p> <p> <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">internal</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> RunSome(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> ignored)<br> {<br> &nbsp;&nbsp;&nbsp;<font color=#deb887 size=4><strong>[...]</strong></font> <br> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;using</span> (TransactionScope scope <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> TransactionScope(TransactionScopeOption.Suppress))<br> &nbsp;&nbsp;&nbsp;{<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this</span>.FireWorkflowExecutionEvent(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>, WorkflowEventInternal.Executing);<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this</span>.RunScheduler();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch</span> (Exception exception)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=#deb887 size=4><strong>[...]</strong></font> <br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finally</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this</span>.FireWorkflowExecutionEvent(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>, WorkflowEventInternal.NotExecuting);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scope.Complete();<br> &nbsp;&nbsp;&nbsp;}<br> <br> &nbsp;&nbsp;&nbsp;<font color=#deb887 size=4><strong>[...]</strong></font> <br> }<br> <br> </span> </p> <p> Questo ci obbliga a trovare nuove soluzioni per scrivere sul database in maniera consistente. </p> <p> La soluzione che ho ricercato ed adottato sfrutta i meccanismi di serializzazione di .NET, per mettere “in coda” una o più operazioni che è necessario associare ad una transazione controllata dal codice host (ossia da noi). Per ottenere l’effetto desiderato, bisogna, per prima cosa, creare una coda di Workflow dove andare ad aggiungere istanze di un nostro tipo custom (con nome <font face="Courier New" color=#ff0000>DbAccessCallDetails</font>), che rappresenta una chiamata ad un metodo di qualsiasi tipo che interagisce col db. L’idea di base è di registrare semplicemente l’operazione di interazione col db in questa coda (quando si è all’interno di una Activity), quindi, andare a chiamare il metodo che implementa tale operazione in un secondo momento, per esempio all’atto della serializzazione del Workflow su database. Considerando che la coda di Workflow (<font face="Courier New" color=#ff0000>WorkflowQueue</font>) è un oggetto che appartiene al Workflow e che le nostre istanze di <font face="Courier New" color=#ff0000>DbAccessCallDetails</font> si trovano depositate in tale coda, quando il servizio <font face="Courier New" color=#ff0000>SqlWorkflowPersistenceService</font>, tramite il <font face="Courier New" color=#ff0000>BinaryFormatter</font>, andrà a serializzare, quindi comprimere e persistere su db il nostro Workflow, noi avremo l’occasione che aspettiamo per svuotare la nostra coda e quindi eseguire quei metodi di cui avevamo procrastinato l’esecuzione. </p> <p> La classe <font face="Courier New" color=#ff0000>DbAccessCallDetails</font> si presenta semplicemente così: </p> <p> <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">[Serializable()]<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> DbAccessCallDetails : ISerializable<br> {<br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;// constructor(s).</span> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;public</span> DbAccessCallDetails(Delegate fnParam, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>[] psParam)<br> &nbsp;&nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fn <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> fnParam;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ps <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> psParam;<br> &nbsp;&nbsp;&nbsp;}<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;public</span> DbAccessCallDetails(SerializationInfo info, StreamingContext context)<br> &nbsp;&nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;}<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;// data.</span> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;public</span> Delegate fn <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;public</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>[] ps <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;// ISerializable stuff.</span> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;void</span> ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)<br> &nbsp;&nbsp;&nbsp;{<br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// call the method.</span> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if</span> (fn !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fn.DynamicInvoke(ps);<br> &nbsp;&nbsp;&nbsp;}<br> }<br> <br> </span> </p> <p> In breve, quando si cerca di serializzare una istanza di questa classe, viene chiamato il metodo <font face="Courier New" color=#ff0000>ISerializable.GetObjectData</font>, che semplicemente invoca il metodo ad essa associato. Questo metodo inserisce dei record su db, nel caso del mio esempio (tabella <strong>UserActivities</strong>). </p> <p> Come detto precedentemente, la serializzazione del Workflow avviene all’atto della chiamata al metodo <font face="Courier New" color=#ff0000>WorkflowInstance.Unload</font>. Come emerge da vari documenti e testimonianze su internet, e come può essere approfondito direttamente attraverso Reflector, questo metodo (intenzionalmente) è l’unico pezzo di codice di WF che non sopprime attivamente la transazione ambientale del thread che lo sta chiamando. Questo significa che è possibile associare ad una stessa transazione ambientale gestita dall’host sia la persistenza dell’istanza del Workflow su database, sia il codice rappresentato dalle varie istanze di <font face="Courier New" color=#ff0000>DbAccessCallDetails</font> eventualmente presenti nella coda del Workflow. Questo “trucco” ci permette di avere sul database uno stato dei dati di interoperabilità tra la nostra applicazione e Workflow Foundation sempre consistenti: </p> <p> <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> CompleteActivity(Guid workflowGuid, Guid activityGuid, DataSet activityData, System.Web.HttpRequest Request, System.Web.HttpResponse resp)<br> {<br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;// notify the completion to the wf.</span> <br> &nbsp;&nbsp;&nbsp;WorkflowInstance wi <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Runtime.GetWorkflow(workflowGuid);<br> &nbsp;&nbsp;&nbsp;wi.EnqueueItem(<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;activityGuid.ToString(),<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new</span> ActivityCompletedEventArgs(activityData),<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null</span>, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>);<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;// tell the workflow to progress.</span> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;string</span> redirectUrl <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;using</span> (TransactionScope scope <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> TransactionScope())<br> &nbsp;&nbsp;&nbsp;{<br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// complete on the db.</span> <br> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;using</span> (Workflows.DataTableAdapters.UserActivitiesTableAdapter ta <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Workflows.DataTableAdapters.UserActivitiesTableAdapter())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// complete on the db.</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ta.CompleteActivity(activityGuid.ToString());<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// get the redirect page url.</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirectUrl <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>)ta.GetDataByActivityGuid(activityGuid.ToString()).Rows[0][<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ReturnPageUrl"</span>];<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirectUrl <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"/"</span> <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> (Request.ApplicationPath <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"/"</span> <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> redirectUrl).Trim('<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/</span>');<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// call the workflow.</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Runtime.GetService&lt;ManualWorkflowSchedulerService&gt;().RunWorkflow(workflowGuid);<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// persist the workflow on the db.</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wi.Unload();<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// commit.</span> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scope.Complete();<br> &nbsp;&nbsp;&nbsp;}<br> <br> <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&nbsp;&nbsp;&nbsp;// redirect.</span> <br> &nbsp;&nbsp;&nbsp;resp.Redirect(redirectUrl);<br> }<br> </span> </p> <p> Il metodo <font face="Courier New" color=#ff0000>CompleteActivity</font> permette di chiudere l’Activity attualmente aperta, di avanzare nell’esecuzione del Workflow (quindi eseguendo le Activity successive) e soprattutto di aggiornare lo stato sul db. Questo avviene all’atto della chiamata al metodo <font face="Courier New" color=#ff0000>wi.Unload()</font>, che, secondo quanto detto in precedenza, persiste il workflow su db ed esegue le varie istanze di <font face="Courier New" color=#ff0000>DbAccessCallDetails</font>, tutto quanto associato alla stessa <font face="Courier New" color=#ff0000>System.Transactions.Transaction </font>(<font face="Courier New" color=#ff0000>TransactionScope</font>). </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=b5b64f9e-ee07-4ed3-a7dd-91fed524df48" /> http://www.vitoplantamura.com/blog/CommentView,guid,b5b64f9e-ee07-4ed3-a7dd-91fed524df48.aspx
http://www.vitoplantamura.com/blog/Trackback.aspx?guid=0be0ecc8-250c-4bf0-923a-5a9d1842b5b0 http://www.vitoplantamura.com/blog/pingback.aspx http://www.vitoplantamura.com/blog/PermaLink,guid,0be0ecc8-250c-4bf0-923a-5a9d1842b5b0.aspx Vito Plantamura http://www.vitoplantamura.com/blog/CommentView,guid,0be0ecc8-250c-4bf0-923a-5a9d1842b5b0.aspx http://www.vitoplantamura.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0be0ecc8-250c-4bf0-923a-5a9d1842b5b0 2

Salve, mi chiamo Vito Plantamura. Come è abitudine in tutti i blog che si rispettino, il primo post deve essere di tipo introduttivo.

Come potete intuire dalla natura del sito, questo blog conterrà principalmente informazioni, notizie ed esperienze di tipo tecnico. Le tecnologie che saranno coperte coincidono sostanzialmente con quelle che sono le mie specializzazioni professionali:

  • .NET Framework / C# / Sviluppo di applicazioni Enterprise.
  • ASP.NET / HTML / Javascript.
  • Win32 / MFC / COM (+) / C++.
  • .NET Framework 3.0 / WinFX.
  • Assembler IA32 / IA64 / X64 e sviluppo di driver per Windows NT.
  • Argomenti relativi alla sicurezza internet e Windows di ogni tipo.

Personalmente, potete trovare informazioni dettagliate su alcuni dei miei prodotti e tecnologie che ho sviluppato e "ricercato" negli anni proprio in questo sito ( www.VitoPlantamura.com ). Mi sento di consigliare di provare GoToTerminal, il nostro servizio di connettività remota basata su Terminal Services e VNC, NDIS Monitor, un packer sniffer sviluppato mistamente con .NET ed il DDK di Windows, BugChecker, un prodotto di ricerca sviluppato interamente dalla mia azienda ricalcato sul modello del famoso kernel debugger SoftICE, MapGen, un editor di tipo CSG di classe professionale, sviluppato diversi anni fà dal sottoscritto per la creazione di contenuto di gioco per un motore tridimensionale alla Quake3.

Concludendo, al momento mi occupo di consulenza sulle tecnologie sopra elencate (attraverso la mia azienda: VPC Technologies) e parallelamente seguo lo sviluppo tecnologico e commerciale dei miei prodotti. Se intendete ottenere maggiori informazioni sulle nostre attività di consulenza e sul nostro/mio curriculum, vi pregherei di contattarmi direttamente al mio indirizzo personale (o, alternativamente, attraverso il sito della mia company).

Inoltre spero di poter replicare quanto prima questo blog (inizialmente solo in italiano) anche in inglese, in modo che anche i miei amici/colleghi/clienti non italiani possano seguirmi in questa nuova avventura... :-) :-) :-)

Detto questo, posso solo augurarvi una buona lettura... :-)

vito

Benvenuti al mio blog ! http://www.vitoplantamura.com/blog/PermaLink,guid,0be0ecc8-250c-4bf0-923a-5a9d1842b5b0.aspx http://www.vitoplantamura.com/blog/2007/08/26/BenvenutiAlMioBlog.aspx Sun, 26 Aug 2007 21:33:59 GMT <p> <font size=3>Salve, mi chiamo Vito Plantamura. Come è abitudine in tutti i blog che si rispettino, il primo post deve essere di tipo introduttivo.</font> </p> <p> <font size=3>Come potete intuire dalla natura del sito, questo blog conterrà principalmente informazioni, notizie ed esperienze di tipo tecnico. Le tecnologie che saranno coperte coincidono sostanzialmente con quelle che sono le mie specializzazioni professionali:</font> </p> <ul> <li> <font size=3>.NET Framework / C# / Sviluppo di applicazioni Enterprise. </font> <li> <font size=3>ASP.NET / HTML / Javascript. </font> <li> <font size=3>Win32 / MFC / COM (+) / C++. </font> <li> <font size=3>.NET Framework 3.0 / WinFX. </font> <li> <font size=3>Assembler IA32 / IA64 / X64 e sviluppo di driver per Windows NT. </font> <li> <font size=3>Argomenti relativi alla sicurezza internet e Windows di ogni tipo.</font> </li> </ul> <p> <font size=3>Personalmente, potete trovare informazioni dettagliate su alcuni dei miei prodotti e tecnologie che ho sviluppato e "ricercato" negli anni proprio in questo sito (</font><a href="http://www.VitoPlantamura.com"><font size=3>www.VitoPlantamura.com</font></a><font size=3>). Mi sento di consigliare di provare GoToTerminal, il nostro servizio di connettività remota basata su Terminal Services e VNC, NDIS Monitor, un packer sniffer sviluppato mistamente con .NET ed il DDK di Windows, BugChecker, un prodotto di ricerca sviluppato interamente dalla mia azienda ricalcato sul modello del famoso kernel debugger SoftICE, MapGen, un editor di tipo CSG di classe professionale, sviluppato diversi anni fà dal sottoscritto per la creazione di contenuto di gioco per un motore tridimensionale alla Quake3.</font> </p> <p> <font size=3>Concludendo, al momento mi occupo di consulenza sulle tecnologie sopra elencate (attraverso la mia azienda: VPC Technologies) e parallelamente seguo lo sviluppo tecnologico e commerciale dei miei prodotti. Se intendete ottenere maggiori informazioni sulle nostre attività di consulenza e sul nostro/mio curriculum, vi pregherei di contattarmi direttamente al mio indirizzo personale (o, alternativamente, attraverso il sito della mia company).</font> </p> <p> <font size=3>Inoltre spero di poter replicare quanto prima questo blog (inizialmente solo in italiano) anche in inglese, in modo che anche i miei amici/colleghi/clienti non italiani possano seguirmi in questa nuova avventura... :-) :-) :-)</font> </p> <p> <font size=3>Detto questo, posso solo augurarvi una buona lettura... :-)</font> </p> <p> <font size=3>vito</font> </p> <img width="0" height="0" src="http://www.vitoplantamura.com/blog/aggbug.ashx?id=0be0ecc8-250c-4bf0-923a-5a9d1842b5b0" /> http://www.vitoplantamura.com/blog/CommentView,guid,0be0ecc8-250c-4bf0-923a-5a9d1842b5b0.aspx