Page 1 of 1

Write value of a lua variable to an address

Posted: Sat Jun 30, 2018 5:40 am
by nihilism
Just messing around with different mono hacking methods, but stuck at this part. I was able to use the mono lua commands to consistently get the base address that I want to use for pointers/other codes. But not able to get that to write to the symbol I made for it.



Thought at first maybe value is not in the correct format but no dice with conversions.



Think I am missing an obvious step. Please point me in the right direction!


Code: Select all

[ENABLE]

registersymbol(baseaddress)

alloc(baseaddress,64)



baseaddress:

dd 0



{$lua}

images={}

for i=1, #a1 do

  images[i]=mono_getImageFromAssembly(a1[i])



  if mono_image_get_name(images[i])=="Assembly-CSharp" then

    classes=mono_image_enumClasses(images[i])



    for j=1, #classes do

      if classes[j].classname=="GameManager" then

        baseaddress=mono_class_findInstancesOfClassListOnly(d[1],classes[j].class)

        --print(string.format("%.8x",baseaddress[1]))

      end

    end

  end

end



--[[addy=readStringLocal(baseaddy,8)

temp=stringToByteTable(addy)

addy1=byteTableToDword(temp)

--]]

{$asm}



[DISABLE]



unregistersymbol(baseaddress)

dealloc(baseaddress)

Write value of a lua variable to an address

Posted: Sat Jun 30, 2018 10:00 am
by koderkrazy
Hey try this:

[CODE=lua]local myLuaAddr = mono_class_findInstancesOfClassListOnly(d[1],classes[j].class)

writeQword('baseaddress', myLuaAddr) --if it is 64bit address

--or writePointer('[baseaddress]', myLuaAddr) if you want to write to address pointed by baseaddress directly[/CODE]



See attached table for example:

1. connect to any process. May be connect to Cheat Engine itself.

2. Load the example table.

3. Run [B]CreateASMVariable [/B]script

4. Keep hitting '[B]Add 5 in Lua[/B]' script.

Write value of a lua variable to an address

Posted: Sat Jun 30, 2018 2:31 pm
by nihilism
Thanks a lot that helped me find what was wrong.



My main problem though is that my lua variable was a table so I needed to add [1] to get the value I wanted.



Knew it was something obvious. Thanks again.

Write value of a lua variable to an address

Posted: Fri Aug 03, 2018 1:42 pm
by tabman
You can also allocate memory and register symbols by means of lua:

[CODE=lua]{$Lua}

[ENABLE]



local size = 4

addr = allocateMemory(size)



--unlike autoassembler, registerered symbol must be unregistered first

unregisterSymbol("var")

registerSymbol("var",addr)



local val = 10

writeInteger("var",val)

--or

--writeInteger(addr,val)



[DISABLE]



unregisterSymbol("var")

deAlloc(addr)[/CODE]