Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawn java.exe on Windows not working #2

Closed
rgl opened this issue Apr 19, 2015 · 6 comments
Closed

spawn java.exe on Windows not working #2

rgl opened this issue Apr 19, 2015 · 6 comments

Comments

@rgl
Copy link

rgl commented Apr 19, 2015

I'm trying to spawn a java application on Windows, but its not working even with an hello world created like:

  cat<<"EOF"> Program.java
public class Program {
  public static void main(String[] args) {
    System.out.println("Hello, World");
  }
}
EOF

  javac Program.java
  jar -cfe Program.jar Program Program.class
  java -jar Program.jar

The node script is:

var frida = require("frida");
var which = require("which");

const JAVA_PATH = which.sync("java");

frida
  .spawn([JAVA_PATH, "-jar", "Program.jar"])
  .then(function(pid) {
    console.log('spawned:', pid);
    // This is where you could attach (see below) and instrument APIs before you call resume()
    return frida.resume(pid);
  })
  .then(function() {
    console.log('resumed');
  })
  .catch(function(error) {
    console.log('error:', error.message);
  });

It will error out with:

spawned: 5784
resumed
Error: Could not find or load main class '-jar'
@oleavr
Copy link
Member

oleavr commented Apr 19, 2015

Interesting. Does it work with any other applications? Did you try this use-case with the python binding by any chance? (I'm curious if it's a frida-node bug or deeper in the stack.)

@rgl
Copy link
Author

rgl commented Apr 19, 2015

I've tried with cat, echo, just java.exe (without arguments) and it works. But, it seems something odd happens when arguments are passed to java.exe.

I didn't try with python. I'll try it later.

@oleavr
Copy link
Member

oleavr commented Apr 19, 2015

Ok! I wonder if there's something wrong with how we construct the argument list.

@rgl
Copy link
Author

rgl commented Apr 19, 2015

it has the same issue with python:

import frida
import os

# NB python 3.3+ already has a shutil.which function. we somewhat emulate it here.
def which(binary):
    extensions = os.getenv("PATHEXT", "").split(os.pathsep)
    for p in os.environ["PATH"].split(os.pathsep):
        path = os.path.join(p, binary)
        for extension in extensions:
            p = os.path.abspath(path + extension)
            if os.path.isfile(p) and os.access(p, os.X_OK):
                return p
    return None

JAVA_PATH = which("java")

args = [JAVA_PATH, "-jar", "Program.jar"]

# this works fine:
#os.spawnv(os.P_WAIT, JAVA_PATH, args)

pid = frida.spawn(args)
frida.resume(pid)

EDIT I've added the os.spawnv call.

@oleavr
Copy link
Member

oleavr commented Apr 19, 2015

Aha, nice. Clearly a bug in frida-core then. I'll have a look at it before the upcoming release. Thanks!

@oleavr
Copy link
Member

oleavr commented Apr 23, 2015

Fixed by frida/frida-core@2ff867f. Thanks for reporting!

@oleavr oleavr closed this as completed Apr 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants