View previous topic :: View next topic |
Author |
Message |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Mon Dec 03, 2007 3:18 am Post subject: Save and Encrypt source code in EXE |
|
|
This is some code I made to encrypt the source of a VDS script and allow it to be included as a resource in an EXE so it can be extracted if the original code is lost. This code uses the VDS encryption but can be changed to use blowfish.dll or something like it. I just didn't want to use an external dll to keep the size of the final exe smaller.
Features:
Adds code to extract the source to the original DSC file. To extract the source just pass the "pin" number as %1 to the EXE file.
Adds [DSC Crypt] to the explorer context menu of DSC file for quick encryption.
Except for the extraction code, the original DSC file is left alone. The encrypted code is saved to <Scriptname>.dsc.enc and this is the file that is added as a resource to the EXE.
I think I got it all. Please let me know if there are any questions or problems. Thanks
EDIT: The code has been updated to work as a tool for VDS 6. Compile and put in the Tools folder. It will ask for a PIN and ask if you wish to use the currently loaded project. If you press yes, your project is saved. The code added at the top to extract the source and then reopened and compiled. If you change the pin the pin is updated in the source as well.
Code: |
#-----------------------------------------------------------------------------#
# #
# Author: Chris Gingerich #
# #
# Copyright: 2005 Chris Gingerich of Code714.com #
# #
# Encrypt source to add to EXE file as a resource to get source back if lost #
#-----------------------------------------------------------------------------#
Title DSCCrypt
DIALOG CREATE,DSCCrypt,-1,0,240,160,ontop
DDE LINK, VDS, System
# Pin number for password (must be a number or left blank)
%%pin = @input(Enter 4 digit PIN number,3031)
if @not(@ok())
DDE TERMINATE
stop
end
#%%pin = 3031
#Add to DSC Context MenuMENU
#if @not(@file(@windir()\DSCCrypt.exe))
# File copy,%0,@windir()\DSCCrypt.exe
# %%zip = @regread(root,.dsc)
# if %%zip
# link create,@windir()\DSCCrypt.exe,@windir(SendTo)\,DSC Crypt
# if @not(@ok())
# Warn Link not created!
# end
# registry write,root,%%zip\Shell\[DSC Crypt]\,,
# registry write,root,%%zip\Shell\[DSC Crypt]\command,,@windir()\DSCCrypt.exe @chr(34)"%1"@chr(34)
# end
# stop
#end
if @equal(%1,install)
File copy,%0,@windir()\DSCCrypt.exe
%%zip = @regread(root,.dsc)
if %%zip
link create,@windir()\DSCCrypt.exe,@windir(SendTo)\,DSC Crypt
if @not(@ok())
Warn Link not created!
end
registry write,root,%%zip\Shell\[DSC Crypt]\,,
registry write,root,%%zip\Shell\[DSC Crypt]\command,,@windir()\DSCCrypt.exe @chr(34)"%1"@chr(34)
end
stop
end
#Look to see if VDS Is Running.
if @winexists(#TMainWin)
if @ask(Use currently loaded project in VDS?)
%t = @wintext(#TMainWin)
%p = @pos(":",%t)
%%Proj = @trim(@substr(%t,@pred(%p),@len(%t)))
%p = @path(%%Proj)
%%in = %p@name(%%Proj)".dsc"
%%Reload = 1
DDE Execute,[FILESAVE(%%Proj)]
else
%%in = @filedlg(*.dsc)
if @not(@ok())
DDE TERMINATE
stop
end
end
elsif @not(%1)
%%in = @filedlg(*.dsc)
if @not(@ok())
DDE TERMINATE
stop
end
else
%%in = %1
end
list create,1
list create,2
list create,3
list loadfile,1,%%in
%m = @match(1,"#resource add,TEXT,"@name(%%in))
if @not(%m)
list add,3,"# ======= Begin Get Source ==========================="
list add,3,"#resource add,TEXT,"@name(%%in)".dsc.enc,SCRIPT2"
list add,3," if @equal(%1,"%%pin")"
list add,3," write resource,TEXT,SCRIPT2,@path(%0)@name(%0)"@chr(34)".src"@chr(34)
list add,3," list create,1"
list add,3," list create,2"
list add,3," list loadfile,1,@path(%0)@name(%0)"@chr(34)".src"@chr(34)
list add,3," %x = 0"
list add,3," repeat"
list add,3," list add,2,@encrypt(@item(1,%x),%1)"
list add,3," %x = @succ(%x)"
list add,3," until @equal(%x,@count(1))"
list add,3," list savefile,2,@path(%0)@name(%0)"@chr(34)"_src.dsc"@chr(34)
list add,3," file delete,@path(%0)@name(%0)"@chr(34)".src"@chr(34)
list add,3," stop"
list add,3," end"
list add,3,"# ======== End Get Source ==========================="
list add,3,
list append,3,1
list assign,1,3
list savefile,1,%%in
else
%n = @next(1)
list put,1," if @equal(%1,"%%pin")"
list savefile,1,%%in
end
%x = 0
repeat
list add,2,@encrypt(@item(1,%x),%%pin)
%x = @succ(%x)
until @equal(%x,@count(1))
list savefile,2,%%in".enc"
if %%Reload
DDE EXECUTE,[FILEOPEN(%%Proj)]
DDE Execute,[COMPILE]
DDE TERMINATE
end
stop
|
_________________ Chris
Http://theblindhouse.com
Last edited by LiquidCode on Sun Feb 07, 2010 9:12 pm; edited 1 time in total |
|
Back to top |
|
|
DavidR Contributor
Joined: 05 Aug 2003 Posts: 83 Location: Bethel Pennsylvania U.S.A.
|
Posted: Mon Dec 03, 2007 12:15 pm Post subject: |
|
|
Wow, that's pretty cool. What a great idea, I never thought of doing that!
Just last week I found myself scrambling to locate the source for a program I wrote several years (and several computers) ago.
This way as long as I've got the exe I've got the source!
Thanks!
.......David |
|
Back to top |
|
|
vtol Valued Contributor
Joined: 05 Feb 2004 Posts: 642 Location: Eastern Indiana
|
Posted: Fri Dec 07, 2007 10:44 pm Post subject: |
|
|
cool
That would also be handy remotely when you discover a small fixible for example (path bug) or some other small external bug when in turn allows you to save the day. hmm that reminds me of superman
Not to spoil your fun here, but I've allways wondered what STOP was for, so I'm guessing it is used with bin file applications yes? no?
Thanks |
|
Back to top |
|
|
DaveR Valued Contributor
Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Sat Dec 08, 2007 12:54 am Post subject: |
|
|
vtol wrote: | I've allways wondered what STOP was for |
STOP is for stopping the script.
Because EXIT can sometimes only exit a gosub or user function or command etc it can often not stop the script like you expect it to (if something unexpected has happened). _________________ cheers
Dave |
|
Back to top |
|
|
vtol Valued Contributor
Joined: 05 Feb 2004 Posts: 642 Location: Eastern Indiana
|
Posted: Tue Dec 11, 2007 8:14 pm Post subject: |
|
|
That makes complete sense.
That was allways my guess.
Guess I was hoping for a new function secret, hehe.
Anyways, never needed it so was allways not sure.
Also it may come in handy as a special intentional tool function for a program I guess.
Thanks to you, I feel much better now, and I'm able to walk again |
|
Back to top |
|
|
DavidR Contributor
Joined: 05 Aug 2003 Posts: 83 Location: Bethel Pennsylvania U.S.A.
|
Posted: Wed Feb 06, 2008 1:48 am Post subject: |
|
|
LiquidCode I'm still thrilled with this program. I use it with every .exe I create.
Just A comment for VDS6 users,
Code: | binfile saveres,TEXT,SCRIPT2,@path(%0)@name(%0)".src" |
will need to be replaced by:
Code: | WRITE RESOURCE,TEXT,SCRIPT2,@path(%0)@name(%0)".src" |
...............David |
|
Back to top |
|
|
vdsalchemist Admin Team
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Wed Feb 06, 2008 7:48 pm Post subject: |
|
|
DavidR wrote: | LiquidCode I'm still thrilled with this program. I use it with every .exe I create.
Just A comment for VDS6 users,
Code: | binfile saveres,TEXT,SCRIPT2,@path(%0)@name(%0)".src" |
will need to be replaced by:
Code: | WRITE RESOURCE,TEXT,SCRIPT2,@path(%0)@name(%0)".src" |
...............David |
DavidR,
Do this instead...
Code: |
If @Greater(@Name(@SysInfo(DSVER)),4)
#DEFINE COMMAND,BINFILE,WRITE
#DEFINE FUNCTION,BINFILE,WRITE
End
If @Greater(@Name(@SysInfo(DSVER)),5)
WRITE RESOURCE,TEXT,SCRIPT2,@path(%0)@name(%0)".src"
Else
Binfile saveres,TEXT,SCRIPT2,@path(%0)@name(%0)".src"
End
|
This will allow the same code to work with any version of VDS. _________________ Home of
Give VDS a new purpose!
|
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Sun Feb 07, 2010 9:13 pm Post subject: |
|
|
The code has been updated to work as a tool for VDS 6. Compile and put in the Tools folder. It will ask for a PIN and ask if you wish to use the currently loaded project. If you press yes, your project is saved. The code added at the top to extract the source and then re-opened and compiled. If you change the pin, the pin is updated in the source as well. _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|