Page 1 of 2 12 LastLast
Results 1 to 20 of 31
  1. #1
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Embedding an external executable inside a Java program

    I want to to merge between an exe to a JRE file that I will create.
    How would I do that?

    Thanks in advanced.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    Pardon?
    You mean you have an executable (an OS specific program) and you have Java program (ie a set of class files possibly in a jar)?
    What does "merge between" mean wrt to these two disparate things?

  3. #3
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    I have an exe which is a game.
    I am creating a launcher that checks x things and if everything is good it starts the game.
    That way everyone will be able to skip the launcher step and just click the game.exe
    My goal is to "add" / "merge" the exe into my launcher(a jar file) so the only way to open the game would be through the launcher.

    Thanks.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    Doubt that would work.
    Not sure how the OS (which is what executes the exe file) would be able to identify it inside the launcher.jar so that it could actually execute it.

  5. #5
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    It's possible in c# windows - Embedding an external executable inside a C# program - Stack Overflow
    I hope it also possible in Java and someone know how to deal with that.

    Anyway thank you.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    Ah I see now.
    You can do exactly the same thing from a jar file.
    getResourceAsStream("your exe"), then stream that out to a temp file and execute.
    I believe you can even mark it as deleteOnExit these days, though you'd have to dig in the API for that.

  7. #7
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    What you'r saying is to get a resource stream from the exe into the jar file and then save it on a temp file and execute it.
    But the problem is that I still got the exe on the folder so people can use it, or I'm getting you wrong?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    That was what the last sentence was about.
    Java keeps running until the other program has exited, then either you (or Java itself if you can find the switch) deletes the file created.
    Exactly (in fact) as the code on Overflow.

  9. #9
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    Sorry I think I wasn't clear enough.
    The java application specify the client.exe name in the getResourceAsStream("your exe") method which means the client is there!
    I know that it will create a new temp exe that will be deleted when the application will be closed but the first exe is there as I said above.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,243
    Rep Power
    19

    Default Re: Embedding an external executable inside a Java program

    The "first exe" would be a JarEntry inside your jar.

    That wouldn't prevent a knowledgeable person from extracting it though. And if it's not your own program, which from your statements it doesn't appear to be, what's to prevent them getting it from wherever you did?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    Quote Originally Posted by tnrh1 View Post
    Sorry I think I wasn't clear enough.
    The java application specify the client.exe name in the getResourceAsStream("your exe") method which means the client is there!
    I know that it will create a new temp exe that will be deleted when the application will be closed but the first exe is there as I said above.
    In (almost) exactly the same way that the resource (exe) is in the C# code referred to in STack Overflow.
    As Darryl says, a knowledgable person will be able to get at the exe...in both cases.

    That exe has to be somewhere.
    It has to be accessible by the software to stream it to a temp area.
    That means someone else can get at it.

    You can't magically create it out of nothing.

  12. #12
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    You can't magically create it out of nothing.
    I agree with you.

    Hmm would it be possible to get the stream from another computer?
    I mean the launcher will be used from the client computer and the client.exe will sit on the server exe.
    So when he'll click the start game it will open a connection to the server and pass the information through a stream as you already said and save it in a temp file.
    Theoretical I know what to do as you can see, so would you mind focus me on some classes to work with?

    I know how to open a connection between 2 computers and send messages to each other.
    So instead of sending messages I will read the exe(is it even possible?i used to read only txt files) save it and send it to the client?
    Now the client will recieve a file instance and it need to save it somewhere while the game is running, how do I save an exe?as I said I used to work just with txt files(or it's the same? :0 ).

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    Yes.
    You could have the exe on a server, but that's still exposed somewhere isn't it?
    The stream has to get to that machine somehow, and so is readable.

    I guess I'm just curious what you are actually trying to prevent with this...because I doubt you'll succeed.

    Anyway, a file is a file is a file. Java doesn't care what sort, so long as you use the correct type of output. In the case of text files that's usually a Writer. In the case of binary (eg exe) files that would be an OutputStream. So you'd open your InputStream to the exe file (wherever you end up putting it), then loop round that stream reading into a byte[] buffer of some size (8k is popular), writing it out to the OutputStream (the temporary file).

  14. #14
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    I guess I'm just curious what you are actually trying to prevent with this...because I doubt you'll succeed.
    Many users used certain softwares to hack my game, for that they have to select my game.exe, then if I will completely remove the game.exe from the folder and make sure that they don't have any file on that folder except mine I can prevent some hacks attemps.

    I will try to code it right now, and I will update you if I'll have some troubles.
    One question, this temp file will be an exe right? if true they will be able to copy that exe (while the game is running).

    big edit:
    lol I opened the eclipse and then something came up.
    All the codes I wrote for connections between game & client had a client code and a server code that has to be executed.
    I really have to make a server side code to run all the time?the only thing I need is to download a single file.
    But the download will be done only if the launcher requested.
    I guess it has to be done by 2 codes, client & server side to verify who is the client.
    I'm asking and anwering my self at the same time
    Last edited by tnrh1; 01-26-2012 at 04:12 PM.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    The file has to be somewhere, which is why I said this isn't going to stop people who are determined enough.

  16. #16
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,243
    Rep Power
    19

    Default Re: Embedding an external executable inside a Java program

    Forget about trying to enforce security by technical measures. The best of programs created and marketed by multi billion dollar companies have been hacked.

    The only true security is by legal enforcement. If you can't afford to pursue that route, just be happy with whatever income your game generates and ignore the losses arising out of piracy.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  17. #17
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    db then your advice is not even try to make my game more secure.
    This type of hackers are not even hackers, they just use a program that someone else did.
    If it will decrease the hack attemps from 1000 in a month into 100, I did mine.

    The file has to be somewhere, which is why I said this isn't going to stop people who are determined enough.
    99% of the hackers are little kids that the only thing they know is to press, select exe, inject and launch game.

    And if I pass in the connection a String that will represent a password and the server will vaildate if it's the correct one I will block all the other unwanted downloads, I hope.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Embedding an external executable inside a Java program

    I seem to remember the Half Life lot used to be happy if they could get a game to a fortnight after release before it's hacked.

  19. #19
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    It took some time but I finally got a code that connect to the server, and download the exe to the client folder (thanks to norm).
    So the only thing I need to know now is how to launch it and "deleteOnExist" as you said.
    Quote Originally Posted by Tolls View Post
    Ah I see now.
    I believe you can even mark it as deleteOnExit these days, though you'd have to dig in the API for that.
    What do you mean by "mark it"? can you be more specific please?
    Launching the game is easy, but the delete on exit part sounds much harder.

    Thanks.

  20. #20
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Embedding an external executable inside a Java program

    Everything is working now,
    you can close the thread.
    Thank you guys.

Page 1 of 2 12 LastLast

Similar Threads

  1. Open external file with external program
    By Wietse de Vries in forum New To Java
    Replies: 1
    Last Post: 12-31-2011, 04:52 PM
  2. Replies: 3
    Last Post: 08-10-2009, 06:34 AM
  3. Execute external program from java
    By ankitmcgill in forum New To Java
    Replies: 1
    Last Post: 06-01-2009, 03:58 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •