Open Design and Integration Environment

Hex Artifact Content
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com or submit via the online form
by Aug 20.

Artifact 6d395bac20364951b16996d2c75efe55f67b441a:

Wiki page [Obfuscating Source Code in Toadkit] by hypnotoad 2017-08-30 22:41:43.
0000: 44 20 32 30 31 37 2d 30 38 2d 33 30 54 32 32 3a  D 2017-08-30T22:
0010: 34 31 3a 34 33 2e 33 38 30 0a 4c 20 4f 62 66 75  41:43.380.L Obfu
0020: 73 63 61 74 69 6e 67 5c 73 53 6f 75 72 63 65 5c  scating\sSource\
0030: 73 43 6f 64 65 5c 73 69 6e 5c 73 54 6f 61 64 6b  sCode\sin\sToadk
0040: 69 74 0a 55 20 68 79 70 6e 6f 74 6f 61 64 0a 57  it.U hypnotoad.W
0050: 20 31 34 33 30 0a 54 6f 61 64 6b 69 74 73 20 69   1430.Toadkits i
0060: 6e 63 6c 75 64 65 20 73 65 76 65 72 61 6c 20 74  nclude several t
0070: 6f 6f 6c 73 20 74 6f 20 61 6c 6c 6f 77 20 64 65  ools to allow de
0080: 76 65 6c 6f 70 65 72 73 20 74 6f 20 6f 62 66 75  velopers to obfu
0090: 73 63 61 74 65 20 74 68 65 20 54 63 6c 20 73 6f  scate the Tcl so
00a0: 75 72 63 65 20 63 6f 64 65 20 65 6d 62 65 64 64  urce code embedd
00b0: 65 64 20 69 6e 20 61 20 56 46 53 2e 20 54 6f 61  ed in a VFS. Toa
00c0: 64 6b 69 74 73 20 74 61 6b 65 20 74 68 65 20 61  dkits take the a
00d0: 70 70 72 6f 61 63 68 20 6f 66 20 4f 4e 4c 59 20  pproach of ONLY 
00e0: 6f 62 66 75 73 63 61 74 69 6e 67 20 69 6e 64 69  obfuscating indi
00f0: 76 69 64 75 61 6c 20 66 69 6c 65 73 2e 20 54 68  vidual files. Th
0100: 65 20 72 65 61 73 6f 6e 73 20 61 72 65 20 6d 61  e reasons are ma
0110: 6e 79 2c 20 61 6e 64 20 73 68 6f 75 6c 64 20 62  ny, and should b
0120: 65 20 6f 62 76 69 6f 75 73 20 74 6f 20 61 6e 79  e obvious to any
0130: 6f 6e 65 20 66 61 6d 69 6c 69 61 72 20 77 69 74  one familiar wit
0140: 68 20 65 6e 63 72 79 70 74 69 6f 6e 2e 0d 0a 0d  h encryption....
0150: 0a 54 6f 61 64 6b 69 74 73 20 69 6e 63 6c 75 64  .Toadkits includ
0160: 65 20 6f 64 69 65 6c 62 2c 20 77 68 69 63 68 20  e odielb, which 
0170: 67 65 6e 65 72 61 74 65 73 20 61 20 72 61 6e 64  generates a rand
0180: 6f 6d 20 70 61 73 73 77 6f 72 64 20 61 6e 64 20  om password and 
0190: 65 6d 62 65 64 73 20 69 74 20 69 6e 20 43 2e 20  embeds it in C. 
01a0: 54 68 61 74 20 73 65 63 72 65 74 20 6b 65 79 20  That secret key 
01b0: 69 73 20 61 76 61 69 6c 61 62 6c 65 20 69 6e 20  is available in 
01c0: 74 68 65 20 62 75 69 6c 64 20 73 79 73 74 65 6d  the build system
01d0: 20 61 73 20 22 70 61 73 73 77 6f 72 64 2e 74 78   as "password.tx
01e0: 74 22 20 69 6e 20 74 68 65 20 62 75 69 6c 64 20  t" in the build 
01f0: 64 69 72 65 63 74 6f 72 79 2e 20 28 59 6f 75 20  directory. (You 
0200: 63 61 6e 20 61 6c 73 6f 20 70 72 6f 76 69 64 65  can also provide
0210: 20 61 20 6d 61 6e 75 61 6c 20 70 61 73 73 77 6f   a manual passwo
0220: 72 64 20 62 79 20 72 65 70 6c 61 63 69 6e 67 20  rd by replacing 
0230: 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66 20  the contents of 
0240: 74 68 61 74 20 66 69 6c 65 20 77 69 74 68 20 79  that file with y
0250: 6f 75 72 20 6f 77 6e 20 63 68 6f 73 65 6e 20 73  our own chosen s
0260: 74 72 69 6e 67 2e 29 0d 0a 0d 0a 41 6c 73 6f 20  tring.)....Also 
0270: 65 6d 62 65 64 64 65 64 20 69 6e 20 6f 64 69 65  embedded in odie
0280: 6c 69 62 20 69 73 20 74 68 65 20 66 6f 6c 6c 6f  lib is the follo
0290: 77 69 6e 67 20 63 6f 6d 6d 61 6e 64 3a 20 3c 62  wing command: <b
02a0: 3e 3a 3a 6b 69 74 3a 3a 63 72 79 70 74 5f 65 76  >::kit::crypt_ev
02b0: 61 6c 3c 2f 62 3e 2e 20 54 68 69 73 20 63 6f 6d  al</b>. This com
02c0: 6d 61 6e 64 20 63 61 6e 20 64 69 72 65 63 74 6c  mand can directl
02d0: 79 20 65 78 65 63 75 74 65 20 61 20 62 6c 6f 63  y execute a bloc
02e0: 6b 20 6f 66 20 63 6f 64 65 20 74 68 61 74 20 77  k of code that w
02f0: 61 73 20 6f 62 66 75 73 63 61 74 65 64 20 77 69  as obfuscated wi
0300: 74 68 20 74 68 65 20 65 6d 62 65 64 64 65 64 20  th the embedded 
0310: 6b 65 79 2e 0d 0a 0d 0a 54 68 65 20 6b 69 74 20  key.....The kit 
0320: 61 6c 73 6f 20 68 61 73 20 61 20 62 75 69 6c 74  also has a built
0330: 20 69 6e 20 66 75 6e 63 74 69 6f 6e 20 74 6f 20   in function to 
0340: 67 65 6e 65 72 61 74 65 20 61 6e 20 6f 62 66 75  generate an obfu
0350: 73 63 61 74 65 64 20 62 6c 6f 63 6b 20 6f 66 20  scated block of 
0360: 63 6f 64 65 3a 20 3c 62 3e 3a 3a 6b 69 74 3a 3a  code: <b>::kit::
0370: 65 6e 63 72 79 70 74 3c 2f 62 3e 2e 20 54 68 65  encrypt</b>. The
0380: 20 64 65 66 61 75 6c 74 20 69 6d 70 6c 65 6d 65   default impleme
0390: 6e 74 61 74 69 6f 6e 20 75 73 65 73 20 61 20 62  ntation uses a b
03a0: 61 72 65 20 6b 69 74 20 63 6f 6d 70 69 6c 65 64  are kit compiled
03b0: 20 77 69 74 68 6f 75 74 20 61 6e 20 61 74 74 61   without an atta
03c0: 63 68 65 64 20 56 46 53 20 74 6f 20 61 63 74 20  ched VFS to act 
03d0: 61 73 20 61 20 73 68 65 6c 6c 20 74 6f 20 72 75  as a shell to ru
03e0: 6e 20 74 68 65 20 73 63 6d 2d 63 6f 70 79 2e 74  n the scm-copy.t
03f0: 63 6c 20 73 63 72 69 70 74 20 64 69 73 74 72 69  cl script distri
0400: 62 75 74 65 64 20 69 6e 20 74 68 65 20 3c 61 20  buted in the <a 
0410: 68 72 65 66 3d 2f 66 6f 73 73 69 6c 2f 6f 64 69  href=/fossil/odi
0420: 65 2f 64 69 72 3f 63 69 3d 74 69 70 26 6e 61 6d  e/dir?ci=tip&nam
0430: 65 3d 73 63 72 69 70 74 73 3e 73 63 72 69 70 74  e=scripts>script
0440: 73 3c 2f 61 3e 20 66 6f 6c 64 65 72 2e 0d 0a 0d  s</a> folder....
0450: 0a 49 6e 73 74 65 61 64 20 6f 66 20 63 6f 70 79  .Instead of copy
0460: 69 6e 67 20 74 68 65 20 66 69 6c 65 73 20 69 6e  ing the files in
0470: 74 6f 20 74 68 65 20 56 46 53 20 64 69 72 65 63  to the VFS direc
0480: 74 6f 72 79 2c 20 74 68 65 20 6d 61 6b 65 20 73  tory, the make s
0490: 79 73 74 65 6d 20 62 75 69 6c 64 20 61 6e 20 6f  ystem build an o
04a0: 62 66 75 73 63 61 74 65 64 20 76 65 72 73 69 6f  bfuscated versio
04b0: 6e 20 69 6e 20 74 68 65 20 56 46 53 2c 20 75 73  n in the VFS, us
04c0: 69 6e 67 20 74 68 69 73 20 62 6c 6f 63 6b 20 6f  ing this block o
04d0: 66 20 63 6f 64 65 3a 0d 0a 3c 76 65 72 62 61 74  f code:..<verbat
04e0: 69 6d 3e 0d 0a 20 20 73 65 74 20 56 46 53 20 5b  im>..  set VFS [
04f0: 66 69 6c 65 20 6a 6f 69 6e 20 24 43 57 44 20 74  file join $CWD t
0500: 6f 61 64 6b 69 74 2e 76 66 73 5d 0d 0a 20 20 66  oadkit.vfs]..  f
0510: 69 6c 65 20 6d 6b 64 69 72 20 24 56 46 53 0d 0a  ile mkdir $VFS..
0520: 20 20 23 20 43 6f 70 79 20 69 6e 20 6f 75 72 20    # Copy in our 
0530: 22 73 65 63 72 65 74 20 73 71 75 69 72 72 65 6c  "secret squirrel
0540: 22 20 63 6f 64 65 0d 0a 20 20 73 65 74 20 53 43  " code..  set SC
0550: 4d 43 4f 50 59 20 5b 6c 69 73 74 20 3a 3a 65 78  MCOPY [list ::ex
0560: 65 63 20 5b 42 41 53 45 4b 49 54 20 64 65 66 69  ec [BASEKIT defi
0570: 6e 65 20 67 65 74 20 74 63 6c 6b 69 74 5f 62 61  ne get tclkit_ba
0580: 72 65 5d 20 5b 66 69 6c 65 20 6a 6f 69 6e 20 24  re] [file join $
0590: 3a 3a 53 52 43 44 49 52 20 73 63 72 69 70 74 73  ::SRCDIR scripts
05a0: 20 73 63 6d 2d 63 6f 70 79 2e 74 63 6c 5d 5d 0d   scm-copy.tcl]].
05b0: 0a 20 20 7b 2a 7d 24 53 43 4d 43 4f 50 59 20 5b  .  {*}$SCMCOPY [
05c0: 66 69 6c 65 20 6a 6f 69 6e 20 24 3a 3a 53 52 43  file join $::SRC
05d0: 44 49 52 20 73 72 63 5d 20 24 7b 56 46 53 7d 0d  DIR src] ${VFS}.
05e0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0a 5a 20 61  .</verbatim>.Z a
05f0: 31 31 63 63 37 37 62 64 61 33 63 32 33 66 37 35  11cc77bda3c23f75
0600: 64 64 35 31 65 65 35 35 65 63 38 65 37 35 34 0a  dd51ee55ec8e754.