• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 The Chromium OS Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  *
6  * This is a very simple binary editor, used to create corrupted structs for
7  * testing. It copies stdin to stdout, replacing bytes beginning at the given
8  * offset with the specified 8-bit values.
9  *
10  * There is NO conversion checking of the arguments.
11  */
12 
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 
main(int argc,char * argv[])17 int main(int argc, char *argv[])
18 {
19 	uint32_t offset, curpos, curarg;
20 	int c;
21 
22 	if (argc < 3) {
23 		fprintf(stderr, "Need two or more args:  OFFSET VAL [VAL...]\n");
24 		return 1;
25 	}
26 
27 	offset = (uint32_t)strtoul(argv[1], 0, 0);
28 	curarg = 2;
29 	for ( curpos = 0; (c = fgetc(stdin)) != EOF; curpos++) {
30 
31 		if (curpos == offset && curarg < argc) {
32 			c = (uint8_t)strtoul(argv[curarg++], 0, 0);
33 			offset++;
34 		}
35 
36 		fputc(c, stdout);
37 	}
38 	return 0;
39 }
40