Need a way to edit program's own file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Need a way to edit program's own file

  1. #1
    Join Date
    Apr 2008
    Posts
    26

    Need a way to edit program's own file

    I need a way to make a program work on only the first computer it is run on, it doesn't need to be very secure but it needs to work. The idea that I came up with is to have the program save the MAC Address (of the first computer it is run on) inside of its own EXE. And then from then on check to see if the MAC Address corresponds to the computer its on..

    So I have a couple questions

    1. How can I have a program edit its own file during execution. Is this possible? Are there workaround ways to do it?

    2. How can I have the compiler tell me where, in the file, a certain piece of data was saved. I'm using GCC, though I could use Visual C++.

    Thanks everybody!

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,019

    Re: Need a way to edit program's own file

    Self modifying executables are quite dangerous: most systems do not allow it. The main problem is that there are checksums embedded in the executable. If you don't patch them correctly, it stops working. Also, moving from one compiler to another or from one OS to another could cause the program to stop working.

    How about alternative techniques like

    1) writing it to the registry.
    2) creating a file in allusers\documents
    3) encrypted file containing the MAC

    These are somewhere other than the directory from which the executable is run so, in theory, an unknowing pirate will only copy the exe and not the registry entry or the file in allusers\documents.

    MAC addresses aren't totally safe (neither is any technique to a really determined cracker). If you are running MS loopback adapter, that is the first MAC address picked so anyone could just install the MS loopback adapter and they've got the Software. Also, network cards can change. Do you have an option to reset this and take a new address.

    Remember that MAC addresses can also be faked. http://fake-mac-address.qarchive.org/
    Succinct is verbose for terse

  3. #3
    Join Date
    Apr 2008
    Posts
    26

    Re: Need a way to edit program's own file

    Thanks, but the problem with storing the MAC address in some hidden file is exactly that, the person would simply copy the EXE, which would be the first thing most users would try.. This protection is aimed against novice users, crackers will find a way around nearly any protection if they are given reason to try, so I'm not worried about making it extremely secure since even big companies like Microsoft and Apple can't seem to keep their programs extremely secure.

    So if there's no way for an EXE to edit itsself I was thinking that I could store another EXE in a resource in the file, and then EXE #1 would export EXE #2, EXE #1 would close and #2 would edit the now available file. Then the only problem remaining is I wouldn't know where to edit the file.. I'd need to know where the constant I set aside in the code was saved. I could do a search for 00-00-00.... but that seems too unreliable to me.

    Suggestions? Or a way to have the EXE edit itself if you know of one..

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Need a way to edit program's own file

    Quote Originally Posted by Brownhead View Post
    I need a way to make a program work on only the first computer it is run on
    I don't understand the use case, I presume. Say Joe Schmoe downloads your app from somewhere, stores it on his flash drive, plugs in the flash drive to PC A , copies the exe and runs it. Now, what would prevent Joe Schmoe from copying the exe from his flash drive onto PC B and run it like a virgin copy ?

  5. #5
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Need a way to edit program's own file

    One of the most effective ways is to modify part of the download so that each one is unique. Then require registration via a webservice. Do not allow multiple registrations of the same "Serial Number"....

    The KEY part is requiring an interaction with the server to achieve activation. Of course it is necessary to provide an alternate if you have people legitimately installing on machines without WebAccess, but there are service providers who specialize in that.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,970

    Re: Need a way to edit program's own file

    Suggestions?
    The suggestion is quite simple: never let your exe run with no registration information present in the system. Consequense: using an application installer (that gathers a registration information, puts it into a system but does nothing really valuable except installation) is a minimal requirement. The optional step is further activation.

    And one more point to be clear: forget about self-modification. This trick is easily cracked by plain binary diffing.
    Best regards,
    Igor

  7. #7
    Join Date
    Apr 2008
    Posts
    26

    Re: Need a way to edit program's own file

    Hmm, alright. I see that requring activation online will be the best and possibly only semi-secure option, thankyou everybody who has helped me and offered their suggestions.

  8. #8
    Join Date
    Nov 2007
    Posts
    613

    Re: Need a way to edit program's own file

    MAC address based identification is a bad ideea. What if the user needs to replace the network card ?

    If you want hardware based identification I suggest you to gather info about as many devices as you can but during the verification allow a 33% error.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center