目前分類:程式語言 (41)

瀏覽方式: 標題列表 簡短摘要

方法一:webbrowser的outhtml法

利用webbrowser打開網頁,然後通過outhtml輸出源碼,再加以分析利用。

方法二:WebClient的Downloaddata法

利用webclient下載源碼,再加以分析利用。

方法三:XMLHTTP及流對象法

利用MSXML2.XMLHTTP與adodb.stream獲取源碼,再加以分析利用。

經過多次的測試,獲得源碼速度的排序是:

方法三 > 方法一 > 方法二

也就是說,用XMLHTTP的方法是獲得網頁源碼最快的方式。方法二所用時間是方法三的三倍,是方法一的二倍

下面我把幾個方法的主要過程(函數)列出來,大家可以參考指正

XMLHTTP及流對象法的基本函數

Function GetPage(ByVal url)

        Dim Retrieval
        Retrieval = CreateObject("MSXML2.XMLHTTP")
        With Retrieval
            .Open("Get", url, False) ', "", ""
              .Send()
            GetPage = BytesToBstr(.ResponseBody)
        End With

        Retrieval = Nothing
End Function
Function BytesToBstr(ByVal body)
        Dim objstream
        objstream = CreateObject("adodb.stream")
        objstream.Type = 1
        objstream.Mode = 3
        objstream.Open()
        objstream.Write(body)
        objstream.Position = 0
        objstream.Type = 2
        objstream.Charset = "utf-8"       '這裡是設定編碼的
        BytesToBstr = objstream.ReadText
        objstream.Close()
        objstream = Nothing
    End Function

WebClient的Downloaddata法的基本函數

Function gethtml(ByVal u As String, ByVal bm As String) As String
        Dim Doc As New WebClient
        Dim T As String = ""
        Try
            If bm = "utf-8" Then
                T = System.Text.Encoding.UTF8.GetString(Doc.DownloadData(u))
            ElseIf bm = "gb2312" Then
                T = System.Text.Encoding.Default.GetString(Doc.DownloadData(u))
            End If
            Return T
        Catch ex As Exception
            Return ""
        End Try
    End Function

webbrowser的outhtml法的基本函數

利用WebBrowser的DocumentCompleted,獲取webBrowser1.Document.Body.OuterHtml





=================================
VB.net保存遠程文件到本地並用進度條進行顯示的方法
 

首先在form裡添加一個ProgressBar,命名為prg1

然後指定要下載的文件路徑比如

dim remote as string ="http://www.abc.com/aa.exe" '遠程文件

dim local as string ="bb.exe" '本地文件

然後進行調用:

DownloadFile(remote, local,Me.prg1)

主函數:

Public Shared Sub DownloadFile(ByVal URL As String, ByVal Filename As String, ByVal Prog As ProgressBar)
    Dim Myrq As HttpWebRequest = HttpWebRequest.Create(URL)
    Dim myrp As HttpWebResponse = Myrq.GetResponse
    Dim totalBytes As Long = myrp.ContentLength
    Prog.Maximum = totalBytes
    Dim st As Stream = myrp.GetResponseStream
    Dim so As Stream = New FileStream(Filename, FileMode.Create)
    Dim totalDownloadedByte As Long = 0
    Dim by(1024) As Byte
    Dim osize As Integer = st.Read(by, 0, by.Length)
    While osize > 0
        totalDownloadedByte = osize + totalDownloadedByte
        System.Windows.Forms.Application.DoEvents()
        so.Write(by, 0, osize)
        Prog.Value = totalDownloadedByte
        osize = st.Read(by, 0, by.LongLength)
    End While
    so.Close()
    st.Close()
End Sub

文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()

一段範例如下

<DT><H3 ADD_DATE="1312850481" LAST_MODIFIED="1319985361">書籤工具列</H3>
        <DL><p>
            <DT><H3 ADD_DATE="1312850481" LAST_MODIFIED="1319985363">Android___</H3>
            <DL><p>
                <DT><A HREF="http://gphonefans.net/forum-49-3.html" ADD_DATE="1310539680" LAST_MODIFIED="1319985346">Android 軟件及遊戲討論 - GPhonefans.net</A>
                <DT><A HREF="http://www.soft4fun.net/website-recommand/10%E5%80%8B-android-%E5%85%8D%E8%B2%BB-app-%E4%B8%8B%E8%BC%89%E3%80%81%E4%BB%8B%E7%B4%B9%E7%B6%B2%E7%AB%99.htm" ADD_DATE="1310722061" LAST_MODIFIED="1319985346">10個 Android 免費 APP 下載、介紹網站 | 硬是要學</A>
                <DT><A HREF="http://www.freewarelovers.com/android/category/system" ADD_DATE="1310740049" LAST_MODIFIED="1319985346">Android Freeware: Browse the SYSTEM category</A> 

 

如果我們想要取

 

<A HREF="http://gphonefans.net/forum-49-3.html" ADD_DATE="1310539680" LAST_MODIFIED="1319985346">Android 軟件及遊戲討論 - GPhonefans.net</A> 


這段 內的 Href= 後面的字串該怎麼寫 程式碼呢

'

文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()

本文轉

http://63.236.73.220/showpost.php?s=74a3f46cfed0f447c52f3435fa53bae1&p=3497640&postcount=9

 

Imports System
Imports System.Net.Sockets
Imports System.Text
Imports System.IO

Module POP3Message1


Dim Server As TcpClient
Dim NetStrm As NetworkStream
Dim RdStrm As StreamReader
Dim _Strm As Net.Security.SslStream

Public Function connect() As Integer
Dim POP3Account As String
POP3Account = "pop.gmail.com"
If POP3Account.Trim = "" Then Exit Function
Try
Server = New TcpClient(POP3Account.Trim, 995)
NetStrm = Server.GetStream
_Strm = New Net.Security.SslStream(Server.GetStream())
DirectCast(_Strm, Net.Security.SslStream).AuthenticateAsClient("pop.gmail.com")
RdStrm = New StreamReader(Server.GetStream)
Catch exc As Exception
MsgBox(exc.Message)

