Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


raw binary to obj conversion


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
19 replies to this topic

#1 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 07 July 2014 - 04:04 PM

 
 

I wonder if in such case i get a .bin file with the raw contents of some procedure (x86-32) is it possible to convert this with some tool (or if it is at all possible) to some linkable object file (like coff) which i can link and use (for example with GCC)

Speciffically it seem to me that when converting i shoulf gabe some export symbol name, dont know what with import symbol names, also do not know if some reallocation table would be needed to use this with such bonary or it is not needed and can be build at the process of conversion, i dont manage to understand what is going on with this realocation data

is it possible to convert data such way? could someone explain this?

 



Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 6263

Like
5Likes
Like

Posted 07 July 2014 - 04:10 PM

Have you looked into disassemblers?
gzip: H4sIAAAAAAAEAG1QTUvEMBC991e8nvaiFfYoS7yo sLCo6MnjtJ1ugmkiyWRL/72z3T1YEQIJ8z4zA2Xp yPvt1qBpGrRFIJZkk9FyRyUzHCbKIHgn4hnZOrm1 TD0mG0HCCs+QGDGWziKXI6Wm2n++GYwUVH2mrGEE PnGCVQ8K8+JYfXA6URDEQfMZh5h6g5eoAlWJdeEI bbH2qYZf7XMUfw8f/Q0oMeZYNL9/WHF0uFEshvMr XYujd9SycFb+F18QcSOvlJauZ8ejqevdnV7/d550 e0t6prmunh73Bu+vz4c/XUeOQXfJgvKNkhf95U8/ Dtgmy5IBAAA=

#3 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 07 July 2014 - 05:49 PM

Have you looked into disassemblers?

 

I use them sometimes but this is somethink different..

 

I need an avaliable converter (bin->obj) or i need to wrote some converter code by myself but im not sure how hard it is ad what exactly need to do (would like need to know which one of obj formats is most easy to easily wrote some code for saving this)



#4 Bluebat   Members   -  Reputation: 487

Like
2Likes
Like

Posted 07 July 2014 - 07:05 PM

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.



#5 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 08 July 2014 - 01:47 AM

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

 

i would later need a way of generating binary object files by myself from c code (try to wrote some very simple assembler elements) but dont know what of the common object formats would be easier to generate

 

right now im thinking about just generating .bin and converting it on linker 'toolchain' side, but would like to get some help with all of this



#6 Tribad   Members   -  Reputation: 980

Like
2Likes
Like

Posted 08 July 2014 - 02:01 AM

Assemblers and compilers are the tools to generate object files.

If you want to generate it in another fine way, write the tool yourself. Look into the specifications for the various object file formats and choose one to implement. Should not be very hard with your experiences.

 

Generating a bin file from objects is called linking. For embedded systems you often have an additional step of locating, because the different sections defined in an object file needs to be moved into the right memory addresses.

 

If someone needs an image file or some binary data within his/her application they use their application development environment and put it in as data. The toolchain do the rest. So it would be surprising if someone would need a special tool to create an object file from a binary.



#7 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 08 July 2014 - 02:09 AM

Assemblers and compilers are the tools to generate object files.

If you want to generate it in another fine way, write the tool yourself. Look into the specifications for the various object file formats and choose one to implement. Should not be very hard with your experiences.

 

Generating a bin file from objects is called linking. For embedded systems you often have an additional step of locating, because the different sections defined in an object file needs to be moved into the right memory addresses.

 

If someone needs an image file or some binary data within his/her application they use their application development environment and put it in as data. The toolchain do the rest. So it would be surprising if someone would need a special tool to create an object file from a binary.

 

i got moderate experience - generating .obj myself is possible

but depends what you mean "not so hard" those are complex formats with many variable size chunks and other stuff so this is considerable more work to succesfully go thru that 

 

need at least some hints which format could be easier one to chose, 

or some hints what i would need to code (and how to make it easy) when writing such kind bin->obj "enveloper" or conventer



#8 Tribad   Members   -  Reputation: 980

Like
1Likes
Like

Posted 08 July 2014 - 02:18 AM

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



#9 BitMaster   Crossbones+   -  Reputation: 5819

Like
1Likes
Like

Posted 08 July 2014 - 02:19 AM

Have you evaluated GNU's Binary File Descriptor library referenced in the Wikipedia article?

#10 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 08 July 2014 - 02:35 AM

Have you evaluated GNU's Binary File Descriptor library referenced in the Wikipedia article?

need something opposite - not variety of 50 formats but info how to generate the only one but as simplest as possible (or even some ready tool as i said - will read on this but its a mountain of docs on this but not exactly the substantial answer i need to find)

 

(the substantial question is : "i got an .bin with some procedure contents - how exactly to do it in an easier way to make some object from that"

 

(i need more some more like quick workable hack than extensible code)



#11 fir   Members   -  Reputation: -460

Like
-9Likes
Like

Posted 08 July 2014 - 02:42 AM

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



#12 Tribad   Members   -  Reputation: 980

Like
0Likes
Like

Posted 08 July 2014 - 02:42 AM

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.



#13 Tribad   Members   -  Reputation: 980

Like
3Likes
Like

Posted 08 July 2014 - 02:47 AM

 

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.



#14 LennyLen   GDNet+   -  Reputation: 5050

Like
0Likes
Like

Posted 08 July 2014 - 02:53 AM

 

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.



#15 fir   Members   -  Reputation: -460

Like
-2Likes
Like

Posted 08 July 2014 - 02:57 AM

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 some people are arleady experienced and can just share some hint, it often works that way - and then its good way of using forums

#16 jbadams   Senior Staff   -  Reputation: 23531

Like
2Likes
Like

Posted 08 July 2014 - 03:25 AM

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.)



#17 Bluebat   Members   -  Reputation: 487

Like
1Likes
Like

Posted 08 July 2014 - 03:32 AM

 

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.



#18 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 08 July 2014 - 04:47 AM

 

 

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


Edited by fir, 08 July 2014 - 09:23 AM.


#19 Bregma   Crossbones+   -  Reputation: 6363

Like
3Likes
Like

Posted 08 July 2014 - 05:42 AM

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

#20 fir   Members   -  Reputation: -460

Like
0Likes
Like

Posted 09 July 2014 - 02:06 AM

 

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...


Edited by fir, 09 July 2014 - 02:15 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS