Posted by Tonic in SWF Studio V3 on Dec 09 2008, 04:23 am

Hello,

I search a solution to protect my application against the copy.

This application is contained in a folder, which can be copied. All of resources is contained in the folder. So if you copy the folder, you can run the application directly.

So, for every computer, it's necessary to be able to generate automatically a unique serial number.
Then, by making a demand, the person recieve a key for activation.
The user will enter the key of activation, finded by the unique serial number.
And in every launch of the application, this key of activation is verified...

At first, I used the method " getMACAddressList " for generated a unique identifier for a computer.
But it would seem that the list of the addresses can change.
Is it possible to have only the address mac of the active network card?

Is it possible to use an external dll, like this : http://www.devlib.net/getdiskserial.htm ?
With this dll, i can have the serial of hard drive.

Or library or external resources exist to implement this method in swf studio?

Thank you. :)


Posted by pompeyd in SWF Studio V3 on Dec 09 2008, 07:37 am


QUOTE: from Tonic;46117
With this dll, i can have the serial of hard drive

Hi Tonic,

You don't need to use the dll, check out FileSys.driveList to get the list of available drives. You can then use FileSys.serialNumber to get the serial number of any of the drives.

HTH

Paul


Posted by Tonic in SWF Studio V3 on Dec 09 2008, 09:41 am

Thank you for your response...

I tested this function, it work good :)

But if you test for a raid hard drive, it is possible to have the same Serial Number.

"Hard drive serial number is a random number that is generated by DOS or Windows every time you format your hard drive. It is NOT a model number or serial number of your physical hard drive. "

Is it possible to have serial number of the physical hard drive?

Thanks :)


Posted by northcode in SWF Studio V3 on Dec 09 2008, 10:36 am

You can access WMI using the JScript support in SWF Studio to get at the device information you need. Here's an example from TechNet that I modified (minor surgery) to work with JScript in SWF Studio. It returns information about the physical drives on your system.



function main(o)
{
   var wbemFlagReturnImmediately = 0x10;
   var wbemFlagForwardOnly = 0x20;

   var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");

   var colDiskDrives = objWMIService.ExecQuery("Select * from Win32_DiskDrive", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);

   var enumDiskDrives = new Enumerator(colDiskDrives);

   for (; !enumDiskDrives.atEnd(); enumDiskDrives.moveNext())
   {
      var objDiskDrive = enumDiskDrives.item();

      var s = "";

      s += "Caption: " + "\t" +  objDiskDrive.Caption + "\r\n";
      s += "Device ID: " + "\t" +  objDiskDrive.DeviceID + "\r\n";
      s += "Index: " + "\t" +  objDiskDrive.Index + "\r\n";
      s += "Interface Type: " + "\t" + objDiskDrive.InterfaceType + "\r\n";
      s += "Manufacturer: " + "\t" + objDiskDrive.Manufacturer + "\r\n";
      s += "Media Loaded: " + "\t"  + objDiskDrive.MediaLoaded + "\r\n";
      s += "Media Type: " + "\t" +  objDiskDrive.MediaType + "\r\n";
      s += "Model: " + "\t" +  objDiskDrive.Model + "\r\n";
      s += "Name: " + "\t" +  objDiskDrive.Name + "\r\n";
      s += "Partitions: " + "\t" + objDiskDrive.Partitions + "\r\n";
      s += "PNP DeviceID: " + "\t" +  objDiskDrive.PNPDeviceID + "\r\n";
      s += "SCSI Bus: " + "\t" +  objDiskDrive.SCSIBus + "\r\n";
      s += "SCSI Logical Unit: " + "\t" +  objDiskDrive.SCSILogicalUnit + "\r\n";
      s += "SCSI Port: " + "\t" +  objDiskDrive.SCSIPort + "\r\n";
      s += "SCSI TargetId: " + "\t" +  objDiskDrive.SCSITargetId   + "\r\n";  
      s += "Sectors Per Track: " + "\t" + objDiskDrive.SectorsPerTrack + "\r\n";
      s += "Signature: " + "\t" +  objDiskDrive.Signature + "\r\n";
      s += "Size: " + "\t" +  objDiskDrive.Size + "\r\n";
      s += "Status: " + "\t" +  objDiskDrive.Status + "\r\n";
      s += "Total Cylinders: " + "\t" +  objDiskDrive.TotalCylinders + "\r\n";
      s += "Total Heads: " + "\t" +  objDiskDrive.TotalHeads + "\r\n";
      s += "Total Sectors: " + "\t" +  objDiskDrive.TotalSectors + "\r\n";
      s += "Total Tracks: " + "\t" +  objDiskDrive.TotalTracks + "\r\n";
      s += "Tracks Per Cylinder: " + "\t" + objDiskDrive.TracksPerCylinder + "\r\n";

      alert(s);
   }

}



