Javassist help.

Hey all, I have a quick question regarding Javassist.

How do I insert an expression directly before/after an expression?

For example, I have a HelloWorld class with a log method that prints out the numbers to screen like this:

1

2

3

5

6

Notice number 4 is missing. I want to be able to insert a log("4"); statement between log("3"); and log("5");

How do I do this?

HelloWorld.java:

publicclass HelloWorld{

publicstaticvoid main(String[] args){

log("1");

log("2");

log("3");

log("5");

log("6");

}

privatestaticvoid log(Object o){

System.out.println(o);

}

}

Note: I don't want to refer to line numbers since I will be obfuscating and deleting the line number tables.

[1364 byte] By [solarwinda] at [2007-11-27 9:19:55]
# 1
WTF is javassist?
petes1234a at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 2
Ah, I see: http://www.csg.is.titech.ac.jp/~chiba/javassist/Perhaps you need to find a javassist forum?
petes1234a at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 3
> WTF is javassist?is 2b assisting teh jav misteire petes.
Navy_Codera at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 4
Boy I ask a simple question and all I get is spam... How sad...
solarwinda at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 5
spam? my link was directly to the javassist site. how is that spam?
petes1234a at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 6

> Boy I ask a simple question and all I get is spam...

> How sad...

This is not the javassist, netbeans, eclipse, JBoss, Joe-Schmoe's Java Junkyard, etc. support forums. Just because a technology is java-related doesn't mean that this is the forum to support it. When dealing with this type of thing, find the developers' mailing-lists, forums, FAQs or what-have-you. You're always more likely to get a better, more rapid - often times more specific response from those sources.

Navy_Codera at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 7
... not to mention the fact that had you taken 10 seconds to type "javassist" into google, you would have found the same results as the only productive post on this thread gave you - a link to the developer's web site.
Navy_Codera at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 8
I suggest you get your attitude straight. I've searched many places, including the Javassist site and could not find any answers relating to my question. Thank you, incompetent fool.
solarwinda at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 9
> I suggest you get your attitude straight. I've> searched many places, including the Javassist site> and could not find any answers relating to my> question. Thank you, incompetent fool.Good way of encouraging others to try to help you in the
petes1234a at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 10

> I suggest you get your attitude straight. I've

> searched many places, including the Javassist site

> and could not find any answers relating to my

> question. Thank you, incompetent fool.

After searching so many places, you concluded this was the best place to ask such a question? I think here's only one person who needs his attituide straight, and it's not Navy_coder.

quittea at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 11
I know, it's great, isn't it? Never fails...
solarwinda at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 12

"After searching so many places, you concluded this was the best place to ask such a question? I think here's only one person who needs his attituide straight, and it's not Navy_coder."

Oh, golly gosh! Could it be.... hmm... YOU?

Yes, I did search a few places, but it's odd how people try to retaliate in odd ways for their stupidity... it was my mistake to ask you all... Never should have bothered...

Message was edited by:

solarwind

solarwinda at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 13
> I know, it's great, isn't it? Never fails...What? Stupidity? Yeah ...
quittea at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 14
This place SERIOUSLY needs moderators...
solarwinda at 2007-7-12 22:12:37 > top of Java-index,Java Essentials,Java Programming...
# 15

> Oh, golly gosh! Could it be.... hmm... YOU?

No, it's not me.

> Yes, I did search a few places, but it's odd how

> people try to retaliate in odd ways for their

> stupidity... it was my mistake to ask you all...

> Never should have bothered...

Yes, people are strange when one starts interacting with 'em, aren't they? Don't be bothered too much, you'll get used to it ...

quittea at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 16
> This place SERIOUSLY needs moderators...You realize this after being a member for just 2 months? I'd call this quick.
quittea at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 17
Ok seriously though, I'd REALLY VERY MUCH appreciate it if SOMEONE can help me solve my petty problem. I'm sure there are many intelligent people who can solve this quickly...
solarwinda at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 18
> I'm sure there are many intelligent people who can solve this quickly...I'm pretty sure.
quittea at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 19

> Ok seriously though, I'd REALLY VERY MUCH appreciate

> it if SOMEONE can help me solve my petty problem. I'm

> sure there are many intelligent people who can solve

> this quickly...

