Storing "Stuff" in an executable

bridged with qdn.public.devtools
Post Reply
Bill Caroselli

Storing "Stuff" in an executable

Post by Bill Caroselli » Wed Feb 19, 2003 7:30 pm

Several programs store things inside of an executable. I.E.
* usage messaeg
* photon widget definitions
* debug information

Is there a utility that I can use to store data of my own choosing
inside of an executable?

If so, how would the running program access that data?
Could the same utility be used to display (assuming it's text data) and
modify that data?

I'm looking for something very similar to a usage mesasge, but readable
by the program itself like the widget definitions.

Does all of this ancelary data get loaded when the executable is loaded
into memory?

Kris Warkentin

Re: Storing "Stuff" in an executable

Post by Kris Warkentin » Wed Feb 19, 2003 8:27 pm

Try "objcopy --addsection section=filename". This will add a section with
'filename' contents.

cheers,

Kris

"Bill Caroselli" <qtps@earthlink.net> wrote in message
news:b30m0m$sh1$2@inn.qnx.com...
Several programs store things inside of an executable. I.E.
* usage messaeg
* photon widget definitions
* debug information

Is there a utility that I can use to store data of my own choosing
inside of an executable?

If so, how would the running program access that data?
Could the same utility be used to display (assuming it's text data) and
modify that data?

I'm looking for something very similar to a usage mesasge, but readable
by the program itself like the widget definitions.

Does all of this ancelary data get loaded when the executable is loaded
into memory?

Bill Caroselli

Re: Storing "Stuff" in an executable

Post by Bill Caroselli » Wed Feb 19, 2003 8:33 pm

Kris Warkentin <kewarken@qnx.com> wrote:
Try "objcopy --addsection section=filename". This will add a section with
'filename' contents.
How does the running program access this data?

Eric Johnson

Re: Storing "Stuff" in an executable

Post by Eric Johnson » Wed Feb 19, 2003 9:04 pm

"Bill Caroselli" <qtps@earthlink.net> wrote in message
news:b30pnh$564$1@inn.qnx.com...
Kris Warkentin <kewarken@qnx.com> wrote:
Try "objcopy --addsection section=filename". This will add a section
with
'filename' contents.

How does the running program access this data?
objcopy will allow you to add sections, and objdump will read them back.
objcopy and objdump are part of the GNU binutils so you can look at the src
for more info. QNX usage info is in a section called QNX_usage. PhAB info is
in QNX_PhAB, etc. This info doesn't get loaded, any more than debug info
does (though with appropriate manipulation of the ELF program header and
section table, anything's possible). To get an idea of what's in there:

objdump -x /usr/photon/bin/ped

It's a very small amount of work to programatically open the executable,
read the section header table, and load the section. (if you choose to code
it directly rather than invoke the utility or use the GNU lib).

- Eric

Bill Caroselli

Re: Storing "Stuff" in an executable

Post by Bill Caroselli » Wed Feb 19, 2003 9:41 pm

kabe@sra-tohoku.co.jp wrote:
qtps@earthlink.net sed in <b30pnh$564$1@inn.qnx.com>:

How does the running program access this data?

Depends whether you want to read it in-memory or from file.
These are just top-of-the-head suggestions:

from file:
Use libelf to get the section contents.
Hmm there's no libelf manual; /usr/lib/libelf.a exists
but not supported?

from memory:
add the section as loadable data region
(--set-section-flags <section>=load ? dunno)

but where should I get the address of it?
Something may could be done by hacking objdump/ld/whatever, but
seems like making a simple asm file and assemble-link
should be easier.
This is proving to be very educational. I'm learning more than I
wanted to know about ELF format files. But information never goes
to waste.

Thanks to all who replied.

Guest

Re: Storing "Stuff" in an executable

Post by Guest » Wed Feb 19, 2003 9:41 pm

qtps@earthlink.net sed in <b30pnh$564$1@inn.qnx.com>:
How does the running program access this data?
Depends whether you want to read it in-memory or from file.
These are just top-of-the-head suggestions:

from file:
Use libelf to get the section contents.
Hmm there's no libelf manual; /usr/lib/libelf.a exists
but not supported?

from memory:
add the section as loadable data region
(--set-section-flags <section>=load ? dunno)

but where should I get the address of it?
Something may could be done by hacking objdump/ld/whatever, but
seems like making a simple asm file and assemble-link
should be easier.
--
kabe

Mike Gorchak

Re: Storing "Stuff" in an executable

Post by Mike Gorchak » Thu Feb 20, 2003 9:28 am

Hello, Bill!

I have article about that problem ... but it is in russian :-)
http://qnx.org.ru/docs-devel/elf.html

In two words: you can read .ELF segments without any library, as base I'm
using print_usage function by Colin Burgess for QNX6. It is in attachment -
use.c. Also here my example how to use .ELF data directly from code.
sections.c and usgcol.h .

But be careful, QNX6 loads up all ELF file into memory, so those overlays in
..elf segments will eat your memory. Here complete archive of sources for my
article ftp://ftp.qnx.org.ru/pub/projects/mike/files.tar.gz .

Good luck ;)

With best regards, Mike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-Y86Y<;B(*(" @(B @(" @("(@55-'7U)%1" @(" @(" @
M(E)E9%QN(@H@(" B(" @(" @(B!54T=?34%'14Y402 @(" B36%G96YT85QN
M(@H@(" B(" @(" @(B!54T=?0E)/5TX@(" @(" B0G)O=VY<;B(*(" @(B @
M(" @("(@55-'7TQ)1TA41U)!62 @(DQI9VAT($=R87E<;B(*(" @(EQN(@H@
M(" B(" @3&EG:'0@8V]L;W)S.B!<;B(*(" @(B @(" @("(@55-'7T1!4DM'
M4D%9(" @(D1A<FL@1W)A>5QN(@H@(" B(" @(" @(B!54T=?3$E'2%1"3%5%
M(" B3&EG:'0@0FQU95QN(@H@(" B(" @(" @(B!54T=?3$E'2%1'4D5%3B B
M3&EG:'0@1W)E96Y<;B(*(" @(B @(" @("(@55-'7TQ)1TA40UE!3B @(DQI
M9VAT($-Y86Y<;B(*(" @(B @(" @("(@55-'7TQ)1TA44D5$(" @(DQI9VAT
M(%)E9%QN(@H@(" B(" @(" @(B!54T=?4$E.2R @(" @(" B4&EN:UQN(@H@
M(" B(" @(" @(B!54T=?645,3$]7(" @(" B665L;&]W7&XB"B @("(@(" @
M(" B(%531U]72$E412 @(" @(")7:&ET95QN(@H*(" @55-'7TQ)1TA41U)!
M62 B7&XB.R O+R!R971U<FX@9&5F875L="!C;VQO<G,*"F-O;G-T(&-H87(@
M:6YF;UM=(%]?871T<FEB=71E7U\H*'-E8W1I;VXH(E%.6%]I;F9O(BDI*2 ]
M"B)35$%413U%>'!E<FEM96YT86Q<;B(*(DE.4U1!3$Q$25(]>#@V+W5S<B]B
M:6XO7&XB"B))3E-404Q,3D%-13US96-T:6]N<W1E<W1<;B(*(DY!344]<V5C
M=&EO;G-<;B(*(E5315(]<F]O=%QN(@HB2$]35#UD969L96MT;W)<;B(*(D1!
M5$4],C P,B\P."\R,2TQ-SHU-3HP,45%4U1<;B(*(D1%4T-225!424]./4IU
M<W0@82!S96=M96YT<R!T97-T('!R;V=R86TN7&XB.PH*:6YT(&UA:6XH*0I[
M"B @(&-H87(@8G5F9F5R6S(U-ET["@H@("!P<FEN=&8H(EQN(BD["B @( H@
J("!S8V%N9B@B)7,B+"!B=69F97(I.PH@(" *(" @<F5T=7)N(# ["GT*
`
end

begin 666 usgcol.h
M(VEF;F1E9B!?7U531T-/3%](7U\*(V1E9FEN92!?7U531T-/3%](7U\*"B-D
M969I;F4@55-'7T),04-+(" @(" @(EQX,4(B(ELR,CLS,&TB"B-D969I;F4@
M55-'7T),544@(" @(" @(EQX,4(B(ELR,CLS-&TB"B-D969I;F4@55-'7T=2
M145.(" @(" @(EQX,4(B(ELR,CLS,FTB"B-D969I;F4@55-'7T-904X@(" @
M(" @(EQX,4(B(ELR,CLS-FTB"B-D969I;F4@55-'7U)%1" @(" @(" @(EQX
M,4(B(ELR,CLS,6TB"B-D969I;F4@55-'7TU!1T5.5$$@(" @(EQX,4(B(ELR
M,CLS-6TB"B-D969I;F4@55-'7T)23U=.(" @(" @(EQX,4(B(ELR,CLS,VTB
M"B-D969I;F4@55-'7TQ)1TA41U)!62 @(EQX,4(B(ELR,CLS-VTB"@HC9&5F
M:6YE(%531U]$05)+1U)!62 @(")<>#%"(B);,3LS,&TB"B-D969I;F4@55-'
M7TQ)1TA40DQ512 @(EQX,4(B(ELQ.S,T;2(*(V1E9FEN92!54T=?3$E'2%1'
M4D5%3B B7'@Q0B(B6S$[,S)M(@HC9&5F:6YE(%531U],24=(5$-904X@(")<
M>#%"(B);,3LS-FTB"B-D969I;F4@55-'7TQ)1TA44D5$(" @(EQX,4(B(ELQ
M.S,Q;2(*(V1E9FEN92!54T=?4$E.2R @(" @(" B7'@Q0B(B6S$[,S5M(@HC
M9&5F:6YE(%531U]914Q,3U<@(" @(")<>#%"(B);,3LS,VTB"B-D969I;F4@
M55-'7U=(251%(" @(" @(EQX,4(B(ELQ.S,W;2(*"B-E;F1I9B O+R!?7U53
)1T-/3%](7U\*
`
end

Post Reply

Return to “qdn.public.devtools”