Jump to content

CodeCrypter - Encrypt your Script


RTFC
 Share

Recommended Posts

@rootx: your example code requires an external .ini file to function; please supply it, else I cannot test your script.

EDIT: Thinking about this a bit more, do you have obfuscation switched on? Because if your .ini defines variable content and those names have changed, you'd have to edit your ini accordingly.

Edited by RTFC
Link to comment
Share on other sites

4 hours ago, RTFC said:

@rootx: your example code requires an external .ini file to function; please supply it, else I cannot test your script.

EDIT: Thinking about this a bit more, do you have obfuscation switched on? Because if your .ini defines variable content and those names have changed, you'd have to edit your ini accordingly.

!!!Sorry.... I extract from a project on the fly without checking .... ok I rewrote it again :muttley:

#include "MCFinclude.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Region ### START Koda GUI section ### Form=
$ini = @ScriptDir & "\cfg.ini"

If Not FileExists($ini) Then
    IniWrite($ini, "CUST", "BackC", "FF0000")
    IniWrite($ini, "CUST", "FontC", "FF0000")
EndIf

    $BackC = IniRead($ini, "CUST", "BackC", "")
    $FontC = IniRead($ini, "CUST", "FontC", "")

Global $Cust, $inpx,$result

    $Custom = GUICreate("Customize",335, 120, -1, -1, $WS_POPUP)
    GUICtrlCreateLabel("BgColor", 5, 55, 65, 21)
    $Btcol = GUICtrlCreateButton("C", 131, 53, 65, 21)
    $Input21 = GUICtrlCreateInput($BackC, 64, 53, 65, 21)
    GUICtrlSetBkColor(-1, "0x"&$BackC)
    GUICtrlCreateLabel("FontColor", 5, 77, 65, 21)
    $Btfcol = GUICtrlCreateButton("C", 131, 75, 65, 21)
    $Input22 = GUICtrlCreateInput($FontC, 64, 75, 65, 21)
    GUICtrlSetBkColor(-1, "0x"&$FontC)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

            Case $Btcol

                Color($Custom, $Input21)

                IniWrite($ini, "CUST", "BackC", $result)

            Case $Btfcol

                Color($Custom, $Input22)

                IniWrite($ini, "CUST", "FontC", $result)
    EndSwitch
WEnd


Func Color($Cust, $inpx)
    $c = _ChooseColor(2, 0x0080C0, 2, $Cust)
    If $c <> -1 Then
        ;GUICtrlSetColor($inpx, $c)
        GUICtrlSetBkColor($inpx, $c)
        $r = BitShift(BitAND($c, 0xFF0000), 16)
        $g = BitShift(BitAND($c, 0xFF00), 8)
        $B = BitAND($c, 0xFF)
        GUICtrlSetData($inpx, StringTrimLeft($c, 2))
        $result = StringTrimLeft($c, 2)
        Return($c)
    Else
        MsgBox(48, "Attention", "Select A Valid Color")
    EndIf
EndFunc   ;==>Color

THX

Link to comment
Share on other sites

@rootx: For an immediate fix, just move the #include MCFinclude.au3 down to below the last regular #include.

The issue is in _ChooseColor (in Misc.au3), but I'm not sure yet what exactly is causing it...:think:

EDIT: Okay, I found the problem, and unfortunately it's not CodeCrypter but Ward's AES, which erroneously interprets the string '0x' as an empty string.

Example:

#include "AES.au3"

_AES_Startup()

$hexstring=_AesEncrypt(@UserName,'This works')
$test=BinaryToString(_AesDecrypt(@UserName,$hexstring))
msgbox(0,"length: " & stringlen($test),$test)

$hexstring=_AesEncrypt(@UserName,'0x')
$test=BinaryToString(_AesDecrypt(@UserName,$hexstring))
msgbox(0,"length: " & stringlen($test),$test)

So again, this is beyond my control to fix, I'm sorry to say.:(

 

EDIT2: Although I cannot solve this at the AES end (or rather, I could, but I don't wish to meddle with the integrity of the Binary data conversion in Ward's code), it is trivial to make MCF.au3 skip string encryption for this specific string ('0x'). So this will be implemented in the next release. But since this particular issue in _ChooseColor can be avoided by simply moving the MCFinclude down in the list of #includes at the top of the script, I don't think this warrants a new release on its own.:P

Edited by RTFC
Link to comment
Share on other sites

Everyting working but gui is crashed like in img. I think this is caused by tabs . I got 5 tabs in gui and after crypt there are not showed up.

I put

; for crypting
#include <MCFinclude.au3>


before gui declarations. I have got 2 guis. First login gui is called _Login() after program start and looks good. but if login is correct ten GuiMain() is called and then it looks like in img below.

If I put

; for crypting
#include <MCFinclude.au3>

After gui declarations then output file doesnt work.

 

Why gui crashing?

 

crash.jpg

Link to comment
Share on other sites

@Miliardsto: So maybe I'm supposed to guess from your screenshot what your code is actually doing, then write my own test script that magically reproduces your error in the exact same way?:blink::( Please provide the shortest-possible script that reproduces (just) the error, so that I can test what might be the issue. Thanks.:)

EDIT: even better, how about you do some testing yourself first. Since you think using Tabs in your gui might be the problem, copy a simple Tabs GUI from the Help and encrypt it, and check if that works. Then start narrowing down the problem until it cannot be broken down any further.

Edited by RTFC
Link to comment
Share on other sites

  • 1 month later...

I tried to insert a map in another project without success, I wrote an example to reproduce what happens, I do not see the map, if I use obfuscation, could you help me understand what conflicts with codecrypter? Thank you

;ROOTX
#include <Array.au3>
#include <Google Maps.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include "MCFinclude.au3"

$map = GUICreate("Google Maps", 800, 700, -1, -1)
$country= GUICtrlCreateInput("Italy", 24, 620, 249, 21)
$city = GUICtrlCreateInput("Milano", 24, 645, 249, 21)
$addr = GUICtrlCreateInput("Via Cavour 1", 24, 670, 249, 21)
$start = GUICtrlCreateButton("Start", 280, 620, 249, 25)
Global $hLabel = GUICtrlCreateLabel("", 550, 620, 130, 50)

global $myaddress = GUICtrlRead($country)&" , "&GUICtrlRead($city)&" , "&GUICtrlRead($addr)

Global $gmap = _GUICtrlGoogleMap_Create($map, 5, 5, 790, 590,$myaddress, 18,1, True, False, 0, 1, 1,0,0,"it","C")
_GUICtrlGoogleMap_ViewLocation($map, $myaddress,  18,  1)
GUICtrlSetResizing($gmap, $GUI_DOCKTOP)

GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $start
                $newadd = GUICtrlRead($country)&" , "&GUICtrlRead($city)&" , "&GUICtrlRead($addr)
                _GUICtrlGoogleMap_ViewLocation($map,$newadd,  18,  1)
        EndSwitch
WEnd

 

Google Maps.au3

Link to comment
Share on other sites

Hey @rootx, first off, thanks for providing me with a small reproducer script! That's how I like to do business.:)

I tested your script in CodeCrypter, first with Backtranslation, then Obfuscation by itself, then Encryption by itself, then everything together, but no dice; it all works flawlessly at my end. So if the script you posted is really reproducing your issue on your machine, then I think your problem may lie elsewhere. At least, I cannot find anything to fix, sorry (the map loads at startup every time).:( Or did I misunderstand what is going wrong?

 

Edited by RTFC
Link to comment
Share on other sites

5 hours ago, RTFC said:

Hey @rootx, first off, thanks for providing me with a small reproducer script! That's how I like to do business.:)

I tested your script in CodeCrypter, first with Backtranslation, then Obfuscation by itself, then Encryption by itself, then everything together, but no dice; it all works flawlessly at my end. So if the script you posted is really reproducing your issue on your machine, then I think your problem may lie elsewhere. At least, I cannot find anything to fix, sorry (the map loads at startup every time).:( Or did I misunderstand what is going wrong?

 

you cant see the maps inside the gui? 4me doesn't work, I used on the tab ENCRYPT.... Key ID 4 and the name of th script test.au3, usually it works well. :(

I uploaded all, thx

test.zip

Link to comment
Share on other sites

On 25/11/2016 at 3:18 PM, rootx said:

you cant see the maps inside the gui? 4me doesn't work

@rootx:Yes, everything works for me when encrypted, I see pretty maps almost instantly. So I am unable to reproduce your issue. I'm going to be offline for the whole of next week, so won't be able to test your second reproducer script until then, sorry.

@legend: You can reduce slowdown by encrypting only part of the script, either by selecting the UDFs  in your scriupt individually (codeScrypter->Encrypt Tab->button UDF) or by encrypting only a specific proportion of the script (E.g.  every nth line, or 10%). See the FAQ for details. Not sure this'll reduce the initialisation time at startup much, however, as the encryption UDF always needs to be initialised.

Link to comment
Share on other sites

41 minutes ago, radienergos said:

Hi , first of all great work :)

I have a question , is there any way to make the codescanner faster ? (to bypass somehow the process of includes or something like that)?

 

 

yeah, excluding includes would be great if that is possible

Link to comment
Share on other sites

1 minute ago, legend said:

yeah, excluding includes would be great if that is possible

i have found something 

from codescanner.au3 find the line 

; skip some special lines completely

then below add what do you want to exclude

for example i have added 

If StringLeft($line,19)='#include "includes"' Then ContinueLoop

(i have all my includes into includes.au3 file)

so now i must find how to add the #include "includes.au3" to the mcfotest.au3 script automatically :) 

Link to comment
Share on other sites

On 01/12/2016 at 9:52 AM, radienergos said:

Hi , first of all great work :)

