Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am looking at an obfuscated application, and the application seems to have a lot of GOTO's which I want to rearrange or remove
The question is, how would I go about doing this?
for(final MethodNode mn : classNode.methods) {
final BIF is = new BIF(mn); //BIF is my bytecode instruction finder
AbstractInsnNode ain;
while ((ain = is.next()) != null) {
if (ain instanceof JumpInsnNode && ain.getOpcode() == GOTO) {
final JumpInsnNode jump = (JumpInsnNode) ain;
mn.instructions.remove(jump);
removed++;
}
}
}
So I've tried just removing them all, but it doesn't seem to work and I don't know how to rearrange them
I don't think you'll be able to solve this easily, it looks like a quite radical obfuscation mechanism. You could try to un-goto it, linearizing the code by defragmenting the chunks between goto jumps. But then, some goto's are legitimate flow control jumps, so you'll need a way to detect this. It looks like a real challenge, one that will take much of your time. But, maybe the challenge is intruguing enough to push forward :)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm new to JUnit testing and I'm struggling to test a method that will search for a specific vehicle registration and output it that it is found
System.out.println("getSpecificVehicle");
CVMQueue instance = new CVMQueue();
VehicleNode newVehicle = new VehicleNode("YBZ5484", "Car", "Ire", 3, 2.2);
instance.enqueue(newVehicle);
String expResult = "YBZ5484";
String result = instance.getSpecificVehicle("YBZ5484");
assertEquals(expResult, result);
This is my code, It keeps looping in the Console.
How can I fix this?
Check your code; if you improve the formatting you find
while (temp != null) {
...
if (reg.equalsIgnoreCase(temp.getRegNum())) {
...
}
}
Your loop is never changing temp. So, why should it ever stop looping upon being entered? So, obviously your problem is that you missed that loop-closing brace; as you put that assignment to temp after that brace.
But the real take-aways here:
Formatting matters. Maybe, if you had put more diligence in writing down your code, you would have spotted this yourself much earlier. And as Gaket points out correctly: any sane IDE (or coding editor) probably has some "auto format" functionality, that well, formats your source code automatically.
Leading to: code readability matters even more. For example, there is the "Single layer of abstraction" principle; which would have told you to not just put that complete if into that loop; instead you would have created a method to do that work. And again, it would have been so much easier to spot this simple problem.
Learn about using a debugger. You see, the real power of unit tests is that they make it also so easy to isolate bugs: you put a breakpoint somewhere; and run your test in the debugger; and you can directly observe what is going on.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Personally, I write my Java like this:
class xyz {
...
}
OR
if (condition) {
...
}
etcetera...
In so many examples, I see code written like this:
class xyz
{
...
}
OR
if (condition)
{
...
}
etcetera...
To me, my way makes the most sense because not only does it take less lines to write, but (again, in my opinion) looks more proper and professional. I'd love to know people's opinions - and reasoning behind them - as to which form is better and why.
The first one with opening braces on the same line is almost the standard Java programming guideline for years.
The original Sun Java guideline, that was never updated since 1999.
http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141270.html
Google Java guideline
https://google.github.io/styleguide/javaguide.html#s4.1-braces
Android style
https://source.android.com/source/code-style.html
On the opposite side, many open source platforms like Apache/maven advocate brace in new line
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
The Boolean array is initialized to true. I need to know how to turn every third value to false and also going through the array over and over. It is essentially duck duck goose without the randomness.
This sounds like a beginners programming exercise, so I'm going to just give you a hint or two:
Go back to your textbook, lecture notes, tutorial and reread the stuff on for loops. Focus on the old style ones.
Think about how to write a for loop that steps through integer index values in the pattern that you require.
Re "... going through the array over and over" - not sure what you mean, but maybe the hint for this is to think about using nested loops; i.e. a loop inside another loop.
But the most important advice is to try and work this out for yourself.
Well I'm really not sure what you mean by going through the array over and over but the following code will turn every third value to false.
for (int i = 0; i < myVar.length; i++) {
if (i % 3 == 0) {
myVar[i] = false;
}
}
Edit: Oops someone beat me to it while I was typing lol.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Ok so if you want to check if a list is not empty
we would need to do something like
if(! mylist.isEmpty())
this affects code readability, so how can we write the same thing in a readable way, calling out negation of condition check.
One of possibility is to have a static helper function like:
static boolean not(boolean condition) { return !condition;}
How bad is this idea? Are there other options in apache common or guava etc? Or any other way you have achieved this?
It is not a bad idea in itself and it will not affect anything.
However I think many people will disagree with you regarding the "unreadability" of the normal way of negating things using !.
if ( ! list.isEmpty() )
versus
if ( not( list.isEmpty() ) )
does not make much of a difference IMHO.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have to deal with a domain object that's real name is 351K-Report. According to the Java naming convention its forbidden to use a number at the beginning of an identifier.
I don't want to fully spell out the number. And, I also think that it's a bad idea to place an underline in front of the number.
But what is the recommended alternative?
UPDATE
There are also other reports, like SpecReport, TopReport, LF10Report and so on. So I'm very doubtful that inverting parts of the noun changes the meaning of the whole project.
Maybe reverse it. For example:
report351K
That would be very bad..
Imagine this:
int 1d = 3;
double d = 1d * 2;
What would be d?
Alternatives:
Since variables that begins with _ usually indicates for class member, I would use report351K.
if you really want to do this then _351KReport but I don't think you should do this. try to make something meaningful of it and at the same time is convineient to Java