Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Including compiled C source file in array

Reply
Thread Tools

Including compiled C source file in array

 
 
sachin
Guest
Posts: n/a
 
      06-05-2008
Hi,

Is it possible to do something like this:

unsigned char arr[] = {
#include "cFile.c"
}

I need that C source file cFile.c to compile and its binary output to
include in array.

How we can achieve it? Any other trick to do this?

Thanks,
Sachin

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      06-05-2008
sachin wrote:

> Hi,
>
> Is it possible to do something like this:
>
> unsigned char arr[] = {
> #include "cFile.c"
> }
>
> I need that C source file cFile.c to compile and its binary output to
> include in array.
>
> How we can achieve it? Any other trick to do this?


You can compile cFile.c and copy it's bytes, (as hexadecimal, decimal or
octal text. All binary editors can show this for you), to your array
declaration.

Alternatively there might be compiler specific extensions for this,
though I doubt it. You might also consider the possibility of loading
the binary file at runtime with fread.

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      06-05-2008
In article <(E-Mail Removed)>,
sachin <(E-Mail Removed)> wrote:

>I need that C source file cFile.c to compile and its binary output to
>include in array.


What do you expect to be able to do with it?

-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      06-05-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard Tobin) writes:

> In article <(E-Mail Removed)>,
> sachin <(E-Mail Removed)> wrote:
>
>>I need that C source file cFile.c to compile and its binary output to
>>include in array.

>
> What do you expect to be able to do with it?
>
> -- Richard


I would expect he has something which produces code based on dynamic
variables and wants to have variable records e.g accept user tweaks,
regenerate record structures, recompile record handling SW, run record
handling SW.
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      06-05-2008
In article <g28kua$bag$(E-Mail Removed)>,
Richard <(E-Mail Removed)> wrote:

>>>I need that C source file cFile.c to compile and its binary output to
>>>include in array.


>> What do you expect to be able to do with it?


>I would expect he has something which produces code based on dynamic
>variables and wants to have variable records e.g accept user tweaks,
>regenerate record structures, recompile record handling SW, run record
>handling SW.


Possibly, but unless he tells us we can't give him much help. For
most uses he'd be wisest to to use system-dependent functions that
(for example) access the symbol table, and reading the compiled file
into an array may well not be the right way to do that.

-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
 
Reply With Quote
 
sachin
Guest
Posts: n/a
 
      06-05-2008
On Jun 5, 5:25 pm, (E-Mail Removed) (Richard Tobin) wrote:
> In article <g28kua$(E-Mail Removed)>,
>
> Richard <(E-Mail Removed)> wrote:
> >>>I need that C source file cFile.c to compile and its binary output to
> >>>include in array.
> >> What do you expect to be able to do with it?

> >I would expect he has something which produces code based on dynamic
> >variables and wants to have variable records e.g accept user tweaks,
> >regenerate record structures, recompile record handling SW, run record
> >handling SW.

>
> Possibly, but unless he tells us we can't give him much help. For
> most uses he'd be wisest to to use system-dependent functions that
> (for example) access the symbol table, and reading the compiled file
> into an array may well not be the right way to do that.
>
> -- Richard
> --
> In the selection of the two characters immediately succeeding the numeral 9,
> consideration shall be given to their replacement by the graphics 10 and 11 to
> facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)


Hi,

I have one C source file which after compiling I need to copy at
specific location.
Until system comes up I don't have access to that memory location. So
I want to keep
that code in executable form with the OS image. When system comes up
will copy that
executable code to designated space.

Thanks,
Sachin
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      06-05-2008
In article <g28k6g$2opa$(E-Mail Removed)>,
Richard Tobin <(E-Mail Removed)> wrote:
>In article <(E-Mail Removed)>,
>sachin <(E-Mail Removed)> wrote:
>
>>I need that C source file cFile.c to compile and its binary output to
>>include in array.

>
>What do you expect to be able to do with it?


Why, to smash the stack, of course.

It's perfectly obvious that all of these queries about needing to
include (seemingly) random sequences of bytes in code are about
"cracking/hacking/freeking/whatever-you-want-to-call-it" - let's not get
into that argument...

Not necessarily for evil purposes, mind you. It's worth the exercise
just to learn what all the fuss is about.

 
Reply With Quote
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      06-05-2008
sachin <(E-Mail Removed)> wrote:
> On Jun 5, 5:25 pm, (E-Mail Removed) (Richard Tobin) wrote:
> > In article <g28kua$(E-Mail Removed)>,
> >
> > Richard <(E-Mail Removed)> wrote:
> > >>>I need that C source file cFile.c to compile and its binary output to
> > >>>include in array.
> > >> What do you expect to be able to do with it?
> > >I would expect he has something which produces code based on dynamic
> > >variables and wants to have variable records e.g accept user tweaks,
> > >regenerate record structures, recompile record handling SW, run record
> > >handling SW.

> >
> > Possibly, but unless he tells us we can't give him much help. For
> > most uses he'd be wisest to to use system-dependent functions that
> > (for example) access the symbol table, and reading the compiled file
> > into an array may well not be the right way to do that.

>
> I have one C source file which after compiling I need to copy at
> specific location.
> Until system comes up I don't have access to that memory location. So
> I want to keep
> that code in executable form with the OS image. When system comes up
> will copy that
> executable code to designated space.


You can't simply include a binary file (the C source will be
of no use anyway). Just write a little utility that opens the
file you want to insert as data at that place, reads the data
from the file in as unsigned chars and writes them out in a
form like this:

unsigned char array[ ] = {
0x01, 0x3A, 0xA6, 0x12, 0x17, 0xC3, 0x7D, 0x5F,
.....
};

Save that to a file (e.g. data.h). Then include the data.h
file at exactly the place where you want the array to be
defined. Lets hope that the binary file isn't too long to
be stored in an array.
Regards, Jens
--
\ Jens Thoms Toerring ___ (E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
Antoninus Twink
Guest
Posts: n/a
 
      06-05-2008
On 5 Jun 2008 at 12:44, sachin wrote:
> I have one C source file which after compiling I need to copy at
> specific location.


If you're writing a virus, the man's way is to write the shellcode by
hand in assembly, not use a compiled C file.

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      06-05-2008
Antoninus Twink wrote, On 05/06/08 17:18:
> On 5 Jun 2008 at 12:44, sachin wrote:
>> I have one C source file which after compiling I need to copy at
>> specific location.

>
> If you're writing a virus, the man's way is to write the shellcode by
> hand in assembly, not use a compiled C file.


On one DSP I used to use there was a perfectly good and "standard"
reason for wanting to achieve what the OP wants to achieve. However, the
implementation provided special tricks in the linker to allow you to
achieve it which did not involved doing what the OP asked about.

The OP needs to ask about the real problem rather than what he thinks
the solution is in a group dedicated to his implementation.
--
Flash Gordon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander ASP .Net 5 03-05-2008 04:34 PM
first C source file to be compiled Marc Jeambrun C Programming 6 12-01-2006 07:07 PM
Saving a compiled source file with the "require"d files Ray Muforosky Perl Misc 3 04-22-2005 10:05 AM
g++ compiled C++ code called from gcc compiled C code Klaus Schneider C++ 1 12-02-2004 01:44 PM
Source files in JAR file are sometimes compiled jd Java 0 10-08-2003 07:34 PM



Advertisments