Results 1 to 8 of 8

Thread: Extract string from exe file

  1. #1

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Arrow Extract string from exe file

    Hello guys

    when i open .net exe file in notepad i will get string like this in image

    How can i get this string programmatically and put in TextBox

    Thank you

    الحمد لله

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Extract string from exe file

    You would get the text contents of that file the same way you would get the text contents of any file, the simplest way being to call File.ReadAllText. You may have to specify a particular Encoding to get the same result as Notepad produces. I'm guessing that it would use UTF8 but I'm not 100% sure.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Arrow Re: Extract string from exe file

    Thank you mr. jmcilhinney , but it gives me only this result in image .. when i use this code

    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim StrArray = System.IO.File.ReadAllLines("c:\WindowsApplication1.exe", Encoding.UTF8)
            For Each L In StrArray
                TextBox1.AppendText(L.ToString & vbNewLine)
            Next
        End Sub

    it's not all the string!!

    الحمد لله

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Extract string from exe file

    Do as I instructed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Arrow Re: Extract string from exe file

    if you mean this code

    Code:
     TextBox1.Text = System.IO.File.ReadAllText("c:\WindowsApplication1.exe", Encoding.UTF8)

    it gives me only this

    الحمد لله

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Extract string from exe file

    Did you try different Encodings?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Arrow Re: Extract string from exe file

    i try it all .. and no result
    الحمد لله

  8. #8
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Extract string from exe file

    An .exe file will almost certainly contain bytes with value = 0. When converting the .exe to a string, these will typically be treated as Null chars (depends to some extent on the Encoding being used).

    A Null char is considered by many languages to indicate the end of the string. When Windows renders text, any characters following a Null char are not rendered.

    In order for Notepad to display the text as it does, it seems to replace Null chars (bytes whose value = 0) with Spaces (bytes whose value = 32).

    You need to do the same if you want your output to look like Notepad's.


    I think the encoding used in Notepad by default is an ANSI encoding, which would be Encoding.Default for me. Probably the same for you, but I'm not 100% sure. Something you can research.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width