where's the output?

hi, Im trying to combine Java with C++ (stupid me!!!)

my problem is with a C++ keylogger

normal (non-Java) programs I can execute in Java and read the output they produce.

With this keylogger (I found it on the net) cannot however...
So I found this logger on internet and changed the code to make it write all output to the stdout ipv to a FILE.

for every key typed a print to the stdout is done for that key
I tried both
fprint(stdout,"%s","SomeKey");
and
printf("%s","SomeKey");

but it seems this logger still doesnt write to the same output as 'normal' programs do because I don't see any input at my Java Process

does anyone actually understand what problem I try to point out here, and if so, what should I change in the C++ logger to make the output come through?

Klaas
Im trying to combine Java with C++
And I'm guessing you'll use the result to transmute lead into gold.

does anyone actually understand what problem I try to point out here, and if so, what should I change in the C++ logger to make the output come through?
That's a tough question, considering you haven't given us any code.

Wouldn't it be easier to code the entire thing either in Java or C++? Both are perfectly capable languages, so interfacing them doesn't make any sense to me.
And I'm guessing you'll use the result to transmute lead into gold

I dont know what turns you on but personally, I'm just trying to make a simple program for my own personal use that I doubt anyone besides me would do any good

the thing is that I have a Thread running in Java and I cant stop it from outside the app, since Java is unable to detect key/mouse events outside its own VM. C++ however can

Wouldn't it be easier to code the entire thing either in Java or C++? Both are perfectly capable languages, so interfacing them doesn't make any sense to me.

It would, if Java was capable...

That's a tough question, considering you haven't given us any code


C++ code
1
2
3
4
5
6
7
while(true) {
   if(keypressed==SomeKey) {
      printf("%s","SomeKey");
   } else if(keypressed==OtherKey) {
      printf("%s","OtherKey");
   }
}


Java code
Thread1: Process p=Runtime.getRuntime().exec("keys.exe");
Thread2:
1
2
3
4
5
6
in=p.getInputStream();
int r=in.read();
while(r!=-1) {
   System.out.write(r);
   r=in.read();
}


Now if I run, for example, 'javadoc' in Thread1, instead of 'keys'
I get to see javadocs output (which is it's help listing)
But for keys I dont get anything!

I'm using protocode in the C++ there because the file is kinda lengthy and, as said I got it from the internet (http://www.rohitab.com/discuss/index.php?showtopic=9931) and I dont really understand the full of it/of C++ (hence also the fact I'm posting this in 'Beginner')
Last edited on
And I'm guessing you'll use the result to transmute lead into gold.

What do you think a help forum is for? Just to ridicule every C++ newbie? You think that is usefull? You think that will do the popularity of C++ any good?

get real dude. If you dont know the answer, its OK to say it. Even if you're a 'pro' or a 'guru' or whatever... - a 'wannabe' perhaps?

Klaas
Last edited on
a 'wannabe' perhaps?

Haha, thats a first. He's more, as you stated, a 'pro' or 'guru'. Just look at his post count for god sake.

Why would you post your code for him to see, and then have a go at him in a second post?
Cause he's not helping me, just tryin to ridicule. Post count aint worth none if its all ridiculing - I can do that too but it wont make me a guru

reasons why I wouldnt hold him for a guru?
1. Like said, he's just riduling
2.
Both are perfectly capable languages

No, Java is pretty incapable on many points

3.
considering you haven't given us any code.

Then what do you call this printf("%s","SomeKey"); in my first post?? And that's basically pretty much all the code there is in the mentioned logger
Last edited on
Post count aint worth none if its all ridiculing

Fair point. However, you clearly haven't taken the time to look at any other of his posts because he is one of the most helpful members in this C++ community - yes he has helped me on various occasions.

I can see why you might think he is 'riduling' but its just his way of getting his point accross. I can assure you that anything he says that might seem to just be 'riduling' you will usually have a deeper meaning - try to understand that.

As for your last point, I imagine that he, like I did, thought you might post code for your entire program, or at least the problematic section.
So...you say Java sucks (is incapable) and yet you're using it to make part of a keylogger?

It's not like C/C++ doesn't have access to the main hardware; you'll find many OS-specific ways of finding keys.

Anyhow, I recommend using cout, not printf(). Like so:

cout << "SomeKey";

cout is specifically written to be redirectable, thus its output may show on the console through Java.

And don't bash helios, he's one of the best on the forums, if annoyable. :D
Last edited on
Thanks QWERTYman, it doesnt help though =)

The reason why I use Java is because that's the language I happen to speak, I'd like to learn more C++ but I'm just too stupid for that and there's noone in my direct neighborhood that can enlighten me at the points I don't grasp...

But I found something that helps me in my current situation, though it doesnt really solve the problem in general:

When I run this C++ I can't get the output in Java, but I found I can detect when it stops
(in.read()==-1).
So when I hardcode a stopping sequence in the C++ logger, I can use that same sequence to stop my Java Thread:
while(in.read()!=-1); AThread.stop();

Klaas
Last edited on
There's no need to be so touchy. I wasn't trying to ridicule you. I was stating my opinion that combining a native language and a language run from a virtual machine/JIT compiler is not unlike turning lead into gold. Any tinge of ridicule was interpreted into existence by you.

And giving us two function calls doesn't go with the question "what should I change in the C++ logger to make the output come through?" I value terseness, but that's just ridiculous.

Now, back on topic.
There's nothing wrong with the printf() calls. The only thing I would change is that they're taking unnecessary parameters: printf("%s","string") is the same as printf("string")
There may a typo in that last snippet of yours:
while(in.read()!=-1); AThread.stop();
is the same as
1
2
while(in.read()!=-1);
AThread.stop();
but different from
1
2
while(in.read()!=-1)
    AThread.stop();


I still think it's worth to learn C++ until you can do this without binding the two languages together into a horrible, unmaintainable mess. The C++ part would seem to be doing most of the work (the key logging part), anyway, so I don't understand why you need Java at all. I think it'd even make more sense (in the order of "it makes more sense to shoot yourself in the foot than stab yourself in the eye") if you used Java to make a portable keylogger and then passed the information to a C++ module.



And don't bash helios, he's one of the best on the forums, if annoyable. :D
Easily annoyable, might I add.
Last edited on
It wasnt a typo - I found that I can detect when the C++ logger stops, so what I'm doing there is
1
2
while(CPP logger is busy) wait for it to stop;
   <when the CPP logger has stopped> stop the Java Thread(AThread) as well;

this code I execute in BThread, so in conclusion:
using BThread, I can stop AThread with keyboard input from outside of the VM

Why I just dont write my complete app in C++?
because I'm a C++ newbie -> In C++ I dont know how to capture screenshots, create frames, trigger mouseclicks, create sub processes, etc, etc.

And you might wanna catch me on Thread.stop(), which is unsave (in some situations it can cause a deadlock):
Yes. It's unsave and deprecated. But its the easiest and shortest way to explain my "solution" here
(if its a sulotion at all that is, because though I bypassed my problem in this particular situation, the root problem of capturing the loggers output so one can read back what keys were pressed, still exists)

Klaas
Topic archived. No new replies allowed.