What’s Going On?

Got some emails asking what’s been going on. I know I haven’t posted in a while. Some people miss my daily code snippets and short tutorials. I’ve been working hard on an anti-cheat system for BHD with http://cheatsense.com

I haven’t completly neglected the site. I’ll post some code tutorials tonight on a few more hashing techniques and string encryption. I will also be posting soon a tutorial on how to control a forms events and controls from within a different class. Unlike VB.NET, C# does not automatically inherit the forms methods and control methods.

I’ll also talk about obfuscation and .Net application security, secure string and anti-debugging methods.

Popularity: unranked [?]

.NET URL Shorten-er Library

I’ve been working on a few applications were I’ve been using TinyURL a lot. So, I thought I’d create a library for .NET that contains functions for the most popular URL Shorten-er sites.

 

Function TinyURL
Function TimesURL
Function DoiopURL
Function MemURL
Function DwarfURL
Function SnipURL
Function ShorlURL
Function LoajURL
Function BitlyURL
Function IsGdURL
Function SixURL
Function TightURL
Function UrlXURL
Function YepItURL

Total there are 14 function that all server the same purpose. It’s really a personal preference as to what service you want to use. Each function accepts 1 overload and returns a single String.

Example: 


dim sTest As String = TimesURL(sURL)

The library will be available soon. Any interest in this or ideas please leave a comment.

Popularity: unranked [?]

Gravatar & .NET

Some emails coming in wanting to know an easy way to get Gravatars into their .NET applications. I’ll show 2 ways, both in C# and VB.

First I’ll share with you my MD5 function used to return the hash of a string. In this case, the hash of a users email address.

Function MD5(ByVal strToHash As String) As String
Dim md5Obj As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)

bytesToHash = md5Obj.ComputeHash(bytesToHash)

Dim strResult As String = ""

For Each b As Byte In bytesToHash
strResult += b.ToString("x2")
Next

Return strResult
End Function

Create a new windows forms application and add a single picturebox control. For test/example purpose, please the following code in your “Form1_Load” sub.

'Declare a constant here that is half of our URL
Const GURL = "http://www.gravatar.com/avatar/"

'GravatarSize ranges from 1-512
'Rating ranged from G, PG, R, X
'IconType ranges from monsterid, identicon, wavatar
Dim tmp As String = GURL & MD5(Email) & "?s=" & GravatarSize & "&r=" & Rating & "&d=" & IconType

'Now lets use the picturebox "ImageLocation" method to load the Image.
picGravatar.ImageLocation = tmp

An example would be:

Dim tmp As String = GURL & MD5(dremation@gmail.com) & "?s=60&r=g&d=monsterid"

The result would be
Gravatar

 

Now, for the C# example. Although C# and VB are very close in syntext I will include this example as well.
First, here is the MD5 function.

 private string  MD5(string Email)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(Email);
data = x.ComputeHash(data);
string ret = "";
for (int i = 0; i < data.Length; i++)
ret += data[i].ToString("x2").ToLower();
return ret;
}

And now let’s get the Gravatar and show it in the picturebox.

 const string GURL = "http://www.gravatar.com/avatar/";

string tmp = GURL + MD5("dremation@gmail.com") + "?s=60&r=g&d=monsterid";
picGravatar.ImageLocation = tmp;

And there you have C# and VB .NET examples on how to retrieve a Gravatar using a users email address. This is nice because using this method is fast and simple.

Popularity: unranked [?]

TimesURL & .NET

I’ve got a few emails regarding http://timesurl.at. If you want to use this service you can still the use code from [TinyURL & .NET]. All you have to do is change one line of code.

Change

http://tinyurl.com/api-create.php?url=

to

http://timesurl.at/api/rest.php?url=

And there you have it. This also works with most other URL shortener sites. If not, just email me and I”ll write up some code for the site you need.

Popularity: unranked [?]

TinyURL & .NET

Ever want to parse a TinyURL in your .NET application? TinyURL has a very simple and easy to use API. I’ll guide you through the process of returning a TinyURL in VB.NET 2008 and C# .NET 2008

First off you want to create a function that returns a string.
Simple enough, this function ask for the parameter of URL and will return a string. 

Public Function GetTinyUrl(ByVal URL As String) As String
End Function

Next you want to make sure you’re not using the TinyURL service for no reason. The API is designed for links over 30 characters long. So if you have a 20 character URL TinyURL will end up giving you a 20-35 character URL. So let’s check this first. We’re going to use the Try/Catch method incase something might go wrong. If so, we’ll return the users URL back to him.

Try
    If Url.Length <= 30 Then
       Return URL
     End If
Catch
       Return Url
     End Try

Next we are going to check our link to make sure it starts with “http”.

If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
  Url = "http://" + Url
End If

Now that we have that done, lets declare some variables. “req” is used to create  our request to use the API, “rsp” is used to get the response from our request. Simple enough, right? “txt” is used to store our ending result from our Stream Reader.

Dim req As WebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url)
Dim rsp As WebResponse = req.GetResponse()
Dim txt As String

Now lets actually read our request and store the result in our txt variable. Also, let’s go ahead and Return our result to the user.

Using rdr As StreamReader = New StreamReader(rsp.GetResponseStream())
          txt = rdr.ReadToEnd()
