Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nopi command it patchs full instructions #959

Merged
merged 5 commits into from
Jul 13, 2023
Merged

add nopi command it patchs full instructions #959

merged 5 commits into from
Jul 13, 2023

Conversation

therealdreg
Copy link
Collaborator

@therealdreg therealdreg commented Jul 12, 2023

Description/Motivation/Screenshots

nopi command patchs full instructions, nop command usually breaks disasm

Also, the current way using nop command + calculating bytes by hand/commands when you want patch N instructions is a pain in the ass hehe

This command should be more useful & user friendly than nop command

Against which architecture was this tested ?

"Tested" indicates that the PR works and the unit test (see docs/testing.md) run passes without issue.

  • x86-32
  • x86-64
  • ARM
  • AARCH64
  • MIPS
  • POWERPC
  • SPARC
  • RISC-V

Checklist

  • My PR was done against the dev branch, not main.
  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • If my change adds new code, adequate tests have been added.
  • I have read and agree to the CONTRIBUTING document.

nopicmd

@hugsy
Copy link
Owner

hugsy commented Jul 12, 2023

I'm not a fan of having two commands that do the same thing, especially when the code is this similar. Why not simply add an option (like --nb-insn) to the nop command to specify the number of instructions instead? That'd seem cleaner and users will still have the option to create an alias to it.

@hugsy
Copy link
Owner

hugsy commented Jul 12, 2023

nop command usually breaks disasm

Thanks for pointing that out. There must have a been a mix-up somewhere, because I thought nop had an instruction granulariy, and use patch for a byte/word/dword/etc. granularity. That's probably what should change, which is another argument for making your nopi the default behavior of nop (i.e. instruction granularity) - and just leave a toggle to switch to a byte-granularity. To explain by example:

  • nop $address 10 will nop out 10 instructions, cleanly
  • whereas nop --bytes $address 10 will forcefully insert 10 nops instructions, regardless of what's there.

Can you update your PR to reflect that?

@therealdreg
Copy link
Collaborator Author

therealdreg commented Jul 12, 2023

So...

nop -> patch $pc 1-full-instruction
nop --nb -> patch $pc with 1-nop

nop --ni 10 -> patch $pc 10-full-instruction
nop --nb 10 -> patch $pc with 10-nop

nop addr -> patch addr 1-full-instruction
nop addr --nb -> patch addr with 1-nop

nop addr --ni 10 -> patch addr 10-full-instructions
nop addr --nb 10 -> patch addr with 10-nop

do you like this way?

@hugsy I updated this comment, now it makes more sense

@therealdreg
Copy link
Collaborator Author

therealdreg commented Jul 12, 2023

IMO, I dont like the "switch idea", have a nop & nopi commands its more fast and easy to use+remember :D (and also easy to mantain, the code+tests will be more simple and easy to follow). So, what do you want? tell me and I will do it :D

@hugsy
Copy link
Owner

hugsy commented Jul 12, 2023

My point is, there should not be two commands: I thought the current nop function we have was behaving your nopi. That's the behavior I wanted. Because if you only want to patch (and maybe break the disassembly) the command patch is here exactly for that.

So yes, let's have nop behave like your nopi i.e. with an instruction granularity and we simply keep a flag to toggle to a byte granularity instead (non-default behavior).

The syntax can be something like:

nop [0xAddress|Symbol] [NumNops] 

For instance (to pile on your examples):

nop -> patch $pc 1-full-instruction
nop --as-bytes -> patch $pc with 1-nop, breaking (maybe) disasm
nop $addr -> patch $addr with one NOP, preserving size, not breaking disasm
nop --as-bytes $addr-> patch $addr with one NOP, not preserving size, breaking disasm
nop 0xaddr 10 -> insert 10 nops, preserve size, not breaking disasm
nop --as-bytes $addr 10-> patch $addr with 10 NOP, not preserving size, breaking (maybe) disasm

WDYT ?

@therealdreg
Copy link
Collaborator Author

Yeah, gotcha

@therealdreg
Copy link
Collaborator Author

therealdreg commented Jul 13, 2023

I think this should be the right thing: nop granularity + instruction granularity (for others uses ... use patch byte cmd)

correcthing

@therealdreg
Copy link
Collaborator Author

done! @hugsy what do you think now?

docs/commands/nop.md Show resolved Hide resolved
docs/commands/nop.md Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
@hugsy hugsy merged commit 74e8626 into hugsy:dev Jul 13, 2023
3 checks passed
@hugsy hugsy added this to the Release: next milestone Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants