annotate target-utils/tf-breakin/mkembed.c @ 784:5cc8a442efad

aci: aoc.c and ati_bas.c done
author Space Falcon <falcon@ivan.Harhan.ORG>
date Wed, 11 Mar 2015 08:27:02 +0000
parents 22c6e39e1789
children 7166c8311b0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
357
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <sys/types.h>
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <sys/file.h>
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <sys/stat.h>
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <stdio.h>
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <stdlib.h>
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <unistd.h>
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #define PAYLOAD_SIZE 112
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 u_char payload_buf[PAYLOAD_SIZE];
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 read_binary(filename)
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 char *filename;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 int fd;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 struct stat st;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 fd = open(filename, O_RDONLY);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 if (fd < 0) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 perror(filename);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 exit(1);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 fstat(fd, &st);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 if (!S_ISREG(st.st_mode)) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 fprintf(stderr, "error: %s is not a regular file\n", filename);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 exit(1);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 if (st.st_size != PAYLOAD_SIZE) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 fprintf(stderr, "error: %s size mismatch\n", filename);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 exit(1);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 if (read(fd, payload_buf, PAYLOAD_SIZE) != PAYLOAD_SIZE) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 perror("read error");
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 exit(1);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 close(fd);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 write_output(filename)
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 char *filename;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 FILE *of;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 int i, j, idx;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 of = fopen(filename, "w");
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 if (!of) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 perror(filename);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 exit(1);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 fprintf(of, "u_char payload[%d] = {\n", PAYLOAD_SIZE);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 idx = 0;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 for (i = 0; i < 14; i++) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 for (j = 0; j < 8; j++) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 if (j)
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 putc(' ', of);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 else
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 putc('\t', of);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 fprintf(of, "0x%02X,", payload_buf[idx++]);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 putc('\n', of);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 fputs("};\n", of);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 fclose(of);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 main(argc, argv)
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 char **argv;
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (argc != 3) {
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 fprintf(stderr, "usage: %s payload.bin output.c\n", argv[0]);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 exit(1);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 read_binary(argv[1]);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 write_output(argv[2]);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 exit(0);
22c6e39e1789 target-utils/tf-breakin: build embeddable form of the payload
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 }