raw binary to obj conversion

Started by
18 comments, last by fir 9 years, 9 months ago

It depends completly on your experiences. Take a look into the specifications. There you find all information you need to make a decission.

I think you should quit this pseudo answers , when someone os asking specific questions, such answer like "go googling" or "go reading dosc" are not valuable at all - so really better not answer at all - Im not sure if i had option to block you but if you will repeating such way i will filter you out

Advertisement

Take awk to make a assembler source and let the assembler create the obj file. This way you are able to set the symbol-table as well. No need to read extensive documentation.

We are again at a point where you refuse to do the obvious. The BFD library is the easiest way to access the obj-file content. It is complex because the file format is complex and you complain about the complexity.

Using an assembler, that is made to come around the complexity of creating obj files, is neither an option for you. So what you expect as an answer. If you want a quick hack, make it yourself. Look into the object file format specification and select the things you need, hardcode the sections of the file and merge in your bin file.

Thats an easy task. I did wrote a fileconverter for object files 20 years ago and needed not very long for it.

It depends completly on your experiences. Take a look into the specifications. There you find all information you need to make a decission.

I think you should quit this pseudo answers , when someone os asking specific questions, such answer like "go googling" or "go reading dosc" are not valuable at all - so really better not answer at all - Im not sure if i had option to block you but if you will repeating such way i will filter you out

So you expect that others read the specification and tell you what to do? Sounds like that. Because you do not ask specifics about the format, this is the first answer to give. Read the doc. If you do not understand parts of it, ask for help. Thats the way it works.

But not asking for help and refuse to read the first information source available, the specification.

It depends completly on your experiences. Take a look into the specifications. There you find all information you need to make a decission.

I think you should quit this pseudo answers , when someone os asking specific questions, such answer like "go googling" or "go reading dosc" are not valuable at all - so really better not answer at all - Im not sure if i had option to block you but if you will repeating such way i will filter you out

I thought you were going to filter this entire site out and leave. At least that's what you promised to do.



I thought you were going to filter this entire site out and leave. At least that's what you promised to do.


Not entire, some people can answer precise question, but such stuff as above is not an answer so dont want to be crude but i will filter you out with pleasure same as tribad - If you are not able to answer i think you should will not produce trash answers - go on topic



So you expect that others read the specification and tell you what to do? Sounds like that. Because you do not ask specifics about the format, this is the first answer to give. Read the doc. If you do not understand parts of it, ask for help. Thats the way it works.


But not asking for help and refuse to read the first information source available, the specification.


Man, get a little wiser - I am NOT expecting anyone to read a docs specifically for me to only fullfill my needs as i would be a king or something - get sober
It is more like s

ome people are arleady experienced and can just share some hint, it often works that way - and then its good way of using forums

All users (including you fir!) please keep your replies polite and on topic.

This topic will be closed if it isn't kept on-point, and any offending members will be warned as appropriate.

(...and please note that staying on topic includes not responding to this post. I can be contacted via private message or a discussion can be started in the "Comments, Suggestions & Ideas" forum if anyone wants to comment on my moderation.)

- Jason Astle-Adams

Check out objcopy from gnu binutils. I used it many times to generate raw firmwares from objs (obj -> bin). It should work the other way, but if it doesn't, just write a simple script to generate C file with data as global array.

what do you mean? I dont want to use assembler, compiler or something like that

want to have a tool for converting bin->obj (othar way is much easier for example nasm can produce bin only, or other tools can strip obj to binary too) - and much preferably understand how this conversion in details look like

Have you actually checked out the objcopy docs? Because it is the right tool for this job. You might need some extra options to get the exact symbol table you need, but a framework of a solution might look like this:


wojtek@wojtek-VirtualBox:~/Desktop$ objcopy -I binary -O elf32-i386 --rename-section .data=.text --redefine-sym _binary_bla_bin_start=_my_raw_code bla.bin bla.o 
wojtek@wojtek-VirtualBox:~/Desktop$ objdump bla.o -x

bla.o:     file format elf32-little
bla.o
architecture: UNKNOWN!, flags 0x00000010:
HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000000a  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
00000000 l    d  .text  00000000 .text
00000000 g       .text  00000000 _my_raw_code
0000000a g       .text  00000000 _binary_bla_bin_end
0000000a g       *ABS*  00000000 _binary_bla_bin_size

It's not elegant or finished right now, but just an example that you can do everything with objcopy.

Check out objcopy from gnu binutils. I used it many times to generate raw firmwares from objs (obj -> bin). It should work the other way, but if it doesn't, just write a simple script to generate C file with data as global array.

what do you mean? I dont want to use assembler, compiler or something like that

want to have a tool for converting bin->obj (othar way is much easier for example nasm can produce bin only, or other tools can strip obj to binary too) - and much preferably understand how this conversion in details look like

Have you actually checked out the objcopy docs? Because it is the right tool for this job. You might need some extra options to get the exact symbol table you need, but a framework of a solution might look like this:


