Page 1 of 1

Is it possible to write compare script with lua ?

Posted: Sat Nov 06, 2021 4:01 pm
by Blackrosemmt
Hi guys

Is it possible to write compare script with lua ?
I need to add 2 offsets then comparing them to value 0 as the below example.

Code: Select all

newmem:
push edx
mov edx,[esi+ec]     //first offset ec
cmp [edx+11c],0	  //second offset 11c
pop edx

jne originalcode

//mov [esi+28],eax
jg game.exe+1861D6
jmp exit

originalcode:

mov [esi+28],eax
jg game.exe+1861D6

Re: Is it possible to write compare script with lua ?

Posted: Sat Nov 06, 2021 7:08 pm
by GreenHouse
Blackrosemmt wrote:
Sat Nov 06, 2021 4:01 pm
Hi guys

Is it possible to write compare script with lua ?
I need to add 2 offsets then comparing them to value 0 as the below example.
Well, yes it is possible to write a compare, but it depends on what you're trying to do. That question is way too broad.
But a compare like that one from ASM to LUA, would be something like this, in a simple way:

Code: Select all

if readInteger(readInteger(Address1)+0x11C) == 0x0
   then print('Something is done here) 
else
   print ('Something else is done here') 
end
But if you're planning to run LUA mid ASM, you can't. LUA will always run first.

Re: Is it possible to write compare script with lua ?

Posted: Sat Nov 06, 2021 11:34 pm
by LeFiXER
GreenHouse wrote:
Sat Nov 06, 2021 7:08 pm
...
But if you're planning to run LUA mid ASM, you can't. LUA will always run first.
With the latest version of CE you can now run in-line Lua code via {$LUACODE}.

Code: Select all

newmem:
push edx
mov edx,[esi+ec]	//first offset ec
cmp [edx+11c],0		//second offset 11c
{$luacode r1=esi r2=edx}
printf("esi = %X\nedx = %X\nesi+ec = %X\nedx+11c = %X", r1,r2,r1+0xEC,r2+0x11C)
{$asm}
pop edx

jne originalcode

//mov [esi+28],eax
jg game.exe+1861D6
jmp exit

originalcode:
Not exactly what you need but will give you an idea of how in-line Lua can be used which happens to print the values held in the registers defined at the point of execution, along with some offsets added.

Re: Is it possible to write compare script with lua ?

Posted: Sat Nov 06, 2021 11:49 pm
by GreenHouse
LeFiXER wrote:
Sat Nov 06, 2021 11:34 pm
With the latest version of CE you can now run in-line Lua code via {$LUACODE}.
That's nice, I didn't know about that. I'll check that out later to see what can be done with it.

Re: Is it possible to write compare script with lua ?

Posted: Sun Nov 07, 2021 12:28 am
by LeFiXER
Sadly, it's not really documented but yeah it's neat for sure.

Re: Is it possible to write compare script with lua ?

Posted: Sun Nov 07, 2021 10:35 am
by Blackrosemmt
With the latest version of CE you can now run in-line Lua code via {$LUACODE}.
Thanks @LeFiXER for the reply. I wanted to write all script in Lua because the games sometimes crash using push pop in ASM becasue of invalid pointers, so I need to give it a try in Lua to see if game will still crash or not.
can you please help me writing it in Lua according to these information :

"game.exe"+18610E //Base address
EC // first offset
11C // second offset
then compare 11C to 0

jne originalcode // jump if not equal to originalcode
mov eax,[esi+28] // if equal then make this injection


I saw in another posts that they are writing pointer and offset scripts something like
[[[game.exe+offset0]+offset1]+offset2]
but I didnt find for compare in Lua.

Re: Is it possible to write compare script with lua ?

Posted: Sun Nov 07, 2021 9:58 pm
by LeFiXER
Blackrosemmt wrote:
Sun Nov 07, 2021 10:35 am
I saw in another posts that they are writing pointer and offset scripts something like
[[[game.exe+offset0]+offset1]+offset2]
but I didnt find for compare in Lua.
You're welcome, although it's not difficult to use a reputable search engine to answer your query. Nevertheless,

Code: Select all

local base = getAddressSafe('game.exe+18610E')
local pointer = getAddressSafe('[[[' .. base .. ']+EC]+11C')

if readInteger(pointer) == 0 then
  -- The value held in pointer = 0
The function readInteger may differ based on the value type you're reading.