Convert Cheat Engine base address - pointers

I found a memory address and used Cheat Engine's pointer scan to get referring pointers. To use it in a script I need a base address, which is [game.exe+009274]. How to convert this to an address for use in AutoIt script?
I use NomadMemory.au3 UDF.

I have written 2 function some time ago. One to load all the modules loaded with the process and one to get the base address of the module you need.
Both might be handy here.
Local $iPID = WinGetProcess("app.exe")
Local $sLoadedModules = _ProcessGetLoadedModules($iPID)
Local $My_dll = _MemoryModuleGetBaseAddress($iPID, "My.dll")
For $i = 0 To UBound($sLoadedModules) - 1
ConsoleWrite($sLoadedModules[$i] & #LF) ; find your process here
Next
ConsoleWrite($My_dll & #LF)
Func _ProcessGetLoadedModules($iPID)
Local Const $PROCESS_QUERY_INFORMATION = 0x0400
Local Const $PROCESS_VM_READ = 0x0010
Local $aCall, $hPsapi = DllOpen("Psapi.dll")
Local $hProcess, $tModulesStruct
$tModulesStruct = DllStructCreate("hwnd [200]")
Local $SIZEOFHWND = DllStructGetSize($tModulesStruct) / 200
$hProcess = _WinAPI_OpenProcess(BitOR($PROCESS_QUERY_INFORMATION, $PROCESS_VM_READ), False, $iPID)
If Not $hProcess Then Return SetError(1, 0, -1)
$aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", DllStructGetSize($tModulesStruct), "dword*", "")
If $aCall[4] > DllStructGetSize($tModulesStruct) Then
$tModulesStruct = DllStructCreate("hwnd [" & $aCall[4] / $SIZEOFHWND & "]")
$aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", $aCall[4], "dword*", "")
EndIf
Local $aReturn[$aCall[4] / $SIZEOFHWND]
For $i = 0 To UBound($aReturn) - 1
$aCall = DllCall($hPsapi, "dword", "GetModuleFileNameExW", "ptr", $hProcess, "ptr", DllStructGetData($tModulesStruct, 1, $i + 1), "wstr", "", "dword", 65536)
$aReturn[$i] = $aCall[3]
Next
_WinAPI_CloseHandle($hProcess)
DllClose($hPsapi)
Return $aReturn
EndFunc ;==>_ProcessGetLoadedModules
Func _MemoryModuleGetBaseAddress($iPID, $sModule)
If Not ProcessExists($iPID) Then Return SetError(1, 0, 0)
If Not IsString($sModule) Then Return SetError(2, 0, 0)
Local $PSAPI = DllOpen("psapi.dll")
Local $hProcess
Local $PERMISSION = BitOR(0x0002, 0x0400, 0x0008, 0x0010, 0x0020)
If $iPID > 0 Then
Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", $PERMISSION, "int", 0, "dword", $iPID)
If $hProcess[0] Then
$hProcess = $hProcess[0]
EndIf
EndIf
Local $Modules = DllStructCreate("ptr[1024]")
Local $aCall = DllCall($PSAPI, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($Modules), "dword", DllStructGetSize($Modules), "dword*", 0)
If $aCall[4] > 0 Then
Local $iModnum = $aCall[4] / 4
Local $aTemp
For $i = 1 To $iModnum
$aTemp = DllCall($PSAPI, "dword", "GetModuleBaseNameW", "ptr", $hProcess, "ptr", Ptr(DllStructGetData($Modules, 1, $i)), "wstr", "", "dword", 260)
If $aTemp[3] = $sModule Then
DllClose($PSAPI)
Return Ptr(DllStructGetData($Modules, 1, $i))
EndIf
Next
EndIf
DllClose($PSAPI)
Return SetError(-1, 0, 0)
EndFunc ;==>_MemoryModuleGetBaseAddress

Related

Script Math's not correct lua minecraft

idk what is wrong but it writes this into the file when it saves the value. If u need more information or have a question please ask me! Thanks for your time and hopefully u your solution!
SebyGHG
My discord: S̸̽̚e̵̓̓b̸̿̕y̴͆͐#4638
Here is a screenshot of the time and the value in the file:
Value in file
Time in game
Code:
name = "Timer"
description = "Just a normal Timer."
positionX = 0
positionY = 0
sizeX = 24
sizeY = 10
scale = 1
START_STOP_KEY = 0x55 --or 'U'
RESET_KEY = 0x4A --or 'J'
--
--[[
Timer Module Script by SebyGHG original script by Onix64(Stopwatch)
if you wish to change the key you can take the key code from here
https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
]] -------------script-code-------------
state = 1
stopTime = 0
startTime = 0
f = io.input("timesave.txt")
result = f :read()
f :close()
stopTime = result
state = 2
function keyboard(key, isDown)
if (isDown == true) then
if (key == RESET_KEY) then
state = 0
elseif (key == START_STOP_KEY) then
if (state == 0) then
state = 1
startTime = os.time()
elseif (state == 1) then
state = 2
io.output("timesave.txt")
timesave= (io.open("timesave.txt","w"))
io.write(stopTime)
io.close(timesave)
stopTime = os.time()
elseif (state == 2) then
state = 1
startTime =startTime + os.time() - stopTime
end
end
end
end
TimerText = "00:00"
TextColor = {r = 30, g = 255, b = 30, a = 255}
function doubleDigit(number)
if (number < 10) then
return "0" .. math.floor(number)
else
return math.floor(number)
end
end
function timeText(time)
local result = ""
local days = 0
while (time > 86399) do
days = days + 1
time = time - 86400
end
local hours = 0
while (time > 3599) do
hours = hours + 1
time = time - 86400
end
local minutes = 0
while (time > 59) do
minutes = minutes + 1
time = time - 60
end
if (days == 0) then
if (hours == 0) then
return doubleDigit(minutes) .. ":" .. doubleDigit(time)
else
return math.floor(hours) .. " : " .. doubleDigit(minutes) .. ":" .. doubleDigit(time)
end
else
return math.floor(days) ..
" : " .. doubleDigit(hours) .. " : " .. doubleDigit(minutes) .. ":" .. doubleDigit(time)
end
end
function update()
if (state == 0) then
TextColor = {r = 255, g = 0, b = 0, a = 255}
TimerText = "00:00"
elseif (state == 1) then
TimerText = timeText(os.time() - startTime)
TextColor = {r = 0, g = 255, b = 255, a = 255}
elseif (state == 2) then
TimerText = timeText(stopTime - startTime)
TextColor = {r = 255, g = 255, b = 0, a = 255}
end
end
function render()
local font = gui.font()
local tw = font.width(TimerText)
gfx.color(0, 0, 0, 0)
gfx.rect(0, 0, tw + 4, 10)
gfx.color(TextColor.r, TextColor.g, TextColor.b, TextColor.a)
gfx.text(2, 1, TimerText)
end
One error I spot is this part
while (time > 3599) do
hours = hours + 1
time = time - 86400
end
this is most likely supposed to be
while (time > 3599) do
hours = hours + 1
time = time - 3600
end

run-time error '5' maps.googleapis.com/maps/api/distancematrix

Yesterday, I ran the following script in excel and it worked, but now it throws an error:
(run-time error '5' )
in the line:
Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1)
Sub Поиск_ближайшего_СБС()
Set Points = Worksheets("Точки")
Set SBS = Worksheets("СБС")
Dim Cordinate11, Cordinate12, Cordinate21, Cordinate22 As String
i = 2
Do While SBS.Cells(i, 1) <> Empty
Rows_of_SBS = i
i = i + 1
Loop
i = 2
Do While Cells(i, 1) <> Empty
Dist = 1000
Cordinate21 = Points.Cells(i + 1, 3)
Cordinate22 = Points.Cells(i + 1, 4)
For j = 2 To Rows_of_SBS
Cordinate11 = SBS.Cells(j, 2)
Cordinate12 = SBS.Cells(j, 3)
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
With IE
.Navigate "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" _
& Cordinate11 & ",+" & Cordinate12 _
& "&destinations=" _
& Cordinate21 & ",+" & Cordinate22 _
& "&mode=driving&language=ru&sensor=false"
Do While .Busy
DoEvents
Loop
For Each MyTable In .Document.getElementsByTagName("text")
Distance = MyTable.innertext
Next
Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1)
If CDbl(Distance) < Dist Then
Dist = CDbl(Distance) s = j
End If
End With
IE.Quit
Set EI = Nothing
Next j
Points.Cells(i + 1, 5) = Dist
Points.Cells(i + 1, 6) = SBS.Cells(s, 1)
i = i + 1
Loop
End Sub
'

