Jump to content


Photo

Create Exes With Gml (tut+gml+sample Program)


  • Please log in to reply
90 replies to this topic

#1 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 20 July 2007 - 08:36 PM


Creating executable files in GM - A how to tutorial


-- Intro on creating EXEs
So how do we create exe's in GM? Some time ago, I discovered that I could add text to the end of the GM exes without harming/corrupting them. So this opened the world of creating exe with GM but without extra files. This is done by having an exe that read itself (ie in the start of game) and check for the extra text, which could be simply GML code.
The problem with finding the text is how to know it was found. So I built up a "header" system, were some text shows that the extra text is starting.

-- Tutorial intro
Next, what we will do is create two actual GM projects.
The first project is the exe that reads itself for the extra code. (named 'p1').
The second project will be used to create the exe's, (we will name this and refer to as 'p2').

-- Project P1 (exe template)
Let's start with 'p1'. First add a new script named "exe_read()", the code is found here.
Then add a new object and put it in one room. Put the following code in an "Execute code" action, in the Create event:
var t,n;
  n=string(round(random(99999)))
  t=exe_read("ThisIsTheCodeHeader",n)
  if (t=n) {
	show_message("Error: No extra code found.")
	game_end()
  } else {
	execute_string(t)
  }
This code will read the exe's extra data using the header 'ThisIsTheCodeHeader' and if no code is found then the text in variable n is returned. Then if the returned code is equal to n (no code found), show error and end game, else run the code.
Next we will put up some tricky things, we will search for special variables found in the extra code. These variables were never created by our program.
Create an 'Execute code' action in 'Step' event and add the following code:
if variable_global_exists("sc_step") then execute_string(global.sc_step)
Then add the following code to an 'Execute code' action in a 'game end' event:
if variable_global_exists("sc_end") then execute_string(global.sc_end)
Then add the following code to an 'Execute code' action in a 'draw' event:
if variable_global_exists("sc_draw") then execute_string(global.sc_draw)
And lastly add the following code in the 'Execute code' action in the 'Create' event, JUST AFTER the code we already did there.
if variable_global_exists("sc_create") then execute_string(global.sc_create)
And thats done the sample named 'p1' exe is done. Save all and build it into a program. (make sure it is named p1.exe)

-- Project P2 (exe writer)
Next p2 is very much simpler, it will 'create' the exe files
Create a new object and a new room. Put the object in the room. Add the following code in the "Execute Code" action of SPACE RELEASED event:
var a,b,c,d,e,f;
show_message("This will create exes with your own code. Press OK to continue.")
a=get_string("Enter game start code:","show_message('Hello Sir!!') s=0")
b=get_string("Enter game step code:","s+=1")
c=get_string("Enter game draw code:","draw_text(0,0,string(s))")
d=get_string("Enter game end code:","show_message('Bye Sir!!')")
e=get_save_filename("Executables|*.exe","Test.exe")
if file_exists(e) then if show_question("WARNING: File already exists. Rewrite?")=false then exit
if file_exists(e) then file_delete(e)
file_copy('p1.exe',e)
f=file_text_open_append(e)
file_text_writeln(f)
file_text_write_string(f,"ThisIsTheCodeHeader")
file_text_writeln(f)
file_text_write_string(f,'global.sc_create="'+a+'" global.sc_step="'+b+'" global.sc_draw="'+c+'" global.sc_end="'+d+'"')
file_text_close(f)
if show_question("File created. Do you want to execute it?") then execute_program(e,"",false)
Save the program and run it. Make sure that p1.exe is in the same directory as this program's gm6 file. When it has started press space.
This will show a series of messages were you enter the new program's code. Then at last you will be asked were to save the file. Afterwords you have the option to test the file by running it, you should click 'yes'.
Note that there is already code in the code messages. To test everything, you should continue with changing the code. As you might have guessed, the program starts and shows a "Hello sir" message. Then it increases a variable "s", which was declared in the first code message. The contents of this variable are drawn in the new program's window (you should see an increasing number). When you close the program, a "Bye sir" message is shown.

-- Encryption, security and compression
Note that the code is writen in the resulting exe as is, uncompressed and unencrypted. Another security risk is that the code read is directly used in execute_string() which may pose a risk to resource unpacking (GMResUnpack TID 129). To avoid execute_string() attack, use security scripts found here: Security Scripts

-- Legality
The software/scripts does not break any GM license (6.x and below). I am not sure this is the same for gm7 as the licence is not clear about this. According to some friends it is legal though, as the licence covers the runner part of exes.

-- Download Sample
After several requests for making some sample program and putting the tutorial code into a GM program, (well two of them), I decided to do it.
Covac Website (Main mirror)
Host-A.net (Secondary Mirror)
To use it, run p2.exe and press SPACE.

