Jump to content
RTFC

CodeCrypter - Encrypt your Script

Recommended Posts

I ran it and with encrypt and obfuscate option enabled and i ran into an error.

It is simply a script with a msgbox but with winapi included.

After i run codecrypter it codes the au3 and it finishes. However i got an error when it is crypted. Global Const + $var always gives me an

error. Everything that is decrared as a const is highlighted as a syntax error.

I attached the script before and after crypted

Edit: IncludeConstants=True for me

guide.rar

Edited by AutID

Share this post


Link to post
Share on other sites

The reason it's coming up as an error is that you have to declare a constant with a value, that obfuscated script isn't doing that, seems like a glitch in the codecrypter script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Guest

Thanks a lot for your big solution for the encryption.

i have a software with 7566 lines and yesterday I managed to encrypt the software after tow days of "trial and error"(i hope this is the good translation from Google Translate)

You forgot to mention a few things in your guide and it made me be unable to to use your solution at the first time.

1) The AES.au3 should from here:

?do=embed' frameborder='0' data-embedContent>

if not then you will get the error that legend got..

2) In AES.au3 you must to do this fix:

?do=embed' frameborder='0' data-embedContent>page-2#entry896283' title="AutoIt Machine Code Algorithm Collection: post #21">#21

If not, the encryption will not work!
I do not understand how no one has noted it out.

 

Now about my results,

After I encrypted my software, I did not expect that everything will be good. And I was right.

The encryption screwed a lot of things in my software.
I do not even know where to start ..

But I do not blame you ..
This is the fun part (to fix everything and adapt the software for encryption).

Can you tell me what could cause problems?


Thank you very much!

Share this post


Link to post
Share on other sites
Guest

I need help!

I want to encrypt a script in two stages:
Step 1) Create a obfuscated script based on the original script
Step 2) Create an encrypted script based on the script from Step 1.

so i will have 4 files:

1) the original script

2) the script  without #includes

3) the obfuscated script

4) the obfuscated & encrypted script

For some reason, I can not do it ....


Please help me!

Edited by Guest

Share this post


Link to post
Share on other sites

Note to all previous posters: Apologies for the long delay in replying; I've been offline for several months. Please bear with me as I try to catch up with your responses...

Hi MagicSpark,

Thanks for your concise example, very clear. Unfortunately, you've hit an AutoIt quirk that I cannot fix. It has nothing to do with the encryption, but with the Execute command. Consider this example:

SetError(1)
If Execute("@error") Then Beep(1111,50)

This does not work, because the Execute statement has apparently already re-initialised the @error macro to zero prior to executing it (which is annoying :mad: ). A crude way around it is to patch an extra line post-encryption, like this:

SetError(1); <<< encrypted line
$error=@error; unencrypted patch
If Execute("$error") Then Beep(1111,50) ; <<< encrypted line

Note that in this second example we evaluate $error, not @error. It's not pretty, and would require quite a bit of editing for a large project that checks lots of returned error codes.AutoIt regrettably does not support "OnError" interrupts, otherwise this patch could be automated.

The next release of CodeCrypter will either incorporate a better solution or skip decrypting lines containing @error/@extended evaluation altogether. It may take a while though...

Sorry I cannot provide a quick fix in this case. :think:

Edit: I've started a thread in the dev chat forum here:

'?do=embed' frameborder='0' data-embedContent>>

Edited by RTFC

Share this post


Link to post
Share on other sites

@legend,

That's an easy one. As explained at the bottom of my initial post, you need to get Ward's AES.au3 UDF and place it in the same directory as Codecrypter. ;) Then you follow the instructions ca line 90 in MCFinclude.au3, which state:

#include "AES.au3"    ; by Ward
; NB in AES.au3 replace line 16    : Global Const Enum $AES_CBC_MODE, $AES_CFB_MODE, $AES_OFB_MODE
;                            by    : Global Const $AES_CBC_MODE=0, $AES_CFB_MODE=1, $AES_OFB_MODE=2

@gil900: Thanks a lot for your efforts :) . I'll update the link to Ward's AES.au3 so as to avoid any more confusion in future. However, as stated above, I did mention this issue in the code remarks, and luckily it is easily fixed.

Now regarding your issue with obfuscation and encryption, if you want to apply both to your script then you simply enable both options simultaneously in CodeCrypter. Doing it as a two-pass in the way you describe won't work. The basis for all substitutions are the MCF# files generated from your original code. If you were to create an obfuscated code first and then load that to be encrypted instead of the original, then Codecrypter would likely have trouble with the mismatches between what it expects (the original code structure) and what you load (the obfuscated version). When you enable both options, an obfuscated intermediate version of the substitution arrays will be produced first, that then immediately serves as input for the encryption pass. The result is a script that is both obfuscated and encrypted.

If you need a separate obfuscated version too, then of course you can generate that as well. Note however that randomisation will generate new obfuscated names for vars and funcs each time CodeCrypter is called. I don't understand why you would want to split the procedure in two, but maybe I've misunderstood your description. If so, please explain in more detail.

Edited by RTFC

Share this post


Link to post
Share on other sites

I'm getting this error: 

http://imgur.com/61vkLuH

Downloaded the bundle, and wards AES Udf.

I removed that func, then it runs, but I can't select any file as for target: it says: [ undefined ] and I can't type it it, and there's no browse button

Edited by legend

Share this post


Link to post
Share on other sites

@legend,

Please read my previous post and check which version of AES.au3 you've got. If it's the one with "Enum" ca. line 16, please apply the patch as suggested in MCFinclude.au3 ca. line 90. AES.au3 needs to be in the same directory as MCFinclude.au3, or else you need to patch the #include line (see previous post) with the full path of wherever it is placed.

Secondly, does Ward's AEStest.au3 run okay?

I suspect that something is going wrong in your #include; is it possible that a local script AES.au3 exists that is not Ward's? Please check that your local version of AES.au3 indeed contains _AES_Startup().

Share this post


Link to post
Share on other sites

Hmm, you shouldn't have to remove _AES_Startup(). Elsewhere other AES UDFs are called. It would be better to find out the underlying cause.

If you cannot see the "Source" button (with which you can browse for input files) then that's really odd, because that button's visibility is not conditional.

Errrm, you did add the line '#include MCFinclude.au3"  in your target script before running it through CodeScanner, didn't you?

Share this post


Link to post
Share on other sites

Okay, I've managed to reproduce the error at my end. Once I figure out what's causing it, I'll get back to you...

Yep, it was as I suggested earlier, the message is CodeScanner warning you about a missing function reference. This was actually a debugging statement  of mine I failed to remove (I'll fix that shortly), but if you click okay whenever the message appears, and then study the report that CodeScanner generates for you, you would read there:

Includes not found: 
source file:<your Autoit scripts path>\MCFinclude.au3 line: 89; reference: 
#include "AES.au3" ; by Ward

So You need to make sure that both MCFinclude.au3 and AES.au3 (Enum-patched) are placed in the same directory as your target script, then run CodeScanner to generate the MCF files. And before you start encrypting, you need to check that your code is okay, that is, that CodeScanner does not identify such glaring errors as missing #includes in your script. That was the whole point of writing CodeScanner.  So please read its report, and examine its other outputs.

Once codeScanner can find no such mistakes in your code, then you can start CodeCrypter. Your best first step then would be to do a BackTranslation and check if that works exactly like your original script. Only then would I try an encryption pass.

I know it's a lot of hassle and a lot of hoops to jump through. I would make it easier if I could, believe me. Once you have your environment set up properly it really should work.

Edited by RTFC

Share this post


Link to post
Share on other sites

@AutID:

Many thanks for the example, with which I was able to reproduce the same error that plagued one of the other responders, legend. Please see the previous posts for the solution (and make sure the ENum patch is applied to AES.au3 as well). If you still have difficulties, please let me know; I have no trouble whatsoever encrypting and running your sample code. :)

Share this post


Link to post
Share on other sites

CodeCrypter beta version 0.9 released. :party:

Added new feature: you can now also encrypt selected UDFs of your choice. :)  This UDF filter is always applied (do not tick/untick the Subset checkbox in the Encrypt panel, that affects only the global proportion encrypted, not this new feature).  By default all encryptable UDFs are set to "encryption enabled." You can flip this state per UDF for all functions for which encryption is possible and optional, and your ensemble settings are saved/reloaded for future use. This gives you more targeted control over which code sections you protect, while dispensing with the slowdown at runtime of added decryption of trivial code sections.