I have a question , is there any way to make the codescanner faster ? (to bypass somehow the process of includes or something like that)?

 

 

@radienergos: thanks!:)

@radienergos & @legend: The UDFs in generic AutoIt  #includes are public, so encrypting these is usually a waste of (processing) time. To avoid this, just place the "#include MCFinclude.au3" below the list of your regular includes in your main script. Excluding #includes from the CodeScanner preprocessing is a really bad idea, as the resulting structural description (MCF1-N.txt) will no longer be able to find any UDFs defined in those #includes (unresolved externals). If you're using a dedicated #include environment, you could prune all UDFs from this file that you don't actually call, to make CodeScanner spend less time processing these. So, if you were to 'include Array.au3, but only use _ArraySort() and _ArrayDisplay(), you could remove the other _Array* UDFs from your dedicated #include. But your code would become less portable that way, and if you change it later, you may have to patch in UDFs you omitted earlier when you discover you now need them.

 

Edited by RTFC
typo
Link to comment
Share on other sites

@rootx: I've now had a chance to examine your work environment as you posted it in your second zip. You need to upgrade to the latest version (2.1) of the bundle (you're apparently still using release 1.9:o); the bug you encounter (doubled underscore in split lines) has since been fixed.:)

Edited by RTFC
typos
Link to comment
Share on other sites

the problem is that if i will not use au3stripper , the preprocessing takes 15+ minutes (winapi only takes few minutes)

with au3stripper (/so option) it takes seconds but i have problems with sqlite and i must add the mcficlude to the stripped au3 (and then i still get error's about const's)  and still can't use obfuscate so it's the same and easier (for me at least)  to just exclude the includes (and use only encryption for phrases and strings)

so , there is another way to speed the preprocessing ? (the mcfinclude is below the list of regular includes)

can we just scan (one time only job) the entire autoit include folder?

or if it isn't easy , to just scan the includes only the first time we run the scanner for the specific script ? 

 

and something else because you know better than me :)

it is "safe" to have a simple exe (created with codecrypter) and then with this exe to run the full encrypted script ? (and passing silently the password through cmdline)

(also created with codecrypter but without preprocessing includes, i will use an allincludes.au3 with file install)

 

i had a project , like a launcher with a lot of different uses , so i had different scripts

and its was faster to dl only the updated au3 files (encrypted with _crypt_decryptfile) file than compiled exe's

Link to comment
Share on other sites

18 hours ago, radienergos said:

it is "safe" to have a simple exe (created with codecrypter) and then with this exe to run the full encrypted script ? (and passing silently the password through cmdline)

In a word: no, that is a disastrously bad idea. :x Command line parameters used to start any application can be retrieved independently.

 

18 hours ago, radienergos said:

can we just scan (one time only job) the entire autoit include folder?

I appreciate your point, but the aim of CodeCrypter is to generate a unique encryption for each pairing of your script with a particular sanctioned environment on a case-by-case basis. So although in theory (and in practice) it would be possible to generate generic pre-encrtypted containers for the generic AutoIt #includes, and slot these into your main script, these would weaken the overall protection because you'd be re-using them time and again, maybe even with the same fixed key. So  using Au3Stripper as preprocessor prior to CodeScanning seems a sensible way forward, minimising the amount of code CodeScanner has to plow through. If you have unresolved externals (e.g., missing constants) at that point, then something is going wrong in the stripping process.