End Using
Return txt

Now, let’s put it all together and we have this. Pass the URL parameter and recieve the TinyURL in return.

    Public Function GetTinyUrl(ByVal URL As String) As String
        Try
            If Url.Length <= 30 Then
                Return URL
            End If
            If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
                Url = "http://" + Url
            End If
            Dim req As WebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url)
            Dim rsp As WebResponse = req.GetResponse()
            Dim txt As String
            Using rdr As StreamReader = New StreamReader(rsp.GetResponseStream())
                txt = rdr.ReadToEnd()
            End Using
            Return txt
        Catch
            Return Url
        End Try
    End Function

I hope this helps you out, and don’t forget to comment!

Popularity: unranked [?]

uStreamer: It’s still alive!

I’ve recieved tons of emails wanting to know when an update to uStreamer will be available. Soon! I’ve been working personal things the last 2 weeks but I did not forget about uStreamer! The next version to come will support custom skins, Twitter integration(and maybe Ping.FM), Radio Mode and a few other nice features. So stay tuned and check back around this time next week. 

Remember, if you like my software, Donate!

Popularity: unranked [?]

uStream Wrapper

I’ve been working on a few uStream.tv applications using the .NET framework. I noticed there are alot of people that are confused on the uStream API provided. I’ve taken it upon myself to wrap the API in a nice and easy to use library. The library is written in C# and VB. I did this so there could be a broader range of use. The wrapper will make use of the entire API and proved comma dilemited or XML results.  I plan to release this soon. This also goes hand-in-hand with my uStream Viewer application.

Popularity: 6% [?]

VB.NET 2008 & Shockwave Flash

Alot of people are wanting to embed flash object,movies or video streams into thier applications these days. I’m going to show some examples and tips & tricks of using the Shockwave Flash object and namespace. VB.NET and the Shockwave object can be very powerful. I’ve used it in several applications including my ‘uStreamer” viewer application.

First things first. Right click on your toolbox and click “Choose Items”. Scroll down and choose the Shockwave Flash Player Object. From your toolbox add a Shockwave Flash control to your form.

To load a movie use the following code. You can specify a url or path using the ‘LoadMovie’ modifer. The first variable, 0, specifies the layer. The layer is not that important to us in the sense of coding with the control. Use the layer ‘0′.

AxShockwaveFlash1.LoadMovie(0, "yourmovie.swf")

The ‘AllowFullScreen’ modifier comes in handy when dealing with movies that try to take over and go fullscreen. You can choose from boolean True/Flase.

AxShockwaveFlash1.AllowFullScreen = True

The ‘StopPlay’ modifier is used to stop the current play state. This is not the same as the ‘Stop’ modifier. Using ‘Stop’ will cause the control to stop it’s current process. Using ‘StopPlay’ will stop the current movie as the current frame.

AxShockwaveFlash1.StopPlay()

Popularity: 33% [?]

INI Handling Using VB.NET 2008

Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
    Private Declare Ansi Function GetPrivateProfileInt Lib "kernel32.dll" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
    Private Declare Ansi Function FlushPrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As Integer, ByVal lpKeyName As Integer, ByVal lpString As Integer, ByVal lpFileName As String) As Integer

    Dim sFile As String

    ReadOnly Property FileName() As String
        Get
            Return sFile
        End Get
    End Property

    Public Function GetString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String) As String
        Dim nCharCount As Integer
        Dim oResult As New System.Text.StringBuilder(256)
        nCharCount = GetPrivateProfileString(Section, Key, [Default], oResult, oResult.Capacity, sFile)
        If nCharCount > 0 Then
        End If
        GetString = Strings.Left(oResult.ToString, nCharCount)
    End Function

    Public Function GetInteger(ByVal Section As String, ByVal Key As String, ByVal [Default] As Integer) As Integer
        Return GetPrivateProfileInt(Section, Key, [Default], sFile)
    End Function

    Public Function GetBoolean(ByVal Section As String, ByVal Key As String, ByVal [Default] As Boolean) As Boolean
        Return (GetPrivateProfileInt(Section, Key, CInt([Default]), sFile) = 1)
    End Function

    Public Sub WriteString(ByVal Section As String, ByVal Key As String, ByVal Value As String)
        WritePrivateProfileString(Section, Key, Value, sFile)
        Flush()
    End Sub

    Public Sub WriteInteger(ByVal Section As String, ByVal Key As String, ByVal Value As Integer)
        WriteString(Section, Key, CStr(Value))
        Flush()
    End Sub

    Public Sub WriteBoolean(ByVal Section As String, ByVal Key As String, ByVal Value As Boolean)
        WriteString(Section, Key, CStr(CInt(Value)))
        Flush()
    End Sub

    Private Sub Flush()
        FlushPrivateProfileString(0, 0, 0, sFile)
    End Sub

within my code I use the following to write a to a [setion] key=value

Dim objIniFile As New IniFile("your file path\yourfile.ini")
objIniFile.WriteString("Section name", "Keyname", "your value as string")

‘to read from a [section] key=value

Dim objIniFile As New IniFile("your file path\yourfile.ini")
Dim boolData As Boolean = objIniFile.GetBoolean("your Section name" "yourkey",True)

Popularity: 6% [?]