Autoit Controlsend to child window

I have from 1-6 commandprompts in a window. When they weren't in the window, I could use controlsend fine.
Code:
$GUI2 = GUICreate("Consoles", 1020, 600, 1282, 300, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
$hwnd00 = WinGetHandle("Consoles")
If GUICtrlRead($Bungee) = 1 Then
$BungeeServer = Run("java -Xmx512M -jar " & '"' & $file0 & "\BungeeCord.jar" & '"', $file0, $Hide)
If Not ProcessWait($BungeeServer) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Bungee")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Bungee")
Global $hwnd0 = WinGetHandle("Bungee")
EndIf
EndIf
If GUICtrlRead($server1) = 1 Then
$1 = Run("java " & $chosen & " -jar " & '"' & $file1 & '"' & "\minecraft_server.jar", $file1, $Hide)
If Not ProcessWait($1) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server1")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server1")
Global $hwnd1 = WinGetHandle("Server1")
EndIf
EndIf
If GUICtrlRead($server2) = 1 Then
$2 = Run("java " & $chosen & " -jar " & '"' & $file2 & '"' & "\minecraft_server.jar", $file2, $Hide)
If Not ProcessWait($2) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server2")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server2")
Global $hwnd2 = WinGetHandle("Server2")
EndIf
EndIf
If GUICtrlRead($server3) = 1 Then
$3 = Run("java " & $chosen & " -jar " & '"' & $file3 & '"' & "\minecraft_server.jar", $file3, $Hide)
If Not ProcessWait($3) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server3")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server3")
Global $hwnd3 = WinGetHandle("Server3")
EndIf
EndIf
If GUICtrlRead($server4) = 1 Then
$4 = Run("java " & $chosen & " -jar " & '"' & $file4 & '"' & "\minecraft_server.jar", $file4, $Hide)
If Not ProcessWait($4) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server4")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server4")
Global $hwnd4 = WinGetHandle("Server4")
EndIf
EndIf
If GUICtrlRead($server5) = 1 Then
$5 = Run("java " & $chosen & " -jar " & '"' & $file5 & '"' & "\minecraft_server.jar", $file5, $Hide)
If Not ProcessWait($5) = 0 Then
WinSetTitle("C:\Windows\system32\java.exe", "", "Server5")
WinSetTitle("C:\WINDOWS\SYSTEM32\java.exe", "", "Server5")
Global $hwnd5 = WinGetHandle("Server5")
EndIf
EndIf
_WinAPI_SetWindowLong($hwnd0, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd0, $GUI2)
_WinAPI_SetWindowLong($hwnd1, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd1, $GUI2)
_WinAPI_SetWindowLong($hwnd2, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd2, $GUI2)
_WinAPI_SetWindowLong($hwnd3, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd3, $GUI2)
_WinAPI_SetWindowLong($hwnd4, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd4, $GUI2)
_WinAPI_SetWindowLong($hwnd5, $GWL_EXSTYLE, $WS_EX_MDICHILD)
_WinAPI_SetParent($hwnd5, $GUI2)
WinMove($hwnd0, "", 0, 0, 340, 300)
WinMove($hwnd1, "", 340, 0, 340, 300)
WinMove($hwnd2, "", 680, 0, 340, 300)
WinMove($hwnd3, "", 0, 300, 340, 300)
WinMove($hwnd4, "", 340, 300, 340, 300)
WinMove($hwnd5, "", 680, 300, 340, 300)
Earlier I used this: ControlSend("Server1", "", $hwnd1, 'stop' & '{ENTER}')
One line for each of the windows. How can I send information to them when they are in the parent window(Even if the parent window is hidden)?
This command allows the window search routines to search child windows as well as top-level windows.
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
0 = Only search top-level windows (default)
1 = Search top-level and child windows

Highcharts Used with Asp.Net

When i set line chart from server side code then chart display in single column and not proper
for this we use below code:
Dim chart1 As Highcharts = New Highcharts("chart1")
chart1.InitChart(New Chart() With {
.PlotShadow = False,
.Type = ChartTypes.Spline,
.BackgroundColor = New BackColorOrGradient(New Gradient() With { _
.LinearGradient = {0, 0, 0, 400}, _
.Stops = New Object(,) {{0, Color.FromArgb(255, 96, 96, 96)}, {1, Color.FromArgb(255, 16, 16, 16)}} _
})})
chart1.SetTitle(New Title() With {.Text = "<spam style=""color:White;"">Money Utilization Report</spam>"})
Dim series As Series() = New Series(Ds.Tables(0).Rows.Count - 1) {}
Min1 = Ds.Tables(0).Rows(0)(1)
Max1 = Ds.Tables(0).Rows(0)(1)
For i As Integer = 0 To Ds.Tables(0).Rows.Count - 1
series(i) = New Series() With { _
.Name = Left(Ds.Tables(0).Rows(i)(0).ToString(), 2), _
.Data = New Data(New Object() {Ds.Tables(0).Rows(i)(1)})}
If Min1 > Ds.Tables(0).Rows(i)(1) Then
Min1 = Ds.Tables(0).Rows(i)(1)
End If
If Max1 < Ds.Tables(0).Rows(i)(1) Then
Max1 = Ds.Tables(0).Rows(i)(1)
End If
Next
chart1.SetYAxis(New YAxis With {.GridLineWidth = 0, .Title = New YAxisTitle With {.Text = "Percentage"}, .Min = Min1 - 2, .Max = Max1 + 2})
chart1.SetTooltip(New Tooltip() With {.Formatter = "function() { return '<b>'+ this.series.name + ': </b>'+ this.y +' %'; }"})
chart1.SetSeries(series)
ltChart.Text = chart1.ToHtmlString()

