Files
rk35xx-android14/external/vboot_reference/tests/futility/binary_editor.c
T
hmz007 36ed224bac Rockchip Anroid14_SDK 20240628-rkr5 (2556df1a)
Signed-off-by: hmz007 <hmz007@gmail.com>
Change-Id: Ib87fdbe7a0be7dc961af3500fe9ea4589a127f9f
2024-10-29 18:12:02 +08:00

40 lines
932 B
C

/*
* Copyright 2014 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* This is a very simple binary editor, used to create corrupted structs for
* testing. It copies stdin to stdout, replacing bytes beginning at the given
* offset with the specified 8-bit values.
*
* There is NO conversion checking of the arguments.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
uint32_t offset, curpos, curarg;
int c;
if (argc < 3) {
fprintf(stderr, "Need two or more args: OFFSET VAL [VAL...]\n");
return 1;
}
offset = (uint32_t)strtoul(argv[1], 0, 0);
curarg = 2;
for ( curpos = 0; (c = fgetc(stdin)) != EOF; curpos++) {
if (curpos == offset && curarg < argc) {
c = (uint8_t)strtoul(argv[curarg++], 0, 0);
offset++;
}
fputc(c, stdout);
}
return 0;
}