Random Homebrew: AiTetris
tetris clone
Friends: Coding 'n Cracking - Nymphaea - PS3 Forum - darkforestgroup - daxhordes.org - Tgames - coldbird - gopsp.it - pspstation.org - prometheus - hgoel.info - MakeSmartTV - ps vita

Tutorial: Interpreting C and compiling Python

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device

Tutorial: Interpreting C and compiling Python

Postby Acid_Snake » Fri Jul 06, 2012 3:12 pm

No, it's not a mistake in the subject name. You can actually interpret C and compile Python. I don't know how viable this is, but it should work with small programs.

- Compiling Python.
There are some tools like py2exe and py2app, but I recommend cxfreeze since it works with Linux.
Download it: http://prdownloads.sourceforge.net/cx-f ... z?download
Unpack it and install it with:
Code: Select all
python setup.py build
python setup.py install

Compile your code with:
Code: Select all
cxfreeze name_of_script.py

It should create a folder name build, inside is your compiled script.

- Interpreting C.
You need to install tcc:
Code: Select all
sudo apt-get install tcc

Just add this line at the beginning of your .c file:
Code: Select all
#! /usr/bin/tcc -run

You can also run code directly from the command line:
Code: Select all
echo 'main(){puts("hello world");}' | tcc -run -


Notes:
What the C interpreter actually does is compile the code into memory and run it, which is basically what interpreters do.
Cxfreeze on the other hand runs the code in the python interpreter and freezes the output to a binary file.
"V2h5IGFyZSB5b3UgcmVhZGluZyBteSBzaWduYXR1cmU/\n".decode("base64")
My forum:
Console Heaven
My Homebrews:
pyMenu 0.3.2, multiBootMenu V3, PSvid 3.0, PSP Tools 0.2
User avatar
Acid_Snake
Moderator
 
Posts: 2051
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Tutorial: Interpreting C and compiling Python

Postby m0skit0 » Mon Jul 09, 2012 11:52 am

Compiling Python and interpreting C gets rid of one of their strongest points.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4787
Joined: Mon Sep 27, 2010 6:01 pm

Re: Tutorial: Interpreting C and compiling Python

Postby Acid_Snake » Mon Jul 09, 2012 12:55 pm

never thought of it that way. I don't really compile my scripts, there isn't any difference.
"V2h5IGFyZSB5b3UgcmVhZGluZyBteSBzaWduYXR1cmU/\n".decode("base64")
My forum:
Console Heaven
My Homebrews:
pyMenu 0.3.2, multiBootMenu V3, PSvid 3.0, PSP Tools 0.2
User avatar
Acid_Snake
Moderator
 
Posts: 2051
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Tutorial: Interpreting C and compiling Python

Postby m0skit0 » Mon Jul 09, 2012 2:09 pm

Compiling scripts really makes little to no sense, since they would lose portability and the speed gain is negligible.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4787
Joined: Mon Sep 27, 2010 6:01 pm

Re: Tutorial: Interpreting C and compiling Python

Postby asgard20032 » Mon Jul 09, 2012 10:04 pm

One of the strongest advantage to compiling python, JAVA, perl and other interpreted language is to be sure that people will have a hard time to reverse engineer our program. With JAVA, decompiler are easy to find. Obfuscator are bad, they make code slower by make it more bloated, to make it more hard to read. And change function and variable name. But with patience, any java programmer can decompile program that used obfuscator. Also, obfuscator abuse of some thing, that in future revision of JAVA may make the code unable to compile.

I like open-source, lgpl, gpl... But I still think that a programmer should also be able to gain his life by programming, so when I choose a language / API, I MUST HAVE THE OPTION TO HAVE CLOSED SOURCE PROGRAM, even if I will rarely make closed source program, I want to have the option. A programmer should have the freedom to choose how he will distribute his program.
Image
asgard20032
 
Posts: 259
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Re: Tutorial: Interpreting C and compiling Python

Postby m0skit0 » Tue Jul 10, 2012 7:29 am

Sorry, but compiling really does not make them harder to RE. Why? Because you're just switching from one machine code (VM machine code) to native machine code. Really not much difference. Maybe RE native machine code is a bit harder, but even so I won't be so sure. JVM for example enforces a set of security operations, where not all classes can access all features. By compiling Java, you surely lose this, because it's a JVM reponsibility. So security really is NOT a feature of compiled languages. Example: most PC games are made in C/C++, and thus native. Games are most cracked software by far. If you want to protect your code, you have to devise much more advanced techniques than mere compiling.

Also if you think OOS programmers doesn't make a living, just look at Torvalds, Stallman, Google, Sun/Oracle, Apache, Mozilla... and you'll see that you're wrong. I suggest you reading about the business of OOS, which is not the same as Microsoft's closed source model.

asgard20032 wrote:A programmer should have the freedom to choose how he will distribute his program.

Sure, but some languages doesn't offer this "closed" option so want as standard. It's also a freedom of the language designer to offer this option or not, isn't it? Just be sure to choose your language/tools accordingly to your choice before starting to code. If you don't like it because it doesn't allow you to "close" your code (whatever does this mean, RE is always an option, no matter what you do), then simply don't use it. You're free to not using it as well ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4787
Joined: Mon Sep 27, 2010 6:01 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest