?
Solved

Exe content

Posted on 2006-05-02
6
Medium Priority
?
266 Views
Last Modified: 2010-05-01
With this code, I can read the content of a line in any executable.
Note: This example required one TextBox and one CommonDialog1

Open FileName For Binary As #Free
ReDim EXEContent(1 To LOF(Free))
Get #Free, , EXEContent
Close #Free

Text1.Text = ""
For i = 79 To 118
Text1.Text = Text1.Text + Chr(EXEContent(i))
Next i
End If

The result: This program cannot be run in DOS mode.

Now my question is:
How can i read some other content of the executable but not 79?
I have try so many times with diferent numbers from 1 to 400 but don't work for me.

I want to read some other content that is not " 79=This program cannot be run in DOS mode. "

For example:

.text
---------------------------------------------------------------------------
.data
---------------------------------------------------------------------------
.rsrc
---------------------------------------------------------------------------
MSVBVM60.DLL
---------------------------------------------------------------------------
_CIcos
---------------------------------------------------------------------------
_adj_fptan
---------------------------------------------------------------------------
_adj_fdiv_m64
---------------------------------------------------------------------------
_adj_fprem1
---------------------------------------------------------------------------
And so on.

Any help will be apreciate.

Thanks.
0
Comment
Question by:Dazm
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:fostejo
ID: 16593424
Dazm,

I suspect you're attempting to dump out all the textual information from the executable - the problem you're encountering is that only a proportion of the executable actually consists of characters that are printable.

Altering your current code, something like the following should help:

Open FileName For Binary As #Free
ReDim EXEContent(1 To LOF(Free))
Get #Free, , EXEContent
Close #Free

Text1.Text = ""
For i = 1 To UBound(EXEContent)  '<- ALTERED
    strC=EXEContent(i) '<-NEW
    IF instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ.,!£$%^&*(),UCASE(strC)) > 0 THEN  '<-NEW
        Text1.Text = Text1.Text + strC '<- ALTERED
    END IF '<-NEW
Next i


As well as looping through all of the EXEContent array, the additional 'IF INSTR..' statement will only append those characters listed as part of the INSTR onto text1.text (obviously, that list of 'printable characters' can be altered to include other valid characters such as the @ sign for instance)

For simplicity, the instr also only tests against the uppercase value of strC (rather than a-z also) - though text1.text is appended with the correctly cased character.

Also, to help you know what to expect when you dump out the textual info from a file, you might want to have a look at FileAlyzer at http://www.safer-networking.org/en/filealyzer/index.html - this allows you to look at the 'internals' of a file in HEX dump mode, and also to list all the printable strings within it.

hope that helps,
0
 
LVL 2

Author Comment

by:Dazm
ID: 16599037

Fostejo: As well as looping through all of the EXEContent array,

Dazm: I don't want to looping through all of the exe content array,
I forgot to mention that all i need it was just a line of content
I just want to read a single line of the exe content in the Textbox.
Thanks for the suggestion about the altering the characters in the exe
But some how didn't work, I get the following error message...

strC = EXEContent(i) '<-NEW

Error: Variable not defined


IF instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ.,!£$%^&*(),UCASE(strC)) > 0 THEN  '<-NEW

Error: Expected: list separator
0
 
LVL 10

Expert Comment

by:fostejo
ID: 16599142
Hi Dazm,

Let's correct the errors first;

The "Variable not defined" error is because you're using 'Option Explicit' elsewhere in the code - to get it working you'll need to add a "dim strC" somewhere above the erroring line (the 'Option Explicit' forces you to declare a variable before you use it and is good programming practice)

The "Expected: list separator" is due to a mistype in the line, change the erroring line to the following (notice the addition of the double quote!):

IF instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ.,!£$%^&*()",UCASE(strC)) > 0 THEN  '<-NEW


When you say you just want "a line of content" then you could stick to the method you've already been using (ie. FOR i=79 TO 118) but this obviously limits you to that specific batch of bytes in the executable.

Is your intention to get the 'first' batch of text found in the executable into the textbox and then a second batch and then a third batch - controlled by the user perhaps?

ta,
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Dazm
ID: 16601108

This project am working on, is for my own use, maybe nothing important,
But my intention is to get an specific line of the content of the exe file by the
Corresponding line number

Line 1: This program cannot be run in DOS mode.
Line 2: .text
Line 3: .data
Line 4: .rsrc

But not all at once
I would like to read line by line in case i want to jump to a specific line number

Now going back to you post...
Look, it sounds to me that it is not about the  'Option Explicit' or the "dim strC"
cus i thought about this too, then i try to correct the error, but nothing happen.

=> IF instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ.,!£$%^&*()",UCASE(strC)) > 0 THEN

Just by adding this piece of code into the project, it turns red. Then vb don't let me continue

With this => "For i = 399 To 445" i get the second line of the exe content which is => ".text"

I believe there may be a way to get the line 3, 4, 5, 6, etc. and so on.

At the very beginning i was trying to get this by using hex address, but i couldn’t make it work.
0
 
LVL 10

Accepted Solution

by:
fostejo earned 120 total points
ID: 16601553
Dazm,

The line

IF instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ.,!£$%^&*()",UCASE(strC)) > 0 THEN

is definately valid in VB - I've just copied from this web page and pasted it into a new VB6 project and it runs as expected.  If it turns red for you than you've perhaps not entered/pasted it correctly? - copy it from just above and it should be fine.


The main issue you've got with trying to get "lines" 1,2,3...n from an executable is that the physical position of the text you want will usually vary and as a consequence, if you hard-code the correct numbers for Executable 'A', they'll more than likely be wrong for Executable 'B'    Therefore, you need to either:

1. Have a generic routine that looks through the specified executable and *attempts* to identify what may be blocks of text within it (this is what FileAlyzer does as per my first post - I mention it because this will show you what you should be able to get out of a specific executable)   The trouble with this approach (and the reason I'm not giving a full example here!) is that it can get quite complex to do properly as you then need to start worrying about *how* to identify a block of text - where it starts, where it ends etc.

or...

2. Have a list of the specific text items you want to find within a specified executable and just search for them - for example, this code will tell you whether the piece of text in 'strToFind' exists within Notepad.exe

free = FreeFile
Open "c:\windows\notepad.exe" For Binary As #free
t$ = String$(LOF(free), 0)
Get #free, , t$
Close #free

strToFind = ".data"

lngPos = InStr(UCase(t$), UCase(strToFind))
If lngPos > 0 Then
    Text1.Text = strToFind + " found at byte" + Str(lngPos) + " onwards"
Else
    Text1.Text = strToFind + " could NOT be found!"
End If



Hope that helps..

0
 
LVL 2

Author Comment

by:Dazm
ID: 16602046

Thanks Fostejo : )

This is even better than the one i was trying to make.

Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question