none
How to protect flash files ? RRS feed

  • Question

  • I have a windows form application which uses many flash files.

    I created a setup file for my application.

    After installing my setup the flash files are visible in program files folder  and users can copy and uses it without my

    application.

    How can protect these flash files so that nobody can use these files without my application ?

    Saturday, October 5, 2013 11:03 AM

Answers

  • Hi Vineeth,

    According to your description, you want to protect your file. I have a way to achieve your goal, but will be a little complicated.

    I recommend you use Serialization. You could read the files which you want to protected, convert them to byte[], and then save them to disk. When you need to use them, you should convert them back to a temporary folder, use them in exclusive mode and delete them.

    Serialization has some advantages. One is that you could customize the file extension. The two advantage is that someone cannot open your file and don’t know how to read your file. However, this method has a disadvantage that the file cannot be too large. Because we need to read it all to memory.

    Here is some code for you to try:

    //create a custom file in disk

            private void button1_Click(object sender, EventArgs e)

            {

                using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\privatefile.dat", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))

                {

                    //if your file was too large, this method will throw exception

                    byte[] bs = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "\\aaaaaa.swf");

                    BinaryFormatter formatter = new BinaryFormatter();

                    formatter.Serialize(fs, bs);

                    MessageBox.Show("done");

                }

            }

    //restore a swf file

            private void button2_Click(object sender, EventArgs e)

            {

                using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\privatefile.dat", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))

                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    byte[] bs = formatter.Deserialize(fs) as byte[];

                    //restore file to another directory, and delete it after use

                    File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + \\tmp\\tmpfile.swf, bs);

                    MessageBox.Show("restore done");

                }

            }

    Hope useful to you.

    Best Regards,

    Hetro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 8, 2013 6:12 AM
    Moderator

All replies

  • Have your flash files as embedded resources in your assembly. At run time you can read them as Stream. Visit below links for more info.

    http://support.microsoft.com/kb/319292/en-us

    http://www.codeproject.com/Articles/3089/Understanding-Embedded-Resources-in-Visual-Studio

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Sunday, October 6, 2013 3:36 AM
  • My application uses a flash game which contains an exe file and some swf files in subfolders, so i cannot use these files as embedded  resource. Is there any other method to protect the supporting files in  an application ?



    • Edited by Vineeth PV Monday, October 7, 2013 6:44 AM
    Monday, October 7, 2013 6:43 AM
  • If the files have to be saved on the disk, then I do not think of any direct way. But you can make it difficult to copy the files by storing them in some other location than installation folder.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, October 7, 2013 7:32 AM
  • Hi Vineeth,

    According to your description, you want to protect your file. I have a way to achieve your goal, but will be a little complicated.

    I recommend you use Serialization. You could read the files which you want to protected, convert them to byte[], and then save them to disk. When you need to use them, you should convert them back to a temporary folder, use them in exclusive mode and delete them.

    Serialization has some advantages. One is that you could customize the file extension. The two advantage is that someone cannot open your file and don’t know how to read your file. However, this method has a disadvantage that the file cannot be too large. Because we need to read it all to memory.

    Here is some code for you to try:

    //create a custom file in disk

            private void button1_Click(object sender, EventArgs e)

            {

                using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\privatefile.dat", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))

                {

                    //if your file was too large, this method will throw exception

                    byte[] bs = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "\\aaaaaa.swf");

                    BinaryFormatter formatter = new BinaryFormatter();

                    formatter.Serialize(fs, bs);

                    MessageBox.Show("done");

                }

            }

    //restore a swf file

            private void button2_Click(object sender, EventArgs e)

            {

                using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\privatefile.dat", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))

                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    byte[] bs = formatter.Deserialize(fs) as byte[];

                    //restore file to another directory, and delete it after use

                    File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + \\tmp\\tmpfile.swf, bs);

                    MessageBox.Show("restore done");

                }

            }

    Hope useful to you.

    Best Regards,

    Hetro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 8, 2013 6:12 AM
    Moderator