Some friendly advice. After having insulted a frequent and well-regarded poster here you assume that you have a good chance of getting help? My guess is probably not. You might want to try over at javaranch.

petes1234a at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 20
Wow. It took me a grand total of about seventeen seconds to find the answer to this. There's no way this guy bothered reading the documentation.
Navy_Codera at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 21
> Wow. It took me a grand total of about seventeen> seconds to find the answer to this. There's no way> this guy bothered reading the documentation.Why should he? There's this forum doing his job ...
quittea at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 22

If you mean that little code block with the before-exptressions in red text colour, that doesn't work, tried that... If you would be so kind as to point me to where you found it, that'd be great. Also, if you're referring to the line number method, already checked that out (wont work for my situation since my class will have its line number tables deleted).

solarwinda at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 23
You guys did seem to come of kind of spammish.Perhaps instead of writing"wtf is this javaasst"You could have googled it? Just like you told the original poster to do about his question.
lethalwirea at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 24

> You guys did seem to come of kind of spammish.

>

> Perhaps instead of writing

> "wtf is this javaasst"

>

> You could have googled it? Just like you told the

> original poster to do about his question.

Thank you, exactly what I was trying to get at.

Hmm, looks like this will require some modification of Javassist. My real objective is to modify an obfuscated class file which has been flow obfuscated, aggressively renamed and line number tables deleted. Inside, it will have several string constructors with secret messages. My goal is to use Javassist to reroute those strings to log(string); statements so as to reveal the string. I know I know that this can be done with reflection, but I must strictly use byte code modification means such as either BCEL, Javassist, ASM and so on. Although revealing hidden messages is one of my first goals, some others include inserting expressions and method calls any where I want through out the code.

solarwinda at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 25
so whose program are you doing this to?
petes1234a at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 26
> I suggest you get your attitude straight.**** Off !!!
corlettka at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 27
> I suggest you get your attitude straight. > ...Yes, that's always a great response to get help around here. Piss off, twat!
prometheuzza at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 28
> so whose program are you doing this to?My own.Edit: Seriously, how immature to spam a thread like this. Especially from some senior members, I expected better.Message was edited by: solarwind
solarwinda at 2007-7-21 22:59:01 > top of Java-index,Java Essentials,Java Programming...
# 29

> > so whose program are you doing this to?

>

> My own.

I'm confused then. If it is your own program, why not modify it directly? Why go through all of this? Why must you manipulate the byte code and not the source code? What you are trying to do is obviously not straight-forward (else you wouldn't be here asking for help). What am I missing?

petes1234a at 2007-7-21 22:59:02 > top of Java-index,Java Essentials,Java Programming...
# 30
I always like challenge =)Well, there will be other uses for this, I'm just flexing my Javassist/BCEL muscle, but this will be more important for other projects... So, any ideas?
solarwinda at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 31
> ...> Edit: Seriously, how immature to spam a thread like> this. Especially from some senior members, I expected> better.> ...You brought it on yourself with your attitude.
prometheuzza at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 32
> ... So, any ideas?Yes: leave this place, and go here:Javassist user questions: http://www.jboss.com/index.html?module=bb&op=viewforum&f=178
prometheuzza at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 33
Already posted there quite a while ago, that place isn't too active. I believe this is the best place to ask as there are quite a few knowledgeable people here...
solarwinda at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 34

> Already posted there quite a while ago, that place

> isn't too active. I believe this is the best place to

> ask as there are quite a few knowledgeable people

> here...

With the exception of the incompetent fools though, right?

>Thank you, incompetent fool.

Navy_Codera at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 35

> Already posted there quite a while ago, that place

> isn't too active. I believe this is the best place to

> ask as there are quite a few knowledgeable people

> here...

You could have stated that in your original post. You also could have been more descriptive and have explained why you posted this here and provided a link to the software you were referring to.

But no, you did not, and when asked what this had to do with Java (in general) and a harmless joke, you displayed your attitude.

Good luck with your problem.

prometheuzza at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 36
Hmm. I figured I can iterate through all calls to log and control which ones get changed. That'll solve the single replace problem but not the insert one... Hmmm...
solarwinda at 2007-7-21 22:59:07 > top of Java-index,Java Essentials,Java Programming...