Results 1 to 5 of 5
  1. #1
    DarkHarbinger is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default How to have program detect own name

    Okay so this is a bit of an experiment, I want to make a program that is password-protected, and that if the password is used incorrectly a certain number of times the program deletes itself. Simple enough, but it doesn't take into account if it was named testProg.* and someone renames it pwProg.*. I was wondering if there was any way to get a File object to detect the running program, so that it would delete itself in any scenario. This is a completely personal experiment, and may or may not have any possible real applications (due to loss of program in certain situations), but I would still like to know if it is at least feasible. I have also considered a File object that has the path of the program and seeing if it can just delete all files until it reaches itself, though I have little hope in that line and it is kind of sloppy. Thanks for your time and any help.

  2. #2
    otacon's Avatar
    otacon is offline Member
    Join Date
    Dec 2010
    Posts
    24
    Rep Power
    0

    Default Re: How to have program detect own name

    Ha, well, I might be completely off base but it should be possible for your program, whatever is renamed to, launch an independent program fed with the file path which started it, designed solely for pw check. This small program would be I believe capable of knowing and deleting the original program is the authentication failed. Never really tried anything on those lines though, so I may be wrong.

    Also, this would not handle a case when someone simply makes a copy of the original program, and can simply retry logging in.
    Last edited by otacon; 07-25-2012 at 05:42 PM.
    --Otacon
    Somebody set up us the bomb.

  3. #3
    durrani is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default Re: How to have program detect own name

    Quote Originally Posted by DarkHarbinger View Post
    Okay so this is a bit of an experiment, I want to make a program that is password-protected, and that if the password is used incorrectly a certain number of times the program deletes itself. Simple enough, but it doesn't take into account if it was named testProg.* and someone renames it pwProg.*. I was wondering if there was any way to get a File object to detect the running program, so that it would delete itself in any scenario. This is a completely personal experiment, and may or may not have any possible real applications (due to loss of program in certain situations), but I would still like to know if it is at least feasible. I have also considered a File object that has the path of the program and seeing if it can just delete all files until it reaches itself, though I have little hope in that line and it is kind of sloppy. Thanks for your time and any help.
    You can force the user to name the file as it was, other wise don't execute anything...
    Java Code:
    public class PassOrDelete {
        
        public static void main(String args[]){
            PassOrDelete passOrDelete = new PassOrDelete();
            
            if (!"PassOrDelete".equals(passOrDelete.getClass().getName())){
                System.err.print("Please name it as PassOrDelete");
            } else {
                System.out.println("File name OK");
                // do your stuff here.
            }
        }
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How to have program detect own name

    The JVM won't like it if the .class file's name is not the name of the class it contains. Have you tried your code?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    stathis is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: How to have program detect own name

    I suspecting that there are some assumptions here.

    A. The classes packaged in a jar.
    B. The whole program consists of a single jar.

    DarkHabbinger expecting to find myFoo.jar somewhere in file system, and if someone will rename it the whole logic would collapse.

    As Norm suggested the real program is something like my.domain.pkg.MyClass and this is unique and if will be renamed it will be not accessible at all. In that case hacker will fail.
    BUT, as otacon noticed. Even if somehow a solution to problem is found, the hacker will still have the ability to keep a copy and continue trying with the copy.

    If you ittention is to avoid a brute force attack. (A robot that is trying a lot of difference passwords) I think that the best way is to delay the whole process. E.g. after some retries introduce some delay.

    Ofcourse allways you have the ability to provide an encrypted file together with your classes, (if you dont want to be discovered, package it in your jar) and whenever you decide that you want to make obsolete this copy of your program write something there. This copy of your program would be unusable any more, and still you can unlock it if you want.

    I am realizing that all of these are little bit general, and we are willing to give you more concrete answers if you provide more descriptive requirementts.

    P.S. I did not wanted to offense any one with that WE
    Last edited by stathis; 08-14-2012 at 09:22 AM.

Similar Threads

  1. How to detect object by going near to it
    By Sudharshan in forum New To Java
    Replies: 10
    Last Post: 03-14-2012, 02:17 AM
  2. JMF: Trying to detect webcam..help!
    By boblettoj99 in forum AWT / Swing
    Replies: 0
    Last Post: 11-10-2011, 12:51 AM
  3. Detect system shutdown/log off
    By cmpie1 in forum New To Java
    Replies: 0
    Last Post: 11-29-2010, 06:07 AM
  4. How to detect deadlocks
    By pinheiroa in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-03-2010, 02:36 PM
  5. Unable to detect OS name
    By neetu.jainvi@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 12-09-2009, 05:56 PM

Posting Permissions

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