473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Including compiled C source file in array

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

Jun 27 '08 #1
13 2250
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.

Jun 27 '08 #2
In article <b6************ *************** *******@u12g200 0prd.googlegrou ps.com>,
sachin <sb******@redif fmail.comwrote:
>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)
Jun 27 '08 #3
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <b6************ *************** *******@u12g200 0prd.googlegrou ps.com>,
sachin <sb******@redif fmail.comwrote:
>>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.
Jun 27 '08 #4
In article <g2**********@r egistered.motza rella.org>,
Richard <rg****@gmail.c omwrote:
>>>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)
Jun 27 '08 #5
On Jun 5, 5:25 pm, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <g28kua$ba...@r egistered.motza rella.org>,

Richard <rgr...@gmail.c omwrote:
>>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
Jun 27 '08 #6
In article <g2***********@ pc-news.cogsci.ed. ac.uk>,
Richard Tobin <ri*****@cogsci .ed.ac.ukwrote:
>In article <b6************ *************** *******@u12g200 0prd.googlegrou ps.com>,
sachin <sb******@redif fmail.comwrote:
>>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.

Jun 27 '08 #7
sachin <sb******@redif fmail.comwrote:
On Jun 5, 5:25 pm, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <g28kua$ba...@r egistered.motza rella.org>,

Richard <rgr...@gmail.c omwrote:
>>>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 ___ jt@toerring.de
\______________ ____________ http://toerring.de
Jun 27 '08 #8
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.

Jun 27 '08 #9
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
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2269
by: LutherRevisited | last post by:
This may be a dumb question, but are there any practical advantages of compiling a python application to *.pyo, or *.pyc? I haven't noticed any difference in the performance of text *.py or a bytecompiled file.
2
252
by: G.H.Lawrence | last post by:
Hello. I am relatively new to VS.NET and have ingerited a web application built by 2 previous developers. The most recent one compiled his C# source to a dll, the first one left her C# source as aspx.cs files. I have to debug and enhance the appliation but am running into a couple of issues 1. in order to analyze the C# code, I must decompile the existing dll someho 2. I have a source tree from the last developer but he wasn't a diligent...
2
1252
by: Craig | last post by:
Is there a way to conditionally include a file in the HTML? <TD> if x= 1 then <!--#INCLUDE FILE="../File1"--> else <!--#INCLUDE FILE="../File2"--> end if
6
1611
by: Al-Burak | last post by:
I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been include in its header file. However, there are times when some of the other classes are not and will not be dealt with, thus the need to include the header files does not arrive. To handle this, I have used compiler preprocessors to prevent the...
8
3706
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
5
1994
by: Marcelo Gosling | last post by:
Hi, everyone. This is on WinXP SP2, with Python 2.4.3 and DJGPP gcc 4.1.0. I'm having trouble including Python.h in a C file. The following C code: #include "Python.h" int main()
6
1634
by: Marc Jeambrun | last post by:
Hello, I have a simple question I would like to ask to you guys... It boils down to a simple observation about all the C libraries existing out there: there must be a C source file that must be compiled first, I mean before all the others. That's why I poke my nose in a C library (GNU glibc for instance) to find out this mysterious file... This is indeed the library programmers (including me) often refer to.
11
15613
by: cooltoriz | last post by:
Hello there, I just found that the compiled code won't hide the string variables so that I can see them by opening the execuable using Notepad. I have couple applications that have password hardcoded and I've been thinking that the string varialbes are hidden in compiled code. I knew that the VS.NET doesn't compile the source code into machine code. But I didn't know that it will expose string variables in the compiled code. Here is my...
13
2147
by: Robert Cloud | last post by:
Is it possible to include assembly language routines in C if I'm using a compiler which has an assembler such as gcc? could I include them in a main function or would I have to write a seperate function? what kind of privilege level would be required to execute a program with assembly in it? how would I denote that the following code is assembly and thus shouldn't be checked for syntax errors? ------------------------------ Robert Cloud...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.