• Victor
    link
    fedilink
    821 month ago

    Ha. Cause there’s no getter. I get it. I think?

  • @[email protected]
    link
    fedilink
    351 month ago

    Where are your gods now?

    public static Joke getTheJoke(Meme yourMeme) {
      Field jokeField = Meme.class.getDeclaredField("joke");
      jokeField.setAccessible(true);
      return (Joke) jokeField.get(yourMeme);
    }
    
    • @[email protected]
      link
      fedilink
      16
      edit-2
      1 month ago

      Is it Java? It looked like Microsoft Java C# to me…

          public static void Main(string[] args)
          {
              var meme = new Meme();
              var joke = GetTheJoke(meme);
          }
          
          public static Joke GetTheJoke(Meme theMeme)
          {
              var memeType = typeof(Meme);
              var jokeField = memeType.GetField("Joke", BindingFlags.NonPublic | BindingFlags.Instance);
              return (Joke)jokeField.GetValue(theMeme);
          }
      
      • @[email protected]
        link
        fedilink
        41 month ago

        Frankly it’s been a while since I wrote either one. I just assumed Java because of the naming convention, and I didn’t see anything I took as obviously un-Java in the class definition

      • @[email protected]
        link
        fedilink
        English
        41 month ago

        There isn’t an unnecessary level of capitalization; seems to be regular Java with Allman braces.

      • @[email protected]
        link
        fedilink
        21 month ago

        Is it Java?

        Wait a minute, that’s an actual thing in java!? What the fuck Java I already didn’t like you and now you start pulling this shit? What even is the point of creating standards if you design backdoors to them

        • @[email protected]
          link
          fedilink
          3
          edit-2
          1 month ago

          If you want to be able to eg. (de)serialize non-public fields of a type for any reason, you’ll need some way to get around the access restriction. Mocking is another use case – although it’s a philosophical discussion whether you should be mocking non-public fields.

          And this isn’t just a Java thing, the comment you’re responding to has an example in C#, and you can do something similar in a lot of languages that support runtime reflection. Barring runtime reflection support you can do pointer math if the language supports it. Access restrictions on fields are there to stop casual misuse of private fields, but sometimes you actually may want to be able to step over those restrictions if you really know what you’re doing.

        • @[email protected]
          link
          fedilink
          1
          edit-2
          1 month ago

          Reflection is sometimes a necessary evil. At least it makes it harder to abuse the class and if you do, then you are responsible if something goes wrong.

        • @[email protected]
          link
          fedilink
          1
          edit-2
          1 month ago

          Yea, what @[email protected] posted is actually Java

          What even is the point of creating standards if you design backdoors to them

          If you’re building in a backdoor anyways, why would the backdoor require 5 lines of weird reflection to get the type, type info, fieldinfo with the correct binding flags, and then invoking the method?

          I think it’s kinda neat compared to C#, just being able to say “Ignore private/protected/internal keywords”

  • _NoName_
    link
    fedilink
    141 month ago

    Is it possible to get the joke at runtime using the spectre exploit?