(Tutorial as written in Romania's message May 26 2007, 07:26 PM)

Good Luck with creating exe's!
There is no limit to what GM can do! (if there is, I didn't find it yet)

Regards,
Christian Sciberras ~ creator

edit: fixed typo and link to script (how the heck did I manage to loose the link?)
edit: renamed script variables.
edit: definately fixed it.
edit: added sample GM programs and their gm6 source code.
edit: fixed download link.

Edited by uuf6429, 07 August 2009 - 12:00 PM.

  • 1

#2 werewolf688

werewolf688

    Real Werewolf

  • New Member
  • 151 posts

Posted 21 July 2007 - 07:54 PM

^_^ I always wanted someting like this.
[EDIT]Under the Legality header, you spelled friends wrong.

Edited by werewolf688, 21 July 2007 - 08:01 PM.

  • 0

#3 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 21 July 2007 - 10:47 PM

Let's start with 'p1'. First add a new script named "exe_read()", the code is found here

<{POST_SNAPBACK}>

Where?
  • 0

#4 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 24 July 2007 - 08:23 PM

Done!
I can't believe I forgot to put the link to the most important script in this thread!
Thanks for the notes guys!
  • 0

#5 Sandro

Sandro

    GMC Member

  • New Member
  • 184 posts

Posted 28 July 2007 - 07:03 PM

WOW, I never knew you could do that...This will help a lot, thanks
  • 0

#6 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 29 July 2007 - 04:58 PM

Thanks for the comments!
400+ views! Not bad <_<
  • 0

#7 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 01 August 2007 - 12:30 AM

Is it me, or is it packed with errors? Could it be because I am using gm7?
  • 0

#8 LuizZak

LuizZak

    GMC Member

  • New Member
  • 78 posts

Posted 03 August 2007 - 01:35 PM

cool, and no it does not break EULA, rules or something like that. Wathever you made on GM it's your problem (ON GM, not WITH gm). debugger for my games so I can test vulnerabilities for it. (using DLLs, of course)

Edited by LuizZak, 03 August 2007 - 01:36 PM.

  • 0

#9 3t3rNAL_Payn

3t3rNAL_Payn

    The Human Genocide

  • New Member
  • 1096 posts

Posted 03 August 2007 - 02:07 PM

You use execute_string.

This is a very slow function.

You should replace it with the following:
object_event_add(self,ev_alarm,0,t)
alarm[0] = 1


I believe that code works, but I'm not entirely sure.


Other than that, this is actually a very incredible discovery. This could be used to add expansions and patches very easily.

Good work, man!
  • 0

#10 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 03 August 2007 - 06:39 PM

Thanks for the replies!
@ Hockeyflyers - It was designed for gm6 but, I think it should work for Gm7, so what's your problems?
@ LuizZak - That should be true, but I'm not using Gm7 right now, soI ain't too sure.
@ 3t3rNAL_Payn - That should work and yes, it's faster, but I wanted to put up a very simple example, that's why there isn't any real encryption or compression.

Regards,
Christian Sciberras

Edited by uuf6429, 03 August 2007 - 06:40 PM.

  • 0

#11 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 03 August 2007 - 10:33 PM

@ Hockeyflyers - It was designed for gm6 but, I think it should work for Gm7, so what's your problems?

<{POST_SNAPBACK}>

First, you used global.end, and since end is a statement in gml, it will return an error. I easily fixed that with global.End. Then, I got errors in the strings, I forgot the exact error. Is it registered only? Because I could try it with gm6 to see what happens.

Edited by Hockeyflyers, 11 April 2010 - 08:06 PM.

  • 0

#12 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 04 August 2007 - 12:23 AM

For me it worked fine, but I'll recheck it anyway.
Edit: Renamed all variables with 'sc_' prefix.

Edited by uuf6429, 04 August 2007 - 12:28 AM.

  • 0

#13 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 04 August 2007 - 01:27 AM

Well, in gm6, I got this error:
---------------------------
Error
---------------------------
COMPILATION ERROR in string to be executed
Error in code at line 1:
   global.sc_create='show_message('Hello Sir!!') s=0' global.sc_step='s+=1' global.sc_draw='draw_text(0,0,string(s))' global.sc_end='show_message('Bye Sir!!')'

at position 39: Assignment operator expected.
---------------------------
Abort   Ignore   
---------------------------
By pressing ctrl+c (pressing those buttons copies text from windows message boxes, in case you didn't know :lol: )
I am assuming you should put double quotes between Hello Sir!! and Bye Sir!!. I'll try it.

Edit: Yep, it worked!!

Edited by Hockeyflyers, 04 August 2007 - 01:29 AM.

  • 0

#14 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 04 August 2007 - 12:38 PM

I fixed it now it should work.
  • 0

#15 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 04 August 2007 - 01:10 PM

Just fix one more error and your done!
replace this:
file_text_write_string(f,'global.sc_create="'+a+'" global.sc_step="'+b+'" global.sc_draw="'+c+'" global.sc_end='"+d+'"')

with this:
file_text_write_string(f,'global.sc_create="'+a+'" global.sc_step="'+b+'" global.sc_draw="'+c+'" global.sc_end="'+d+'"')
You switched a single quote with a double quote at position 115. :)
Fix that and this is awesome!!

Edited by Hockeyflyers, 04 August 2007 - 01:11 PM.

  • 0

#16 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 04 August 2007 - 01:19 PM

Arrgghh!!! BUGS!! I'll do it.

Edit: DONE.

Edited by uuf6429, 04 August 2007 - 01:20 PM.

  • 0

#17 cbruno (brazil)

cbruno (brazil)

    GMC Member

  • New Member
  • 56 posts

Posted 04 August 2007 - 07:48 PM

^^ places an example here

It does not find odd my English, I am Brazilian xD

Please: It places in gm6, gm7 does not function here.

Edited by cbruno (brazil), 04 August 2007 - 07:51 PM.

  • 0

#18 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 04 August 2007 - 09:38 PM

Sorry mate, can't understand the wording, what do you mean?
  • 0

#19 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 04 August 2007 - 10:10 PM

I'm thinking he wants a gm6/gmk example?
  • 0

#20 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 04 August 2007 - 10:13 PM

Ok, I'll do it.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users