Secondly, after a dev chat I decided to write a workaround for the issue flagged by MagicSpark in a previous post in this thread. As a result, phrases containing the @error or @extended macros will no longer be encrypted, as Execute (which drives the decryption step) resets their state prior to their evaluation.

Thirdly, I've extended and updated the FAQ (MCFQA.pdf), not just to explain this added feature, but also to clarify in more detail how to set up your environment. This was mostly in response to the issue of Ward's AES.au3 not being found in the local directory where MCFinclude.au3 exepcted it to be. I've also referred to the simple workaround for the Enum version incompatibility issue in AES as decribed in the MCFinclude remarks (some people may not find this description otherwise). :whistle:

The UDF selection feature required MCF.au3 and CodeScanner to be updated too, so either download the bundle, or ensure you get all the latest versions (dated 25 Feb or later). The various code alterations and additions may of course give rise to new bugs and glitches, so beware, this is still a beta release... :unsure:

Share this post


Link to post
Share on other sites

Version 1.0 released.

No new bells and whistles, just trying to keep up with the changing times, i.e., AutoIt version 3.3.12.1.

Edited by RTFC

Share this post


Link to post
Share on other sites

RTFC:

I feel like I'm a little over my head, but if you wouldn't mind helping a noob, how do I just obfuscate my script?  I'm not interested in the encryption, just obfuscation.

Thanks

Share this post


Link to post
Share on other sites

Hi jack71,

Obfuscation is quite easy to accomplish. Just follow these simple steps:

  1. Start CodeScanner, and load it with your script.  Once loaded, a scan will be performed.
  2. Check CodeScanner's report and/or its other outputs for any major mistakes that might cause your script to malfunction (like missing includes, etc), and fix these. Don't worry about any "redundant include" warnings.
  3. Make sure CodeScanner's switch WriteMetaCode (checkbox in the Settings panel) is enabled, and do another scan, then Exit CodeScanner.
  4. Start CodeCrypter, and load it with your script (press the <Source> button under the <Main> Tab).
  5. Press the Tab <Presets> and click <Obfuscate> (this just changes the selected CodeCrypter settings, no action is taken yet)
  6. Press the Tab <Main> and click  <Run>
  7. If all is well, the obfuscated version of your script called MCF0test.au3 is placed in the same directory as your original script.
  8. Test your obfuscated script. If it display unexpected behaviour (unlikely in this case), follow the steps in the MCFQA.pdf FAQ to identify and fix the problem.
  9. You're done. :)

 

PS I just found a tiny mistake in the latest version of the MCF library (for AutoIt 3.3.12.1+); I'll update this post as soon as I've uploaded the corrected version.

Edit: okay, updated everywhere.

