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 rz_lang_byte_array and remove rz_print_code #2444

Merged
merged 8 commits into from
Mar 25, 2022
Merged

Add rz_lang_byte_array and remove rz_print_code #2444

merged 8 commits into from
Mar 25, 2022

Conversation

wargio
Copy link
Member

@wargio wargio commented Mar 24, 2022

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the rizin book with the relevant information (if needed)

Detailed description

Book issue here: rizinorg/book#91

Extra tests have been added to cover all cases

Removed

  • pcA .bytes with instructions in comments removes the dependency on RzCore
  • pci C array of bytes with instructions same reason as pcA and was returning same output as pcA
  • pcs string useless since ps<cmd> does the same and better.
  • pcP python alias for pcp

Moved

  • pcv JaVa is now pcJ
  • pcz Swift is now pcs
  • pcJ javascript is now pcn because the output can be only used on NodeJS.
  • pcS bash shellscript is now pcb

Added

  • pcg for golang output

Also almost all the outputs (with the exception of ObjC and Vlang) has been tested and validated.

New shell output

Usage: pc[?]   # Print bytes as code byte arrays.
| pc  # Generate a C/C++ byte array.
| pch # Generate a C/C++ 16 bits array.
| pcw # Generate a C/C++ 32 bits array.
| pcd # Generate a C/C++ 64 bits array.
| pca # Generate a byte array in GAS assembly.
| pcb # Generate a bash script with the byte array.
| pcg # Generate a Golang byte array.
| pcJ # Generate a Java byte array.
| pcj # Generate a JSON byte array.
| pck # Generate a Kotlin byte array.
| pcn # Generate a NodeJS buffer.
| pco # Generate a Objective-C/C++ byte array.
| pcp # Generate a Python byte array.
| pcr # Generate a Rust byte array.
| pcs # Generate a Swift byte array.
| pcy # Generate a Yara match pattern.
| pc* # Generate a rizin commands for writing the byte array.

Useful modifiers:
| pch @e:cfg.bigendian=<true|false> # Change endianness for pch, pcw and pcd commands
| pc @! <n>                     # Change the N of bytes (i.e. block size).

Example of usages:
| pch @! 64 @e:cfg.bigendian=true # Generate a C 32 bits array in big endian format, using 64 bytes
| pcp @! 1024                   # Generate a Python byte array of size 1024
| pcj @! 10                     # Generate a JSON bytes array of size 10

Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from a couple nitpicks.

librz/core/cmd/cmd_print.c Outdated Show resolved Hide resolved
librz/core/cmd/cmd_print.c Show resolved Hide resolved
librz/util/lang_byte_array.c Outdated Show resolved Hide resolved
Copy link
Member

@ret2libc ret2libc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove all the n_bytes arguments as they just provide a way to replace the blocksize, which can already be done with @!.

Niiice anyway!

@wargio
Copy link
Member Author

wargio commented Mar 25, 2022

I would remove all the n_bytes arguments as they just provide a way to replace the blocksize, which can already be done with @!.

Niiice anyway!

i had the same thought, but i wanted to double check with you

@wargio wargio requested a review from ret2libc March 25, 2022 10:55
@XVilka XVilka merged commit acc339f into dev Mar 25, 2022
@XVilka XVilka deleted the byte-array-lang branch March 25, 2022 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants