Solved

C or C++ File Extaction Program

Posted on 2004-09-21
7
301 Views
Last Modified: 2010-04-21
Hello All,

Let me start off by saying I am very new to the Linux/Unix platform and I'm trying to come up to speed.  I am currently researching how to create a simple binary program that you can concatinate a file onto another file and then extract the file when run.  Basically I figured out how to implement this using a script but it does not statisfy what I need because as a script a user can modify my script to get the file and also see how I embedded the file.  This is not something i can allow.  So unless there is some way of making my script file unreadable or uneditable it looks like I am going to have to go the binary route.   Below I have included some of my script code that i need to duplicate using C/C++


With my script I basically just concatinate a file(which happens to be a tar file) by doing this:

cat myscript.sh  file.tar.gz > mypackage.sh

The myscript.sh script myscript.sh i wrote looks like this:

#!/bin/sh
echo ""
echo "Package - extracting archive... please wait"
echo ""

SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`

# take the archive portion of this file and pipe it to tar
tail +$SKIP $0 | tar xz


exit 0

__ARCHIVE_FOLLOWS__


Like I previously mentioned I basically need to reproduce this functionality by making a C/C++ implentation of this script.

Since I have little or no experience with programming for this platform I was hoping someone could help me.  Any information you can provide would be greatly appreciated.

Best Regards,
-Jim
0
Comment
Question by:jim_welch_se
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12120267
Hi Jim,

If you plan to use this script for your own machine, change it permissions to be owned by root and allow only execution to all users. Something like passwd.

If you plan to distribute it, then binary approach makes sense. But realize that :
- Linux is primarily thriving on open source. Users, not knowing what you are doing in your program and  easy availablity of several good options is likely to prevent it from being a big hit :)
- If you do make a binary, it is not a big task to reverse engineer a program of that size.

That been said I cannot think of any pretty way to incorporate a binary within a C program binary.What we can do is to generate the C source code on the fly and include the binary within the source code as a char array and then compile this source code to give us a self extracting archive.

Somethin on the lines of:

fp = fopen ( "new_source.c", "w");
fprintf (fp,"#include<stdio.h>\n");
...
fprintf (fp,"char [] file = \"{");
arch_file = fopen (argv[1], "r");
while ( fread, (buffer, 1, BUF_LEN, archfile) != 0 )
      fwrite (buffer, ,1 BUF_LEN, fp);
fprintf ( fp , "};\n");
...
Next comes printing the code in the new_source for extracting the tar file in array file[]
Last comes code to close and compile the newly generated source file.

Messy, but looks like the only way out

cheers
sunnycoder
0
 
LVL 2

Expert Comment

by:sneeuw_chan
ID: 12121403
If you'll always be adding tar files, or gzip files, you could of course search for the tar or gzip header, then all the program needs to do is find itself as file.
Which should normally be argv[0], although I don't think you can always depend on that.
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 12127883
So you have a program that has some kind of proprietary file embedded within it, and you are going to distribute this program to hostile users in some kind of way that they can successfully run the program, yet have no way to see the proprietary file?

That is provably impossible, unless you keep the program on a system you control that prevents the user from ever reading the program file.  Once the hostile user can read the program file it will always always always be possible for the user to disassemble, simulate, or debug the program and gain access to your secret file.  You can only make it a little more difficult for them, or only keep the secret from your less able users.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:jim_welch_se
ID: 12128162
Hello All,

Thank you all for your feed back I really appreciate it.

Maybe I should give some more details about the major issue I am trying to take care of by writing this app.  Basically my program has to prompt a user with a License agreement and if they accept this then I supposed to allow them to get the file.  The script I wrote accomplishes this task but its a bit to modifiable to users.  If a user is wants to get at my file I want to make it somewhat difficult to do so.    I hope that clarify what I am trying to accomplish.

Best Regards,
-Jim

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12131456
Hi Jim,

the approach I outlined should work in that case.
0
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 125 total points
ID: 12135841
If you are in the US, then the DMCA is on your side.

You don't have to do anything heroic.  Just mildly encode your file (add 1 to each character or something similarly simple) and somehow label the data so that it is obvious that it is protected by an access control mechanism, and circumventing the mechanism would be in violation of the DMCA.

Why don't you just put up a website and only serve the file out to people who click through a licensing agreement?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question