Page 1 of 1

Help with ASProtect & PB

Posted: Tue Aug 17, 2004 6:17 pm
by coffeebean
Hi, because VB6 is a bit dodgy I need to write a launcher program for a "Blitz game" that does not use VB6.
I've tried the demo of PB to see if PB can use asprotect... this is what I have done but It dont work.. probably cus i've done it wrong. I've seen a few posts about asprotect and from what I've read PB can be protected with ASProtect.

Can any 1 help me?

Code: Select all

If OpenLibrary(0,"asprotect.dll")

  CallFunction(0,"GetTrialExecs",t,l)
  total=t
  left=l
Else
  OpenConsole()
Print("cant find asprotect.dll")
Delay(4000)
End
EndIf

r$=Str(total)
OpenConsole()
Print(r$)
Delay(4000)
end

Posted: Tue Aug 17, 2004 6:23 pm
by Paul
The problem here is not ASProtect but the fact you are using CallFunction wrong.

The parameters used in CallFunction are for sending variables to the DLL. The result returned is a variable or a pointer to a variable or memory address containing any returned data.
Syntax
Result = CallFunction(#Library, FunctionName$ [,Parameter1 [, Parameter2...]])
Read help file for more details (under Library command)

Posted: Tue Aug 17, 2004 6:58 pm
by coffeebean
Believe me I've read those documents over and over I just dont get it.

Code: Select all

If OpenLibrary(0,"asprotect.dll") 

  result=CallFunction(0,"GetTrialExecs") 
  
Else 
  OpenConsole() 
Print("cant find asprotect.dll") 
Delay(4000) 
End 
EndIf 

r$=Str(result) 
OpenConsole() 
Print(r$) 
Delay(4000) 
End
Result just returns 0.



Heres the Delphi Code as given in the ASProtect help.
(GetTrialExecs – obtains the trial run parameters, i.e. total and remaining runs.).

Code: Select all

    const

  TrialExTotal : Integer = -1;

  TrialExLeft   : Integer = -1;

procedure GetTrialExecs(Total, Left : DWORD);stdcall;

begin

  TrialExTotal := Total;

  TrialExLeft  := Left;

end;

exports GetTrialExecs;

begin

   Label2.Caption := 'Unregistered trial version'#13#10#13#10'You have '+IntToStr(TrialExLeft)+' execution(s) left';

end;
Can any 1 convert this to work with PB?

Posted: Tue Aug 17, 2004 7:10 pm
by thefool
Try calling it with CallCfunction isntead of callfunction!

and you are 100% sure result is not a string?

here the code is changed to callcfuncion. result is still saved as long.
but try anyway :

Code: Select all

If OpenLibrary(0,"asprotect.dll") 

  result=CallCFunction(0,"GetTrialExecs") 
  
Else 
  OpenConsole() 
Print("cant find asprotect.dll") 
Delay(4000) 
End 
EndIf 

r$=Str(result) 
OpenConsole() 
Print(r$) 
Delay(4000) 
End

Posted: Tue Aug 17, 2004 7:33 pm
by coffeebean
Thanks 4 the reply.

Didn't help :( Returned value is an integer\Long

Posted: Wed Aug 18, 2004 10:11 am
by Rings
the problem is the old ByValue and ByReference method.
please replace

CallFunction(0,"GetTrialExecs",t,l)

with

CallFunction(0,"GetTrialExecs",@t,@l)

to get values back from the DLL-Call

Posted: Wed Aug 18, 2004 10:40 am
by coffeebean
Kind worked.. iI protected then .exe with 30 executions but it returned 4223426 to @t not 30.

Code: Select all

If OpenLibrary(0,"asprotect.dll") 

  CallFunction(0,"GetTrialExecs",@t,@l) 

  total=@t
Else 
  OpenConsole() 
Print("cant find asprotect.dll") 
Delay(4000) 
End 
EndIf 

r$=Str(total) 
OpenConsole() 
Print(r$) 
Delay(4000
End
)

Method below return 0 instead of 30.

Code: Select all

If OpenLibrary(0,"asprotect.dll") 

  result=CallFunction(0,"GetTrialExecs",@t,@l) 

Else 
  OpenConsole() 
Print("cant find asprotect.dll") 
Delay(4000) 
End 
EndIf 

r$=Str(result) 
OpenConsole() 
Print(r$) 
Delay(4000) 
End
Any more ideas?

Posted: Wed Aug 18, 2004 10:59 am
by Rings
lol
you better take a look in the manual about variables,Pointers or do a search here for that topic.
To give you a solution:

@t is the Pointer to the variable t

so your code should look like this:


Code: Select all

If OpenLibrary(0,"asprotect.dll") 

  CallFunction(0,"GetTrialExecs",@t,@l) 

  total=t 
Else 
  OpenConsole() 
Print("cant find asprotect.dll") 
Delay(4000) 
End 
EndIf 

r$=Str(total) 
OpenConsole() 
Print(r$) 
Delay(4000 
End 

Posted: Wed Aug 18, 2004 11:28 am
by coffeebean
Hum... didn't work.. returned 0 again.

In a Blitz Boy so all these pointers are new to me....

I couldn't get this to work with Blitz either.

Posted: Wed Aug 18, 2004 12:26 pm
by Rings
i have found a trialversion of asprotect and tested some code with it:

Code: Select all

; VB declares
; Declare Function apiGetRegistrationBuffer Lib "asprotect.dll" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
; Declare Function apiGetHardwareID Lib "asprotect.dll" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
; Declare Function apiGetTrialDays Lib "asprotect.dll" () As Long
; Declare Function apiGetTrialExecs Lib "asprotect.dll" () As Long


MessageRequester("Test","Info",0)
lib=OpenLibrary(0,"c:\programme\asprotect\asprotect.dll")
If lib
 apiGetTrialExecs=IsFunction(0,"apiGetTrialExecs")
 apiGetTrialDays=IsFunction(0,"apiGetTrialDays")
 apiGetHardwareID=IsFunction(0,"apiGetHardwareID")
 If apiGetTrialDays
  result=CallFunctionFast(apiGetTrialDays)
  MessageRequester("Test apiGetTrialDays",Str(result),0)
 EndIf
 If apiGetTrialExecs
  result=CallFunctionFast(apiGetTrialExecs)
  MessageRequester("Test apiGetTrialExecs",Str(result),0)
 EndIf
 If apiGetHardwareID
  HardwareKey.s = Space(255) ;String$(255, 0)
  LenGetHardwareKey = CallFunctionFast( apiGetHardwareID,HardwareKey )
  MessageRequester("Test apiGetHardwareID",Left(HardwareKey.s,LenGetHardwareKey ),0);
 EndIf
 CloseLibrary(0)
Else
 MessageRequester("Test","DLL ?",0)
EndIf 

Posted: Wed Aug 18, 2004 1:23 pm
by coffeebean
Thanks 4 all your help.... did that work for you... it didn't work for me. :roll:

I protected the exe with 30 days trial and 42 executes. (using trial version of asprotect also).

It returned -1 days, -1 executes and the hardware key was "123456789".

Im using the Demo version of PB 3.90... dont know if thats the problem.

Posted: Thu Aug 19, 2004 8:08 am
by Rings
coffeebean wrote:Thanks 4 all your help.... did that work for you... it didn't work for me. :roll:

I protected the exe with 30 days trial and 42 executes. (using trial version of asprotect also).

It returned -1 days, -1 executes and the hardware key was "123456789".

Im using the Demo version of PB 3.90... dont know if thats the problem.
i have exactly the same results.
For more Info you should contact 'ASProtect's service i think.(send them these files, they can evaluate it with the Demo-version)
It has nothing to do that you are evaluating the DEMO-version of Purebasic.

Posted: Mon Nov 15, 2004 10:48 pm
by MrMat
From the manual it says:
To work with these functions while developing the application ASProtect.dll is used. It replaces protection functions when the application is not processed by ASProtect.

Asprotect.dll uses asprotect.ini file, in which you can specify different parameters of protection for debugging puproses.

When processing the application with ASProtect all calls to ASProtect.dll are replaced with internal function calls and including of ASProtect.dll to the final distribution is not required.
When using the .ini file the values returned are correct but after running ASProtect on the file the calls to the dll should be replaced, but it looks like they are not when using PureBasic. I've emailed their support to see if they can help.

Does anyone use ASProtect successfully with PureBasic? If so could you give some examples please?