![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Sep 2009
Posts: 10
| |
| redone is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| And which OS are you trying to accomplish this on? The first big question is are you even allowed to open your own executable image for writing?
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #3 |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 801
| If you are in Linux, you could always use getenv() in your code to gather "global" variables passed in by the outside world doing a export <VAR>=<STUFF>. |
| Kennedy is offline | |
| | #4 |
| Registered User Join Date: Sep 2009
Posts: 10
| I m using ubuntu .Here is the project : "Managing user names and passwords for email, network, accounts etc. can be a real hassle. A solution consist in listing ones credentials (in the form of tuples usernames, passwords) in a text file, then encrypting the entire file with a strong encryption algorithm requiring a pass phrase. To retrieve ones credentials i.e., usernames and passwords one has to have both the encrypted textfile and the decryption algorithm at hand. A more elegant solution uses only one executable file that contains both encryption and decryption algorithms as well as the credentials (in a data segment in OS/compiler terms). In this project you are required to implement this elegant solution. When executed, this executable file runs user choices to either view/append or delete credential tuples. Hints: You can use libelf for managing data segments of executable files dynamically " I think this would be better to understand my problem tanx for your replies |
| redone is offline | |
| | #5 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| Took about 5 seconds libelf by Example
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #6 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| The project description says "You can use libelf", not that you MUST. There are far easier ways of doing this than mucking with ELF format. In fact, you can do this in a completely portable way with no knowledge at all of the underlying executable format. The trick is to embed a large block of data (as a global array) into the program. The beginning of this data is marked by some kind of unique signature. To read or write from this data block, then, all you need to do is open the file, scan until you find the signature, and then you know you are in the correct position to read or write data. Of course, this is not even possible if the OS doesn't allow you to alter the program file while the program is executing. But most UNIX-like operating systems do allow you to do this.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #7 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Neat trick. Linux will presumably allow it, since you can recompile an executable while it is running.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #8 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
The tool didn't need any knowledge of the executable format, it just scanned the file for the signature and then it knew where the data was. The downside is that the size of the DIB is fixed and can't be changed, but we didn't need something like that anyway.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | |
| brewbuck is offline | |
| | #9 | |
| Registered User Join Date: Sep 2009
Posts: 10
| Quote:
thanksi advance | |
| redone is offline | |
| | #10 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
Code: #include <string.h>
int main() {
char sig[1029]="XOXOX", *start=&sig[5];
memset(start,'Z',1024);
strcpy(start,"hello world");
return 0;
}
There are some interesting things in the hexdump that imply to me you could access the data segment without using libelf but probably not in as naive a way as this... ps. anyone know why gcc's default output file is still called a.out? AFAIK an "a.out" binary is historically not the same as an ELF binary, but of course the a.out from gcc on linux is an ELF binary.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 09-11-2009 at 08:51 AM. | |
| MK27 is offline | |
| | #11 |
| Registered User Join Date: Sep 2009
Posts: 10
| Normally what i understood is that I should scan my executable file until i find the the location of the global variable is that right ?? if it's right then how can compare a file descriptor with the my global variable |
| redone is offline | |
| | #12 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| > how do i know the signature of the variable if possible give a source code example You mean it's not YOUR executable? And why does it seem like we're the ones doing all the work all of a sudden.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #13 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
Code: ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x400420 Start of program headers: 64 (bytes into file) Start of section headers: 2992 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 8 Size of section headers: 64 (bytes) Number of section headers: 30 Section header string table index: 27 On the other hand, it must be possible: http://www.cse.iitm.ac.in/moodle/mod...iew.php?id=459 But you are the one studying this stuff! Since you have to write something to the binary anyway, you might as well start experimenting. It is not as if it will matter if you accidentally wreck your executable.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 09-11-2009 at 09:21 AM. | |
| MK27 is offline | |
| | #14 |
| Guest Join Date: Aug 2001
Posts: 4,923
| >> if it's right then how can compare a file descriptor with the my global variable Why would you want to do that? The point is simply to find the target block so that you can read/replace the stored data. Does that make sense? |
| Sebastiani is offline | |
| | #15 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
You won't find the name of the variable (eg, from my previous example, "sig" or "start"), but what you will find is the content ("XOXOX" and "hello world"). Now get busy, try some code and then ask more questions.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Writing and modifying data in a file | Micko | C Programming | 2 | 02-17-2005 03:42 AM |