Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
868 views
in Technique[技术] by (71.8m points)

java - JNA - Getting Base address

Recently I have been working on a little project of mine, which is Memory reading/writing in java for native games (C/C++/etc).

At the moment I have a base where I can read and write to memory of games, but I now need a way to get the Base address of the running application. For example:

I have a list of pointers that I have collected using Cheat Engine and its Pointer searcher. These are stable and work each time the game reloads.

The problem I am facing now, is the first pointer uses the base address of the program (which changes every time the program restarts): "ac_client.exe"+000DF73C

I am in need of a way to get the base value of "ac_client.exe" using JNA.

I have done a lot of research and found a few ways to do it in C++, but my knowledge of C/C++ is pretty limited.. I am finding it difficult to convert it to Java using JNA and I thought I would ask here and see if anyone would be able to be of assistance or know of alternate ways of doing such a feat.

Thanks for any help in advance, Kaden.

[EDIT]

Read my solution bellow! thanks for the help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I got it working after a bit of messing around with what Alex posted, and managed to get it working.

for anyone else who wanted to get something like this working, have a look at that project that Alex posted and you will see the required classes you will need. then I just used this:

public int getBaseAddress() {
        try {
                Pointer hProcess = gethProcess();
                List<Module> hModules = PsapiHandler.getInstance().EnumProcessModules(hProcess);

                for(Module m: hModules){
                        if(m.getFileName().contains(exeName)){
                                misc.log(m.getFileName() + ": 0x" + Long.toHexString(Pointer.nativeValue(m.getEntryPoint())));
                                return Integer.valueOf("" + Pointer.nativeValue(m.getLpBaseOfDll()));
                        }
                }
        } catch (Exception e) {  e.printStackTrace(); }
        return -1;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...