Page 1 of 1

[help] Mono Failed to allocate memory near...

Posted: Sun May 07, 2023 4:13 am
by peddroelm
I'm trying to save a input parameter ( R15 ) on a method call ..

this alloc(newmem,$1000,TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4) sometimes fails :(

Is there a better to do it ?

Code: Select all

[ENABLE]

{$lua}
if syntaxcheck then return end
  if(getCEVersion() < 7.4) then
    ShowMessage('Warning! CE version should be 7.4 or above')
  end

LaunchMonoDataCollector()

{$asm}

alloc(newmem,$1000,TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4)

label(code)
label(return)
label(selectedHERO)
registerSymbol(selectedHERO)

newmem:
selectedHERO:
dq 0

code:
// orig
  sub rsp,00000090
 // end orig code

  mov [selectedHERO],r15

  jmp return

TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4:
  jmp code // 5 bytes
  nop 2
return:


[DISABLE]

TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4:
  db 48 81 EC 90 00 00 00   // 7 bytes   sub rsp,00000090

unregistersymbol(selectedHERO)
dealloc(newmem)
EDIT: Will to make sense of this [Link]
" ... there's nothing that can be done but to force Cheat Engine to use the 14-byte `jmp` pseudoinstruction..... "

EDIT2: far jmp seems to have done the trick

Code: Select all

[ENABLE]

{$lua}
if syntaxcheck then return end
  if(getCEVersion() < 7.4) then
    ShowMessage('Warning! CE version should be 7.4 or above')
  end

LaunchMonoDataCollector()

{$asm}

//alloc(newmem,$1000,TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4)
alloc(newmem,$1000)

label(code)
label(return)
label(selectedHERO)
registerSymbol(selectedHERO)

newmem:
selectedHERO:
dq 0

code:
// orig
  sub rsp,00000090
  mov [rbp-18],rsi
  mov [rbp-10],rdi
// end orig

  mov [selectedHERO],r15

  jmp return

TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4:
  jmp far code  // 14 bytes
  nop 1
return:


[DISABLE]

TheLastStand.View.Unit.UnitPortraitView:RefreshPortrait+4:
  db 48 81 EC 90 00 00 00 48 89 75 e8 48 89 7D F0 // 15 bytes sub rsp,00000090; mov [rbp-18],rsi; mov [rbp-10],rdi

unregistersymbol(selectedHERO)
dealloc(newmem)