Dllcall autoit partially getting results

I am having problem with the following code in autoit.
it is suppose to list all printers available in my system and the curresponding papernames supported by each printer.
but am getting only the printer names ans series of '0s' which is suppose to be the papernames
#include <Debug.au3>
#include <String.au3>
Const $DC_BINS = 6
Const $DC_BINNAMES = 12
Const $DC_PAPERNAMES = 16
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Dim $BinNameList
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
$s_struct = ""
_DebugSetup ($s_struct)
$s_struct=_StringRepeat("0", $result[0]*64)
;$s_struct = StringTrimRight($s_struct, 1)
$struct = DllStructCreate($s_struct)
$result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
_DebugOut ( $objPrinter.Name)
For $i = 0 To $result[0]-1
_DebugOut (DllStructGetData($struct, $i))
Next
$struct = 0
Next
Check this out: http://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx
Example that uses just WMI:
#include <Array.au3>
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48)
For $objPrinter In $colInstalledPrinters
$arr = $objPrinter.PrinterPaperNames
_ArrayDisplay($arr, $objPrinter.Name)
Next
Or try this which prints the actual paper names (run in SciTE so you can see the output from ConsoleWrite):
Const $DC_PAPERS = 2
Const $DC_PAPERSIZE = 3
Const $DC_PAPERNAMES = 16
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer")
For $objPrinter In $colInstalledPrinters
$result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0)
$s_struct = ""
$s_struct2 = ""
For $i = 1 To $result[0]
$s_struct = $s_struct & "char[64];"
Next
For $i = 1 To $result[0]
$s_struct2 &= "long x;long y;"
Next
$s_struct = StringTrimRight($s_struct, 1)
$s_struct2 = StringTrimRight($s_struct2, 1)
$j = 1
$struct = DllStructCreate($s_struct)
$pointStruct = DllStructCreate($s_struct2)
$result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0)
$result3 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERSIZE, "ptr", DllStructGetPtr($pointStruct), "long", 0)
ConsoleWrite($objPrinter.Name & " on Port: " & $objPrinter.PortName & #CRLF)
For $i = 1 To $result[0]
ConsoleWrite(DllStructGetData($struct, $i) & " (" & DllStructGetData($pointStruct, $j) & "mm x " & DllStructGetData($pointStruct, $j + 1) & "mm)" & #CRLF)
$j += 2
Next
$struct = 0
$pointStruct = 0
Next

Resources