Files
hakril-PythonForWindows/docs/build/html/com.html
T
2018-08-03 10:10:31 +02:00

199 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>9. windows.com - Component Object Model &#8212; PythonForWindows 0.4 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/mbasic.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="10. windows.crypto CryptoAPI" href="crypto.html" />
<link rel="prev" title="8. windows.debug Debugging" href="debug.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="crypto.html" title="10. windows.crypto CryptoAPI"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="debug.html" title="8. windows.debug Debugging"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">PythonForWindows 0.4 documentation</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-windows.com">
<span id="windows-com-component-object-model"></span><h1>9. <a class="reference internal" href="#module-windows.com" title="windows.com"><code class="xref py py-mod docutils literal notranslate"><span class="pre">windows.com</span></code></a> - Component Object Model<a class="headerlink" href="#module-windows.com" title="Permalink to this headline"></a></h1>
<p>A module to call <cite>COM</cite> interfaces from <cite>Python</cite> or
<cite>COM</cite> vtable in python.</p>
<p>This code is only used in <a class="reference internal" href="wmi.html#module-windows.winobject.wmi" title="windows.winobject.wmi"><code class="xref py py-mod docutils literal notranslate"><span class="pre">windows.winobject.wmi</span></code></a> and <a class="reference internal" href="network.html#module-windows.winobject.network" title="windows.winobject.network"><code class="xref py py-mod docutils literal notranslate"><span class="pre">windows.winobject.network</span></code></a> for the firewall.
The ability to create <cite>COM</cite> vtable is used in the <a class="reference external" href="https://github.com/sogeti-esec-lab/LKD/">LKD project</a> .</p>
<div class="section" id="using-a-com-interface">
<h2>9.1. Using a COM interface<a class="headerlink" href="#using-a-com-interface" title="Permalink to this headline"></a></h2>
<p>Its possible to directly call <cite>COM</cite> interface from python. All you need is the definition of the <cite>COM</cite> interface.</p>
<p>There are three ways to get the definition of the code interface:</p>
<blockquote>
<div><ul class="simple">
<li>By using it from <code class="xref py py-mod docutils literal notranslate"><span class="pre">windows.generated_def.interfaces</span></code></li>
<li>By writing it yourself : &lt;<a class="reference external" href="https://github.com/sogeti-esec-lab/LKD/blob/ba40727d7d257b00f89fc6ca7296c9833b7b75b2/dbginterface/remote.py#L56">https://github.com/sogeti-esec-lab/LKD/blob/ba40727d7d257b00f89fc6ca7296c9833b7b75b2/dbginterface/remote.py#L56</a>&gt;`_</li>
<li>By generating it.</li>
</ul>
</div></blockquote>
<p>To generate a <cite>COM</cite> interface you need its definition from the “.c” file.
Then add thisit to <code class="docutils literal notranslate"><span class="pre">PythonForWindows\ctypes_generation\com\MyInterface.txt</span></code>.
Finally re-generate the interface using <code class="docutils literal notranslate"><span class="pre">generate.py</span></code>.</p>
<p>When you have the <cite>COM</cite> interface defintion you can create an instance of it.
Then you need to retrieve the interface by using an API returning an object or <code class="xref py py-func docutils literal notranslate"><span class="pre">window.com.create_instance()</span></code>.
You can then use the instance to call whatever method you need.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">see samples <a class="reference internal" href="sample.html#sample-com"><span class="std std-ref">windows.com</span></a></p>
</div>
</div>
<div class="section" id="implementing-a-com-interface">
<h2>9.2. Implementing a COM interface<a class="headerlink" href="#implementing-a-com-interface" title="Permalink to this headline"></a></h2>
<p>To create <cite>COM</cite> object you need to:</p>
<blockquote>
<div><ol class="arabic simple">
<li>Create your <code class="docutils literal notranslate"><span class="pre">COMImplementation</span></code> with an <code class="docutils literal notranslate"><span class="pre">IMPLEMENT</span></code> attribute that should be a cominterface <a class="reference external" href="https://github.com/sogeti-esec-lab/LKD/blob/efabf3cc38b94d4180ebe8d2c554da5d76b2fea1/lkd/dbginterface/base.py#L48">CODE 1</a></li>
<li>Implements the methods of the interface <a class="reference external" href="https://github.com/sogeti-esec-lab/LKD/blob/efabf3cc38b94d4180ebe8d2c554da5d76b2fea1/lkd/dbginterface/base.py#L55">CODE 2</a></li>
<li>Create an instance <a class="reference external" href="https://github.com/sogeti-esec-lab/LKD/blob/efabf3cc38b94d4180ebe8d2c554da5d76b2fea1/lkd/dbginterface/base.py#L59">CODE3</a></li>
<li>Pass it to whatever native function expects it <a class="reference external" href="https://github.com/sogeti-esec-lab/LKD/blob/efabf3cc38b94d4180ebe8d2c554da5d76b2fea1/lkd/dbginterface/base.py#L272">CODE4</a></li>
</ol>
</div></blockquote>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">see samples <a class="reference internal" href="sample.html#sample-com-icallinterceptor"><span class="std std-ref">ICallInterceptor</span></a></p>
</div>
</div>
<div class="section" id="api">
<h2>9.3. API<a class="headerlink" href="#api" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="windows.com.init">
<code class="descclassname">windows.com.</code><code class="descname">init</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/windows/com.html#init"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#windows.com.init" title="Permalink to this definition"></a></dt>
<dd><p>Init COM with some default parameters</p>
</dd></dl>
<dl class="function">
<dt id="windows.com.create_instance">
<code class="descclassname">windows.com.</code><code class="descname">create_instance</code><span class="sig-paren">(</span><em>clsiid</em>, <em>targetinterface</em>, <em>custom_iid=None</em>, <em>context=5L</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/windows/com.html#create_instance"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#windows.com.create_instance" title="Permalink to this definition"></a></dt>
<dd><p>A simple wrapper around <code class="docutils literal notranslate"><span class="pre">CoCreateInstance</span> <span class="pre">&lt;https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx&gt;</span></code></p>
</dd></dl>
<dl class="class">
<dt id="windows.com.COMImplementation">
<em class="property">class </em><code class="descclassname">windows.com.</code><code class="descname">COMImplementation</code><a class="reference internal" href="_modules/windows/com.html#COMImplementation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#windows.com.COMImplementation" title="Permalink to this definition"></a></dt>
<dd><p>The base class to implements COM object respecting a given interface</p>
<dl class="method">
<dt id="windows.com.COMImplementation.AddRef">
<code class="descname">AddRef</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/windows/com.html#COMImplementation.AddRef"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#windows.com.COMImplementation.AddRef" title="Permalink to this definition"></a></dt>
<dd><p>Default <code class="docutils literal notranslate"><span class="pre">AddRef</span></code> implementation that returns <code class="docutils literal notranslate"><span class="pre">1</span></code></p>
</dd></dl>
<dl class="method">
<dt id="windows.com.COMImplementation.QueryInterface">
<code class="descname">QueryInterface</code><span class="sig-paren">(</span><em>this</em>, <em>piid</em>, <em>result</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/windows/com.html#COMImplementation.QueryInterface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#windows.com.COMImplementation.QueryInterface" title="Permalink to this definition"></a></dt>
<dd><p>Default <code class="docutils literal notranslate"><span class="pre">QueryInterface</span></code> implementation that returns <code class="docutils literal notranslate"><span class="pre">self</span></code> if piid is the implemented interface</p>
</dd></dl>
<dl class="method">
<dt id="windows.com.COMImplementation.Release">
<code class="descname">Release</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/windows/com.html#COMImplementation.Release"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#windows.com.COMImplementation.Release" title="Permalink to this definition"></a></dt>
<dd><p>Default <code class="docutils literal notranslate"><span class="pre">Release</span></code> implementation that returns <code class="docutils literal notranslate"><span class="pre">1</span></code></p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">9. <code class="docutils literal notranslate"><span class="pre">windows.com</span></code> - Component Object Model</a><ul>
<li><a class="reference internal" href="#using-a-com-interface">9.1. Using a COM interface</a></li>
<li><a class="reference internal" href="#implementing-a-com-interface">9.2. Implementing a COM interface</a></li>
<li><a class="reference internal" href="#api">9.3. API</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="debug.html"
title="previous chapter">8. <code class="docutils literal notranslate"><span class="pre">windows.debug</span></code> Debugging</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="crypto.html"
title="next chapter">10. <code class="docutils literal notranslate"><span class="pre">windows.crypto</span></code> CryptoAPI</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/com.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="crypto.html" title="10. windows.crypto CryptoAPI"
>next</a> |</li>
<li class="right" >
<a href="debug.html" title="8. windows.debug Debugging"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">PythonForWindows 0.4 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2015, Clement Rouault.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.5.
</div>
</body>
</html>