To call this from Flash you can just add this ActionScript to a new FLA.


ssCore.init();
ssDefaults.synchronousCommands = true;

ssCore.Script.create({module:"module", language:"jscript"});

r = ssCore.Script.loadCode({module:"module", path:"startdir://script.js"});

if (r.success == false)
{
   ssCore.App.showMsgBox({prompt:"load failed: " + r.Error.description});
   ssCore.App.quit({});
}

r = ssCore.module.main({argument:""});

if (r.success == false) 
{
   ssCore.App.showMsgBox({prompt:e.code + " " + e.description});      
   ssCore.App.quit({});
}


Once you've created your EXE, put the JScript code in a file called jscript.js and put it in the same folder as your EXE and run the application. You should see an alert box(es) for each physical drive attached to your system. Note: CDROM drives are in a different collection so they won't show up in this list.

The PNPDeviceID field contains the information you want. See Device Idenification Strings for tips on how to decode the device id for various device types (IDE, SCSI, etc.) and get the serial number from the device id string.


Posted by Tonic in SWF Studio V3 on Dec 10 2008, 10:53 am

Thank you very much for your response.

It works good with a JScript file.

I would like to embed the script in my application.

So i try to create a script, and use "addCode" to generate the main function.


ssCore.init();
ssDefaults.synchronousCommands = true;
            
ssCore.Script.create({module:"module", language:"jscript"});
            
var moduleStript : String = 'function main(o)'+
               '{'+
                     'var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");'+
                     'var colDiskDrives = objWMIService.ExecQuery("Select PNPDeviceID from Win32_DiskDrive", "WQL", 0x10 |  0x20);'+                                       
                  'var enumDiskDrives = new Enumerator(colDiskDrives);'+
                  'var objDiskDrive = enumDiskDrives.item();'+
                     'return objDiskDrive.PNPDeviceID;'+
               '}';
            
            ssCore.Script.addCode({module : "module", code : moduleStript});

var r : Object = ssCore.module.main({argument:""});      
_log.info("r : "+ObjectUtil.toString(r));      


But when i trace the result, there is an error :

QUOTE:

argument = ""
Error = (northcode.swfstudio.v3.types.ssCore::ErrorReturnObject)#1
code = 7
command = "module.main"
description = "SCRIPT_ERROR_RUNTIME_ERROR"
result = ""
scriptError = "description: (-2147217375)
error:
line: 1
column: 17
source:"
success = false


I have juste try to execute this code :


var moduleStript : String = 'function main(o)'+
               '{'+
                     'return "ok";'+
               '}';


It work good.

But with code, there is an error :


var moduleStript : String = 'function main(o)'+
               '{'+
                     'GetObject("winmgmts:\\\\.\\root\\CIMV2");'+

                     'return "ok";'+
               '}';


Do you see an error?

May be with slashes?

Thanks for yours responses :)


Posted by pompeyd in SWF Studio V3 on Dec 10 2008, 11:00 am

Hi Tonic,

Haven't looked for any errors in your code, but, if you want to keep your JScript file away from 'prying eyes' then you could add it to the Layout, and extract it at runtime when you need it.

You can load it straight into your application from the Layout without it touching the hard drive, so no-one will have access to the file or code.

Paul


Posted by Tonic in SWF Studio V3 on Dec 10 2008, 12:13 pm

Hello pompeyd,

thanks :)

have you got an exemple of your description?


Posted by northcode in SWF Studio V3 on Dec 10 2008, 01:27 pm

You can load the file from the Files tab like this...

var r1:Object = ssCore.Layout.loadFile({resource:"\\jscript.js"});

Then instad of usng ssCore.Script.loadCode like I did in my example you can use Script.addCode and pass it the result variable from the call to Layout.loadFile.

var r2:Object = ssCore.Script.addCode({module:"module", code:r1.result});


Posted by Tonic in SWF Studio V3 on Dec 11 2008, 03:29 am

Great, it works very well.

Thank you very much! :)

I have a last question. Is it possible to generate a file during the application run, and include in the layout dynamically?


Posted by northcode in SWF Studio V3 on Dec 11 2008, 04:09 am

You can generate files at runtime but you can't add them to the Layout. If you want to store data as part of your EXE at runtime, you can use the Scratch commands for that.

The Scratch commands allow you to store data in your EXE but it comes at a price. You can't sign your EXE files and use the Scratch commands. The EXE must be in a location where it can be written (not in the Program Files folder on Vista for example). There is also no format to the data you write, you have to manage whatever data you add to the file.


Posted by megadar in SWF Studio V3 on Jul 01 2010, 01:50 pm



ssCore.init();
ssDefaults.synchronousCommands = true;

ssCore.Script.create({module:"module", language:"jscript"});
var r1:Object = ssCore.Layout.loadFile({resource:"\\script.js"});
if (r1.success) {
   ssCore.Script.addCode({module:"module", code:r1.result});
   ssDebug.trace(ssCore.module.main().result); // emtpy
}


script.js

function main() {
   var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
   var colDiskDrives = objWMIService.ExecQuery("Select PNPDeviceID from Win32_DiskDrive", "WQL", 0x10 | 0x20);
   var enumDiskDrives = new Enumerator(colDiskDrives);
   var objItem = enumDiskDrives.item();
   var s = objItem.PNPDeviceID;
   var ss = s.split('\\').join('|').split('&').join('|');
   # alert(ss); // нужные данные выводятся ( <I>necessary data are derived</I>)
   return ss;
}


подскажите, где моя ошибка?
как забрать данную objItem.PNPDeviceID в проект?

show you where my mistake?
like to take this objItem.PNPDeviceID in the project?


Posted by northcode in SWF Studio V3 on Jul 01 2010, 02:47 pm

Your jscript is fine, but I don't think the call to module.main will work like that. I don't think we can resolve the result object if it's specified like that. Here's an example that works for sure...


ssCore.init();
ssDefaults.synchronousCommands = true;

ssCore.Win.show({});

ssCore.Script.create({module:"module", language:"jscript"});

r = ssCore.Layout.loadFile({resource:"\\script.js"});
if (r.success == false)
{
   ssCore.App.showMsgBox({prompt:r.Error.code + " " + r.Error.description});
   //ssCore.App.quit({});
}

r = ssCore.Script.addCode({module:"module", code:r.result});

if (r.success == false)
{
   ssCore.App.showMsgBox({prompt:"load failed: " + r.Error.description});
   //ssCore.App.quit({});
}

r = ssCore.module.main({});

if (r.success == false) 
{
   ssCore.App.showMsgBox({prompt:r.Error.code + " " + r.Error.description});      
   //ssCore.App.quit({});
}
else
{
   ssCore.App.showMsgBox({prompt:r.result});      
}


Posted by megadar in SWF Studio V3 on Jul 01 2010, 03:47 pm

to northcode,

Большое спасибо! Как всегда помогли.
Thank you! As always helped.


Posted by zengara in SWF Studio V3 on Apr 14 2011, 01:29 am

Hello

I try to use the code you post the js file but it didn't work.
Do I need to do something else?


Posted by northcode in SWF Studio V3 on Apr 14 2011, 02:47 am

If you used the example just above, it loads the jscript file from the Files Tab

