Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Obscuring your code
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Wed 24 Nov 2004 06:32 PM (UTC) |
Message
| I have been asked a couple of times if it is possible to obscure scripts, so plugin authors can hide their workings (with a view to getting a fee, I think).
With Lua this is reasonably possible, although bear in mind any copy protection scheme can be cracked if you try hard enough.
Basically you write your script/plugin or whatever "in the clear" first to test it. Then when you are ready, save the script part to a separate file, (eg. myscript.lua) and then use the Lua standalone compiler to "compile" it. This produces byte-code (intermediate interpreter code, not machine code) that can be read by Lua.
eg.
Test file: test.lua
print ("Hello, world")
table.foreach (string, print)
print "done"
Compile it:
luac -o test.luac test.lua
Run it:
Inside your script file load the compiled file:
The 'dofile' command will load both source or object, auto-detecting the difference.
You can list the "object", and get some information from it, however if suitably obscured then it should hide what you are doing:
luac -l test.luac
main <test.lua:0> (12 instructions, 48 bytes at 00411590)
0 params, 3 stacks, 0 upvalues, 0 locals, 6 constants, 0 functions
1 [1] GETGLOBAL 0 0 ; print
2 [1] LOADK 1 1 ; "Hello, world"
3 [1] CALL 0 2 1
4 [3] GETGLOBAL 0 2 ; table
5 [3] GETTABLE 0 0 253 ; "foreach"
6 [3] GETGLOBAL 1 4 ; string
7 [3] GETGLOBAL 2 0 ; print
8 [3] CALL 0 3 1
9 [5] GETGLOBAL 0 0 ; print
10 [5] LOADK 1 5 ; "done"
11 [5] CALL 0 2 1
12 [5] RETURN 0 1 0
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #1 on Thu 25 Nov 2004 12:49 PM (UTC) |
Message
| By the way, compiling your script is also a way to speed up the parsing process (if it's anything like Python, that is), since what it does is probably parse the script and then dump the entire parser tree in the compiled file, so the next time you use it, it doesn't have to be parsed again. |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Thu 25 Nov 2004 06:35 PM (UTC) |
Message
| True, however I am finding the parser is pretty fast. And, for scripts and plugins it is parsed once anyway.
When you (re-)load your script file or plugin, it passes the script to the parser as part of creating the Lua "state". Then later on when you call functions from triggers etc. that is the pre-parsed code that is called. The same remark applies to other languages, assuming that they pre-parse as well.
The savings would be very slight. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Michen
(6 posts) Bio
|
Date
| Reply #3 on Fri 30 Jan 2015 04:48 AM (UTC) |
Message
| Compile error
World: HSZ
Immediate execution
Script file: bad header in precompiled chunk
allways got this error....
Nick Gammon said:
I have been asked a couple of times if it is possible to obscure scripts, so plugin authors can hide their workings (with a view to getting a fee, I think).
With Lua this is reasonably possible, although bear in mind any copy protection scheme can be cracked if you try hard enough.
Basically you write your script/plugin or whatever "in the clear" first to test it. Then when you are ready, save the script part to a separate file, (eg. myscript.lua) and then use the Lua standalone compiler to "compile" it. This produces byte-code (intermediate interpreter code, not machine code) that can be read by Lua.
eg.
Test file: test.lua
-----
print ("Hello, world")
table.foreach (string, print)
print "done"
-----
Compile it:
luac -o test.luac test.lua
Run it:
Inside your script file load the compiled file:
The 'dofile' command will load both source or object, auto-detecting the difference.
You can list the "object", and get some information from it, however if suitably obscured then it should hide what you are doing:
luac -l test.luac
main <test.lua:0> (12 instructions, 48 bytes at 00411590)
0 params, 3 stacks, 0 upvalues, 0 locals, 6 constants, 0 functions
1 [1] GETGLOBAL 0 0 ; print
2 [1] LOADK 1 1 ; "Hello, world"
3 [1] CALL 0 2 1
4 [3] GETGLOBAL 0 2 ; table
5 [3] GETTABLE 0 0 253 ; "foreach"
6 [3] GETGLOBAL 1 4 ; string
7 [3] GETGLOBAL 2 0 ; print
8 [3] CALL 0 3 1
9 [5] GETGLOBAL 0 0 ; print
10 [5] LOADK 1 5 ; "done"
11 [5] CALL 0 2 1
12 [5] RETURN 0 1 0
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Fri 30 Jan 2015 05:17 AM (UTC) |
Message
| Possibly you are using a different version of lua (luac) than MUSHclient uses. Without a lot more information (eg. version numbers) it is very hard to say. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Michen
(6 posts) Bio
|
Date
| Reply #5 on Fri 30 Jan 2015 07:43 AM (UTC) |
Message
| I use mushclient 4.92,which lua version can I use?
Nick Gammon said:
Possibly you are using a different version of lua (luac) than MUSHclient uses. Without a lot more information (eg. version numbers) it is very hard to say.
| Top |
|
Posted by
| Michen
(6 posts) Bio
|
Date
| Reply #6 on Fri 30 Jan 2015 07:48 AM (UTC) |
Message
| I will try lua 5.1.1,thanks~:)
Michen said:
I use mushclient 4.92,which lua version can I use?
Nick Gammon said:
Possibly you are using a different version of lua (luac) than MUSHclient uses. Without a lot more information (eg. version numbers) it is very hard to say.
| Top |
|
Posted by
| Michen
(6 posts) Bio
|
Date
| Reply #7 on Fri 30 Jan 2015 07:51 AM (UTC) |
Message
| It's ok now~~~~
Michen said:
I will try lua 5.1.1,thanks~:)
Michen said:
I use mushclient 4.92,which lua version can I use?
Nick Gammon said:
Possibly you are using a different version of lua (luac) than MUSHclient uses. Without a lot more information (eg. version numbers) it is very hard to say.
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #8 on Fri 30 Jan 2015 09:03 PM (UTC) |
Message
|
Quote:
Reply #2 on Fri 26 Nov 2004 05:35 AM
...
Reply #3 on Fri 30 Jan 2015 03:48 PM
I'm puzzled as to how you replied to that old thread. It's just that I added "anti-thread-necro" code a while back (like, last year) and it shouldn't be possible to reply to a 9-year old thread.
Was there a "reply" link (do you recall?) or did you manipulate the URL at the top of the page to get a reply through?
I ask because there may be some bug in the forum software. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Fri 30 Jan 2015 11:39 PM (UTC) |
Message
| Never mind, I worked it out. The "quote" link was active when it should not have been. Fixed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
26,808 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top