Alternatively, you could take control of the stripping process yourself. CodeScanner produces separate lists of all available UDFs and the ones your script is actually calling, so you could build your own meta-include file which includes all of the latter an none of the redundant ones (including the required constants, also listed by CodeScanner). You'd have to construct that once (and maybe make a few edits to it later on when your main script changes), but once that is working, you'd have reduced the code to the minimum required, and future CodeScanning passes should be faster.

Another way of speeding up the scanning process would be to place your entire work environment on a ramdisk.:mellow:

 

Edited by RTFC
clarification
Link to comment
Share on other sites

21 hours ago, RTFC said:

@rootx: I've now had a chance to examine your work environment as you posted it in your second zip. You need to upgrade to the latest version (2.1) of the bundle (you're apparently still using release 1.9:o); the bug you encounter (doubled underscore in split lines) has since been fixed.:)

Mea culpa, with the new version (2.1)  everything works perfectly.

PS:It might be nice to put a combo box with the relative options in encrypt mask, if @scriptname do autocomplete in the mask define key content etc ... 4 my personal business :-) I inserted a (msgbox yes=@scriptname / no=it remains unchanged) inside the  Func _DefineKey function ()  ... If $ CCkeytype = 4  the msgbox run and if is yes get the name myscript.au3 and autocomplete the second mask with namescript.exe. THX 4 ALL have nice day.

Link to comment
Share on other sites

3 hours ago, RTFC said:

In a word: no, that is a disastrously bad idea. :x Command line parameters used to start any application can be retrieved independently.

you are right , that was an example :)

the idea is ok or also bad ? (without password , actually i want to choose either a "license" file , or something else, it doesn't matter now, i guess this is another question about the cckey :) )

well i tried something like this 

i create a script with (ok it isn't "clean" right now , i just want to test it)

$file="rma-choose.au3"
$filestrip="rma-choose_stripped.au3"
$exe=stringreplace($file,"au3","exe")
RunWait(@ProgramFilesDir&"\AutoIt3\SciTE\au3Stripper\AU3Stripper.exe"&" "&@ScriptDir&"\"&$file,@ScriptDir)
_ReplaceStringInFile(@ScriptDir&"\"&$filestrip,'#RequireAdmin','#RequireAdmin'&@CRLF&'#include "MCFinclude.au3"'&@crlf)
RunWait(@ScriptDir&"\codescanner.exe "&$filestrip&" /q",@ScriptDir)
RunWait(@ScriptDir&"\codecrypter.exe /i"&$filestrip&" /l /e /k5",@ScriptDir)
FileCopy(@ScriptDir&"\MCF0test.au3",@ScriptDir&"\enc-"&$filestrip,1)
$exe=StringReplace($file,".au3",".exe")
Run(@ProgramFilesDir&"\AutoIt3\Aut2Exe\Aut2exe.exe"&" /in '"&@ScriptDir&"\enc-"&$filestrip&"' /out "&$exe&" /icon cyberit.ico /pack /x86 /gui /comp 3",@ScriptDir)

so i run the au3stripper with #Au3Stripper_Parameters=/sf /sv /rm 

then put the "mcfinclude.au3" into the stripped script and everything seems to work

the main "problem" is the sqlite 

a get a warning from stripper

Warning for line:$iCbRval = Call($sCallBack, $aDataRow)  

and also i had to remove the consolewrite function from sqlite.au3 because i got always errors (with obsfucator and encryption)

Link to comment
Share on other sites

3 hours ago, rootx said:

PS:It might be nice to put a combo box with the relative options in encrypt mask

Thanks for the suggestion, @rootx, i'll look into it. Glad to hear it's worknig for you now.:)

@radienergos: I've never tested encrypting sqlite-based scripts myself. Please post the smallest possible script that reproduces your issue, if you want me to have a look at it.

I wouldn't just use a license file (although you could use a hash of its contents as part of your key/one of your keys in multi-key cycling), because people may just copy the license file together with the exe (if they know it's needed). Combining multiple features of your target environment would make your encryption more robust, IMHO.

1 hour ago, radienergos said:

i create a scrip

I like the way you're automating the entire process from start to finish.;)

1 hour ago, radienergos said:

the idea is ok or also bad ?

If you're thinking of parsing a decryption key from one script to another, be advised that any IPC can in principle be eavesdropped, and shared memory is difficult to shield from reading access. Moreover, if the parent programme extracts this key from the work environment anyway (you'd better not be storing it inside the script!), why can't the child programme isntead do the same thing for itself? The less scope for third-parties to gain access, the better.

Edited by RTFC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...