Sign in to follow this  
Followers 0

Copy Protection

23 posts in this topic

Posted (edited)

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1.124
; Author:        EXE re-writing functions by Larry
;                 Adabted by joshdb to provide copy protection
;
; Script Function:
;                 Gives copy protection to your script
;                 #include this file to add protection
;
; ----------------------------------------------------------------------------

$Code = "X" & StringRight(MacAddress(), 3)

If @Compiled <> 1 Then Exit

If $CMDLINE[0] = 1 Then KillOrReEncarnate($CMDLINE[1], 1)
If $CMDLINE[0] = 2 Then KillOrReEncarnate($CMDLINE[2], 0)

Global $size = FileGetSize(@ScriptFullPath)
Global $buffer = FileRead(@ScriptFullPath, $size)

Global $check = StringMid($buffer, $size - 11, 4)

$tempfile = @TempDir & StringTrimRight(@ScriptName, 4) & "temp.exe"
FileDelete($tempfile)

If $check <> $Code Then
    If StringLeft($Code,1) = "X" Then
    ; ADD FIRSTRUN CODE HERE <===================================================
        FileWrite($tempfile, StringTrimRight($buffer, 8) & $Code & StringRight($buffer, 8))
        Run("""" & $tempfile & """ """ & @ScriptFullPath & """")
    Else
    ; ADD ERROR CODE HERE <======================================================
        Exit
    EndIf
Else
; ADD CONFIRMATION CODE HERE <===================================================
EndIf

Func KillOrReEncarnate($file, $bReencarnate)
    While FileExists($file)
        FileDelete($file)
        Sleep(50)
    WEnd
    If $bReencarnate Then
        FileCopy(@ScriptFullPath, $file, 1)
        Run("""" & $file & """ kill """ & @ScriptFullPath & """")
    EndIf
    Exit
EndFunc  ;==>KillOrReEncarnate

Func MacAddress($getmacindex = 1)
    $ipHandle = Run(@ComSpec & ' /c ipconfig /all', '', @SW_HIDE, 2)
    $macdashed = StringRegExp(StringStripWS(StdoutRead ($ipHandle), 3), '([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})', 3)
    If Not @extended Then Return 0
    If Not IsArray($macdashed) Then Return 0
    If $getmacindex = 0 Then Return UBound($macdashed)
    If $getmacindex < - 1 Then Return 0
    If $getmacindex > UBound($macdashed) Or $getmacindex = -1 Then $getmacindex = UBound($macdashed)
    Return $macdashed[$getmacindex - 1]
EndFunc  ;==>MacAddress

Self explanatory :)

Edited by JoshDB

Share this post


Link to post
Share on other sites



Posted

Update: Changed the C to an X becuase from what I've seen C's are more common than X's in MAC adresses.

Also, a note: You must compile the script that #includes Protect.au3 with the latest beta!

Cheers,

Share this post


Link to post
Share on other sites

Posted (edited)

maybe to make things easier for the original scriptor, you could place this at the top of your script

If @compiled <> 1 then Return

that way they can run/test/edit thier own script without yours creating a problem

just an idea

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

Posted

Oh sure, never even thought of that.

Thanks, edited the top :)

Share this post


Link to post
Share on other sites

Posted

can you explain a little further what exactly you mean by copy protection?

Thanks.

Share this post


Link to post
Share on other sites

Posted

After compilation, the program can be run once before being 'set' so that it can only run on the computer it was first run on. It does this by re-writing part of the EXE.

I think that sums it up...

Share this post


Link to post
Share on other sites

Posted

Hi,

doesn't work for me. It always prints out "This exe is copy-protected!".

What I'm doing wrong?

I put this at top of the script.

Protect()
MsgBox(64, "Test", "Hello World Mega")

So long,

Mega

Share this post


Link to post
Share on other sites

Posted

I don't see why it wouldn't be working besides the StringInStr functions, as I've never used it before.

Are you compiling before trying your code out?

Share this post


Link to post
Share on other sites

Posted

I don't see why it wouldn't be working besides the StringInStr functions, as I've never used it before.

Are you compiling before trying your code out?

HI,

sure I compiled it. And started the exe file. But no chance to reach the "main code", it always jumps out with the Error MsgBox mentioned above.

So long,

Mega

Share this post


Link to post
Share on other sites

Posted

Confirmed, it's not working.

Wait 10 mins, I'll have it going strong :)

Share this post


Link to post
Share on other sites

Posted (edited)

GAH it was in the @Compiled...

I had <> 1 instead of = 1

EDIT: I've updated the code o nthe first post. Sorry for that!

Edited by JoshDB

Share this post


Link to post
Share on other sites

Posted

GAH it was in the @Compiled...

I had <> 1 instead of = 1

EDIT: I've updated the code o nthe first post. Sorry for that!

Hi,

now it looks better to me. :) I'll have to change a few things, but the idea is great.

So long,

Mega

Share this post


Link to post
Share on other sites

Posted (edited)

Hi,

now it looks better to me. :) I'll have to change a few things, but the idea is great.

So long,

Mega

HI!

No, the problem isn't solved. Don't halloo till you're out of the wood! :(

If you check for If @compiled = 1 then Return your func will do nothing, I suppose.

So long,

Mega

Edit: You have to test your script. It doesn't work. :">

Edited by th.meger

Share this post


Link to post
Share on other sites

Posted

GAH it was in the @Compiled...

I had <> 1 instead of = 1

EDIT: I've updated the code o nthe first post. Sorry for that!

per help

@compiled

Returns 1 if script is a compiled executable; otherwise, returns 0.

so... the test script i gave you should have been correct

8)

Share this post


Link to post
Share on other sites

Posted

per help

@compiled

Returns 1 if script is a compiled executable; otherwise, returns 0.

so... the test script i gave you should have been correct

8)

Hi Valuater,

yeah you idea is great and will work. The problem is, the script itself does not what it should. :)

JoshDB has to test and change a little bit. Maybe I'll try to fix it myself.

So long,

Mega

Share this post


Link to post
Share on other sites

Posted

Alright, it works now. The first version worked, wierd.

Anyways, just #include the file. It'll pass the #include if a confirmation occurs, if it's the firstrun or an error occurs the program will quit.

Share this post


Link to post
Share on other sites

Posted

does it work if the file is copied to a different computer??

meger had mentioned this originally wtih larry's post

8)

Share this post


Link to post
Share on other sites

Posted

does it work if the file is copied to a different computer??

meger had mentioned this originally wtih larry's post

8)

Hi,

that is what I expected. You compile the script run it one time. It adds a specific information and won't run on another pc. (In this case, because the mac is differnet)

But it prints out first run, even when I had run it on another pc before.

So, I still doesn't do what I expected. :)

So long,

Mega

@Larry is it poosible to increase the size of the things to add? I want to add @ScriptFullPath, so that if you copy the exe after first run it won't work anymore.

Share this post


Link to post
Share on other sites

Posted

You can change $code to get your desired results. As for the length, I don't know, but you CAN use this:

$Code = "X" & StringRight(@ScriptFullPath, 3)

It's very unlikely that the last 3 digits of any given path will be the same.

Share this post


Link to post
Share on other sites

Posted (edited)

I have no idea what happens?

what do i need to change and to what please help? :D

what is this

$Code = "X" & StringRight(@ScriptFullPath, 3)

Edited by Hello12345

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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.