Exit Function
End Try

 

dark99 發表在 痞客邦 留言(0) 人氣()

如何要在一個儲存格 多行顯示

請參考這篇連結

http://www.dotblogs.com.tw/chou/archive/2011/10/23/46092.aspx

 

 

直接使用

    DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
    DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
    DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders

 

文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()

DataGridView新特色、常用操作 列操作 c# dataGridView1.Columns.Insert
 

[推薦]DataGridView新特色、常用操作

1、自定義列 srxljl

Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their
     Behavior and Appearance
     Host Controls in Windows Forms DataGridView Cells
     繼承 DataGridViewTextBoxCell 類生成新的Cell類,然後再繼承 DataGridViewColumn 生成新的Column類,並指定
     CellTemplate為新的Cell類。新生成的Column便可以增加到DataGridView中去。

2、自動適應列寬 srxljl

Programmatically Resize Cells to Fit Content in the Windows Forms DataGridView Control
     Samples:

 

 
DataGridView.AutoSizeColumns(
       DataGridViewAutoSizeColumnCriteria.HeaderAndDisplayedRows);
DataGridView.AutoSizeColumn(
            DataGridViewAutoSizeColumnCriteria.HeaderOnly,
            2, false);
DataGridView.AutoSizeRow(
            DataGridViewAutoSizeRowCriteria.Columns,
            2, false);
DataGridView.AutoSizeRows(
          DataGridViewAutoSizeRowCriteria.HeaderAndColumns,
            0, dataGridView1.Rows.Count, false);
文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()


        /// <summary>
        
/// 得到灰度图像前景背景的临界值 最大类间方差法,yuanbao,2007.08
        
/// </summary>
        
/// <returns>前景背景的临界值</returns>
        public int GetDgGrayValue()
        {
            
int[] pixelNum = new int[256];           //图象直方图,共256个点
            int n, n1, n2;
            
int total;                              //total为总和,累计值
            double m1, m2, sum, csum, fmax, sb;     //sb为类间方差,fmax存储最大方差值
            int k, t, q;
            
int threshValue = 1;                      // 阈值
            int step = 1;
            
//生成直方图
            for (int i =0; i < bmpobj.Width ; i++)
            {
                
for (int j = 0; j < bmpobj.Height; j++)
                {
                    
//返回各个点的颜色,以RGB表示
                    pixelNum[bmpobj.GetPixel(i,j).R]++;            //相应的直方图加1
                }
            }
            
//直方图平滑化
            for (k = 0; k <= 255; k++)
            {
                total 
= 0;
                
for (t = -2; t <= 2; t++)              //与附近2个灰度做平滑化,t值应取较小的值
                {
                    q 
= k + t;
                    
if (q < 0)                     //越界处理
                        q = 0;
                    
if (q > 255)
                        q 
= 255;
                    total 
= total + pixelNum[q];    //total为总和,累计值
                }
                pixelNum[k] 
= (int)((float)total / 5.0 + 0.5);    //平滑化,左边2个+中间1个+右边2个灰度,共5个,所以总和除以5,后面加0.5是用修正值
            }
            
//求阈值
            sum = csum = 0.0;
            n 
= 0;
            
//计算总的图象的点数和质量矩,为后面的计算做准备
            for (k = 0; k <= 255; k++)
            {
                sum 
+= (double)k * (double)pixelNum[k];     //x*f(x)质量矩,也就是每个灰度的值乘以其点数(归一化后为概率),sum为其总和
                n += pixelNum[k];                       //n为图象总的点数,归一化后就是累积概率
            }

            fmax 
= -1.0;                          //类间方差sb不可能为负,所以fmax初始值为-1不影响计算的进行
            n1 = 0;
            
for (k = 0; k < 256; k++)                  //对每个灰度(从0到255)计算一次分割后的类间方差sb
            {
                n1 
+= pixelNum[k];                //n1为在当前阈值遍前景图象的点数
                if (n1 == 0) { continue; }            //没有分出前景后景
                n2 = n - n1;                        //n2为背景图象的点数
                if (n2 == 0) { break; }               //n2为0表示全部都是后景图象,与n1=0情况类似,之后的遍历不可能使前景点数增加,所以此时可以退出循环
                csum += (double)k * pixelNum[k];    //前景的“灰度的值*其点数”的总和
                m1 = csum / n1;                     //m1为前景的平均灰度
                m2 = (sum - csum) / n2;               //m2为背景的平均灰度
                sb = (double)n1 * (double)n2 * (m1 - m2) * (m1 - m2);   //sb为类间方差
                if (sb > fmax)                  //如果算出的类间方差大于前一次算出的类间方差
                {
                    fmax 
= sb;                    //fmax始终为最大类间方差(otsu)
                    threshValue = k;              //取最大类间方差时对应的灰度的k就是最佳阈值
                }
            }
            
return threshValue;
        }

dark99 發表在 痞客邦 留言(0) 人氣()

最近写了几个网站的验证码图片自动识别程序,尽管每个网站的验证码图片都不相同,识别的方法有所差别。但写得多了,也总结出不少相同之处。今天抽空封装出一个基础类来,发现可以很好地重复利用,编写不同的验证码识别程序,效率提高了不少。好东东不能独享,现放出来供大家共同研究,请网友们妥善用之。 

封装后的类使用很简单,针对不同的验证码,相应继承修改某些方法,即可简单几句代码就可以实现图片识别了: 

GrayByPixels(); //灰度处理

GetPicValidByValue(128, 4); //得到有效空间

Bitmap[] pics = GetSplitPics(4, 1);     //分割

string code = GetSingleBmpCode(pics[i], 128);   //得到代码串

