I have tried several things, but I just can't get this to work. What I need is a snippet which scans a program for value X, and then simply assigns a varible within the python script to the X value. I'm new to Python, but not to programming. Please be patient with me. Thanks in advance!

Explain what you mean by "scans a program". Do you mean communicate with a running program ? Or scan a text file?

By scanning a program, I mean that it should find a value stored at a certain adress in the RAM, if I've gotten this right. A common program that does this is the freeware "Cheat Engine" (http://www.cheatengine.org/)

This function can be used for many things; Debugging, Writing plugins, Logging etc.

I hope this made the problem more clear.

You can use module subprocess and Popen() to pass arguments to and from external programs.

Example please? : /

From what I understood, subprocess and POpen only lets you send an argument to a program, wich you can't do with the project I'm attempting.

Here is a general example you can adopt, let us know if it works for your case:

# using module subprocess to pass arguments to and from an
# external program

import subprocess

# put in the corresponding strings for
# "mycmd" --> external program name
# "myarg" --> arg for external program
# several args can be in the list ["mycmd", "myarg1", "myarg2"]
# might need to change bufsize
p = subprocess.Popen(["mycmd", "myarg"], bufsize=2048, shell=True,
    stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)

# allow external program to work
p.wait()

# read the result to a string
result_str = p.stdout.read()
commented: Good post, well commented, although not exactly what I was looking for ;) +2

No, this will apparantly not work. From what I see, the subprocess module lets you, say, send a ping command to Google.com via CMD.EXE. (I'm working with WIN32XP)

This is not what I intend to do. I intend to make an applet for the G15 keyboard. (Long story short: A backlit gaming keyboard with an built- in LCD- screen, used for displaying info from games, news and media players)

I want to make an applet wich you can configure for different programs, effectivly giving the LCD screen support for almost any game without a decent hack- protection, and loads of other programs.

The code I need is for scanning an user- defined program at a certain adress, (which can be obtained with CHEAT ENGINE, WWW.CHEATENGINE.ORG) returning the value of a defined variable within that specified program. The rest I can manage myself.

I would like to thank you for helping me this far, you're a good teacher.

BUMP.

In C you can set up a variable with a memory address (say, some PCI-mapped memory) and use pointer constructs to Read/Write it. Python does not naturally allow for this kind of direct access to memory, so you will need to work around this restriction (sometimes called a "feature" by those with different viewpoints).

From what I can tell CheatEngine is basically a GUI that talks to dbk32.dll which in turn talks to driver dbk32.sys to do the Kernel mode work required for cross-process scanning.

What you could do, with Python 2.4.1, is use the calldll module to interface to dbk32.dll in much the same way the CheatEngine GUI interfaces to dbk32.dll. Ah, but that means you would need to know what routines are available in dbk32.dll and how to call them. Fortunately it's all Open Source so you can look at where CheatEngine calls dbk32.dll and mimic that code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.