Help with ASProtect & PB

Just starting out? Need help? Post your questions and find answers here.
coffeebean
User
User
Posts: 14
Joined: Sat Aug 16, 2003 6:16 pm

Help with ASProtect & PB

Post 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
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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)
Image Image
coffeebean
User
User
Posts: 14
Joined: Sat Aug 16, 2003 6:16 pm

Post 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?
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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
coffeebean
User
User
Posts: 14
Joined: Sat Aug 16, 2003 6:16 pm

Post by coffeebean »

Thanks 4 the reply.

Didn't help :( Returned value is an integer\Long
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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
SPAMINATOR NR.1
coffeebean
User
User
Posts: 14
Joined: Sat Aug 16, 2003 6:16 pm

Post 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?
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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 
SPAMINATOR NR.1
coffeebean
User
User
Posts: 14
Joined: Sat Aug 16, 2003 6:16 pm

Post 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.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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 
SPAMINATOR NR.1
coffeebean
User
User
Posts: 14
Joined: Sat Aug 16, 2003 6:16 pm

Post 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.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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.
SPAMINATOR NR.1
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post 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?
Mat
Post Reply