Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Completely confused with file formats
#1
I'm so confused with how I would make a bitmap loader, let alone how to open any other files(my attempt is .elf here). I know about the GET, PUT statements and stuff, www.wotsit.org for file information. but how would I go about reading the files, getting certain data such as the headers, flags, etc. I've recieved code before but I really just don't understand it. Is it basically just loading a certain address within the file, then by examining the hex data and seeing if it equals a certain value, it represents something?

Thanks for any help!!! This has been something I've been curious about for a long time.
quote="na_th_an"]
Greenday, Spice Girls... Can you tell the difference?
[/quote]
Reply
#2
whats an elf file? post the spec
Reply
#3
Do you mean an ELF executable (used on Linux)? Why would you need to load one of those in QB? In any case, the ELF format docs are at wotsit; what more informatino do you need?
Reply
#4
Practically it is very difficult to load any compressed formats.
At the same time BMP and ICO are very easy so you can load them having no problem.
url=http://zerodivide.h15.ru/cyclone.html]Cyclone v2.5.2 GUI For QBasic 4.5/7.1[/url]
Explorer For DOS
Reply
#5
Quote:Practically it is very difficult to load any compressed formats.
At the same time BMP and ICO are very easy so you can load them having no problem.

Yes, but how would you go about finding the header information, flags, etc. This is what I mainly trying to learn how to do(not specifically for any certain file either).

@DrV

Yes..that ELF file. It's also the executable that PS2 uses. I'm trying to load for a few reasons, it's kind of confusing to explain. This is what I don't understand, well..basically I completely confused with all of it :o . I don't know how to read it at all. And that's probably because I don't know how to read files in the first place.

Quote:(Data Encoding)1 590 1 1168 2280 t
9 CW f
(E L F D A T A 2 M S B)10 554 1 1781 2280 t
9 H f
(1-6)5170 2280 w
9 HB f
(Figure 1-7Smile1 460 1 658 2390 t
9 H f
(32-bit Intel Architecture Identi\256cation,)3 1480 1 1168 2390 t
9 CW f
(e _ i d e n t)6 354 1 2671 2390 t
9 H f
(1-7)5170 2390 w
9 HB f
(Figure 1-8Smile1 460 1 658 2500 t
9 H f
( 1-8)1 3172(Special Section Indexes)2 960 2 1168 2500 t
9 HB f
(Figure 1-9Smile1 460 1 658 2610 t

I don't have the slightest idea what that would mean.


However, I did recieve faulty VB code(the guy that gave it to me knew C++), and I tried fixing it to the best of my abilities, but there were still a few things that I could not fix to get the code to run. Should I post it here?
quote="na_th_an"]
Greenday, Spice Girls... Can you tell the difference?
[/quote]
Reply
#6
Sure, you could post the relevant parts that you need help with.
Reply
#7
Quote:Yes, but how would you go about finding the header information, flags, etc. This is what I mainly trying to learn how to do(not specifically for any certain file either).
That's very easy if you cas use any of HEX editors Smile
[/quote]
url=http://zerodivide.h15.ru/cyclone.html]Cyclone v2.5.2 GUI For QBasic 4.5/7.1[/url]
Explorer For DOS
Reply
#8
@ Zero Divide:

Well yes, but I'm trying to open these up in QB.

This is VB code btw:

Code:
Public Type Elf32_Header
   e_ident      As String * 16
   e_type       As Integer
   e_machine    As Integer
   e_version    As Long
   e_entry      As Long
   e_phoff      As Long
   e_shoff      As Long
   e_flags      As Long
   e_ehsize     As Integer
   e_phentsize  As Integer
   e_phnum      As Integer
   e_shentsize  As Integer
   e_shnum      As Integer
   e_shstrndx   As Integer
End Type

Public Type Elf32_SegHeader
   sh_name      As Long
   sh_type      As Long
   sh_flags     As Long
   sh_addr      As Long
   sh_offset    As Long
   sh_size      As Long
   sh_link      As Long
   sh_info      As Long
   sh_addralign As Long
   sh_entsize   As Long
End Type

Dim strElfFileName As String
Dim elfHeader As Elf32_Header
Dim segHeader As Elf32_SegHeader
Dim i As Long

strElfFileName = "C:\myelfs\test.elf"
Open strElfFileName For Binary As #1


elfHeader = Input(52, #1)

'seek into the file the number of bytes indicated by elfHeader.e_shoff
'having never done seek/set file i/o in VB,
'  I have no idea how to skip ahead here.
'You could also load the entire bloody file, which seems to be VB's preferred approach

'Now process the table of segment headers.
'  This will read them one at a time from the file (theoretically).
'  You're better served by calculating the size of the entire segment header block,
'  and loading them all into an array.
i = 0
While i < Header.e_shnum
    segHeader = Input(40, #1)
    'sh_type and the sh_flags in each header will determine what is "the" executable.
    '  More than one segment can contain executable code in an ELF, but the primary
    '  executable segment (.text) is identified by sh_type [bitwise and] SHT_PROGBITS = 1 and
    '  sh_flags [bitwise and] (SHF_ALLOC [bitwise or] SHF_EXECINSTR) = 6.
    '  In other words, as long as bit 0 in the type, and bits 1 and 2 in the flags are set
    '  this is the .text segment.
    progbits = segHeader.sh_type And 1
    exeFlags = segHeader.sh_flags And 6
    If (progbits And exeFlags) Then
        i = Header.e_shnum
    End If
Wend

'Now the segHeader variable contains the information on the .text segment.
'seek in the file to sh_offset (sh_offset is the byte offset of the segment from the beginning
'  of the file).
'sh_size is the number of bytes in the segment.  sh_size/4 is the number of opcodes

Dim opcodes(segHeader.sh_size / 4) As Long
opcodes = Input(segHeader.sh_size, #1)

'sh_addr is the memory location this segment will be loaded to.

'In order to retrieve the opcode at 0x3D5FA0 you could simply:

Dim myOp As Long
myOp = opcodes((&H3D5FA0 - segHeader.sh_addr) / 4)
Debug.Print Hex(myOp)

(Credit goes to Pyriel for that code)

I'm to lazy to correct the errors again.. :oops:

One thing that I don't know how to correct at all is
elfHeader = Input(52, #1). How would I convert that correctly to QB?

Thanks for any replies guys..
quote="na_th_an"]
Greenday, Spice Girls... Can you tell the difference?
[/quote]
Reply
#9
You would just use INPUT$()

As for the other stuff, the problem is most-likely with the fact that UDTs are used where INPUT$ returns a string.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#10
Rather than use INPUT$(), I would personally just do:
Code:
strElfFileName = "C:\myelfs\test.elf"
Open strElfFileName For Binary As #1

Get #1, , elfHeader
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)