<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8536115727336389420</id><updated>2024-09-01T15:52:06.099+02:00</updated><category term="Snippets"/><category term="Controls"/><category term="Security"/><category term="Graphics"/><category term="Networking"/><title type='text'>The Power Of DotNet, Using Visual Basic</title><subtitle type='html'>Find VB.NET Snippets, Source Codes, Demo Projects, And More, Well Explained For The Best Understanding Of The Code.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-8965859799137979435</id><published>2011-07-06T21:49:00.001+02:00</published><updated>2011-11-28T20:03:53.881+01:00</updated><title type='text'>I Got Busy, But Well...</title><content type='html'>I was planning to write a couple of articles about custom controls and 3D with Opengl (i already started writing one).&lt;br /&gt;
well i got a bit busy, but i promise i&#39;ll post them soon.&lt;br /&gt;
i&#39;ll also update the downloads page with demo source codes for every article in the blog.&lt;br /&gt;
Brahim.&lt;br /&gt;
&lt;br /&gt;
Re : I&#39;ve been away for so long now, it&#39;s 28th noverber, so...&lt;br /&gt;
I got really busy in studies, and work on &lt;a href=&quot;https://www.odesk.com/users/~~6b4de52eb9da7f4c&quot; target=&quot;_blank&quot;&gt;oDesk&lt;/a&gt;, so i really didn&#39;t have time to add whatever to the blog, even that article about GDI+ is still in the drafts folder, but i&#39;m sure i&#39;ll finish it as soon as i get some free time.&lt;br /&gt;
See ya.</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/8965859799137979435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/8965859799137979435' title='26 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/8965859799137979435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/8965859799137979435'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/07/i-got-busy-but-well.html' title='I Got Busy, But Well...'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>26</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-4320160670479124184</id><published>2011-06-24T19:35:00.009+02:00</published><updated>2011-11-28T20:04:58.624+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Graphics"/><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><title type='text'>Image Effect : Bluring - Fast with Graphics Drawing</title><content type='html'>one of the famous effects that we can apply to images is Blur. it is used to reduce &quot;noise&quot; and details.&lt;br /&gt;
you can read here about &lt;a href=&quot;http://en.wikipedia.org/wiki/Gaussian_blur&quot; target=&quot;_blank&quot;&gt;Gaussian blur&lt;/a&gt; in this wiki article.&lt;br /&gt;
&lt;br /&gt;
one basic&amp;nbsp;blurring&amp;nbsp;consist in adding to the rgb values of a pixel, all rgb values of the pixels surrounding it.&lt;br /&gt;
another article explaining it well, and its&amp;nbsp;implementation&amp;nbsp;in Visual Basic on &lt;a href=&quot;http://www.codeproject.com/KB/GDI-plus/GausianBlur.aspx&quot; target=&quot;_blank&quot;&gt;CodeProject&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
the problem - for me -&amp;nbsp;is the speed. this method is slow. so after a second thought, why treating pixel by pixel? let&#39;s try blurring the hole image at the same time.&lt;br /&gt;
&lt;br /&gt;
Here is what i came up with :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Sub BlurBitmap(ByRef image As Bitmap, Optional ByVal BlurForce As Integer = 1)
        &#39;We get a graphics object from the image
        Dim g As Graphics = Graphics.FromImage(image)
        &#39;declare an ImageAttributes to use it when drawing
        Dim att As New ImageAttributes
        &#39;declare a ColorMatrix
        Dim m As New ColorMatrix
        &#39; set Matrix33 to 0.5, which represents the opacity. so the drawing will be semi-trasparent.
        m.Matrix33 = 0.5F
        &#39;Setting this ColorMatrix to the ImageAttributes.
        att.SetColorMatrix(m)
        &#39;drawing the image on it self, but not in the same coordinates, in a way that every pixel will be drawn on the pixels arround it.
        For x = -BlurForce To BlurForce
            For y = -BlurForce To BlurForce
                &#39;Drawing image on it self using out ImageAttributes to draw it semi-transparent.
                g.DrawImage(image, New Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, att)
            Next
        Next
        &#39;disposing ImageAttributes and Graphics. the effect is then applied. 
        att.Dispose()
        g.Dispose()
    End Sub
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGozclG_kQvxsiLLO624XJ93T_jujbzJaW_wxN0ipNX07p2V89Hb7iveh_rrIoaX4K__o1zQ74Q4V_JeqS-_Xx9Vd2dOCZI-OzfK68r8c15UlMN31_1VcgV3DtqwO9xrjsK7mNc486Ajo/s1600/6a00e009925a73883300e5529314898834-800hwi.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;265&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGozclG_kQvxsiLLO624XJ93T_jujbzJaW_wxN0ipNX07p2V89Hb7iveh_rrIoaX4K__o1zQ74Q4V_JeqS-_Xx9Vd2dOCZI-OzfK68r8c15UlMN31_1VcgV3DtqwO9xrjsK7mNc486Ajo/s400/6a00e009925a73883300e5529314898834-800hwi.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cccccc; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
Testing :&lt;br /&gt;
I find this way faster than treating a it pixel per pixel. try changing the value of BlurForce (which should be an integer &amp;gt; 0) and check the effect. have fun with it!&lt;br /&gt;
&lt;br /&gt;
Any comments are very welcome.</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/4320160670479124184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/4320160670479124184' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/4320160670479124184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/4320160670479124184'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/image-effect-bluring.html' title='Image Effect : Bluring - Fast with Graphics Drawing'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGozclG_kQvxsiLLO624XJ93T_jujbzJaW_wxN0ipNX07p2V89Hb7iveh_rrIoaX4K__o1zQ74Q4V_JeqS-_Xx9Vd2dOCZI-OzfK68r8c15UlMN31_1VcgV3DtqwO9xrjsK7mNc486Ajo/s72-c/6a00e009925a73883300e5529314898834-800hwi.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-6992876437752909593</id><published>2011-06-24T18:44:00.003+02:00</published><updated>2011-11-28T20:08:21.560+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><title type='text'>Handling Registry in DotNet - RegNotifyChangeKeyValue</title><content type='html'>In other programming languages, it is most likely a must to use the registry Api&#39;s, listed on msdn &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724875(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt;.&lt;br /&gt;
But using dotnet, thanks to the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/fr-fr/library/microsoft.win32.registry.aspx&quot; target=&quot;_blank&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;Microsoft.Win32&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&lt;span xmlns=&quot;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;Registry&lt;/span&gt;&lt;/a&gt;&amp;nbsp;Class, we have all methods needed to Open a key, enumerate keys, create or delete keys, or even&amp;nbsp;enumerating values, reading names, values, adding, modifying and deleting. there are various&amp;nbsp;examples&amp;nbsp;on msdn for almost every method of this class, they could really show you the simplicity of handling registry.&lt;br /&gt;
&lt;br /&gt;
Probably the function that i find&amp;nbsp;important&amp;nbsp;and &quot;missing&quot; in this class is the ability to monitor changes in the registry.&lt;br /&gt;
therefor, we are going to use the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724892(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegNotifyChangeKeyValue&lt;/a&gt;&amp;nbsp;as we do in any other language.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;but first, we are going to use&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724897(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegOpenKeyEx&lt;/a&gt;&amp;nbsp;to open the key with the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px; line-height: 18px;&quot;&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724878(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;KEY_NOTIFY&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here is an exemple :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Private Declare Function RegNotifyChangeKeyValue Lib &quot;advapi32.dll&quot; (ByVal hKey As IntPtr, _
ByVal watchSubtree As Boolean, ByVal dwNotifyFilter As Integer, ByVal hEvent As IntPtr, _
ByVal fAsynchronous As Boolean) As Integer

Private Declare Auto Function RegOpenKeyEx Lib &quot;advapi32.dll&quot; ( _
ByVal hKey As IntPtr, _
ByVal lpSubKey As String, _
ByVal ulOptions As Integer, _
ByVal samDesired As Integer, _
ByRef phkResult As Integer) As Integer

Const REG_NOTIFY_CHANGE_LAST_SET As Integer = &amp;amp;H4L
Const HKEY_CURRENT_USER As Integer = &amp;amp;H80000001
Const KEY_NOTIFY As Integer = &amp;amp;H10 
Const ERROR_SUCCESS As Integer = 0


Sub RegNotifyChange()
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dim regkey As IntPtr
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If RegOpenKeyEx(HKEY_CURRENT_USER, &quot;Software\Microsoft\Windows&quot;, 0, KEY_NOTIFY, regkey) = ERROR_SUCCESS Then
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If RegNotifyChangeKeyValue(regkey, False, REG_NOTIFY_CHANGE_LAST_SET, Nothing, False) = ERROR_SUCCESS Then
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox(&quot;Change!&quot;)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Else
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox(&quot;RegNotifyChangeKeyValue Failed.&quot;)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Else
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox(&quot;RegOpenKeyEx Failed.&quot;)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If
&amp;nbsp; &amp;nbsp; End Sub&lt;/pre&gt;
&lt;br /&gt;
Explaining the code :&lt;br /&gt;
we need to open a registry key with the notify access, so we can tell&amp;nbsp;RegNotifyChangeKeyValue to &quot;notify&quot; us whenever something changed.&lt;br /&gt;
we call&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724897(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegOpenKeyEx&lt;/a&gt;&amp;nbsp;with&amp;nbsp;HKEY_CURRENT_USER as the root key, which is already opened.&lt;br /&gt;
our subkey for exemple will be &quot;Software\Microsoft\Windows&quot;. set 0 for the reserved parameter, KEY_NOTIFY  for desired Access, and our variable regkey where the handle will be stored.&lt;br /&gt;
after that, we call&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724892(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegNotifyChangeKeyValue&lt;/a&gt;&amp;nbsp;with the specified opened key. we set true if want to monitor subkeys also, in this case we dont (for example). Then, when need to specify a filter, which can be a combination of&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px; line-height: 18px;&quot;&gt;REG_NOTIFY_CHANGE_NAME,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px; line-height: 18px;&quot;&gt;REG_NOTIFY_CHANGE_ATTRIBUTES,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px; line-height: 18px;&quot;&gt;REG_NOTIFY_CHANGE_LAST_SET and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px; line-height: 18px;&quot;&gt;REG_NOTIFY_CHANGE_SECURITY,&lt;/span&gt; they are all described in the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724892(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegNotifyChangeKeyValue&lt;/a&gt;&amp;nbsp;page. in our case, all we need is to monitor changes in values only.&lt;br /&gt;
in the next parameter, we need to specify whether we want to &quot;fire&quot; an event when a change occurs, so we set hEvent to a handle of an event, and&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&lt;em&gt;fAsynchronous&lt;/em&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/span&gt;to True. in our case, where&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&lt;em&gt;fAsynchronous&lt;/em&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/span&gt;is set to false, the calling thread will sleep after the call, and the function will only return when a change occurs. in this case hEvent is ignored.&lt;br /&gt;
&lt;br /&gt;
Debugging :&lt;br /&gt;
When this method is called, the thread will be waiting for the function to return, in other words, will be waiting for a specific changes in the registry, a messagebox will pop up, and our sub will exit. if we want to continue to monitor changes, we can keep calling&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724892(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegNotifyChangeKeyValue&lt;/a&gt;&amp;nbsp;in a loop, but it is better to use another thread for the job, because this thread will be busy.&lt;br /&gt;
&lt;br /&gt;
After Finishing using the key, it is best to call &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms724837(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;RegCloseKey&lt;/a&gt; to close the handle.</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/6992876437752909593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/6992876437752909593' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/6992876437752909593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/6992876437752909593'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/handling-registry-in-dotnet.html' title='Handling Registry in DotNet - RegNotifyChangeKeyValue'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-3355637288667476586</id><published>2011-06-18T22:25:00.006+02:00</published><updated>2011-11-28T20:09:26.265+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Networking"/><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><title type='text'>Listing All Tcp connections on Local Computer</title><content type='html'>For this part of code, it will be based on this Api called &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa365928(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;GetExtendedTcpTable&lt;/a&gt;.&lt;br /&gt;
What we are going to do is, to try and&amp;nbsp;retrieve&amp;nbsp;every tcp&amp;nbsp;connection, its state, its local and remote adresses and ports, and it&#39;s owning process. We could also use &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb408406(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;GetTcpTable&lt;/a&gt; to for the same job, but i noticed that it is only&amp;nbsp;available in Vista, so we&#39;ll go with&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa365928(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;GetExtendedTcpTable&lt;/a&gt;&amp;nbsp;for now, as it is working on both Vista and Xp Sp2.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s start with coding, here is a detailed module about what we need, so create a new module and paste this :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Imports System.Runtime.InteropServices
Imports System.Net.NetworkInformation
Imports System.Net

Public Module TCPGet
&#39;Api to get table
Declare Auto Function GetExtendedTcpTable Lib &quot;iphlpapi.dll&quot; (ByVal pTCPTable As IntPtr, ByRef OutLen As Integer, ByVal Sort As Boolean, ByVal IpVersion As Integer, ByVal dwClass As Integer, ByVal Reserved As Integer) As Integer
&#39;const : we are asking for connections with ProcessIDs&#39;, all of them.
Const TCP_TABLE_OWNER_PID_ALL As Integer = 5
&#39;represents a full table
&amp;lt;StructLayout(LayoutKind.Sequential)&amp;gt; _
Public Structure MIB_TCPTABLE_OWNER_PID
Public NumberOfEntries As Integer &#39;number of rows
Public Table As IntPtr &#39;array of tables
End Structure
&#39;represents a row
&amp;lt;StructLayout(LayoutKind.Sequential)&amp;gt; _
Public Structure MIB_TCPROW_OWNER_PID
Public state As Integer &#39;state of the connection
Public localAddress As UInteger
Public LocalPort As Integer
Public RemoteAddress As UInteger
Public remotePort As Integer
Public PID As Integer &#39;Process ID
End Structure
&#39;this a structure that we made to store a connection after formatting it
Structure TcpConnection
Public State As TcpState
Public localAddress As String
Public LocalPort As Integer
Public RemoteAddress As String
Public remotePort As Integer
Public Proc As String
End Structure
&#39;Main Function
Function GetAllTCPConnections() As MIB_TCPROW_OWNER_PID()
GetAllTCPConnections = Nothing
&#39;we need to know how much memory we need to store all the connections
Dim cb As Integer
&#39;so we call GetExtendedTcpTable without a pointer to a table to get the size
GetExtendedTcpTable(Nothing, cb, False, 2, TCP_TABLE_OWNER_PID_ALL, 0)
&#39;after getting the size, we allocate memory
Dim tcptable As IntPtr = Marshal.AllocHGlobal(cb)
&#39;the call where we store the connections in that memory
If GetExtendedTcpTable(tcptable, cb, False, 2, TCP_TABLE_OWNER_PID_ALL, 0) = 0 Then
&#39;we convert it to a MIB_TCPTABLE_OWNER_PID variable
Dim tab As MIB_TCPTABLE_OWNER_PID = Marshal.PtrToStructure(tcptable, GetType(MIB_TCPTABLE_OWNER_PID))
&#39;and we make an array with a size of number of connections
Dim Mibs(tab.NumberOfEntries - 1) As MIB_TCPROW_OWNER_PID
&#39;row represents the adress of a MIB_TCPROW in memory
Dim row As IntPtr
&#39;for each connection
For i As Integer = 0 To tab.NumberOfEntries - 1
&#39;adress = adress of table + 4(int32) + (size of a MIB_TCPROW * i)
row = New IntPtr(tcptable.ToInt32 + Marshal.SizeOf(tab.NumberOfEntries) + Marshal.SizeOf(GetType(MIB_TCPROW_OWNER_PID)) * i)
&#39;convert pointer to a MIB_TCPROW, and store it in the array
Mibs(i) = Marshal.PtrToStructure(row, GetType(MIB_TCPROW_OWNER_PID))
Next
&#39;returning the array
GetAllTCPConnections = Mibs
End If
&#39;just before leaving, clean up your memory!
Marshal.FreeHGlobal(tcptable)
End Function
&#39;MIB_TCPROW_OWNER_PID is not well formatted, we need to format it.
Function MIB_ROW_To_TCP(ByVal row As MIB_TCPROW_OWNER_PID) As TcpConnection
Dim tcp As New TcpConnection
tcp.State = DirectCast(row.state, TcpState) &#39;a State enum is better than an int
&#39;IP adresses are stored in long format, we can simply convert it this way
Dim ipad As New IPAddress(row.localAddress)
tcp.localAddress = ipad.ToString
&#39;also the port is in network byte order,we need to convert it as well
tcp.LocalPort = row.LocalPort / 256 + (row.LocalPort Mod 256) * 256
&#39;another ip
ipad = New IPAddress(row.RemoteAddress)
tcp.RemoteAddress = ipad.ToString
&#39;another port
tcp.remotePort = row.remotePort / 256 + (row.remotePort Mod 256) * 256
&#39;for the process, all we get is the ID. Let&#39;s get also the name.
Dim p As Process = Process.GetProcessById(row.PID)
tcp.Proc = p.ProcessName &amp;amp; &quot; (&quot; &amp;amp; row.PID.ToString &amp;amp; &quot;)&quot;
&#39;just freeing this variable since we don&#39;t need it anymore.
p.Dispose()
&#39;done.
Return tcp
End Function
End Module
&lt;/pre&gt;
&lt;br /&gt;
Let&#39;s Create a Listview as the following to display connections :&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXzGmgvuKGMdmzDEpuSyBviDYNPmkymMfXj1hhpdR77w7foxCZVIqInIXWNXEuUa0Wfh2FdsFa6tgqjsPHmhfYbPYzO-xYx-lpD9yDtEu02IX8mLpYPPxH3RTI8MKRBzTvwMyDUzQXZTg/s1600/Sans+titre.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;158&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXzGmgvuKGMdmzDEpuSyBviDYNPmkymMfXj1hhpdR77w7foxCZVIqInIXWNXEuUa0Wfh2FdsFa6tgqjsPHmhfYbPYzO-xYx-lpD9yDtEu02IX8mLpYPPxH3RTI8MKRBzTvwMyDUzQXZTg/s400/Sans+titre.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now let&#39;s call our function and add each connection to this listview :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;&#39;Clear Items
        ListView1.Items.Clear()
        &#39;For Each MIB_TCPROW
        For Each Row In GetAllTCPConnections()
            &#39;We Convert It
            Dim Tcp As TcpConnection = MIB_ROW_To_TCP(Row)
            &#39;Add SubItems to a ListViewItem
            Dim l As New ListViewItem(New String() {Tcp.State.ToString, Tcp.localAddress, Tcp.LocalPort, Tcp.RemoteAddress, Tcp.remotePort, Tcp.Proc})
            &#39;Add The Item
            ListView1.Items.Add(l)
        Next
&lt;/pre&gt;
&lt;br /&gt;
That&#39;s about it, we can now see all tcp connections thanks to this great API.&lt;br /&gt;
As for UDP Connections, we can use the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa365930(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;GetExtendedUdpTable&lt;/a&gt;&amp;nbsp;Function with&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa366932(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;MIB_UDPTABLE_OWNER_PID&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa366928(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;MIB_UDPROW_OWNER_PID&lt;/a&gt;&amp;nbsp;Structures with a very similar piece of code to list them in an array, and show them in a listview if you like so.</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/3355637288667476586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/3355637288667476586' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/3355637288667476586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/3355637288667476586'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/listing-all-tcp-connections-on-local.html' title='Listing All Tcp connections on Local Computer'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXzGmgvuKGMdmzDEpuSyBviDYNPmkymMfXj1hhpdR77w7foxCZVIqInIXWNXEuUa0Wfh2FdsFa6tgqjsPHmhfYbPYzO-xYx-lpD9yDtEu02IX8mLpYPPxH3RTI8MKRBzTvwMyDUzQXZTg/s72-c/Sans+titre.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-8456096100365598323</id><published>2011-06-17T23:43:00.013+02:00</published><updated>2011-11-28T20:10:22.102+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Security"/><title type='text'>Recovering Google Chrome Passwords</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjooIVqhjUht0LCsmSZkuUIxqZn_auuvnIjtMSyRZ89HGw4h51EnPIpBdB6Wwmzt0c1D-OvRTRuNrbL6xa48-Wb005oQpBMSzsAJhWCTzfwxy62YXB6DQJs45-iA1dGPVCCEO_5wHXMlmA/s1600/images.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;184&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjooIVqhjUht0LCsmSZkuUIxqZn_auuvnIjtMSyRZ89HGw4h51EnPIpBdB6Wwmzt0c1D-OvRTRuNrbL6xa48-Wb005oQpBMSzsAJhWCTzfwxy62YXB6DQJs45-iA1dGPVCCEO_5wHXMlmA/s200/images.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
It was a while when i was curious about how my favorite web browser saves passwords.&lt;br /&gt;
i started browsing Chrome files, watching files that changes when i save a password.&lt;br /&gt;
&lt;br /&gt;
after a few tries i found the file that stores the passes called &lt;i&gt;web data&lt;/i&gt; (updated later to &lt;i&gt;login data&lt;/i&gt;) in the Local Application Data Folder, which is an &lt;a href=&quot;http://sqlite.org/&quot; target=&quot;_blank&quot;&gt;SQLite&lt;/a&gt; Database, wasn&#39;t that hard to find out with any DB Software.&lt;br /&gt;
after finding the table called &quot;&lt;i&gt;logins&lt;/i&gt;&quot; that stores passwords, all we need to do is to read the &quot;&lt;i&gt;origin_url&lt;/i&gt;&quot;, &quot;&lt;i&gt;username_value&lt;/i&gt;&quot; and &quot;&lt;i&gt;password_value&lt;/i&gt;&quot; for each entry, but we need to decrypt the &quot;&lt;i&gt;password_value&lt;/i&gt;&quot; using the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa380882(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;CryptUnprotectData&lt;/a&gt;&amp;nbsp;Api, without any&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&lt;em&gt;pOptionalEntropy &lt;/em&gt;&lt;/span&gt;(Optionnal password, read&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa380882(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;CryptUnprotectData&lt;/a&gt;&amp;nbsp;for more info). The other two values are stored as&amp;nbsp;plain-text&amp;nbsp;and no need to decrypt them.&lt;br /&gt;
&lt;br /&gt;
There is planty of exemples about reading from SQLite DB, and also about using the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa380882(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;CryptUnprotectData&lt;/a&gt;&amp;nbsp;Api.&lt;br /&gt;
&lt;br /&gt;
PS : Msdn recommands freeing memory of the pDataOut by calling &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa366730(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;LocalFree&lt;/a&gt;&amp;nbsp;to free the&amp;nbsp;pDataOut.pbData handle.&lt;br /&gt;
&lt;br /&gt;
if anyone is having problem with sqlite reading or using&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa380882(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;CryptUnprotectData&lt;/a&gt;&amp;nbsp;, Please Leave me a Comment i would be happy to help.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the Downloads page for the demo that includes reading from the database and decrypting.&lt;br /&gt;
i also included system.data.sqlite releases incase it failed due to compatibility issues.&lt;br /&gt;
you can also find it here :&amp;nbsp;&lt;a href=&quot;http://sourceforge.net/projects/sqlite-dotnet2/&quot; target=&quot;_blank&quot;&gt;http://sourceforge.net/projects/sqlite-dotnet2/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/8456096100365598323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/8456096100365598323' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/8456096100365598323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/8456096100365598323'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/recovering-google-chrome-passwords.html' title='Recovering Google Chrome Passwords'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjooIVqhjUht0LCsmSZkuUIxqZn_auuvnIjtMSyRZ89HGw4h51EnPIpBdB6Wwmzt0c1D-OvRTRuNrbL6xa48-Wb005oQpBMSzsAJhWCTzfwxy62YXB6DQJs45-iA1dGPVCCEO_5wHXMlmA/s72-c/images.jpg" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-1174817103439029922</id><published>2011-06-17T19:11:00.003+02:00</published><updated>2011-11-28T20:10:51.004+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Controls"/><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><title type='text'>Textual Cue For TextBox Control</title><content type='html'>In this article, every thing is based on this : &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb761639(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;EM_SETCUEBANNER&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
this is a Windows Message that we can send to an edit control such as a textbox, so we can have something like this :&lt;br /&gt;
&amp;nbsp;&lt;a href=&quot;http://www.amirliberman.com/images/utils/cue1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;51&quot; src=&quot;http://www.amirliberman.com/images/utils/cue1.png&quot; style=&quot;cursor: move;&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
this tip &quot;Enter your full name here&quot; on the textbox is usally useful to the user and avoid some confusion.&lt;br /&gt;
All we need to do, is to send this message to the handle of the control, via &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;SendMessage&lt;/a&gt; Api.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Declare Unicode Function SendMessageW Lib &quot;User32.dll&quot; (ByVal Hwnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Boolean, ByVal lParam As String) As Boolean
    Const EM_SETCUEBANNER = 5377
    Function SetCueText(ByRef Textbox1 As TextBox, ByVal CueText As String, Optional ByVal ShowOnFocus As Boolean = False) As Boolean
        Return SendMessageW(Textbox1.Handle, EM_SETCUEBANNER, ShowOnFocus, CueText)
    End Function
&lt;/pre&gt;
&lt;br /&gt;
Usage :&lt;br /&gt;
Call SetCueText wih these parameters: :&lt;br /&gt;
Textbox1 : the textbox control that you want to add a cue text to it. (Textbox)&lt;br /&gt;
CueText : The Tip that will show on the textbox (String)&lt;br /&gt;
ShowOnFocus : Set to true if you want the cue text visible even if the textbox has the focus (boolean)&lt;br /&gt;
Return value : returns true if it&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;succeeds, otherwise it returns false.&lt;br /&gt;
Even Better, we can extend the textbox control, and add a property Called &quot;CueText&quot;, just like this :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Imports System.Windows.Forms

Public Class mTextBox
    Inherits TextBox
    Declare Unicode Function SendMessageW Lib &quot;User32.dll&quot; (ByVal Hwnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Boolean, ByVal lParam As String) As Boolean
    Const EM_SETCUEBANNER = 5377
    Private _CueText As String
    Private _CueFocus As Boolean
    Public Property CueText() As String
        Get
            Return _CueText
        End Get
        Set(ByVal value As String)
            _CueText = value
            If Me.Handle &amp;lt;&amp;gt; IntPtr.Zero Then SendMessageW(Me.Handle, EM_SETCUEBANNER, New IntPtr(CInt(_CueFocus)), _CueText)
        End Set
    End Property
    Property CueTextFocus() As Boolean
        Get
            Return _CueFocus
        End Get
        Set(ByVal value As Boolean)
            _CueFocus = value
            CueText = CueText
        End Set
    End Property
End Class
&lt;/pre&gt;
&lt;br /&gt;
What we did, we created a control that inherits from the usual textbox, and added two properties that allow us to get and set the cue text, and also whether to show on focus or not.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cccccc; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/1174817103439029922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/1174817103439029922' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/1174817103439029922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/1174817103439029922'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/textual-cue-for-textbox-control.html' title='Textual Cue For TextBox Control'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-8520163650941329857</id><published>2011-06-17T18:39:00.006+02:00</published><updated>2011-11-28T20:12:00.956+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Controls"/><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><title type='text'>OpenIconDialog</title><content type='html'>If you noticed in your tool box, you&#39;ve got your OpenFileDialog, SaveFileDialog, ColorDialog, ect...&lt;br /&gt;
But There Is No OpenIconDialog.&lt;br /&gt;
What we are going to do, is to use the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb776481(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;PickIconDlg&lt;/a&gt;&amp;nbsp;Api to show a dialog to choose an&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;embedded&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Segoe UI&#39;, Verdana, Arial; font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/span&gt;icon in a file,it will return the index of the selected icon in the file, and then we use the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms648069(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;ExtractIconEx&lt;/a&gt;&amp;nbsp;Api to load the icon of that index to memory, get its handle and return a variable of type &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.drawing.icon.aspx&quot; target=&quot;_blank&quot;&gt;System.Drawing.Icon&lt;/a&gt;.&lt;br /&gt;
So basically, we made an OpenIconDialog.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Declare Unicode Function PickIconDlg Lib &quot;shell32.dll&quot; (ByVal hwnd As IntPtr, ByVal pszIconPath As StringBuilder, ByVal cchIconPath As Integer, ByRef piIconIndex As Integer) As Integer
    &amp;lt;DllImport(&quot;shell32.dll&quot;, CharSet:=CharSet.Auto)&amp;gt; _
    Private Shared Function ExtractIconEx(ByVal stExeFileName As String, ByVal nIconIndex As Integer, ByVal phiconLarge As IntPtr(), ByVal phiconSmall As IntPtr(), ByVal nIcons As Integer) As Integer
    End Function
    Function OpenIconDialog(Optional ByVal IcoPath As String = &quot;Shell32.dll&quot;) As Icon
        Dim buff As New StringBuilder(IcoPath, 500)
        Dim ind As Integer
        If PickIconDlg(Nothing, buff, buff.Capacity, ind) = 1 Then
            Dim bitm As New Bitmap(1, 1)
            Dim hIcon() As IntPtr = New IntPtr(0) {}
            If (ExtractIconEx(buff.ToString, ind, hIcon, Nothing, 1) = 1) AndAlso hIcon(0) &amp;lt;&amp;gt; IntPtr.Zero Then
                Return Icon.FromHandle(hIcon(0))
            End If
        End If
        Return Nothing
    End Function
&lt;/pre&gt;
It would look something like this :&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJSNY2iRLpLro4MK2aIhGCJK86njjPqXaxQUq9J6h72FCqbBLCnjBkt49kI5M6xAFkpWSTq4oMW8L9MA5dfu7bwHGxNTO1j_fnb2C2BmVGF1cJrrTzd3WeIc7_ThTS6tkKOP-KxE28EcQ/s1600/t%25C3%25A9l%25C3%25A9chargement.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJSNY2iRLpLro4MK2aIhGCJK86njjPqXaxQUq9J6h72FCqbBLCnjBkt49kI5M6xAFkpWSTq4oMW8L9MA5dfu7bwHGxNTO1j_fnb2C2BmVGF1cJrrTzd3WeIc7_ThTS6tkKOP-KxE28EcQ/s1600/t%25C3%25A9l%25C3%25A9chargement.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Msdn&amp;nbsp;recommends&amp;nbsp;that we call &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms648063(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;DestroyIcon&lt;/a&gt;&amp;nbsp;api after finishing of using the icon, but we don&#39;t need to add that api declaration to our code since the type&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.drawing.icon.aspx&quot;&gt;System.Drawing.Icon&lt;/a&gt;&amp;nbsp;has a method called Dispose, that will eventually cleanup and call the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms648063(v=vs.85).aspx&quot; target=&quot;_blank&quot;&gt;DestroyIcon&lt;/a&gt;&amp;nbsp;api.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/8520163650941329857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/8520163650941329857' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/8520163650941329857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/8520163650941329857'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/openicondialog.html' title='OpenIconDialog'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJSNY2iRLpLro4MK2aIhGCJK86njjPqXaxQUq9J6h72FCqbBLCnjBkt49kI5M6xAFkpWSTq4oMW8L9MA5dfu7bwHGxNTO1j_fnb2C2BmVGF1cJrrTzd3WeIc7_ThTS6tkKOP-KxE28EcQ/s72-c/t%25C3%25A9l%25C3%25A9chargement.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8536115727336389420.post-273630719732510384</id><published>2011-06-16T02:26:00.006+02:00</published><updated>2011-06-30T12:51:57.462+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Security"/><category scheme="http://www.blogger.com/atom/ns#" term="Snippets"/><title type='text'>Custom Encryption : Polymorphic Stairs</title><content type='html'>An Encryption is a process to make a plaintext unreadable to anyone unless they have the algorithm and the key to transform the data to it&#39;s orginal state. It is usally -in general- used to PROTECT data from being read/understood/stolen.&lt;br /&gt;
check out more on wiki : &lt;a href=&quot;http://en.wikipedia.org/wiki/Encryption&quot;&gt;http://en.wikipedia.org/wiki/Encryption&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
A stronger encryption method is the one with less chance to&amp;nbsp;reverse data to original plaintext&amp;nbsp;without knowing the password, which is called cracking.&lt;br /&gt;
&lt;br /&gt;
today we are going to make our own &quot;Custom Encryption&quot;, even if dotnet provides us with a fine list of encryption routines, check them out on msdn : &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
What is Polymorphic?&lt;br /&gt;
Polymorphic stands for &quot;multiple forms&quot;. in our case, the output of the encryption is diffrent everytime we use it, which gives some&amp;nbsp;confusion to the one who tries to &quot;crack&quot; it without the password.&lt;br /&gt;
&lt;br /&gt;
here is an exemple, which i called &quot;Polymorphic Stairs&quot;&lt;br /&gt;
 &lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;vb&quot;&gt;Imports System.Text
Public Class PolyMorphicStairs
    Overloads Shared Function PolyCrypt(ByVal Data As String, ByVal Key As String, Optional ByVal ExtraRounds As UInteger = 0) As String
        Dim buff() As Byte = PolyCrypt(Encoding.Default.GetBytes(Data), Encoding.Default.GetBytes(Key), ExtraRounds)
        PolyCrypt = Encoding.Default.GetString(buff)
        Erase buff
    End Function
    Overloads Shared Function PolyDeCrypt(ByVal Data As String, ByVal Key As String, Optional ByVal ExtraRounds As UInteger = 0) As String
        Dim buff() As Byte = PolyDeCrypt(Encoding.Default.GetBytes(Data), Encoding.Default.GetBytes(Key), ExtraRounds)
        PolyDeCrypt = Encoding.Default.GetString(buff)
        Erase buff
    End Function
    Overloads Shared Function PolyCrypt(ByRef Data() As Byte, ByVal Key() As Byte, Optional ByVal ExtraRounds As UInteger = 0) As Byte()
        Array.Resize(Data, Data.Length + 1)
        Data(Data.Length - 1) = Convert.ToByte(New Random().Next(1, 255))
        For i = (Data.Length - 1) * (ExtraRounds + 1) To 0 Step -1
            Data(i Mod Data.Length) = CByte(CInt((Data(i Mod Data.Length)) + CInt(Data((i + 1) Mod Data.Length))) Mod 256) Xor Key(i Mod Key.Length)
        Next
        Return Data
    End Function
    Overloads Shared Function PolyDeCrypt(ByRef Data() As Byte, ByVal Key() As Byte, Optional ByVal ExtraRounds As UInteger = 0) As Byte()
        For i = 0 To (Data.Length - 1) * (ExtraRounds + 1)
            Data(i Mod Data.Length) = CByte((CInt(Data(i Mod Data.Length) Xor Key(i Mod Key.Length)) - CInt(Data((i + 1) Mod Data.Length)) + 256) Mod 256)
        Next
        Array.Resize(Data, Data.Length - 1)
        Return Data
    End Function
End Class
&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;Lets take a look at this Class :&lt;/div&gt;&lt;div&gt;First, we have two&amp;nbsp;functions, one to encrypt data and the other to decrypt data.&lt;/div&gt;&lt;div&gt;there are two parameters, one is the data, the other is the key, and the return value is the data after the transformation. they are both overloaded to accept strings or byte arrays as parameters. there is also an optionnal parameter called ExtraRounds, which represents how many addtional times you want to encrypt your data. for exemple, you want to encrypt it twise, set ExtraRounds to 1 when calling the function.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Here is how it works :&lt;/div&gt;&lt;div&gt;We first generate a random byte, and add it the end of the bytearray of the plaintext. after that, we add the value of that byte to the previous one, and using the bitwise operator XOR with a byte from the key. we just loop and do the same with every byte in the array.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;The Output :&lt;/div&gt;&lt;div&gt;With the random byte sticked to the end of the array, its value is gonna be added to the previous byte, which also be added to the one before it... in other words the random byte will affect the hole array : the output will be completely randomized each time.&lt;br /&gt;
Here is an exemple where the plain-text and key are pretty basic :&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_Ko5W7Ecu4Ond95KyFCmk1J4iADXI4a6cqD8OKLBWojFynNfc7PKbx8wML44kzpDuCxEjjgqDoMitqYuxVeH1gunpQ_52xlModiFc_94c_4rmAMOrVKfRrPHVruuXV6lYjLd9Iu_fYkI/s1600/Sans+titre.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_Ko5W7Ecu4Ond95KyFCmk1J4iADXI4a6cqD8OKLBWojFynNfc7PKbx8wML44kzpDuCxEjjgqDoMitqYuxVeH1gunpQ_52xlModiFc_94c_4rmAMOrVKfRrPHVruuXV6lYjLd9Iu_fYkI/s1600/Sans+titre.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;As you can see, outputs are random and scrambled each time.&lt;br /&gt;
But the more complex the key is, the better.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;Decryption&amp;nbsp;:&lt;br /&gt;
&lt;div&gt;In the decryption routine, we do the exact same thing, but backwards. First, we Xor the byte, and then remove the value next to it. after the loop finishes, we just remove the random value in the end of the buffer and we get our plaintext back to normal.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Weakness :&lt;/div&gt;&lt;div&gt;Xor operator is a weak Cipher by it self, the password can be guessed by analysing the output. the addition of a value to another and the use of a random value covers xor weakness, but there is alot of cracking routines, such as bruteforcing for exemple.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Why the random value was added to the end of the array?&lt;/div&gt;&lt;div&gt;Good Quesion. Why? this would work also if we add it at the start of the array. it is simply added to the end for a faster performance, because i don&#39;t really want copy the full array to a new one, or push all values to give space for the random one. as simple as that.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbdotnetpower.blogspot.com/feeds/273630719732510384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8536115727336389420/273630719732510384' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/273630719732510384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8536115727336389420/posts/default/273630719732510384'/><link rel='alternate' type='text/html' href='http://vbdotnetpower.blogspot.com/2011/06/custom-encryption-polymorphic-stairs.html' title='Custom Encryption : Polymorphic Stairs'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_Ko5W7Ecu4Ond95KyFCmk1J4iADXI4a6cqD8OKLBWojFynNfc7PKbx8wML44kzpDuCxEjjgqDoMitqYuxVeH1gunpQ_52xlModiFc_94c_4rmAMOrVKfRrPHVruuXV6lYjLd9Iu_fYkI/s72-c/Sans+titre.png" height="72" width="72"/><thr:total>1</thr:total></entry></feed>