dark99 發表在 痞客邦 留言(0) 人氣()

  • 這是一篇加密文章,請輸入密碼
  • 密碼提示:電話
  • 請輸入密碼:


  Sub ListV_ADD2(ByVal MyLen As Int16)


    ListView1.View = View.Details


    ListView1.GridLines = True


    ListView1.Columns.Clear()


    For a1 = 0 To MyLen - 1


      ListView1.Columns.Add("111", 100, HorizontalAlignment.Left)


    Next


    'ListView1.Columns.Add("列 2", 50, HorizontalAlignment.Left)


    'ListView1.Columns.Add("列 3", 50, HorizontalAlignment.Left)


    'ListView1.Columns.Add("列 4", 50, HorizontalAlignment.Center)


    ListView1.Refresh()


  End Sub



'初始化
  Dim Mylist As ListViewItem = New ListViewItem

 

文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()

原始碼片段 如下


<input type="checkbox" name="safe" id="safe" value="1">我已詳細閱讀
  <input type="submit" name="button" id="button" value="我已詳細閱讀">

 程式碼寫法 vb.net


      If spcheck.TagName = "INPUT" Then

        If spcheck.GetAttribute("ID") = "safe" Then

          spcheck.SetAttribute("CHECKED", "CHECKED")

          '送出按鍵 兩種方式

         'spcheck.invokemember("click")


          webbrowser_show.WebBrowser1.Document.GetElementById("button").InvokeMember("click")


        End If
      End If

文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()

先加入 參考 

Microsoft.mshtml.dll (或者 mshtml.tlb)

 

範例 :網頁原始碼大約如下

文章標籤

dark99 發表在 痞客邦 留言(0) 人氣()

下載點

    http://www.ziddu.com/download/14543606/Net_Open_Close.rar.html

 

 

Imports System.Runtime.InteropServices.GCHandle
Imports System.Runtime.InteropServices.GCHandleType


Public Class Form1


Private Const NetConnect As Integer = &H31
Private Function ExcNetLinkMenu(ByVal AdapterName As String, ByVal MenuName As String) As Boolean
On Error Resume Next
Dim Shell32 As Object
Dim lNameLenPtr As Integer
Dim lNameLen As Integer
Dim Handle As System.Runtime.InteropServices.GCHandle
Dim GCHandle As System.Runtime.InteropServices.GCHandleType
Handle = System.Runtime.InteropServices.GCHandle.Alloc("NetConnection", Pinned)
lNameLenPtr = Handle.AddrOfPinnedObject.ToInt32

Dim mShell As Shell32.Shell = New Shell32.Shell
Dim NetConnection As Shell32.Folder
Dim FolderItem As Shell32.FolderItem
Dim NetConnectionItem As New Shell32.ShellFolderItem
Dim verb As Shell32.FolderItemVerb
NetConnection = mShell.NameSpace(49)
If lNameLenPtr = 0 Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
Dim flag As Boolean
flag = False
For Each FolderItem In NetConnection.Items
If FolderItem.Name = AdapterName Then
NetConnectionItem = FolderItem
flag = True
Exit For
End If
Next FolderItem
If flag = False Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
For Each verb In NetConnectionItem.Verbs
If verb.Name = MenuName Then
flag = True
verb.DoIt()
ExcNetLinkMenu = True
GoTo exitfunction
End If
Next verb
If flag = False Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
exitfunction:
mShell = Nothing
NetConnection = Nothing
FolderItem = Nothing
NetConnectionItem = Nothing
verb = Nothing
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  '把區域連線 6 換成你 網路名字
Dim blnRelust As Boolean
blnRelust = ExcNetLinkMenu("區域連線 6", "停用(&B)")
If blnRelust Then
MsgBox("停用成功")
Else
blnRelust = ExcNetLinkMenu("區域連線 6", "禁用(&B)")
End If
If blnRelust Then
MsgBox("停用成功")
Else
MsgBox("停用失败")
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim blnRelust As Boolean
blnRelust = ExcNetLinkMenu("區域連線 6", "啟用(&A)")
If blnRelust Then
MsgBox("启用成功")
Else
MsgBox("启用失败")
End If
End Sub
End Class


dark99 發表在 痞客邦 留言(0) 人氣()

利用 VB.net 取得本機 IP
Imports System.Net.Dns
 


Public Function GetIPaddress() As String
Try
Dim ipEntry As System.Net.IPHostEntry = GetHostByName(Environment.MachineName)
Dim IpAddr As System.Net.IPAddress() = ipEntry.AddressList
 


GetIPaddress = IpAddr(0).ToString
Catch ex As Exception
GetIPaddress = "無法取得IP"
End Try
End Function

dark99 發表在 痞客邦 留言(0) 人氣()

VB.net

'
' WebClient.DownloadFile
'
Dim wc As New WebClient()
wc.DownloadFile("http://www.google.com.tw", "c:/test.htm")

'
' WebClient.DownloadData
'
Dim wc As New WebClient()
Dim myDataBuffer As Byte() = wc.DownloadData("http://www.google.com.tw")
Dim sDownload As String = Encoding.GetEncoding("big5").GetString(myDataBuffer)
Console.Write(sDownload)

'
' WebRequest and WebResponse
'
Dim myHttpWebRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.google.com.tw"), HttpWebRequest)
Dim myHttpWebResponse As HttpWebResponse = DirectCast(myHttpWebRequest.GetResponse(), HttpWebResponse)
Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
Dim encode As Encoding = System.Text.Encoding.GetEncoding("big5")
Dim readStream As New StreamReader(receiveStream, encode)
Dim read As [Char]() = New [Char](255) {}
Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0


Dim str As New [String](read, 0, count)


Console.Write(str)

count = readStream.Read(read, 0, 256)
End While
myHttpWebResponse.Close()
readStream.Close()


 ========================

C 語言

//
// WebClient.DownloadFile
//
WebClient wc = new WebClient();
wc.DownloadFile("http://www.google.com.tw", "c:/test.htm");

//
// WebClient.DownloadData
//
WebClient wc = new WebClient();
byte[] myDataBuffer = wc.DownloadData("http://www.google.com.tw");
string sDownload = Encoding.GetEncoding("big5").GetString(myDataBuffer);
Console.Write(sDownload);

