JNA-获取基本地址 [英] JNA - Getting Base address

查看:62
本文介绍了JNA-获取基本地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在从事我的一个小项目,该项目是用Java为本地游戏(C/C ++/etc)进行内存读/写.

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.

我现在面临的问题是,第一个指针使用程序的基地址(每次程序重新启动时都会改变): "ac_client.exe" + 000DF73C

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

我需要一种使用JNA来获取"ac_client.exe"基本值的方法.

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

我已经做了大量研究,发现了几种用C ++进行处理的方法,但是我对C/C ++的了解非常有限.我发现很难使用JNA将其转换为Java,我想我会在这里询问,看看是否有人能够提供帮助或知道执行此壮举的其他方法.

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.

阅读下面的解决方案!谢谢你的帮助.

Read my solution bellow! thanks for the help.

推荐答案

在弄乱了Alex发布的内容后,我使其开始工作了,并设法使其工作.

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

对于其他想要获得类似效果的人,请查看Alex发布的项目,您将看到所需的必修课.然后我就用这个:

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;
}

这篇关于JNA-获取基本地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