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

Draft: Fix wb single byte write behavior #23418

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions libr/core/cmd_write.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2166,9 +2166,11 @@ static int cmd_wb(void *data, const char *input) {
R_LOG_ERROR ("wb only operates on bytes");
} else if (uil > 0) {
int shift = 8 - uil;
b <<= shift;
b >>= shift;
b |= (n << shift);
// Shift left and right to zero uil most significant bits
b <<= uil;
b >>= uil;
// Overwrite uil most significant bits and keep the rest
b += (n << shift);
r_io_write_at (core->io, core->offset, &b, 1);
} else {
r_core_cmd_help_match (core, help_msg_w, "wb");
Expand Down
33 changes: 32 additions & 1 deletion test/db/cmd/cmd_print_bitformat
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,38 @@ EXPECT=<<EOF
00000000
11000000
00010000
10110010
10100010
EOF
RUN

NAME=pbwb least significant bit
FILE=-
CMDS=<<EOF
pb 8
wb 00000001
pb 8
wb 00000000
pb 8
EOF
EXPECT=<<EOF
00000000
00000001
00000000
EOF
RUN

NAME=pbwb most significant bit
FILE=-
CMDS=<<EOF
pb 8
wb 11111111
pb 8
wb 0
pb 8
EOF
EXPECT=<<EOF
00000000
11111111
01111111
EOF
RUN
Loading