r = ssCore.Layout.loadFile({resource:"\\script.js"});

So you need to add a valid JS file called "script.js" to the Files Tab in SWF Studio for that exampel to work properly.


Posted by zengara in SWF Studio V3 on Apr 14 2011, 03:46 pm

Hello

The app freezes and I get an error.

4 LAYOUT ERROR RESOURCE NOT FOUND

7 SCRIPT ERROR RUNTIME ERROR

By the way what I do for ask for a access key and create such key?


Posted by northcode in SWF Studio V3 on Apr 14 2011, 05:49 pm


QUOTE:
you need to add a valid JS file called "script.js" to the Files Tab in SWF Studio for that exampel to work properly

QUOTE:
By the way what I do for ask for a access key and create such key?You can do this whatever way you like. The serial number you generate automatically. When the app starts you ask them for a key that only works with that serial number. They get the key from you after they pay you.


Posted by zengara in SWF Studio V3 on Apr 15 2011, 12:43 am

Hi

I add the script.js and the jscript.js to the Files Tab.


But when I run the app I get this error:

load failed: SCRIPT_ERROR_SYNTAX_ERROR

7 SCRIPT_ERROR_RUNTIME_ERROR


Posted by northcode in SWF Studio V3 on Apr 15 2011, 04:14 am

What's in the script file?


Posted by zengara in SWF Studio V3 on Apr 15 2011, 08:59 pm

script.js

function main() {
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var colDiskDrives = objWMIService.ExecQuery("Select PNPDeviceID from Win32_DiskDrive", "WQL", 0x10 | 0x20);
var enumDiskDrives = new Enumerator(colDiskDrives);
var objItem = enumDiskDrives.item();
var s = objItem.PNPDeviceID;
var ss = s.split('\\').join('|').split('&').join('|');
# alert(ss);
return ss;
}

jscript.js

function main(o)
{
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;

var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");

var colDiskDrives = objWMIService.ExecQuery("Select * from Win32_DiskDrive", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);

var enumDiskDrives = new Enumerator(colDiskDrives);

for (; !enumDiskDrives.atEnd(); enumDiskDrives.moveNext())
{
var objDiskDrive = enumDiskDrives.item();

var s = "";

s += "Caption: " + "\t" + objDiskDrive.Caption + "\r\n";
s += "Device ID: " + "\t" + objDiskDrive.DeviceID + "\r\n";
s += "Index: " + "\t" + objDiskDrive.Index + "\r\n";
s += "Interface Type: " + "\t" + objDiskDrive.InterfaceType + "\r\n";
s += "Manufacturer: " + "\t" + objDiskDrive.Manufacturer + "\r\n";
s += "Media Loaded: " + "\t" + objDiskDrive.MediaLoaded + "\r\n";
s += "Media Type: " + "\t" + objDiskDrive.MediaType + "\r\n";
s += "Model: " + "\t" + objDiskDrive.Model + "\r\n";
s += "Name: " + "\t" + objDiskDrive.Name + "\r\n";
s += "Partitions: " + "\t" + objDiskDrive.Partitions + "\r\n";
s += "PNP DeviceID: " + "\t" + objDiskDrive.PNPDeviceID + "\r\n";
s += "SCSI Bus: " + "\t" + objDiskDrive.SCSIBus + "\r\n";
s += "SCSI Logical Unit: " + "\t" + objDiskDrive.SCSILogicalUnit + "\r\n";
s += "SCSI Port: " + "\t" + objDiskDrive.SCSIPort + "\r\n";
s += "SCSI TargetId: " + "\t" + objDiskDrive.SCSITargetId + "\r\n";
s += "Sectors Per Track: " + "\t" + objDiskDrive.SectorsPerTrack + "\r\n";
s += "Signature: " + "\t" + objDiskDrive.Signature + "\r\n";
s += "Size: " + "\t" + objDiskDrive.Size + "\r\n";
s += "Status: " + "\t" + objDiskDrive.Status + "\r\n";
s += "Total Cylinders: " + "\t" + objDiskDrive.TotalCylinders + "\r\n";
s += "Total Heads: " + "\t" + objDiskDrive.TotalHeads + "\r\n";
s += "Total Sectors: " + "\t" + objDiskDrive.TotalSectors + "\r\n";
s += "Total Tracks: " + "\t" + objDiskDrive.TotalTracks + "\r\n";
s += "Tracks Per Cylinder: " + "\t" + objDiskDrive.TracksPerCylinder + "\r\n";

alert(s);
}

}


Posted by northcode in SWF Studio V3 on Apr 16 2011, 04:42 pm

What you've shown is actually two different scripts. The first one is something that another user posted (no idea if it works) and the seond one is something I posted. If you put that whole thing in a JS file it's not going to work and you will get errors.

Try just this bit of jscript...


function main() 
{
   var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
   var colDiskDrives = objWMIService.ExecQuery("Select PNPDeviceID from Win32_DiskDrive", "WQL", 0x10 | 0x20);
   var enumDiskDrives = new Enumerator(colDiskDrives);
   var objItem = enumDiskDrives.item();
   var s = objItem.PNPDeviceID;
   var ss = s.split('\\').join('|').split('&').join('|');
   return ss;
}


When you run ths script from the example FLA I provided it should display a nessage box with something like this in it.


IDE|DISKWDC_WD3200BEKT-00F3T0___________________11.01A11|5|1EE2287D|0|0.0.0


Posted by zengara in SWF Studio V3 on Apr 18 2011, 08:38 pm

I having an issue.

When I try to publish the FLA using Northcode AS 3.0 classes lib
Flash shows several 1120 errors.
1120: access of undefined property r.
1120: access of undefined property SSCore.

I am using Flash CS 5.0 and 5.5
Should I try to install CS4 or there is some way to load the classes?


Posted by northcode in SWF Studio V3 on Apr 19 2011, 01:31 am

Our SWF should work witb CS5, we haven't tested it with CS5.5 yet. You can drop the SWC in the same folder as your project or you can add a classpath to the AS files to get rid of those errors.


Posted by mbd in SWF Studio V3 on Apr 19 2011, 11:11 am

Make sure r is defined in your code and that you are typing ssCore, not SSCore.

I noticed Tim has an example line above that uses:
r = ssCore.Layout.loadFile({resource:"\\script.js"});
If you haven't defined r you'll get the message you are seeing. Make sure you change that to
var r = ssCore.Layout.loadFile({resource:"\\script.js"});


Posted by zengara in SWF Studio V3 on Apr 19 2011, 02:47 pm

I just add the var

But I got this error:

Error #1010: A term is undefined and has no properties.

I think there is other var that is not defined but I can not find it.


Posted by mbd in SWF Studio V3 on Apr 19 2011, 05:23 pm

That's a runtime error. You should be able to get more info from the error if you build your application using the Flash debug player (dropdown option in the SWF Studio Output tab).


Posted by zengara in SWF Studio V3 on Apr 19 2011, 08:43 pm

I build the app with the Flash 10.0 r45 debug
And I get this info:

Error #1010: A term is undefined and has no properties.
at BlackScreen_fla::MainTimeline/checkForApplications()
at BlackScreen_fla::MainTimeline/myTimerListener()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()


Posted by northcode in SWF Studio V3 on Apr 19 2011, 11:23 pm

Did you include the checkForApplications functions (and the other functions that it calls) that I wrote for you in the other thread where we've been talking? The checkForApplications function is not part of SWF Studio, it just uses SWF Studio functions.


Posted by zengara in SWF Studio V3 on Apr 27 2011, 12:52 pm

No.
I was using the code alone in a new file.
Today I just download the new beta, I compile the app, I don't get the error but the protection didn't work.


Posted by northcode in SWF Studio V3 on Apr 27 2011, 01:14 pm

This JScript does not add protection to your application. It gives you a way to read some unique data about the machine it's running on. That's something you need as PART of a protection system.


Posted by zengara in SWF Studio V3 on Apr 29 2011, 03:40 pm

Hi

What I mean if I didn't get the info.