//
// WebRequest and WebResponse
//
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com.tw");
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("big5");
StreamReader readStream = new StreamReader( receiveStream, encode );
Char[] read = new Char[256];
int count = readStream.Read( read, 0, 256 );
while (count > 0) {
String str = new String(read, 0, count);
Console.Write(str);
count = readStream.Read(read, 0, 256);
}
myHttpWebResponse.Close();
readStream.Close();

dark99 發表在 痞客邦 留言(0) 人氣()


------------------------------------------------------------------
Method 1
------------------------------------------------------------------
'測量己耗用的時間
Dim Watch As New Stopwatch

Watch.Start()
'程式內容
Watch.Stop()
Dim i As Integer = Watch.ElapsedMilliseconds / 1000
Watch.Reset()

------------------------------------------------------------------
Method 2
------------------------------------------------------------------
Dim t1 As DateTime = DateTime.Now
'程式內容
Dim t2 As DateTime = DateTime.Now
MessageBox.Show("總共花費:" & t2.Subtract(t1).TotalSeconds & "秒")
------------------------------------------------------------------

資料來源:程式設計俱樂部
http://tinyurl.com/3af8su

dark99 發表在 痞客邦 留言(0) 人氣()

 

    Private Function X_累乘(ByVal X As Integer)
        Dim a As Long

        A = 1

        For I = 1 To X

            a = a * 256

        Next I

        Return a

    End Function

dark99 發表在 痞客邦 留言(0) 人氣()

有的網頁會自動放 MP3 有時候當你很不喜歡聽音樂的時候 該怎辦呢?

FLV 也可以用這種方式 取代掉

Vb.net 方式

 

    Sub Stop_Mp3()
        Dim tmp

        tmp = WebBrowser1.Document.Body.InnerHtml
        tmp = Replace(tmp, "http://f10.wretch.yimg.com/aa850206aa/2/1977997273.mp3", "")
        WebBrowser1.Document.Body.InnerHtml = tmp
    End Sub

 

dark99 發表在 痞客邦 留言(0) 人氣()

 Private Sub Buttons(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                        Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click


'連續按鈕可以用這種方式來作


        Select Case sender.text
            Case "+"
                scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Relitive, -5)
            Case "-"
                scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Relitive, 5)
            Case "50"
                scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Jump, 50)
            Case "100"
                scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Jump, 100)
        End Select

    End Sub


dark99 發表在 痞客邦 留言(0) 人氣()

Drawing Text in GDI+

Drawing Text in GDI+
By  Dinesh Beniwal November 19, 2009

In this article I will explain you how to drawing Text in GDI+.



 







Drawing Text

This section briefly discusses the drawing of text.

The DrawString method draws a text string on a graphics surface. It has many overloaded forms. Drawstring takes arguments that identify the text, font, brush, starting location, and string format.

Listing 3.6 uses the DrawString method to draw "Hello GDI+ World!" on a form.

LISTING 3.6: Drawing text

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        e.Graphics.DrawString("Hello GDI+ World!", New Font("Verdana", 16), New SolidBrush(Color.Red), New Point(20, 20))
    End Sub

Note:
You might notice in Listing 3.6 that we create Font, SolidBrush, and Point objects directly as parameters of the DrawString method. This method of creating objects means that we can't dispose of these objects, so some cleanup is left for the garbage collector.

Figure 3.7 shows the output from Listing 3.6




FIGURE 3.7: Drawing text

Now let's see another example of drawing text- this time using the StringFormat class, which defines the text format. Using StringFormat, you can set flags, alignment, trimming, and other options for the text. Listing 3.7 shows different ways to draw text on a graphics surface. In this example the FormatFlags property is set to StringFormatFlags.DirectionVertical, which draws a vertical text.

LISTING 3.7: Using DrawString to draw text on a graphics surface

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        ' create brushes
        Dim blueBrush As New SolidBrush(Color.Blue)
        Dim redBrush As New SolidBrush(Color.Red)
        Dim greenBrush As New SolidBrush(Color.Green)
        ' Create a rectangle
        Dim rect As New Rectangle(20, 20, 200, 100)

        ' The text to be drawn
        Dim DrawString As [String] = "Hello GDI+ World!"

        ' Create a Font object
        Dim DrawFont As New Font("Verdana", 14)
        Dim x As Single = 100.0F
        Dim y As Single = 100.0F
        Dim DrawFormat As New StringFormat()

        ' Set string format flag to direction vertical,
        ' which draws text vertically
        DrawFormat.FormatFlags = StringFormatFlags.DirectionVertical

        ' Draw string
        e.Graphics.DrawString("Drawing text", New Font("Tahoma", 14), greenBrush, rect)
        e.Graphics.DrawString(DrawString, New Font("Arial", 12), redBrush, 120, 140)
        e.Graphics.DrawString(DrawString, DrawFont, blueBrush, x, y, DrawFormat)

        ' Dispose of objects
        blueBrush.Dispose()
        redBrush.Dispose()
        greenBrush.Dispose()
        DrawFont.Dispose()
    End Sub

Figure 3.8 shows the output from Listing 3.7



FIGURE 3.8: Drawing text with different directions

Conclusion

Hope the article would have helped you in understanding drawing Text in GDI+. Read other articles on GDI+ on the website.

dark99 發表在 痞客邦 留言(0) 人氣()

http://www.leetcoders.org/showthread.php?tid=496&pid=2916

 

