Solved

C or C++ File Extaction Program

Posted on 2004-09-21
7
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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