wojtek@wojtek-VirtualBox:~/Desktop$ objcopy -I binary -O elf32-i386 --rename-section .data=.text --redefine-sym _binary_bla_bin_start=_my_raw_code bla.bin bla.o 
wojtek@wojtek-VirtualBox:~/Desktop$ objdump bla.o -x

bla.o:     file format elf32-little
bla.o
architecture: UNKNOWN!, flags 0x00000010:
HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000000a  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
00000000 l    d  .text  00000000 .text
00000000 g       .text  00000000 _my_raw_code
0000000a g       .text  00000000 _binary_bla_bin_end
0000000a g       *ABS*  00000000 _binary_bla_bin_size

It's not elegant or finished right now, but just an example that you can do everything with objcopy.

allright, not checked yet (gots a tons of stuff but it is not easy to go to the point), some more on topic hints will be yet welcome - tnx

does maybe someone know which format (except bin who i think is not quite linkable) could be te the easiest? or the tool to convertung bin to some linkable? Could you maybe yet explain a bit what is in this frame? Im always happy to talk in some details on this stuff im interested in

edit

ok if it would be working it would be ok, tnx for info - that could be good if this is really working - i would try to generate pure bin with nasm then convert such way then link then i giove info if it works, tnx for hint

It's not entirely on topic but I'm going to suggest you seriously consider adopting GNU/Linux as your development platform of choice. It's a toolchain hacker's dream, documentation on the tools is generally at hand, and it uses openly-sourced tools for pretty much everything so you can either read the source to see how they work or read the detailed specificaction to see what they're supposed to do.

You'll find MinGW is a reduced copy of the GNU environment you usually get by default on Linux, so you're probably already familiar with much of how things work. You can also bring much of what you learn back to MinGW to apply to Windows applications.

Trust me, you're going to make the switch sooner or later.

Linux uses the Extensible Link Format (ELF) for its binary objects (object files, shared libraries, executable binaries). If you learn and understand the basics of that, it will go a long way toward understanding what you would need to do to convert other binary formats (.bin, COFF, etc).

Stephen M. Webb
Professional Free Software Developer

Have you actually checked out the objcopy docs? Because it is the right tool for this job. You might need some extra options to get the exact symbol table you need, but a framework of a solution might look like this:

objcopy -I binary -O elf32-i386 --rename-section .data=.text --redefine-sym _binary_bla_bin_start=_my_raw_code bla.bin bla.o

I checked it but it is aggreviating work becouse this obj copy has no examples not enumerates possible options - aggreviating thing

i used

objcopy -I binary -O elf32-i386 --rename-section .data=.text,alloc,load,readonly,code,contents --redefine-sym _binary_tezt_bin_start=_my_raw_code tezt.bin tezt.o

and get


; Disassembly of file: tezt.o
; Wed Jul 09 09:54:46 2014
; Mode: 32 bits
; Syntax: YASM/NASM
; Instruction set: SSE2
 
 
global _binary_tezt_bin_size
global _my_raw_code
global _binary_tezt_bin_end
 
_binary_tezt_bin_size equ 00000018H                     ; 24
 
 
SECTION .text   align=1 execute                         ; section number 1, code
 
_my_raw_code:; Function begin
        mov     edx, dword [esp+4H]                     ; 0000 _ 8B. 54 24, 04
        mov     ecx, dword [esp+8H]                     ; 0004 _ 8B. 4C 24, 08
        xorps   xmm0, xmm0                              ; 0008 _ 0F 57. C0
?_001:  movdqu  oword [edx], xmm0                       ; 000B _ F3: 0F 7F. 02
        add     edx, 16                                 ; 000F _ 83. C2, 10
        sub     ecx, 16                                 ; 0012 _ 83. E9, 10
        jg      ?_001                                   ; 0015 _ 7F, F4
        ret                                             ; 0017 _ C3
; _my_raw_code End of function
where reference .obj file (assembled from source to win32coff without binary stage) is

 

 Disassembly of file: tezt.obj
; Wed Jul 09 09:49:29 2014
; Mode: 32 bits
; Syntax: YASM/NASM
; Instruction set: SSE2
 
 
extern loop11                                           ; byte
extern ZeroMemorySSE                                    ; byte
 
.absolut equ 00000000H                                  ; 0
@feat.00 equ 00000001H                                  ; 1
 
 
SECTION .text   align=16 execute                        ; section number 1, code
 
.text:  ; Local function
        mov     edx, dword [esp+4H]                     ; 0000 _ 8B. 54 24, 04
        mov     ecx, dword [esp+8H]                     ; 0004 _ 8B. 4C 24, 08
        xorps   xmm0, xmm0                              ; 0008 _ 0F 57. C0
?_001:  movdqu  oword [edx], xmm0                       ; 000B _ F3: 0F 7F. 02
        add     edx, 16                                 ; 000F _ 83. C2, 10
        sub     ecx, 16                                 ; 0012 _ 83. E9, 10
        jg      ?_001                                   ; 0015 _ 7F, F4
        ret                                             ; 0017 _ C3
 

so it seems like it mostly works but i dont know what is with this alignment - i see no option to set it to 16...

This topic is closed to new replies.

Advertisement