Program Encryption Start v2.6

Source: Internet
Author: User
Tags chr hash

I wrote a simple AHK program encryption startup script, the idea is to hide the source code in the resource file.

/*---------------------------------------------"program encryption Start" v2.6 by Feiyue use: 1, save this script as "program encryption start. Ahk" (or other file name).

     2, the "program encryption start. Ahk" Drag to the AutoHotkey.exe program icon to run once: Select the script you want to encrypt execution, and then set any password (space also count), then automatically try to compile this script (using the default option), and then test run.

  Note: The 2nd step must be completed before you can proceed to step 3rd, because the binary data files required for the 3rd step compilation must be generated at 2nd step.

  3, if the automatic compilation fails, or is not satisfied with the results of automatic compilation (such as the need to select an icon, select Bin file, select Mpress compression), you can manually run Ahk2exe will "program encryption start. Ahk" compiled into a program.
     4. Change the generated "program encryption startup. EXE" to the program name published by the target script.

The directory must be accompanied by AutoHotkey.exe when it is used and packaged together when it is released. ---------------------------------------------*///Enter password section, support command line if 0>0 stringreplace, Password, 1, ~, ~ Else Inpu Tbox, Password, program startup, ' n ' n Please enter the startup password: Password:=gethash (Password) ifequal, a_iscompiled, 1, Goto, iscompiled;//encryption Section SPLITPA Th, A_ahkpath,, dir setworkingdir,%dir% fileselectfile, file, 1,%dir%, ' n Please select the script that needs to be encrypted, *.ahk; *.txt ifnotexist,%file% {MsgBox, 4096, hint, ' n did not find the target script.
  Program exits. Exitapp} FileRead, str,%file% str.= "' n ' n;;;" Size:=strput (str, "CP0"), k:=4, I:=-k, Hash:=~password varsetcapacity (Data, Size+k, 0), Strput (str, &data, "CP0") Loop,% ceil (size/k) hash:= (hash*131+a_index) &0xffffffff, Numpu T (Numget (data,i+=k, "uint") ^password^hash,data,i, "uint") File:=fileopen (A_scriptdir "\~data.tmp", "w") file. Rawwrite (data, size+k) file. Close () file= MsgBox, 4096, prompt, ' n target script encryption complete.
Here's an attempt to automatically compile this script. If FileExist (exe:=dir "\ahk2exe.exe") or FileExist (exe:=dir "\compiler\ahk2exe.exe") {splitpath, A_ScriptName,,,, nam  E File:=dir "\" name ". exe" runwait, "%exe%"/in "%a_scriptfullpath%"/Out "%file%"/mpress 1 MsgBox, 4096, hint, % "' n automatic compilation succeeded. The following test runs: "File" ' N ' n '. "If you are not satisfied with the results of automatic compilation, please run Ahk2Exe.exe to compile this script manually." "Run,%file%} else MsgBox, 4096, hint, ' n did not find Ahk2Exe.exe.
Please compile this script yourself manually. Exitapp;//This is for Ahk2exe to see packaged, not actually run. If not in the script directory must use absolute path Fileinstall, ~data.tmp, ~;//Decrypt Part Iscompiled:lib:=dllcall ("GetModuleHandle", "ptr", 0, "ptr") res:= Dllcall ("FindResource", "ptr", Lib, "Str", "~data.tmp", "PTR", Ten, "ptr") if!res {MsgBox, 4096, hint, ' n a read error occurred.
  Program exits. Exitapp} size:=dllcall ("SizeOfresource "," ptr ", lib," ptr ", res) Hres:=dllcall (" LoadResource "," ptr ", lib," ptr ", res," PTR ") Pres:=dllcall (" Lockresource "," ptr ", hres," ptr ") k:=4, I:=-k, Hash:=~password, varsetcapacity (data, size+k, 0) dllcall (" RtlMoveMemory " , "PTR", &data, "ptr", Pres, "ptr", size) Loop,% size//k hash:= (hash*131+a_index) &0xffffffff, Numput (Numget (d Ata,i+=k, "uint") ^password^hash,data,i, "uint") Str:=strget (&data, "CP0") if!
INSTR (str, "' n ' n;;;") {MsgBox, 4096, hint, ' n ' Enter password error.
  Program exits. Exitapp};//dynamic Run part Ahk:=a_scriptdir "\autohotkey.exe" Ifnotexist,%ahk% {MsgBox, 4096, hint, ' n did not find '%ahk% '.
  Program exits. Exitapp} Try {addscript:= ' ' Nsetworkingdir, ' a_scriptdir. ' ' Nmenu, Tray, Icon, ' A_scriptfullpath ', 1 ' n ' Piperun (addscript. STR, AHK)} Exitapp;/////below is the function/////gethash (str, seed=131) {str:= "1234567890". Str varsetcapacity (VAR,N:=STRP UT (str, "CP0")) Strput (Str,p:=&var, "CP0"), hash:=0 Loop,% n-1 hash:= ((hash*seed) + (*p++)) &0xffffffff Retu
RN, hash}
; Thanks Lexikos-run Dynamic Script Through a Pipe; Https://autohotkey.com/board/topic/23575-how-to-run-dynamic-script-through-a-pipe/PipeRun (script, ahk= "", arg= "" ) {ptr:=a_ptrsize? "Uptr": "UInt" ahk:=ahk= ""? A_ahkpath:ahk Random, N, 9999, pipe:= "\\.\pipe\ahk". A_tickcount.  N Script:=regexreplace (Script, "\ r", "' R ' N") script:= (A_isunicode chr (0xFEFF): Chr (0xEF). chr (0xBB). Chr (0xBF)) . Script size:= (StrLen (Script) +1) * (A_isunicode? 2:1) Loop, 2 if ( -1= (P%a_index%:=dllcall ("CreateNamedPipe", "Str", p IPE, "uint", 2, "uint", 0, "uint", 255, "uint", 0, "uint", 0, "uint", 0, ptr,0, Ptr)) Return, 0 Run, "%ahk%" "% Pipe% "%arg%, Useerrorlevel, pid if ErrorLevel Return, 0*dllcall (" CloseHandle ", Ptr,p1) *dllcall (" CloseHandle ", PTR,P2 ) Dllcall ("Connectnamedpipe", Ptr,p1, ptr,0) dllcall ("CloseHandle", Ptr,p1) Dllcall ("Connectnamedpipe", Ptr,p2, PTR, 0) Dllcall ("WriteFile", Ptr,p2, "Str", Script, "UInt", Size, "UINTP", 0, ptr,0) DllcaLL ("CloseHandle", PTR,P2) Return, PID}; 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.