473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

VB - APP - Extracting Certain Block From Hex File

Hello,

Im new to the site and was hoping some of you could help me,

I would like to be able to open a file locate a certain offset in that file and extract up to a certain part

the item type i would want to extract is PNG from offsets

171A


to


(This number is varied depending on what size the PNG is :S*)

so put simply

Open File > Read data > Extract (171A - (See Above*) > Save it as a PNG

Oh and if needed the image will always be 64x64

Thank you very much for any help!
Nov 6 '08 #1
13 2068
Plater
7,872 Expert 4TB
The FileStream object should accomplish what you need.

If "171A" is the value you are looking for, you can cycle through it until you find 171A and then start keeping track of what you read

if "171A" is the offset address then you can probably use the Seek() function to seek to 0x171A and then start reading/keeping track of what you read
Nov 6 '08 #2
Hey thanks for replying but im sorta new to these kinds of funtions maybe and exmaple? please,


Thanks
Nov 6 '08 #3
Plater
7,872 Expert 4TB
Plenty of examples as MSDN
Nov 6 '08 #4
:( This is where im at

Dim asci As System.Text.Encoding

TOP:
Expand|Select|Wrap|Line Numbers
  1.         Dim buffera(3) As Byte
  2.         asci = System.Text.Encoding.ASCII
  3.         Dim FSA As System.IO.FileStream
  4.         FSA = System.IO.File.OpenRead(OFD.FileName)
  5.         FSA.Seek(CONType, 0)
  6.         FSA.Read(buffera, 0, 3)
  7.         cnType = asci.GetString(buffera)
  8.  
  9.         AuthOffset = &H171A
  10.  
  11.  
  12.         Dim author As String
  13.         Dim buffer2(2678) As Byte
  14.         asci = System.Text.Encoding.ASCII
  15.         Dim filestream2 As System.IO.FileStream
  16.         filestream2 = System.IO.File.OpenRead(OFD.FileName)
  17.         filestream2.Seek(AuthOffset, 0)
  18.         filestream2.Read(buffer2, 0, 2678)
  19.         author = asci.GetString(buffer2)
  20.         filestream2.Write()
  21.         filestream2.Close()
  22.  
Anywhere close?
Nov 6 '08 #5
Plater
7,872 Expert 4TB
Is 171A the value you are looking for in the file, or an offset length?
Nov 6 '08 #6
Is 171A the value you are looking for in the file, or an offset length?

171A is the start of the "block" i want and the end of the block varies like i said im not sure how to specify what to look for to complete the block,

e.g.

1 file
(Offsets)
Start = 171A

End = 2190

2nd file
(Offsets)
Start = 171A

End = 20E1
Nov 6 '08 #7
Plater
7,872 Expert 4TB
Well then, once you open the file you would want to call:
myFileStream.Seek(0x171A, SeekOrigin.Begin);

That will put you at the correct offset to begin reading from. Now you can start reading the data and saving it somewhere
Know you said you don't know how much to read? Well I don't know what to tell you on that.

What type of file is it that you are opening? Maybe there is headered data somewhere?
Nov 6 '08 #8
Hey thanks for the reply so do i need any of that extra stuff do i simply add what you said to the OFD_FileOk ? well the reason i dont know where it ends is because it is an image and the image will sometimes vary in size as you will know

The file = CON File
Nov 6 '08 #9
Plater
7,872 Expert 4TB
Are you just wanting to read to the end of the file then?
If you don't know how much you need to read, i'm not sure how you are going to do this.
I've never heard of a CON file?
CON, Configuration file, Simdir
CON, MSTS Consist file, MSTS
Nov 6 '08 #10
Hmm its ok then i will have to postpone i guess thanks for the help!

Regards,

Silly
Nov 6 '08 #11
Hmm its ok then i will have to postpone i guess thanks for the help!

Regards,

Silly
On seconds thoughts if you could maybe show me how if the end offset was


2190

Thanks
Nov 6 '08 #12
Plater
7,872 Expert 4TB
Ok, I'll show a quick example of how things COULD be done.
Given:
Start = 0x171A
End = 0x2190

Expand|Select|Wrap|Line Numbers
  1. int Start = 0x171A;
  2. int End = 0x2190;
  3. int lengthtoRead= End - Start;
  4. FileStream fs =new FileStream("SomeFile.Com");//you made need to use an overload to support seek
  5. fs.Seek(0x171A, SeekOrigin.Begin);
  6. byte[] buff = new byte[lengthtoRead];
  7. int ActualAmountRead = fs.Read(buff,0,buff.Length);
  8. //now if ActualAmountRead is = lengthtoRead, then you have all your bytes in a nice byte[]
  9.  
Nov 6 '08 #13
Thank you very much you have been so much help and i greatly appreciate it!
Nov 6 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Nazgul | last post by:
Hi! I want to implement a small tool in Python for distributing "patches" and I need Your advice. This application should be able to package all files chosen by a user into a self-extracting.exe...
2
by: Avi | last post by:
hi, Can anyone tell me what the problem is and how to solve it The following piece of code resides on an asp page on the server and is used to download files from the server to the machine...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
7
by: nephish | last post by:
Hey there, i have a text file with a bunch of values scattered throughout it. i am needing to pull out a value that is in parenthesis right after a certain word, like the first time the word...
4
by: Tony Clarke | last post by:
Hi All, I have been trying to extract data from a text file using the fscanf() functions and sscanf() functions. The file is of various characters and integers separated by semicolons, the...
1
by: Terry Olsen | last post by:
Ok, now that I've got my disk imager program working, I'd like to attach a "self-extractor" to the front end of the image file and make it a self-extracting disk image executable file. The idea...
6
by: Werner | last post by:
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. False Is there a wrapper or has...
4
by: poolboi | last post by:
hi guys i've having some problem extracting data from a text file example if i got a text file with infos like: Date 2008-05-01 Time 22-10 Date 2008-05-01 Time 21-00 Date 2008-05-02 Time...
15
by: Andy B | last post by:
I need to count files in a certain directory that has the string -Contract Template.xml at the end of it. How would I do this?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.