473,783 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to insert unique ID into binary file that created after compilation?

hello All,
how can i insert unique ID into binary file (that created by compiler)?
(so after compiling i can to identify the src that i use)

thx

Nov 15 '05
24 3185
On 2005-11-09, Alan Balmer <al******@att.n et> wrote:
On Wed, 9 Nov 2005 19:36:20 +0000 (UTC), Jordan Abel
<jm****@purdue. edu> wrote:
On 2005-11-08, Gordon Burditt <go***********@ burditt.org> wrote:
There's no guarantee that SEEK_END on a binary file will work.
(Some OS such as CP/M only keep file sizes in sectors, so
there may be unwritten stuff at the end of the last sector in
a binary file, with no way to tell how much of it is unwritten.)
But those will be null bytes. You could always decide "that is part of
the file for purposes of what i'm doing" - just keep in mind that there
also may be extra null bytes after whatever _you_ wrote.


They won't necessarily be null.


C89 4.9.2

A binary stream is an ordered sequence of characters that can
transparently record internal data. Data read in from a binary stream
shall compare equal to the data that were earlier written out to that
stream, under the same implementation. Such a stream may, however, have
an implementation-defined number of null characters appended.

IOW... If the underlying filesystem doesn't zero such "garbage
characters" out, the C implementation is required to on closing the
file.
Even if they are, how do you know they weren't written on purpose, and
part of the data?


You'll have to keep track of that yourself. Anyway, it's
"Implementa tion-defined", not unspecified, so you have to be able to
look it up in the documentation.
Nov 15 '05 #21
>> Even if they are, how do you know they weren't written on purpose, and
part of the data?


You'll have to keep track of that yourself. Anyway, it's
"Implementatio n-defined", not unspecified, so you have to be able to
look it up in the documentation.


You can't keep track of that yourself. The idea here was that the
code takes a random executable, having absolutely no idea whatever
of the format of an executable, and appends some stuff to the end
of it to stamp it with some kind of tag, hopefully without destroying
its usefulness as an executable in the process. Since the code has
no idea what the format of an executable is, it has no way to tell
whether trailing 0 bytes are an intentional part of the executable
or not.

A possible consequence of doing this is that some of the global
variables that are supposed to be zeroed on program loading are
now initialized to the contents of the tag. Or the executable
could fail its checksum and the OS would refuse to run it.

Gordon L. Burditt
Nov 15 '05 #22
On 2005-11-09, Gordon Burditt <go***********@ burditt.org> wrote:
Even if they are, how do you know they weren't written on purpose, and
part of the data?


You'll have to keep track of that yourself. Anyway, it's
"Implementati on-defined", not unspecified, so you have to be able to
look it up in the documentation.


You can't keep track of that yourself. The idea here was that the
code takes a random executable, having absolutely no idea whatever
of the format of an executable, and appends some stuff to the end
of it to stamp it with some kind of tag, hopefully without destroying
its usefulness as an executable in the process. Since the code has
no idea what the format of an executable is, it has no way to tell
whether trailing 0 bytes are an intentional part of the executable
or not.


It doesn't need to. It just has to leave everything it finds intact. I
didn't say it should overwrite the null bytes. I said it should write
beyond it, leaving everything it finds, including the null bytes,
intact.
Nov 15 '05 #23
At about the time of 11/8/2005 1:01 PM, Skarmander stated the following:
Otherwise, you'll have to try and outsmart your compiler (this is
generally a bad idea, but it may be the only option). That is, involve
the constant in expressions that are too complicated for the compiler to
detect as going unused or evaluating to a constant. If you find such an expression, it may be a good idea to encapsulate it
in a function, otherwise it'll look very mysterious.

S.


For an embedded solution, that might not be a bad idea. It would throw
those off who are trying to hack the code. But, because the compiler is
compiling for an embedded system, there may not be a way to disable this
because embedded systems only have a few K of program storage at most.
For example, the Atmel ATmega16 has only 8K locations at 16-bits wide.
The processor word side is 16-bits, and it's a RISC.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Nov 15 '05 #24
>On 2005-11-09, Gordon Burditt <go***********@ burditt.org> wrote:
... The idea here was that the
code takes a random executable, having absolutely no idea whatever
of the format of an executable, and appends some stuff to the end
of it to stamp it with some kind of tag, hopefully without destroying
its usefulness as an executable in the process. Since the code has
no idea what the format of an executable is, it has no way to tell
whether trailing 0 bytes are an intentional part of the executable
or not.

In article <sl************ *******@random. yi.org>
Jordan Abel <jm****@purdue. edu> wrote:It doesn't need to. It just has to leave everything it finds intact. I
didn't say it should overwrite the null bytes. I said it should write
beyond it, leaving everything it finds, including the null bytes,
intact.


Indeed, you can certainly append data to the file (if it is writeable
in such fashion at all) -- but systems exist in which this will
make the file non-executable. In particular, some systems include
a "cryptographica lly-strong" checksum of the binary in the binary,
and will not excute a binary whose checksum is incorrect. (This
does not guarantee that the binary will *not* run either, even
ignoring the -- tiny, one hopes -- possibility that the checksum
still matches: it depends on whether the checksum covers the entire
binary, or only the parts that are used when executing the binary.)

There are also systems that *will* run the resulting binary, but
on which it will behave incorrectly. In particular, the tail end
of the file will be mapped as data+bss on Unix-like systems that
do virtual memory by mapping correctly-aligned files. The first
few bytes of "bss", which are supposed to be zero, will now be
nonzero and contain the appended data. This may cause some
static-duration variables that must be zero to be nonzero:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
static int mbz; /* must be 0 */

if (mbz != 0)
puts("broken");
return mbz == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

(One's chances of hitting "mbz" here are small in some cases, large
in others, depending on any shared library mechanisms. You can
often "improve" the chance by fiddling with linker options.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 15 '05 #25

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

Similar topics

4
2062
by: Randell D. | last post by:
Folks, I use PHP to write my form data to MySQL. I have a database with about ten tables. I'm trying to fill one table with some dummy data (its a contact manager table holding names of people, addresses and whatever but I'm createing random values for the moment). The insert fails telling me that access is denied - however I use the exact same username/password/database name/host name on the other tables, and the insert and updates...
6
12358
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of 10 columns into a table with 12. How can I specify which columns to insert to? I think format files are what I'm supposed to use, but I can't figure them out. I've also tried using a view, as was suggested on one of the many websites I've...
16
17019
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
2
6560
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the assignment of version numbers: CREATE TRIGGER "trg_audio_file_insert" BEFORE INSERT ON "public"."audio_file" FOR EACH ROW EXECUTE PROCEDURE "public"."trg_audio_file_insert"(); My trigger function looks like this...
1
5376
by: cricrin | last post by:
Hello guys! This is Cristian From Argentina, and I wanted to ask you some help, I've looking on this and it makes me mad, I found that the error is in the $content , when y try to insert the record into the table via PHP code i receive an error message saying that the sin taxis its incorrect,however if i print the query echo ($query) and i copy and paste the query in the PHPmyAdmin the insert executes successfully. the $content variable...
16
2885
by: horacius.rex | last post by:
Hi, I don't know if it is better to post this question to a C or C++ group, so my apologies. My general question: I have a very big C++ program (Main.cpp) which compiles on machine X with compiler XA++.
0
9480
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
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
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
6737
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();...
1
4044
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
3645
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.