FreeCalypso > hg > freecalypso-reveng
annotate mot931c/emu.c @ 182:c38075b8a625
calextract: forgot the final semicolon after the last closing brace
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 13 Jul 2014 07:51:24 +0000 |
parents | 9082f3991fe5 |
children |
rev | line source |
---|---|
157
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <sys/types.h> |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <sys/file.h> |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <stdio.h> |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <stdlib.h> |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <string.h> |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <strings.h> |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 static int fd; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 static u_char verquery[13] = {0x02, 0x14, 0x41, 0x20, 0x20, 0x00, 0x00, |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 0x04, 0x00, 0x00, 0x00, 0x45, 0x02}; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 static u_char verquery_resp[10] = {0x41, 0x00, 0x04, 0x00, 0x00, 0x00, |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 '8', '.', '8', '.'}; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 static u_char download_hdr[3] = {0x02, 0x14, 0x40}; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 static u_char download_resp[2] = {0x40, 0x00}; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 send_stx() |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 static u_char stx = 0x02; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 write(fd, &stx, 1); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 send_rvtmux_byte(b) |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 u_char buf[2]; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 int l, o; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 buf[0] = 0x10; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 buf[1] = b; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 if (b == 0x02 || b == 0x10) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 o = 0; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 l = 2; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 } else { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 o = 1; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 l = 1; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 write(fd, buf + o, l); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 send_etm_resp(data, datalen) |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 u_char *data; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 u_char csum; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 int i; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 printf("Responding with:"); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 send_stx(); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 send_rvtmux_byte(0x14); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 csum = 0; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 for (i = 0; i < datalen; i++) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 printf(" %02X", data[i]); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 send_rvtmux_byte(data[i]); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 csum ^= data[i]; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 send_rvtmux_byte(csum); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 send_stx(); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 putchar('\n'); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 main(argc, argv) |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 char **argv; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 u_char buf[1024]; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 int cc, i; |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 if (argc != 2) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 fprintf(stderr, "usage: %s pty\n", argv[0]); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 exit(1); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 fd = open(argv[1], O_RDWR); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 if (fd < 0) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 perror(argv[1]); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 exit(1); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 for (;;) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 cc = read(fd, buf, sizeof buf); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 if (cc < 0) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 perror("read error"); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 exit(1); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 if (cc == 0) { |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 fprintf(stderr, "read EOF\n"); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 exit(1); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 printf("read %d bytes:", cc); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 for (i = 0; i < cc; i++) |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 printf(" %02X", buf[i]); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 putchar('\n'); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 if (cc == sizeof(verquery) && !bcmp(buf, verquery, cc)) |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 send_etm_resp(verquery_resp, sizeof verquery_resp); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 if (cc > 3 && !bcmp(buf, download_hdr, 3)) |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 send_etm_resp(download_resp, sizeof download_resp); |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 } |
9082f3991fe5
mot931c break-in procedure cracked
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 } |