Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How can I inject two lines or more into one script?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
LionKing
Newbie cheater
Reputation: 0

Joined: 21 Jul 2021
Posts: 16

PostPosted: Wed Aug 18, 2021 10:30 pm    Post subject: How can I inject two lines or more into one script? Reply with quote

I want to inject two lines of code into one script.

Code:
sub [esi+00000088],edi
sub [eax+000001FC],edi


As we know the traditional way just injects one line per script like that:

Code:
[ENABLE]

aobscanmodule(INJECT,file.exe,29 BE 88 00 00 00) // should be unique
alloc(newmem,$1000)

label(code)
label(return)

newmem:

code:
  sub [esi+00000088],edi
  jmp return

INJECT:
  jmp newmem
  nop
return:
registersymbol(INJECT)

[DISABLE]

INJECT:
  db 29 BE 88 00 00 00

unregistersymbol(INJECT)
dealloc(newmem)


**How can I inject multi-lines into one script?**
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Thu Aug 19, 2021 12:49 am    Post subject: Reply with quote

Code:
...
code:
  sub [esi+00000088],edi
  sub [eax+000001FC],edi
  jmp return
...

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 124
Location: Migrating

PostPosted: Thu Aug 19, 2021 1:31 am    Post subject: Reply with quote

As above, you simply just add it in.

The standard aobscan template creates a nearby code section you have control over, and jmp's to it at where the original instruction(s) are, when enabled. In this sense you're just writing a larger chunk of instructions that all get ran before returning to the original injection point, where it will resume.

If you look at where you're injecting in the Memory Viewer you can see what's happening, and can follow the jmp when it's injected to see the code you wrote, if that helps you out.

You can write a lot, within some constraints, in that code cave it allocates.. others know more about the limitations than I do. That's the benefit of the aobscan template, compared to simply replacing bytes without a jump, where you need to be mindful of the byte count and surrounding instructions.
Back to top
View user's profile Send private message Visit poster's website
LionKing
Newbie cheater
Reputation: 0

Joined: 21 Jul 2021
Posts: 16

PostPosted: Thu Aug 19, 2021 11:26 am    Post subject: Reply with quote

ParkourPenguin wrote:
Code:
...
code:
  sub [esi+00000088],edi
  sub [eax+000001FC],edi
  jmp return
...


Your code doesn't ignore the second line, so, the second line will be implemented twice as follow.

Code:

jmp 060C0000
nop
00A815A1: sub [eax+000001FC],edi
...
...
060C0000:
mov [esi+00000088],000000C8
mov [eax+000001FC],000000C8
jmp 00A815A1
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Thu Aug 19, 2021 12:08 pm    Post subject: Reply with quote

Oh. So you want the injection point to be bigger than it needs to be?
Code:
[ENABLE]

aobscanmodule(INJECT,file.exe,29 BE 88 00 00 00 29 B8 FC 01 00 00) // should be unique
...
INJECT:
  jmp newmem
  nop 7
...
[DISABLE]

INJECT:
  db 29 BE 88 00 00 00 29 B8 FC 01 00 00


But if you're not doing anything else, why not just nop the second instruction?
Code:
[ENABLE]
aobscanmodule(INJECT,file.exe,29 BE 88 00 00 00 29 B8 FC 01 00 00)
registersymbol(INJECT)

INJECT+6:
  nop 6

[DISABLE]
INJECT+6:
  db 29 B8 FC 01 00 00  // sub [rax+000001FC],edi

unregistersymbol(INJECT)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
LionKing
Newbie cheater
Reputation: 0

Joined: 21 Jul 2021
Posts: 16

PostPosted: Thu Aug 19, 2021 1:03 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Oh. So you want the injection point to be bigger than it needs to be?
Code:
[ENABLE]

aobscanmodule(INJECT,file.exe,29 BE 88 00 00 00 29 B8 FC 01 00 00) // should be unique
...
INJECT:
  jmp newmem
  nop 7
...
[DISABLE]

INJECT:
  db 29 BE 88 00 00 00 29 B8 FC 01 00 00


But if you're not doing anything else, why not just nop the second instruction?
Code:
[ENABLE]
aobscanmodule(INJECT,file.exe,29 BE 88 00 00 00 29 B8 FC 01 00 00)
registersymbol(INJECT)

INJECT+6:
  nop 6

[DISABLE]
INJECT+6:
  db 29 B8 FC 01 00 00  // sub [rax+000001FC],edi

unregistersymbol(INJECT)




Thank you the first one has worked fine, but what's the benefit of

Code:

nop 7


Why did you add a number (7) next to the nop instruction?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4697

PostPosted: Thu Aug 19, 2021 3:13 pm    Post subject: Reply with quote

A nop mnemonic with an integer operand is a pseudoinstruction CE adds that lets you nop a specified number of bytes at a time. nop 7 means CE will replace 7 bytes with an instruction that does nothing. 7 bytes is enough to cover the rest of the original instruction taken up by the jump (6 original bytes - 5 jump bytes = 1 extra) and the instruction after it (6 bytes).
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
LionKing
Newbie cheater
Reputation: 0

Joined: 21 Jul 2021
Posts: 16

PostPosted: Thu Aug 19, 2021 5:23 pm    Post subject: Reply with quote

I thank you again. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites