Author Topic: Java quiz series  (Read 23592 times)

0 Members and 1 Guest are viewing this topic.

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: Java quiz series
« Reply #75 on: January 23, 2014, 02:03:54 am »
I apologize. I forgot to say that I dont have the next quiz if it's correct. Great question, by the way, Deque. Im learning a lot from these :)

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java quiz series
« Reply #76 on: January 23, 2014, 09:54:38 am »
What  happens here?

Code: [Select]
for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
   if (b == 0x90) {
      System.out.print("Joy!");
   }
}
« Last Edit: January 23, 2014, 09:58:08 am by Deque »

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: Java quiz series
« Reply #77 on: January 23, 2014, 03:20:44 pm »
You're looping for the minimum and maximum value of a byte as defined by Java's Byte class and printing text in the event of an Intel NOP instruction. This does not occur and hence nothing is printed.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java quiz series
« Reply #78 on: January 24, 2014, 10:01:14 am »
You're looping for the minimum and maximum value of a byte as defined by Java's Byte class and printing text in the event of an Intel NOP instruction. This does not occur and hence nothing is printed.
Yeah, but why does it not occur?

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: Java quiz series
« Reply #79 on: January 24, 2014, 03:29:40 pm »
Hmmm.

Well, 0x90 in decimal is equal to 144, so that's outside of the byte range (up to 127).

Thus I'm assuming this is an actually integer, and to get this to work you'll either need to cast 0x90 to byte or convert the byte to an integer.
« Last Edit: January 25, 2014, 06:46:34 pm by Deque »
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java quiz series
« Reply #80 on: January 25, 2014, 06:47:34 pm »
Hmmm.

Well, 0x90 in decimal is equal to 144, so that's outside of the byte range (up to 127).

Thus I'm assuming this is an actually integer, and to get this to work you'll either need to cast 0x90 to byte or convert the byte to an integer.

Your explanation is correct, do you have the next quiz?
(Sorry for editing your post. I pressed the wrong button while trying to quote you, but I didn't change anything)

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: Java quiz series
« Reply #81 on: January 25, 2014, 06:58:29 pm »
Pass the quiz on to the next person.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java quiz series
« Reply #82 on: January 29, 2014, 10:04:39 pm »
The next one is not a program, but a question.

What is the magic number of a .class file and where did it come from?

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: Java quiz series
« Reply #83 on: January 30, 2014, 04:08:29 am »
The magic number is a hex number meant to identify the file format. It is 0xCAFEBABE.

Came from a combination of eating at a cafe and a band who used to play there (grateful dead) and a friend dying there. Not sure whether it was the band or the actual death but then the founder of java and friends started calling the place cafe dead. james gosling realized CAFEDEAD was a hex number and started using it for the persistent object format. Deciding on cafe as a theme, he grepped for characters that made sense with it and got CAFEBABE.


Dont have next quiz if im correct, and nice question :)
« Last Edit: January 30, 2014, 04:08:51 am by Uriah »

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java quiz series
« Reply #84 on: January 30, 2014, 07:18:30 am »
The magic number is a hex number meant to identify the file format. It is 0xCAFEBABE.

Came from a combination of eating at a cafe and a band who used to play there (grateful dead) and a friend dying there. Not sure whether it was the band or the actual death but then the founder of java and friends started calling the place cafe dead. james gosling realized CAFEDEAD was a hex number and started using it for the persistent object format. Deciding on cafe as a theme, he grepped for characters that made sense with it and got CAFEBABE.


Dont have next quiz if im correct, and nice question :)

You are correct.
Does anybody else have a quiz? You are free to go.

Offline Matriplex

  • Knight
  • **
  • Posts: 323
  • Cookies: 66
  • Java
    • View Profile
Re: Java quiz series
« Reply #85 on: February 04, 2014, 04:54:41 am »
Sure :)

Let's say you have the following class Man:

Code: [Select]
    public class Man implements java.io.Serializable {
        public String name;
        public String number;
        public transient int age;
        public boolean male;
    }

And the following PersonInLog class:

Code: [Select]
    public class PersonInLog {
        public static void main(String[] args) {
            Man e = new Man();
            e.name = "Bill";
            e.number = "555-555-5555";
            e.age = 30;
            e.male = true;
            try {
                FileOutputStream personFile = new FileOutputStream("/tmp/bill.ser");
                ObjectOutputStream out = new ObjectOutputStream(personFile);
                out.writeObject(e);
                out.close();
                personFile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

And finally this:

Code: [Select]
import java.io.*;
public class PersonOutLog {

        public static void main(String[] args) {
            Man e = null;
            try {
                FileInputStream personFile = new FileInputStream("/tmp/bill.ser");
                ObjectInputStream in = new ObjectInputStream(personFile);
                e = (Man) in.readObject();
                in.close();
                personFile.close();
            } catch (IOException e) {
                return;
            } catch (ClassNotFoundException c) {
                return;
            }
            System.out.println("Name: " + e.name);
            System.out.println("Number: " + e.number);
            System.out.println("Age: "  + e.age);
            System.out.println("Male: " + e.male);
        }
    }

What will be printed?

Edit:
100 posts!
Also, just to clear it up this is a trick question in a way. Just throwin that out there.

Edit 2:
Excuse me for all the mistakes this is pseudo code written while half asleep. I think I've fixed most of them by now though.
« Last Edit: February 15, 2014, 01:42:18 am by Matriplex »
\x64\x6F\x75\x65\x76\x65\x6E\x00

Offline Lac

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -3
    • View Profile
Re: Java quiz series
« Reply #86 on: February 15, 2014, 07:09:25 pm »
Name: Bill
Number: 555-555-5555
Age: 30
Male: true


If you were to attempt to read the Man object using your PersonOutLog class, then the above would be printed.
« Last Edit: February 15, 2014, 07:13:47 pm by Lac »

Offline Matriplex

  • Knight
  • **
  • Posts: 323
  • Cookies: 66
  • Java
    • View Profile
Re: Java quiz series
« Reply #87 on: February 15, 2014, 10:19:47 pm »
Excuse me I forgot I posted this, I was going to revise it the next day..

This is a completely unfair question, I don't tell you what class I'm running or in which order. If I said you run PersonInLog and the PersonOutLog, then yes you would be correct.

Forgive me, I wasn't thinking when I wrote this. Consider Lac correct :)
\x64\x6F\x75\x65\x76\x65\x6E\x00

Offline Lac

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -3
    • View Profile
Re: Java quiz series
« Reply #88 on: February 15, 2014, 11:42:48 pm »
 :) Yeah that's why I made sure to say IF you try to call the Man object.
« Last Edit: February 16, 2014, 07:14:26 am by Lac »

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Java quiz series
« Reply #89 on: February 23, 2014, 08:09:40 pm »
So what's the next question ? Or has the previous question been accepted as complete.
"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins