potatos_x86

Reading a Double value from memory

5 posts in this topic

#1 ·  Posted

Hi guys and gals,

I do IT support for a school, and they recently bought a no-name Chinese laser engraver for one of their classes. This thing has really basic software and hardly any documentation. My problem is that I want to create a script that alerts me (or a teacher) when it is done running a job, but it has no API or web interface or anything like that. I hate this machine, but it's my job to support it :/

I know the amount of Gcode steps that are required for a given job, so I was able to find the memory address in CheatEngine. I am attempting to read it with Nomadmemory.au3.

The value required is a Double, which apparently AutoIt does not play nicely with. I researched this for a few hours and didn't have any luck. I've run the variable against command like IsArray, IsBinary, IsNumber, etc.

The value is:

- A double, 8 bytes

- Is not a fraction

- Not an array

- Not a binary

- Is a number

- Is not hex

- Is not a string

 

So basically, I'm stumped as to how to read this value and turn it into a variable that my script can work with. I just need to logically compare it to my known amount of steps (173, in my case) and act based on that. I've tried converting the double value using Number, Int, Dec, Hex, etc., and calling the Double flag where applicable. No luck - it always shows $steps as a 0.

My (very rough) code:

#RequireAdmin
#AutoIt3Wrapper_UseX64=n
#include <NomadMemory.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <String.au3>
SetPrivilege("SeDebugPrivilege", 1)



$dAddress = 0x0A65A4D8  ;;gcode steps count

$MemOpen = _MemoryOpen(ProcessExists("cdscutter_x86.exe"))
While 1
   $steps = Number((_MemoryRead($dAddress, $MemOpen)),2)

    
    ToolTip($steps,0,0)
    call("alert")
    Sleep(200)
 WEnd
 
 If $steps >= 173 then
 call("alert")
 EndIf
 
 Func alert ()
 ;;placeholder - email or Prowl alert;;
 EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Can't edit my original post?

Also meant to say that I can successfully read values from this program when they are 4-byte integers, but doubles don't work at all.

Share this post


Link to post
Share on other sites

#3 ·  Posted

@potatos_x86: Welcome to the forums.:)

I would suggest you load the value into a struct (check out DllstructCreate and related commands in the Help), and then read the value from the struct. I can assure you that AutoIt most definitely supports doubles; I use them all the time.

Share this post


Link to post
Share on other sites

#4 ·  Posted

Ok, I've pasted this together with guidance from the DllStructCreate remarks, but it only passes zeroes.

Do you guys know what I'm doing wrong? Not sure if I need to specify that it's byte data, or specify that its source is a double. Deeply confused and would appreciate any input.

 

Local Const $tagSTRUCT1 = "struct;byte var1;byte var2;byte var3;byte var4[128];endstruct"
DllStructSetData($tSTRUCT1, "var4", ((_MemoryRead($dAddress, $MemOpen))))



 MsgBox($MB_SYSTEMMODAL, "", "Struct Size: " & DllStructGetSize($tSTRUCT1) & @CRLF & _
            "Struct pointer: " & DllStructGetPtr($tSTRUCT1) & @CRLF & _
            "Data:" & @CRLF & _
            DllStructGetData($tSTRUCT1, 1) & @CRLF & _ ; Or "var1" instead of 1.
            DllStructGetData($tSTRUCT1, "var2") & @CRLF & _ ; Or 2 instead of "var2".
            DllStructGetData($tSTRUCT1, 3) & @CRLF & _ ; Or "var3" instead of 3.
            DllStructGetData($tSTRUCT1, 4)) ; Or "var4" instead of 4.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Your code doesn't create the structure.

Provided the address is correct, what does this give?

Local $dAddress = 0x0A65A4D8  ;;gcode steps count address (example)

Local $tNbSteps = DllStructCreate("double", $dAddress)
DllStructSetData($tNbSteps, 1, (_MemoryRead($dAddress, $MemOpen)))

 MsgBox($MB_SYSTEMMODAL, "", "Struct Size: " & DllStructGetSize($tNbSteps) & @CRLF & _
            "Struct pointer: " & DllStructGetPtr($tNbSteps) & @CRLF & _
            "Data:" & @CRLF & DllStructGetData($tNbSteps, 1))

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now