Note: even though you do not need all additional files of the MCF environment for your particular purpose, you will still need to set up the complete environment (including Ward's AES.au3) for CodeCrypter, otherwise it will fail to run or compile.

Don't hesitate to ask if you need more info. ;)

Edited by RTFC

Share this post


Link to post
Share on other sites

Hello legend,

Yes, well, what did CodeScanner tell you about your script? :ermm:  I would hazard a guess that it has trouble locating the required include AES.au3, which you have to download separately and put where MCFinclude.au3 can find it. So open MCFinclude.au3 and check the very first #include line against where you actually put AES.au3, and make sure these two agree (so either move AES.au3 to the expected path or edit the include line to match the current path of AES.au3).

If this does not solve your problem, then please submit the smallest-possible test script that reproduces the problem, and I'll have a look.

Edited by RTFC

Share this post


Link to post
Share on other sites

Hi jack71,

Obfuscation is quite easy to accomplish. Just follow these simple steps:

  1. Start CodeScanner, and load it with your script.  Once loaded, a scan will be performed.
  2. Check CodeScanner's report and/or its other outputs for any major mistakes that might cause your script to malfunction (like missing includes, etc), and fix these. Don't worry about any "redundant include" warnings.
  3. Make sure CodeScanner's switch WriteMetaCode (checkbox in the Settings panel) is enabled, and do another scan, then Exit CodeScanner.
  4. Start CodeCrypter, and load it with your script (press the <Source> button under the <Main> Tab).
  5. Press the Tab <Presets> and click <Obfuscate> (this just changes the selected CodeCrypter settings, no action is taken yet)
  6. Press the Tab <Main> and click  <Run>
  7. If all is well, the obfuscated version of your script called MCF0test.au3 is placed in the same directory as your original script.
  8. Test your obfuscated script. If it display unexpected behaviour (unlikely in this case), follow the steps in the MCFQA.pdf FAQ to identify and fix the problem.
  9. You're done. :)

 

PS I just found a tiny mistake in the latest version of the MCF library (for AutoIt 3.3.12.1+); I'll update this post as soon as I've uploaded the corrected version.

Edit: okay, updated everywhere.

Note: even though you do not need all additional files of the MCF environment for your particular purpose, you will still need to set up the complete environment (including Ward's AES.au3) for CodeCrypter, otherwise it will fail to run or compile.

Don't hesitate to ask if you need more info. ;)

Thanks RTFC.  I downloaded your bundle, plus Ward's bundle (extracted the AES.au3) and put that inside a folder called "CodeCrypter" inside my AutoIt dir.  I ran the codescanner.au3 and I get this error:

Global Const Enum $AES_CBC_MODE, $AES_CFB_MODE, $AES_OFB_MODE

error: syntax error

error: Statement cannot be just an expression

"C:Program Files (x86)AutoIt3CodeCrypterAES.au3"(16,14) : error: syntax error

What did I do wrong?

Thanks again!

Share this post


Link to post
Share on other sites

@jack71,

Great :thumbsup: , now if you scroll back up to post #27 in this thread you'll find the answer.

It's also mentioned at the top of the second page in  the FAQ (MCFQA.pdf).

Detailed instructions can be found in the header remarks of MCFinclude.au3 (basically you have to patch one line of Ward's code, explciitly assigning a few values to globals. That's all. :guitar:

RT

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By RTFC
      The CodeScannerCrypterBundle (ca. 2.5 MB unzipped) contains the following UDFs and utilities:
      CodeScanner: analyse AutoIt script structure and content, identify potential issues, generate MCF data files CodeCrypter: front-end GUI for the MCF library, for script encryption (without storing the decryption key(s) in the script!) MetaCodeFile UDF (MCF library): for analysis and user-defined alterations of AutoIt script structure and content MCFinclude.au3: #include this UDF in any AutoIt script that you wish CodeCrypter to process AES.au3, by Ward; machine code UDF for AES encryption (32-bit, patched version) CryptoNG, by TheXman; encryption UDF using Bcrypt dll calls (32/64-bit; various algorithms) StoreCCprofile.au3/readCSdatadump.au3/helloworld.au3: auxiliary utilities and example script HowToCodeCrypt.pdf: a simple guide in five steps CodeCrypterFAQ.pdf: questions and answers, partly based upon exchanges in the CodeCrypter thread. Please follow the links for additional information.
    • By TheXman
      Encryption / Decryption / Hashing
      Purpose
      Cryptography API: Next Generation (CNG) is Microsoft's long-term replacement for their CryptoAPI.  CNG is designed to be extensible at many levels and cryptography agnostic in behavior.  Although the Crypt.au3 UDF that is installed with AutoIt3 still works perfectly, the advapi32.dll functions that it uses have been deprecated.  This UDF was created to offer a replacement for the deprecated functions.  According to Microsoft, deprecated functions may be removed in future release.  Therefore, this UDF will be available when/if that happens.
      Description
      This UDF implements some of Microsoft's Cryptography API: Next Generation (CNG) Win32 API functions.  In its initial release, it implements functions to encrypt text & files, decrypt text and files, generate hashes, and the Password-Based Key Derivation Function 2 (PBKDF2) function.  The UDF can implement any of the encryption/decryption algorithms or hashing algorithms that are installed on the PC in which it is running.  Most, if not all, of the values that you would commonly use to specify that desired algorithms, key bit lengths, and other magic number type values, are already defined as constants or enums in the UDF file.
      To flatten the learning curve, there is an example file that shows examples of all of the major functionality.  This example file is not created to be an exhaustive set of how to implement each feature and parameter.  It is designed to give you a template or guide to help you hit the ground running in terms of using the functions.  I have tried to fully document the headers of all of the functions as well as the code within the functions themselves.    As of v1.4.0, there is also a Help file that includes all of the functions, with examples.
      Current UDF Functions
      _CryptoNG_3DES_CBC_DecryptData _CryptoNG_3DES_CBC_DecryptFile _CryptoNG_3DES_CBC_EncryptData _CryptoNG_3DES_CBC_EncryptFile _CryptoNG_AES_CBC_DecryptData _CryptoNG_AES_CBC_DecryptFile _CryptoNG_AES_CBC_EncryptData _CryptoNG_AES_CBC_EncryptFile _CryptoNG_CreateRSAKeyPair _CryptoNG_DecryptData _CryptoNG_DecryptFile _CryptoNG_EncryptData _CryptoNG_EncryptFile _CryptoNG_EnumAlgorithms _CryptoNG_EnumRegisteredProviders _CryptoNG_GenerateRandom _CryptoNG_HashData _CryptoNG_HashFile _CryptoNG_LastErrorMessage _CryptoNG_PBKDF2 _CryptoNG_Version  
      Related Links
      Cryptography API: Next Generation - Main Page
      Cryptography API: Next Generation - Reference
      Cryptography API: Next Generation - Primitives
      Cryptography API: Next Generation - Cryptographic Algorithm Providers
    • By RTFC
      MetaCode offers a way to:
      separate a script's structure from its content remove all redundant definitions (globals and UDFs) change any content (and some structure) combine (new) structure and (new) content into a new script The most useful applications implemented so far are:
      Fast language translation (not just text strings, also variable names and UDF names) Obfuscation (vars and/or UDFs) Script Encryption (conditionals, calls, and macros) Encryption is powerful because the key is not stored anywhere; you can define it to be a user password, macro, environment spec/variable, server response, something you define yourself, or a combination thereof; anything goes, as long as it's not a fixed string or fixed value. More info in the CodeCrypter thread: ?do=embed' frameborder='0' data-embedContent>'?do=embed' frameborder='0' data-embedContent>>
      ?do=embed' frameborder='0' data-embedContent>
      But MetaCode has more potential than that; it allows you to tinker with any type of content separately, then rebuild a new version. So for example, you can have a single script structure and numerous different language modules you just plug in to create a new version in a different language.
      A brief Tutorial is here: MetaCode Tutorial.pdf
      The MCF library itself can be found in the CodeScannerCrypter bundle.
      And a little example how to use it for translating your GUI into a different language:
       UI_Translator.7z (new version that should work with the new version of Google Translate, see post #13 below)
       
       
      MCF.au3 is just the library plus the MCFinclude.au3 file you need to include in any script you wish to encrypt.
      There is no GUI here. However, I did write a separate front-end for it called CodeCrypter, which you can find here:
      ?do=embed' frameborder='0' data-embedContent>'?do=embed' frameborder='0' data-embedContent>>
      ?do=embed' frameborder='0' data-embedContent>
      MCF uses output generated by my CodeScanner version 2.8+, which you can find here:
      '?do=embed' frameborder='0' data-embedContent>>
      CodeScanner also depends on MCF.au3 now, as it can now call a few of its functions.
      I should also mention Ward's excellent AES.au3 UDFs used for the encryption and decryption calls,  which is now included in the CodeScannerCrypter bundle (thanks to Ward for allowing to include it). You can find the original (unpatched) version here:
      '?do=embed' frameborder='0' data-embedContent>>
      Note: you can replace the encryption/decryption calls with whatever algorithm you like (hint: the native <Crypt.au3> library is too slow for most purposes, better stick to machine code routines)
      So just to be clear:
      CodeScanner (v2.8+) needs MCF (earlier versions won't work!) CodeCrypter needs MCF (plus anything that MCF needs) MCF itself needs MCFinclude (part of MCF zip) MCF also needs readCSdatadump (part of the CodeScanner package, you need the latest version packaged with CodeScanner v2.8; earlier versions won't work!) both MCF and MCFinclude currently rely on AES.au3 by Ward So you basically need to download the whole bundle for any of it to work.
       
      If you have any questions, please start by reading the MCF Tutorial and the CodeCrypter FAQ (you can download the latter separately from the CodeCrypter thread).
      Next, read the extensive Remarks sections in MCF.au3, MCFinclude.au3, and CodeCrypter.au3
      If still no joy, then please post. However, I'm not online that often, and logged in to the forum even less, so response may take a while).
      RT
×
×
  • Create New...