Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Instance Variables with Applet Reflection

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Instance Variables with Applet Reflection

    Hey guys, so I have a problem with hooking using reflection, the software I have was built so it can get methods from the applet. However I do not know how to grab instance variables.

    This is the Class that Loads the applet and puts the main class into an interface called Client.
        Client hook;
     
       public void a() {
            try {
                ClassThing b1 = new ClassThing();
     
                byte abyte0[] = a("http://applet.com/appletlinkgoeshere", "Starting up");
                if (abyte0 == null)
                    throw new Exception("Client download failed");
                b1.a = new ClientClassLoader(abyte0);
                Class class1 = b1.loadClass("sign.signlink");
                class1.getField("mainapp").set(null, this);
                Class class2 = b1.loadClass("client");
                reflectObject = class2.newInstance();
                _fldfor = (Applet) reflectObject;
                _fldfor.init();
                _fldfor.start();
                setClient((Client) _fldfor);
                /*java.lang.reflect.Field[] fields = class2.getFields();
                for (int i=0; i<fields.length;i++) {
                	System.out.println(fields[i]);
               }*/
            } catch (Exception exception) {
                String s = exception.getMessage();
                if (s == null)
                    s = "null";
                a(s);
                exception.printStackTrace();
            }
        }
     
        public void setClient(Client c) {
            hook = c;
        }

    This is the client interface with all the methods from within the applet
    package com.bsbot.hooks;
     
    import java.awt.*;
     
    public interface Client extends RSApplet {
     
        public String getUsername();
     
        public String getPassword();
     
        public Component getGameComponentHook(int a);
     
        public Npc[] getNpcs();
     
        public int getBaseX();
     
        public int getBaseY();
     
        public Player getMyPlayer();
     
        public int getPlayerId();
     
        public int getTime();
     
     
        public int[] getMaxStats();
     
        public int[] getCurrentStats();
     
        public int[] getExperience();
     
        public boolean isLoggedIn();
     
        public Player[] getPlayers();
     
        public String getLoginMessage2();
     
        public boolean isMenuOpen();
     
        public String[] getMenuActionNames();
     
        public int getMenuActionRow();
     
        int getMenuOffsetX();
     
        int getMenuOffsetY();
     
        String[] getChatMessages();
     
        int getMinimapInt1();
     
        int getMinimapInt2();
     
        int getMinimapInt3();
     
        int getXCameraCurve();
     
        int getYCameraCurve();
     
        int getXCameraPos();
     
        int getYCameraPos();
     
        int getZCameraPos();
     
        int getPlane();
     
        public void setLoginIndex(int i);
     
        public int getLoginIndex();
     
        int getOpenTab();
     
        int[][][] getGroundIntArray();
     
        byte[][][] getGroundByteArray();
     
        GameInterface[][] getInterfaceCache();
     
     
        public String getSelectedItemName();
     
        public ItemDef getForId(int id);
     
        public ObjectDef getForIdObject(int id);
     
        int getMouseX();
     
        int getMouseY();
     
        public NodeList[][][] getGroundArray();
     
        public WorldController getWorldController();
     
    }

    So my question is how can I get and use an instance variable that already exists in the applet? For example, in the applet there is: public String eN;
    How can I get the value of eN to use in my reflection program?
    Help is VERY appreciated, because I've spent some time banging my head against my desk.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Instance Variables with Applet Reflection

    Look at the Field class and the Class class methods that get them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Instance Variables with Applet Reflection

    I understand how to use the Field class to get the data but I just need help putting it all together so its inside the interface.
    Each of the methods inside that Client class just returns the instance variables I want to get, but I can't do it though the getter methods, I need to obtain it directly using the Field stuff.
    Last edited by Azurit3; July 31st, 2012 at 09:35 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Instance Variables with Applet Reflection

    Can you post code that shows the problem? Something that compiles and executes.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Instance Variables with Applet Reflection

    Quote Originally Posted by Norm View Post
    Can you post code that shows the problem? Something that compiles and executes.
    It's basically a bot program that grabs information from the game client using the methods such as getUsername(). Since I can't have getUsername() return a field in the client (jar reflection) because it is an interface, I need a way to do this. The bot scripts that I have written uses this hook to grab the information using methods such as getUsername().
    Last edited by Azurit3; August 1st, 2012 at 01:49 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Instance Variables with Applet Reflection

    Can you make a small program that shows the problem, not the whole program that will have lots of things not related to this problem.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    Azurit3 (August 1st, 2012)

Similar Threads

  1. Replies: 10
    Last Post: April 3rd, 2013, 03:16 PM
  2. Differences between local variables and instance variables
    By rob17 in forum Java Theory & Questions
    Replies: 2
    Last Post: March 6th, 2012, 08:34 PM
  3. Changing al instance variables at once?
    By Swen in forum Java Theory & Questions
    Replies: 1
    Last Post: December 30th, 2011, 07:42 AM
  4. Instance Variables and local variables difference
    By dcwang3 in forum Java Theory & Questions
    Replies: 3
    Last Post: October 31st, 2011, 06:33 AM
  5. [SOLVED] Instance data member vs Local variables (primitive/object reference)
    By chronoz13 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 23rd, 2011, 12:42 AM