1 #include <libcgc.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 struct stack_func_1 {
6 char buf[0x20];
7 char *where;
8 };
9
receive_n(int fd,void * dst_a,size_t n_bytes)10 size_t receive_n( int fd, void *dst_a, size_t n_bytes )
11 {
12 char *dst = (char *)dst_a;
13 size_t len = 0;
14 size_t rx = 0;
15 while(len < n_bytes) {
16 if (receive(fd, dst + len, n_bytes - len, &rx) != 0) {
17 len = 0;
18 break;
19 }
20 len += rx;
21 }
22
23 return len;
24 }
25
send_all(int fd,const void * msg,size_t n_bytes)26 int send_all(int fd, const void *msg, size_t n_bytes)
27 {
28 size_t len = 0;
29 size_t tx = 0;
30 while(len < n_bytes) {
31 if (transmit(fd, (char *)msg + len, n_bytes - len, &tx) != 0) {
32 return 1;
33 }
34 len += tx;
35 }
36 return 0;
37 }
38
39 char
to_hex(unsigned char v)40 to_hex(unsigned char v)
41 {
42 if (v < 10)
43 return '0' + v;
44 else if (v < 16)
45 return 'a' + (v - 10);
46 else
47 return '\0';
48 }
49
50 int myglobal;
51
main(int secret_page_i)52 int __attribute((fastcall)) main(int secret_page_i) {
53
54 int x;
55 int i;
56 char *flag = (void *)secret_page_i;
57 char flag_buf[41];
58
59 for(int i=0;i<40;i++) {
60 flag_buf[i++] = to_hex((unsigned char) *flag / 16 % 16);
61 flag_buf[i] = to_hex((unsigned char) *flag++ % 16);
62 }
63
64 for(int i=0;i<20;i++) {
65 transmit(1, "A", 1, NULL);
66 }
67 transmit(1, flag_buf, 40, NULL);
68
69 for(int i=0;i<20;i++) {
70 transmit(1, "B", 1, NULL);
71 }
72
73 return 0;
74 }
75
76
77