gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Compiling files inaccessible to the user into object files

#27114 - DiscoStew - Sun Oct 03, 2004 11:44 pm

I plan to make a couple of libraries that uses data that is created by editors I plan to make. The editors will export data into C arrays of structures within arrays of structures, with the libraries linking to the main structures externally. The problem is that I don't want people looking through the exported files created by the editors. What I want to do is generate object code from the data I create, but the only method I see to do that is export the data into files, then using DevKitARM to create the object files. That still requires me to export into files.

Is there a simple solution to do this?
_________________
DS - It's all about DiscoStew

#27119 - tepples - Mon Oct 04, 2004 2:47 am

DiscoStew wrote:
The problem is that I don't want people looking through the exported files created by the editors.

Why not? Is there some business model reason for this digital restrictions management, or do you just want to keep the build directories cleaner?

Quote:
What I want to do is generate object code from the data I create, but the only method I see to do that is export the data into files, then using DevKitARM to create the object files.

Try piping ARM assembly language into as of devkitARM, which emits an object file.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#27126 - DiscoStew - Mon Oct 04, 2004 6:20 am

tepples wrote:
Why not? Is there some business model reason for this digital restrictions management, or do you just want to keep the build directories cleaner?


Well, even though I plan to make these libraries available to the people here, without compiling the created data, I would be forced to have to reveal the format that this data is held as, because the files cannot be compiled without the structures being defined. Plus, that would also allow people to mess with the data, even the header. I would much rather give people just 3 files...
1) a header with prototypes and error values
2) the library file, and
3) the object file that the library gets its data from.

Quote:
Try piping ARM assembly language into as of devkitARM, which emits an object file.

That would seem like quite a task for me, because everything is made up of normal value, structures, pointers to structures, a lot of things embedded (did I mention structures?), plus I am still learning ASM, even if it is Intel ASM.

I could just write the data to some undisclosed file in an undisclosed folder. Is there a way to prevent access to a file by the user, and only allow DevKitARM to access the file to create an object file? Once the data is outputted, the editor only needs to call DevKitARM to comple it.
_________________
DS - It's all about DiscoStew

#27128 - MumblyJoe - Mon Oct 04, 2004 6:39 am

You could force people to set some configuration settings first for what compilers they are using, then test them to ensure they are valid, then output the files and compile and delete them etc, but it seems like alot of work, and I suggest a better way below.

My best advice would be to make the program output a binary file people can put into thier project (there are several ways people can do this) and supply a header file and library to use this data.

This way the header can have functions to do whatever you need them to, this is necessary to expose to the user because they have to use it. The library is precompiled (several versions for thumb,arm,thumb with interwork, arm with thumb interwork etc) so that is as hidden from the user as it ever will be. And lastly your program outputs binary files with a structure that isn't known by the header file but is known by the library.

Of course if people want to they will always find a way to decode your formats, but they wont ever want to if you supply them with everything they need to use the formats.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#27131 - DiscoStew - Mon Oct 04, 2004 8:22 am

MumblyJoe wrote:
My best advice would be to make the program output a binary file people can put into thier project (there are several ways people can do this) and supply a header file and library to use this data.
I wish I knew how to do this. Would you be able to direct me to some methods to do this?

Or for those people wanting to look throughthe generated C files, I could really tick them off by messing with the naming conventions, and perhaps even the member variables in the structure themselves. Besides, the editors will just take the ouputted files and generate object files through DevKitARM, then delete the old files. If they do get a hold of those C files, they can deal with the horrendous names and symbols my editor will generate. The library and the header containing the function prototypes and error values will obviously not be tampered with. It sounds good, what do you think? Perhaps I'm getting a little too crazy here..... =P
_________________
DS - It's all about DiscoStew

#27135 - torne - Mon Oct 04, 2004 1:10 pm

Use GNU libbfd to directly generate ELF object files programatically, if you want to do it that way.

#27136 - poslundc - Mon Oct 04, 2004 2:10 pm

I think if you are considering screwing around with your internal file format to purposefully obfuscate the meaning of your code, then you ought to revisit your reasons both for creating this tool for the public and for trying to hide the structure.

Remember that even if you precompile the code the user is still going to require access to the data layout (in the form of a header file) in order to make use of it.

So far tepples' suggestion of piping into GAS (or in my case I would probably create a temporary file and run GAS on it) is the one I would go with for easy programmatic creation of object files.

Dan.

#27148 - DiscoStew - Mon Oct 04, 2004 6:20 pm

poslundc wrote:
I think if you are considering screwing around with your internal file format to purposefully obfuscate the meaning of your code, then you ought to revisit your reasons both for creating this tool for the public and for trying to hide the structure.

Remember that even if you precompile the code the user is still going to require access to the data layout (in the form of a header file) in order to make use of it.

Perhaps I should explain a little more about the libraries I am making. The way my library access the data in the object file is by indexes. No need to access the data directly, or by sending in a pointer of a structure. Therefore, it doesn't matter if people don't understand the data as long as the library know how to use it, and that there is explanation as to what the functions do and the library in whole.

I had been looking at the ASM code that jd's AAS convert program outputs for his audio library, and although I don't know what his format is, I do see how he sets up his things. All structures that are the same are placed sequentially, and other stuctures using another structure just use indexing, since the library would know how big the structures. Is this the idea that you and tepples are pointing me towards?
_________________
DS - It's all about DiscoStew

#27156 - sajiimori - Mon Oct 04, 2004 10:39 pm

You'll have to forgive us, DiscoStew, if we can't offer the answers you want when your goal is obfuscation. Most good programmers spend their effort on trying to make things clearer and simpler, and that sort of expertise is unlikely to help you in this case.

#27160 - DiscoStew - Tue Oct 05, 2004 2:07 am

Why does it feel like I just got insulted? If you didn't mean to, then it's ok, but doesn't anyone understand what I mean?

All I wanted to do was take the outputted C arrays and structures from the editor and directly compile it into an object file. If I wanted to do that, why would it matter if that data was understandable? All it is is just plain data, not code. No one needs to see it, therefore it doesn't matter is it is understandable.

You know what? Just forget it. I appreciate the help given.
_________________
DS - It's all about DiscoStew

#27162 - tepples - Tue Oct 05, 2004 3:02 am

torne wrote:
Use GNU libbfd to directly generate ELF object files programatically, if you want to do it that way.

This would place your program under the GPL. The non-infectious way to interact with libbfd is by piping into as.

Or you can output C code to a randomly named file in the system temp folder (%TEMP% on windows or $TMP on unix), compile that with GCC to an object file, and then delete the temporary file. In fact, GCC does exactly that with the assembly language files it generates.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#27166 - fabel - Tue Oct 05, 2004 7:35 am

tepples wrote:
torne wrote:
Use GNU libbfd to directly generate ELF object files programatically, if you want to do it that way.

This would place your program under the GPL. The non-infectious way to interact with libbfd is by piping into as.


Thank you for making my night, that line just totally cracked me up =).

#27167 - sajiimori - Tue Oct 05, 2004 7:59 am

Quote:
No one needs to see it, therefore it doesn't matter is it is understandable.
I wasn't trying to be insulting, but I'm not suprised that people aren't understanding you. The above quote is a much less severe statement than the following:
Quote:
I don't want people looking through the exported files created by the editors.
Do you see how we might interpret that as a desire for obfuscation or some other kind of intentional obscurity?

I also wasn't suggesting that you must be a bad programmer if you are interested in intentional obfuscation. On the contrary, some of the most brilliant programmers of our time have been pioneers in the field of encryption. Still, if that's your area of interest, gbadev is probably not a good place to find experts in the field.

#27169 - DiscoStew - Tue Oct 05, 2004 9:18 am

Don't you just hate it when you mean to say one thing, but end up saying something that people interpret as something else? Then you get all frustrated because you (yourself) understand what you mean to say, but everyone else still interprets it differently?
Right now I'm feeling pretty dumb because you brought up a quote that I see now would lead people to think "WTH!?" You even brought up the subject of encryption which was something I wasn't even heading towards. Dang it! I'm confusing everyone here!

I'll probably just go with the method described by tepples and poslundc (even myself at the time I was confusing everyone) to just output it normally, but to some file in some folder, generate the object file, and delete the unneeded. Plain and simple.

Now, I'll just go back into my little cave and practice my social skills. I apologize for my bad mind-to-mouth-to-hands-to-keyboard skills.
_________________
DS - It's all about DiscoStew