Imports System
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Text
''' <summary>
''' Written to make reading the information from a PE (Portable Executable)
''' easier and simple.
''' </summary>
'''
Public Class Form1

    Public Const IMAGE_SUBSYSTEM_UNKNOWN As UInteger = 0
    ' Unknown subsystem.
    Public Const IMAGE_SUBSYSTEM_NATIVE As UInteger = 1
    ' Image doesn't require a subsystem.
    Public Const IMAGE_SUBSYSTEM_WINDOWS_GUI As UInteger = 2
    ' Image runs in the Windows GUI subsystem.
    Public Const IMAGE_SUBSYSTEM_WINDOWS_CUI As UInteger = 3
    ' Image runs in the Windows character subsystem.
    Public Const IMAGE_SUBSYSTEM_OS2_CUI As UInteger = 5
    ' image runs in the OS/2 character subsystem.
    Public Const IMAGE_SUBSYSTEM_POSIX_CUI As UInteger = 7
    ' image runs in the Posix character subsystem.
    Public Const IMAGE_SUBSYSTEM_NATIVE_WINDOWS As UInteger = 8
    ' image is a native Win9x driver.
    Public Const IMAGE_SUBSYSTEM_WINDOWS_CE_GUI As UInteger = 9
    ' Image runs in the Windows CE subsystem.
    Public Const IMAGE_SUBSYSTEM_EFI_APPLICATION As UInteger = 10
    '
    Public Const IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER As UInteger = 11
    '
    Public Const IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER As UInteger = 12
    '
    Public Const IMAGE_SUBSYSTEM_EFI_ROM As UInteger = 13
    Public Const IMAGE_SUBSYSTEM_XBOX As UInteger = 14

    'DllCharacteristics Entries  **************************************************************
    Public Const IMAGE_DLLCHARACTERISTICS_NO_SEH As UInteger = &H400
    ' Image does not use SEH.  No SE handler may reside in this image
    Public Const IMAGE_DLLCHARACTERISTICS_NO_BIND As UInteger = &H800
    ' Do not bind this image.
    Public Const IMAGE_DLLCHARACTERISTICS_WDM_DRIVER As UInteger = &H2000
    ' Driver uses WDM model
    Public Const IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE As UInteger = &H8000

    'DOS header format ************************************************************************
    Public Structure IMAGE_DOS_HEADER
        Public Magic As UShort
        Public SizeOfLastPage As UShort
        Public NumberOfPages As UShort
        Public Relocations As UShort
        Public SizeOfHeader As UShort
        Public MinimumExtraParagraphs As UShort
        Public MaximumExtraParagraphs As UShort
        Public InitialSSValue As UShort
        Public InitialSPValue As UShort
        Public Checksum As UShort
        Public InitialIPValue As UShort
        Public InitialCSValue As UShort
        Public RelocationTableAddress As UShort
        Public OverlayNumber As UShort
        '[MarshalAs(UnmanagedType.U2, SizeConst=8)]
        'public ushort[] ReservedWords;
        Public OemIdentifier As UShort
        Public OemInformation As UShort
        '[MarshalAs(UnmanagedType.U2, SizeConst=20)]
        'public ushort[] ReservedWords2;
        Public PEHeaderAddress As UInteger
    End Structure

    'File header format ***********************************************************************
    Public Const IMAGE_SIZEOF_FILE_HEADER As Integer = 20
    Public Structure IMAGE_FILE_HEADER
        Public Machine As UShort
        Public NumberOfSections As UShort
        Public TimeDateStamp As UInteger
        Public PointerToSymbolTable As UInteger
        Public NumberOfSymbols As UInteger
        Public SizeOfOptionalHeader As UShort
        Public Characteristics As UShort
    End Structure
    Public Const IMAGE_FILE_RELOCS_STRIPPED As UShort = &H1
    ' Relocation info stripped from file.
    Public Const IMAGE_FILE_EXECUTABLE_IMAGE As UShort = &H2
    ' File is executable  (i.e. no unresolved externel references).
    Public Const IMAGE_FILE_LINE_NUMS_STRIPPED As UShort = &H4
    ' Line nunbers stripped from file.
    Public Const IMAGE_FILE_LOCAL_SYMS_STRIPPED As UShort = &H8
    ' Local symbols stripped from file.
    Public Const IMAGE_FILE_AGGRESIVE_WS_TRIM As UShort = &H10
    ' Agressively trim working set
    Public Const IMAGE_FILE_LARGE_ADDRESS_AWARE As UShort = &H20
    ' App can handle >2gb addresses
    Public Const IMAGE_FILE_BYTES_REVERSED_LO As UShort = &H80
    ' Bytes of machine word are reversed.
    Public Const IMAGE_FILE_32BIT_MACHINE As UShort = &H100
    ' 32 bit word machine.
    Public Const IMAGE_FILE_DEBUG_STRIPPED As UShort = &H200
    ' Debugging info stripped from file in .DBG file
    Public Const IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP As UShort = &H400
    ' If Image is on removable media, copy and run from the swap file.
    Public Const IMAGE_FILE_NET_RUN_FROM_SWAP As UShort = &H800
    ' If Image is on Net, copy and run from the swap file.
    Public Const IMAGE_FILE_SYSTEM As UShort = &H1000
    ' System File.
    Public Const IMAGE_FILE_DLL As UShort = &H2000
    ' File is a DLL.
    Public Const IMAGE_FILE_UP_SYSTEM_ONLY As UShort = &H4000
    ' File should only be run on a UP machine
    Public Const IMAGE_FILE_BYTES_REVERSED_HI As UShort = &H8000
    ' Bytes of machine word are reversed.
    Public Const IMAGE_FILE_MACHINE_UNKNOWN As UShort = 0
    Public Const IMAGE_FILE_MACHINE_I386 As UShort = &H14C
    ' Intel 386.
    Public Const IMAGE_FILE_MACHINE_R3000 As UShort = &H162
    ' MIPS little-endian, 0x160 big-endian
    Public Const IMAGE_FILE_MACHINE_R4000 As UShort = &H166
    ' MIPS little-endian
    Public Const IMAGE_FILE_MACHINE_R10000 As UShort = &H168
    ' MIPS little-endian
    Public Const IMAGE_FILE_MACHINE_WCEMIPSV2 As UShort = &H169
    ' MIPS little-endian WCE v2
    Public Const IMAGE_FILE_MACHINE_ALPHA As UShort = &H184
    ' Alpha_AXP
    Public Const IMAGE_FILE_MACHINE_SH3 As UShort = &H1A2
    ' SH3 little-endian
    Public Const IMAGE_FILE_MACHINE_SH3DSP As UShort = &H1A3
    Public Const IMAGE_FILE_MACHINE_SH3E As UShort = &H1A4
    ' SH3E little-endian
    Public Const IMAGE_FILE_MACHINE_SH4 As UShort = &H1A6
    ' SH4 little-endian
    Public Const IMAGE_FILE_MACHINE_SH5 As UShort = &H1A8
    ' SH5
    Public Const IMAGE_FILE_MACHINE_ARM As UShort = &H1C0
    ' ARM Little-Endian
    Public Const IMAGE_FILE_MACHINE_THUMB As UShort = &H1C2
    Public Const IMAGE_FILE_MACHINE_AM33 As UShort = &H1D3
    Public Const IMAGE_FILE_MACHINE_POWERPC As UShort = &H1F0
    ' IBM PowerPC Little-Endian
    Public Const IMAGE_FILE_MACHINE_POWERPCFP As UShort = &H1F1
    Public Const IMAGE_FILE_MACHINE_IA64 As UShort = &H200
    ' Intel 64
    Public Const IMAGE_FILE_MACHINE_MIPS16 As UShort = &H266
    ' MIPS
    Public Const IMAGE_FILE_MACHINE_ALPHA64 As UShort = &H284
    ' ALPHA64
    Public Const IMAGE_FILE_MACHINE_MIPSFPU As UShort = &H366
    ' MIPS
    Public Const IMAGE_FILE_MACHINE_MIPSFPU16 As UShort = &H466
    ' MIPS
    Public Const IMAGE_FILE_MACHINE_AXP64 As UShort = &H284
    Public Const IMAGE_FILE_MACHINE_TRICORE As UShort = &H520
    ' Infineon
    Public Const IMAGE_FILE_MACHINE_CEF As UShort = &HCEF
    Public Const IMAGE_FILE_MACHINE_EBC As UShort = &HEBC
    ' EFI Byte Code
    Public Const IMAGE_FILE_MACHINE_AMD64 As UShort = &H8664
    ' AMD64 (K8)
    Public Const IMAGE_FILE_MACHINE_M32R As UShort = &H9041
    ' M32R little-endian
    Public Const IMAGE_FILE_MACHINE_CEE As UShort = &HC0EE

    'Directory format *************************************************************************
    Public Const IMAGE_DIRECTORY_ENTRY_EXPORT As UInteger = 0
    ' Export Directory
    Public Const IMAGE_DIRECTORY_ENTRY_IMPORT As UInteger = 1
    ' Import Directory
    Public Const IMAGE_DIRECTORY_ENTRY_RESOURCE As UInteger = 2
    ' Resource Directory
    Public Const IMAGE_DIRECTORY_ENTRY_EXCEPTION As UInteger = 3
    ' Exception Directory
    Public Const IMAGE_DIRECTORY_ENTRY_SECURITY As UInteger = 4
    ' Security Directory
    Public Const IMAGE_DIRECTORY_ENTRY_BASERELOC As UInteger = 5
    ' Base Relocation Table
    Public Const IMAGE_DIRECTORY_ENTRY_DEBUG As UInteger = 6
    ' Debug Directory
    Public Const IMAGE_DIRECTORY_ENTRY_COPYRIGHT As UInteger = 7
    ' Copyright
    Public Const IMAGE_DIRECTORY_ENTRY_GLOBALPTR As UInteger = 8
    ' RVA of GP
    Public Const IMAGE_DIRECTORY_ENTRY_TLS As UInteger = 9
    ' TLS Directory
    Public Const IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG As UInteger = 10
    ' Load Configuration Directory
    Public Const IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT As UInteger = 11
    ' Bound Import Directory in headers
    Public Const IMAGE_DIRECTORY_ENTRY_IAT As UInteger = 12
    ' Import Address Table
    Public Const IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT As UInteger = 13
    ' Delay Load Import Descriptors
    Public Const IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR As UInteger = 14
    ' COM Runtime descriptor
    Public Const IMAGE_NUMBEROF_DIRECTORY_ENTRIES As Integer = 16
    Public Structure IMAGE_DATA_DIRECTORY
        Public Type As String
        Public VirtualAddress As UInteger
        Public Size As UInteger
    End Structure

    'Optional header 64-bit *******************************************************************
    Public Structure IMAGE_OPTIONAL_HEADER64
        Public Magic As UShort
        Public MajorLinkerVersion As Byte
        Public MinorLinkerVersion As Byte
        Public SizeOfCode As UInteger
        Public SizeOfInitializedData As UInteger
        Public SizeOfUninitializedData As UInteger
        Public AddressOfEntryPoint As UInteger
        Public BaseOfCode As UInteger
        Public ImageBase As UInt64
        Public SectionAlignment As UInteger
        Public FileAlignment As UInteger
        Public MajorOperatingSystemVersion As UShort
        Public MinorOperatingSystemVersion As UShort
        Public MajorImageVersion As UShort
        Public MinorImageVersion As UShort
        Public MajorSubsystemVersion As UShort
        Public MinorSubsystemVersion As UShort
        Public Win32VersionValue As UInteger
        Public SizeOfImage As UInteger
        Public SizeOfHeaders As UInteger
        Public CheckSum As UInteger
        Public Subsystem As UShort
        Public DllCharacteristics As UShort
        Public SizeOfStackReserve As UInt64
        Public SizeOfStackCommit As UInt64
        Public SizeOfHeapReserve As UInt64
        Public SizeOfHeapCommit As UInt64
        Public LoaderFlags As UInteger
        Public NumberOfRvaAndSizes As UInteger
        Public DataDirectory As IMAGE_DATA_DIRECTORY()
    End Structure

    'Optional header 32-bit *******************************************************************
    Public Structure IMAGE_OPTIONAL_HEADER32
        Public Magic As UShort
        Public MajorLinkerVersion As Byte
        Public MinorLinkerVersion As Byte
        Public SizeOfCode As UInteger
        Public SizeOfInitializedData As UInteger
        Public SizeOfUninitializedData As UInteger
        Public AddressOfEntryPoint As UInteger
        Public BaseOfCode As UInteger
        Public BaseOfData As UInteger
        Public ImageBase As UInteger
        Public SectionAlignment As UInteger
        Public FileAlignment As UInteger
        Public MajorOperatingSystemVersion As UShort
        Public MinorOperatingSystemVersion As UShort
        Public MajorImageVersion As UShort
        Public MinorImageVersion As UShort
        Public MajorSubsystemVersion As UShort
        Public MinorSubsystemVersion As UShort
        Public Win32VersionValue As UInteger
        Public SizeOfImage As UInteger
        Public SizeOfHeaders As UInteger
        Public CheckSum As UInteger
        Public Subsystem As UShort
        Public DllCharacteristics As UShort
        Public SizeOfStackReserve As UInteger
        Public SizeOfStackCommit As UInteger
        Public SizeOfHeapReserve As UInteger
        Public SizeOfHeapCommit As UInteger
        Public LoaderFlags As UInteger
        Public NumberOfRvaAndSizes As UInteger
        Public DataDirectory As IMAGE_DATA_DIRECTORY()
    End Structure

    'Section header format ********************************************************************
    Public Structure IMAGE_SECTION_HEADER
        Public Name As String
        Public PhysicalAddress As UInteger
        Public VirtualSize As UInteger
        Public VirtualAddress As UInteger
        Public SizeOfRawData As UInteger
        Public PointerToRawData As UInteger
        Public PointerToRelocations As UInteger
        Public PointerToLinenumbers As UInteger
        Public NumberOfRelocations As UShort
        Public NumberOfLinenumbers As UShort
        Public Characteristics As UInteger
    End Structure

    Private inputExe As FileStream
    Private inputReader As BinaryReader
    Private m_dosHeader As IMAGE_DOS_HEADER
    Private m_fileHeader As IMAGE_FILE_HEADER
    Private dataDirectory As IMAGE_DATA_DIRECTORY() = New IMAGE_DATA_DIRECTORY(15) {}
    Private optionalHeader32 As IMAGE_OPTIONAL_HEADER32
    Private m_sectionHeaders As IMAGE_SECTION_HEADER()
    Private isExeLoaded As Boolean = False
    Private directoryTypeStrings As String() = New String(15) _
         {"Export Table", "Import Table", "Resource Table", "Exception Table", "Certificate Table", "Base Relocation Table", _
         "Debug Directory", "Architecture Specific Data", "Global Pointer Register", "Thread Local Storage Table", "Load Configuration Table", "Bound Import Table", _
         "Import Address Table", "Delay Load Import Descriptors", "COM Runtime Descriptor", "Reserved"}

    Public ReadOnly Property DOSHeader() As IMAGE_DOS_HEADER
        Get
            Return m_dosHeader
        End Get
    End Property

    Public ReadOnly Property FileHeader() As IMAGE_FILE_HEADER
        Get
            Return m_fileHeader
        End Get
    End Property

    Public ReadOnly Property PEHeader() As IMAGE_OPTIONAL_HEADER32
        Get
            Return optionalHeader32
        End Get
    End Property

    Public ReadOnly Property DataDirectories() As IMAGE_DATA_DIRECTORY()
        Get
            Return dataDirectory
        End Get
    End Property

    Public ReadOnly Property SectionHeaders() As IMAGE_SECTION_HEADER()
        Get
            Return m_sectionHeaders
        End Get
    End Property

    Public Function DoesSectionExist(ByVal sectionName As String) As Boolean
        For i As Integer = 0 To m_fileHeader.NumberOfSections - 1
            If m_sectionHeaders(i).Name = sectionName Then
                Return True
            End If
        Next
        Return False
    End Function

    Public Function GetSectionDataByName(ByVal sectionName As String) As Byte()
        Dim result As Byte()
        For i As Integer = 0 To m_fileHeader.NumberOfSections - 1
            If m_sectionHeaders(i).Name = sectionName Then
                inputExe.Position = m_sectionHeaders(i).PointerToRawData
                result = inputReader.ReadBytes(CInt(m_sectionHeaders(i).SizeOfRawData))
                Return result
            End If
        Next
        Return Nothing
    End Function

    Public Function LoadExecutable(ByVal fileName As String) As Boolean
        Try
            inputExe = New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)
            inputReader = New BinaryReader(inputExe)
            ReadMZHeader()
            If m_dosHeader.PEHeaderAddress > 0 Then
                inputExe.Position = m_dosHeader.PEHeaderAddress + 4
                ReadFileHeader()
                ReadSectionHeaders()
            End If
            isExeLoaded = True
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Sub CloseExecutable()
        If isExeLoaded Then
            inputExe.Close()
        End If
        isExeLoaded = False
    End Sub

    Private Function ReadMZHeader() As Boolean
        Try
            m_dosHeader.Magic = inputReader.ReadUInt16()
            m_dosHeader.SizeOfLastPage = inputReader.ReadUInt16()
            m_dosHeader.NumberOfPages = inputReader.ReadUInt16()
            m_dosHeader.Relocations = inputReader.ReadUInt16()
            m_dosHeader.SizeOfHeader = inputReader.ReadUInt16()
            m_dosHeader.MinimumExtraParagraphs = inputReader.ReadUInt16()
            m_dosHeader.MaximumExtraParagraphs = inputReader.ReadUInt16()
            m_dosHeader.InitialSSValue = inputReader.ReadUInt16()
            m_dosHeader.InitialSPValue = inputReader.ReadUInt16()
            m_dosHeader.Checksum = inputReader.ReadUInt16()
            m_dosHeader.InitialIPValue = inputReader.ReadUInt16()
            m_dosHeader.InitialCSValue = inputReader.ReadUInt16()
            m_dosHeader.RelocationTableAddress = inputReader.ReadUInt16()
            m_dosHeader.OverlayNumber = inputReader.ReadUInt16()
            For i As Integer = 0 To 3
                inputReader.ReadUInt16()
            Next
            m_dosHeader.OemIdentifier = inputReader.ReadUInt16()
            m_dosHeader.OemInformation = inputReader.ReadUInt16()
            For i As Integer = 0 To 9
                inputReader.ReadUInt16()
            Next
            m_dosHeader.PEHeaderAddress = inputReader.ReadUInt32()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function ReadFileHeader() As Boolean
        Try
            m_fileHeader.Machine = inputReader.ReadUInt16()
            m_fileHeader.NumberOfSections = inputReader.ReadUInt16()
            m_fileHeader.TimeDateStamp = inputReader.ReadUInt32()
            m_fileHeader.PointerToSymbolTable = inputReader.ReadUInt32()
            m_fileHeader.NumberOfSymbols = inputReader.ReadUInt32()
            m_fileHeader.SizeOfOptionalHeader = inputReader.ReadUInt16()
            m_fileHeader.Characteristics = inputReader.ReadUInt16()
            If m_fileHeader.SizeOfOptionalHeader > 0 Then
                If ReadPEHeader() Then
                    Return True
                Else
                    Return False
                End If
            End If
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function ReadPEHeader() As Boolean
        Try
            optionalHeader32.Magic = inputReader.ReadUInt16()
            optionalHeader32.MajorLinkerVersion = inputReader.ReadByte()
            optionalHeader32.MinorLinkerVersion = inputReader.ReadByte()
            optionalHeader32.SizeOfCode = inputReader.ReadUInt32()
            optionalHeader32.SizeOfInitializedData = inputReader.ReadUInt32()
            optionalHeader32.SizeOfUninitializedData = inputReader.ReadUInt32()
            optionalHeader32.AddressOfEntryPoint = inputReader.ReadUInt32()
            optionalHeader32.BaseOfCode = inputReader.ReadUInt32()
            optionalHeader32.BaseOfData = inputReader.ReadUInt32()
            optionalHeader32.ImageBase = inputReader.ReadUInt32()
            optionalHeader32.SectionAlignment = inputReader.ReadUInt32()
            optionalHeader32.FileAlignment = inputReader.ReadUInt32()
            optionalHeader32.MajorOperatingSystemVersion = inputReader.ReadUInt16()
            optionalHeader32.MinorOperatingSystemVersion = inputReader.ReadUInt16()
            optionalHeader32.MajorImageVersion = inputReader.ReadUInt16()
            optionalHeader32.MinorImageVersion = inputReader.ReadUInt16()
            optionalHeader32.MajorSubsystemVersion = inputReader.ReadUInt16()
            optionalHeader32.MinorSubsystemVersion = inputReader.ReadUInt16()
            optionalHeader32.Win32VersionValue = inputReader.ReadUInt32()
            optionalHeader32.SizeOfImage = inputReader.ReadUInt32()
            optionalHeader32.SizeOfHeaders = inputReader.ReadUInt32()
            optionalHeader32.CheckSum = inputReader.ReadUInt32()
            optionalHeader32.Subsystem = inputReader.ReadUInt16()
            optionalHeader32.DllCharacteristics = inputReader.ReadUInt16()
            optionalHeader32.SizeOfStackReserve = inputReader.ReadUInt32()
            optionalHeader32.SizeOfStackCommit = inputReader.ReadUInt32()
            optionalHeader32.SizeOfHeapReserve = inputReader.ReadUInt32()
            optionalHeader32.SizeOfHeapCommit = inputReader.ReadUInt32()
            optionalHeader32.LoaderFlags = inputReader.ReadUInt32()
            optionalHeader32.NumberOfRvaAndSizes = inputReader.ReadUInt32()
            Console.WriteLine("Magic: {0}", optionalHeader32.Magic)
            Console.WriteLine("Number of Directories: {0}", optionalHeader32.ImageBase)
            For i As Integer = 0 To dataDirectory.Length - 1
                dataDirectory(i).Type = directoryTypeStrings(i)
                dataDirectory(i).VirtualAddress = inputReader.ReadUInt32()
                dataDirectory(i).Size = inputReader.ReadUInt32()
            Next

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function ReadSectionHeaders() As Boolean
        Try
            Dim sectionNameBuffer As Byte()
            Dim sectionName As String
            Dim sectionNameClean As String
            m_sectionHeaders = New IMAGE_SECTION_HEADER(m_fileHeader.NumberOfSections - 1) {}
            For i As Integer = 0 To m_fileHeader.NumberOfSections - 1
                sectionNameBuffer = inputReader.ReadBytes(8)
                sectionName = Encoding.ASCII.GetString(sectionNameBuffer)
                sectionNameClean = sectionName.Substring(0, sectionName.IndexOf(vbNullChar))
                m_sectionHeaders(i).Name = sectionNameClean
                'm_sectionHeaders(i).PhysicalAddress = inputReader.ReadUInt32()
                m_sectionHeaders(i).VirtualSize = inputReader.ReadUInt32()
                m_sectionHeaders(i).VirtualAddress = inputReader.ReadUInt32()
                m_sectionHeaders(i).SizeOfRawData = inputReader.ReadUInt32()
                m_sectionHeaders(i).PointerToRawData = inputReader.ReadUInt32()
                m_sectionHeaders(i).PointerToRelocations = inputReader.ReadUInt32()
                m_sectionHeaders(i).PointerToLinenumbers = inputReader.ReadUInt32()
                m_sectionHeaders(i).NumberOfRelocations = inputReader.ReadUInt16()
                m_sectionHeaders(i).NumberOfLinenumbers = inputReader.ReadUInt16()
                m_sectionHeaders(i).Characteristics = inputReader.ReadUInt32()
            Next
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Protected Overrides Sub Finalize()
        Try
            If isExeLoaded Then
                inputReader.Close()
                inputExe = Nothing
                inputReader = Nothing
            End If
        Finally
            MyBase.Finalize()
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        LoadExecutable("G:\tempx\1.exe")

        RichTextBox1.Text &= m_sectionHeaders(0).VirtualAddress & vbCrLf
        RichTextBox1.Text &= m_sectionHeaders(1).VirtualAddress & vbCrLf
        RichTextBox1.Text &= m_sectionHeaders(2).VirtualAddress & vbCrLf
        RichTextBox1.Text &= Hex(optionalHeader32.AddressOfEntryPoint)


    End Sub
End Class


dark99 發表在 痞客邦 留言(0) 人氣()

«12 3