| View previous topic :: View next topic |
| Author |
Message |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jan 21, 2021 12:39 am Post subject: Using registerAutoAssemblerCommand |
|
|
I'm using CE's default AOB Injection template with an added custom aa command "cctest":
| Code: |
[ENABLE]
aobscanmodule(INJECT,Tutorial-x86_64.exe,29 83 F0 07 00 00) // should be unique
alloc(newmem,$1000,INJECT)
cctest(INJECT,newmem)
label(code)
label(return)
newmem:
code:
sub [rbx+000007F0],eax
jmp return
INJECT:
jmp newmem
nop
return:
registersymbol(INJECT)
[DISABLE]
INJECT:
db 29 83 F0 07 00 00
unregistersymbol(INJECT)
dealloc(newmem) |
cctest takes 2 parameters(or at least i expect it to):
1.INJECTION address
2.newmem address
Lua code that handles cctest:
| Code: |
registerAutoAssemblerCommand("cctest",function(c,s)
if s then return end
local params = {string.split(c,",")}
if #params ~= 2 then return nil,"Wrong number of parameters2" end
print(c)
return ""
end) |
However when I print the results it only "parses" the INJECTION, but newmem stays newmem
example:
| Code: |
>LUA PRINT OUTPUT
100002BBB,newmem |
How can i pass the address of newmem?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25827 Location: The netherlands
|
Posted: Thu Jan 21, 2021 3:45 am Post subject: |
|
|
try returning nil instead of an empty string so it gets called again in phase2
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jan 21, 2021 11:26 am Post subject: |
|
|
| Code: | registerAutoAssemblerCommand("cctest",function(c,s)
if s then return end
local params = {string.split(c,",")}
if #params ~= 2 then return nil,"Wrong number of parameters2" end
print(c)
return nil
end) |
Still the same output
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25827 Location: The netherlands
|
Posted: Thu Jan 21, 2021 12:15 pm Post subject: |
|
|
right, aa commands do not survive after pass 1, and allocation happens at pass2
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jan 21, 2021 12:25 pm Post subject: |
|
|
| hmm, so I should maybe ditch alloc from the aa script and alloc inside lua? or is there a better way?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25827 Location: The netherlands
|
Posted: Thu Jan 21, 2021 12:28 pm Post subject: |
|
|
yup. Alloc from within Lua and emit assembler code on return or whatever you wish to do.
or do whatever you wish after the AA script has finished when you have access to all the alloc addresses and optional registered symbols
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jan 21, 2021 1:30 pm Post subject: |
|
|
Now the problem is deallocating memory
Lua code for allocating memory
| Code: |
registerAutoAssemblerCommand("BPDE_alloc",function(c,s)
if s then return end
local params = {string.split(c,",")}
if #params ~= 3 then return nil,"Wrong number of parameters. (Required 3 arguments, you passed "..#params end
local newmem = params[1]
if newmem == nil then return nil,"error1" end
local allocsz = tonumber((string.gsub(params[2],"%$","0x")))
if allocsz == 0 or allocsz == nil then return nil,"error2" end
local inject = getAddressSafe(params[3])
if inject == nil then return nil,"error3" end
alloc = allocateMemory(allocsz,inject)
print(newmem,allocsz,inject,string.format("%X",alloc))
return string.format("define(%s,%X)",newmem,alloc)
end)
|
But what if i want to do | Code: | | BPDE_dealloc(newmem) |
Still the same problem as before, as newmem does not resolve to an address.
I was thinking of creating a table and tracking names and addresses, but then there is a problem if a same alloc name(such as newmem) is used in multiple scripts
EDIT:
It would be nice if there was a way to get the script ID(if there is such thing) when parsing/handling the command in lua. That way there wouldn't be confusions about which newmem to dealloc(from the global table i would create in BPDE_alloc() )
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25827 Location: The netherlands
|
Posted: Thu Jan 21, 2021 1:52 pm Post subject: |
|
|
hmm, not really no. if it was a {$lua} block you could use memrec.ID but for the callback not so much (lua blocks are handled before custom aa commands so you can't emit those)
Best use unique labels , or use a {$lua} block
-
But if you really intent on adding custom alloc then combine it with a registerAutoAssemblerPrologue which scans for BPDE_alloc and BPDE_dealloc
and then replaces those lines with something like
| Code: |
{$lua}
if memrec then
return string.format('BPDE_alloc_%d(therest...)', memrec.ID)
end
{$asm}
|
(and same for dealloc)
afterwards it will call your BPDE command which does the allocation etc... with the given ID
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jan 21, 2021 1:56 pm Post subject: |
|
|
This sounds like a great solution. I will give it a try. Very much thanks
EDIT: I can't double post yet so i have to do it this way:
I think i did this right, but the script won't activate(with an error: Error in line 3 print("ok") can't be compiled.
| Code: | unregisterAutoAssemblerPrologue(a)
a = registerAutoAssemblerPrologue(function(script,syn)
if syn then return end
for i=0,script.Count-1 do
if string.match(script[i],"BPDE_alloc") then
script[i] = [==[
{$lua}
print("ok")
{$asm}
]==]
end
end
print("FINAL:_____________________________\n",script.Text)
end)
registerAutoAssemblerCommand("BPDE_alloc",function() end) |
Output:
| Code: | FINAL:_____________________________
{$lua}
print("ok")
{$asm}
aobscanmodule(INJECT,Tutorial-x86_64.exe,29 83 F0 07 00 00) // should be unique
alloc(newmem,$1000,INJECT)
//cctest(INJECT,newmem)
label(code)
label(return)
newmem:
code:
sub [rbx+000007F0],eax
jmp return
INJECT:
jmp newmem
nop
return:
registersymbol(INJECT) |
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25827 Location: The netherlands
|
Posted: Thu Jan 21, 2021 5:44 pm Post subject: |
|
|
instead of replacing a string with another string with linebreaks in it try inserting single lines.
e.g
| Code: |
script.delete(i)
script.insert(i,"{$lua}")
script.insert(i+1,[[print("ok")]])
script.insert(i+2, "{$asm}")
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Skyrimfus Cheater
Reputation: 1
Joined: 17 Mar 2016 Posts: 43
|
Posted: Thu Jan 21, 2021 7:58 pm Post subject: |
|
|
| That did the trick. Thank you
|
|
| Back to top |
|
 |
|