Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2009, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 17 | |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 18 | /* Based upon the freeware version of the Obfuscated Tiny C Compiler |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 19 | * by Francis Bellard. <francis@bellard.org>. |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 26 | int d, z, C, h, K, q, G, L, W; |
| 27 | char* P; |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 28 | char* ac; |
| 29 | char* v; |
| 30 | char* D; |
| 31 | char* M; |
| 32 | char* R; |
| 33 | FILE* Q; |
| 34 | |
| 35 | void ab (int j); |
| 36 | void w(); |
| 37 | |
| 38 | void E(e) { |
| 39 | *(char*) D++=e; |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 40 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 41 | |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 42 | void o() { |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 43 | if (L) { |
| 44 | h = *(char*) L++; |
| 45 | if (h == 2) { |
| 46 | L = 0; |
| 47 | h = W; |
| 48 | } |
| 49 | } else |
| 50 | h = fgetc(Q); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 51 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 52 | |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 53 | int X() { |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 54 | return isalnum(h) | h == 95; |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 55 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 56 | |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 57 | void Y() { |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 58 | if (h == 92) { |
| 59 | o(); |
| 60 | if (h == 110) |
| 61 | h = 10; |
| 62 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 63 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 64 | |
| 65 | void ad() { |
| 66 | int j, m; |
| 67 | while (isspace(h) | h == 35) { |
| 68 | if (h == 35) { |
| 69 | o(); |
| 70 | ad(); |
| 71 | if (d == 536) { |
| 72 | ad(); |
| 73 | E(32); |
| 74 | *(int*) d = 1; |
| 75 | *(int*) (d + 4) = (int) D; |
| 76 | } |
| 77 | while (h != 10) { |
| 78 | E(h); |
| 79 | o(); |
| 80 | } |
| 81 | E(h); |
| 82 | E(2); |
| 83 | } |
| 84 | o(); |
| 85 | } |
| 86 | C = 0; |
| 87 | d = h; |
| 88 | if (X()) { |
| 89 | E(32); |
| 90 | M = D; |
| 91 | while (X()) { |
| 92 | E(h); |
| 93 | o(); |
| 94 | } |
| 95 | if (isdigit(d)) { |
| 96 | z = strtol(M, 0, 0); |
| 97 | d = 2; |
| 98 | } else { |
| 99 | *(char*) D = 32; |
| 100 | d = strstr(R, M - 1) - R; |
| 101 | *(char*) D = 0; |
| 102 | d = d * 8 + 256; |
| 103 | if (d > 536) { |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 104 | d = ((int) P) + d; |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 105 | if (*(int*) d == 1) { |
| 106 | L = *(int*) (d + 4); |
| 107 | W = h; |
| 108 | o(); |
| 109 | ad(); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } else { |
| 114 | o(); |
| 115 | if (d == 39) { |
| 116 | d = 2; |
| 117 | Y(); |
| 118 | z = h; |
| 119 | o(); |
| 120 | o(); |
| 121 | } else if (d == 47 & h == 42) { |
| 122 | o(); |
| 123 | while (h) { |
| 124 | while (h != 42) |
| 125 | o(); |
| 126 | o(); |
| 127 | if (h == 47) |
| 128 | h = 0; |
| 129 | } |
| 130 | o(); |
| 131 | ad(); |
| 132 | } else { |
| 133 | char* e = "++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b"; |
| 134 | while (j = *(char*) e++) { |
| 135 | m = *(char*) e++; |
| 136 | z = 0; |
| 137 | while ((C = *(char*) e++ - 98) < 0) |
| 138 | z = z * 64 + C + 64; |
| 139 | if (j == d & (m == h | m == 64)) { |
| 140 | if (m == h) { |
| 141 | o(); |
| 142 | d = 1; |
| 143 | } |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 149 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 150 | |
| 151 | void ae( g) { |
| 152 | while( g&&g!=-1) { |
| 153 | *(char*) q++=g; |
| 154 | g=g>>8; |
| 155 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 156 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 157 | |
| 158 | void A(e) { |
| 159 | int g; |
| 160 | while( e) { |
| 161 | g=*(int*) e; |
| 162 | *(int*) e=q-e-4; |
| 163 | e=g; |
| 164 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 165 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 166 | |
| 167 | int s( g, e) { |
| 168 | ae(g); |
| 169 | *(int*) q = e; |
| 170 | e = q; |
| 171 | q = q + 4; |
| 172 | return e; |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 173 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 174 | |
| 175 | int H(e) { |
| 176 | s(184,e); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 177 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 178 | |
| 179 | int B(e) { |
| 180 | return s(233,e); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 181 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 182 | |
| 183 | S( j, e) { |
| 184 | ae(1032325); |
| 185 | return s(132 + j, e); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 186 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 187 | |
| 188 | void Z(e) { |
| 189 | ae( 49465); |
| 190 | H(0); |
| 191 | ae( 15); |
| 192 | ae( e+144); |
| 193 | ae( 192); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 194 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 195 | |
| 196 | void N( j, e) { |
| 197 | ae(j + 131); |
| 198 | s((e < 512) << 7 | 5, e); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 199 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 200 | |
| 201 | void T (j) { |
| 202 | int g,e,m,aa; |
| 203 | g=1; |
| 204 | if( d == 34) { |
| 205 | H(v); |
| 206 | while( h!=34) { |
| 207 | Y (); |
| 208 | *(char*) v++=h; |
| 209 | o (); |
| 210 | } |
| 211 | *(char*) v=0; |
| 212 | v= (char*) (((int)v) +4&-4); |
| 213 | o (); |
| 214 | ad(); |
| 215 | } |
| 216 | else { |
| 217 | aa=C; |
| 218 | m= z; |
| 219 | e=d; |
| 220 | ad(); |
| 221 | if( e == 2) { |
| 222 | H(m); |
| 223 | } |
| 224 | else if( aa == 2) { |
| 225 | T(0); |
| 226 | s(185,0); |
| 227 | if( e == 33)Z(m); |
| 228 | else ae( m); |
| 229 | } |
| 230 | else if( e == 40) { |
| 231 | w (); |
| 232 | ad(); |
| 233 | } |
| 234 | else if( e == 42) { |
| 235 | ad(); |
| 236 | e=d; |
| 237 | ad(); |
| 238 | ad(); |
| 239 | if( d == 42) { |
| 240 | ad(); |
| 241 | ad(); |
| 242 | ad(); |
| 243 | ad(); |
| 244 | e=0; |
| 245 | } |
| 246 | ad(); |
| 247 | T(0); |
| 248 | if( d == 61) { |
| 249 | ad(); |
| 250 | ae( 80); |
| 251 | w (); |
| 252 | ae( 89); |
| 253 | ae( 392+(e == 256)); |
| 254 | } |
| 255 | else if( e) { |
| 256 | if( e == 256)ae( 139); |
| 257 | else ae( 48655); |
| 258 | q++; |
| 259 | } |
| 260 | } |
| 261 | else if( e == 38) { |
| 262 | N(10,*(int*) d); |
| 263 | ad(); |
| 264 | } |
| 265 | else { |
| 266 | g=*(int*) e; |
| 267 | if(!g)g=dlsym(0,M); |
| 268 | if( d == 61&j) { |
| 269 | ad(); |
| 270 | w (); |
| 271 | N(6,g); |
| 272 | } |
| 273 | else if( d!= 40) { |
| 274 | N(8,g); |
| 275 | if( C == 11) { |
| 276 | N(0,g); |
| 277 | ae( z); |
| 278 | ad(); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | if( d == 40) { |
| 284 | if( g == 1)ae( 80); |
| 285 | m= s(60545,0); |
| 286 | ad(); |
| 287 | j=0; |
| 288 | while( d!= 41) { |
| 289 | w (); |
| 290 | s(2393225,j); |
| 291 | if( d == 44)ad(); |
| 292 | j=j +4; |
| 293 | } |
| 294 | *(int*) m= j; |
| 295 | ad(); |
| 296 | if(!g) { |
| 297 | e=e +4; |
| 298 | *(int*) e=s(232,*(int*) e); |
| 299 | } |
| 300 | else if( g == 1) { |
| 301 | s(2397439,j); |
| 302 | j=j +4; |
| 303 | } |
| 304 | else { |
| 305 | s(232,g-q-5); |
| 306 | } |
| 307 | if( j)s(50305,j); |
| 308 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 309 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 310 | |
| 311 | void O (j) { |
| 312 | int e,g,m; |
| 313 | if( j--== 1)T(1); |
| 314 | else { |
| 315 | O (j); |
| 316 | m= 0; |
| 317 | while( j == C) { |
| 318 | g=d; |
| 319 | e=z; |
| 320 | ad(); |
| 321 | if( j>8) { |
| 322 | m= S(e,m); |
| 323 | O (j); |
| 324 | } |
| 325 | else { |
| 326 | ae( 80); |
| 327 | O (j); |
| 328 | ae( 89); |
| 329 | if( j == 4|j == 5) { |
| 330 | Z(e); |
| 331 | } |
| 332 | else { |
| 333 | ae( e); |
| 334 | if( g == 37)ae( 146); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | if( m&&j>8) { |
| 339 | m= S(e,m); |
| 340 | H(e^1); |
| 341 | B(5); |
| 342 | A(m); |
| 343 | H(e); |
| 344 | } |
| 345 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 346 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 347 | |
| 348 | void w() { |
| 349 | O(11); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 350 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 351 | |
| 352 | U() { |
| 353 | w(); |
| 354 | return S(0, 0); |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 355 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 356 | |
| 357 | void I (j) { |
| 358 | int m,g,e; |
| 359 | if( d == 288) { |
| 360 | ad(); |
| 361 | ad(); |
| 362 | m= U (); |
| 363 | ad(); |
| 364 | I (j); |
| 365 | if( d == 312) { |
| 366 | ad(); |
| 367 | g=B(0); |
| 368 | A(m); |
| 369 | I (j); |
| 370 | A(g); |
| 371 | } |
| 372 | else { |
| 373 | A(m); |
| 374 | } |
| 375 | } |
| 376 | else if( d == 352|d == 504) { |
| 377 | e=d; |
| 378 | ad(); |
| 379 | ad(); |
| 380 | if( e == 352) { |
| 381 | g=q; |
| 382 | m= U (); |
| 383 | } |
| 384 | else { |
| 385 | if( d!= 59)w (); |
| 386 | ad(); |
| 387 | g=q; |
| 388 | m= 0; |
| 389 | if( d!= 59)m= U (); |
| 390 | ad(); |
| 391 | if( d!= 41) { |
| 392 | e=B(0); |
| 393 | w (); |
| 394 | B(g-q-5); |
| 395 | A(e); |
| 396 | g=e +4; |
| 397 | } |
| 398 | } |
| 399 | ad(); |
| 400 | I(&m); |
| 401 | B(g-q-5); |
| 402 | A(m); |
| 403 | } |
| 404 | else if( d == 123) { |
| 405 | ad(); |
| 406 | ab(1); |
| 407 | while( d!= 125)I (j); |
| 408 | ad(); |
| 409 | } |
| 410 | else { |
| 411 | if( d == 448) { |
| 412 | ad(); |
| 413 | if( d!= 59)w (); |
| 414 | K=B(K); |
| 415 | } |
| 416 | else if( d == 400) { |
| 417 | ad(); |
| 418 | *(int*) j=B(*(int*) j); |
| 419 | } |
| 420 | else if( d!= 59)w (); |
| 421 | ad(); |
| 422 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 423 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 424 | |
| 425 | void ab (int j) { |
| 426 | int m; |
| 427 | while( d == 256 | d != -1 & !j ) { |
| 428 | if( d == 256) { |
| 429 | ad(); |
| 430 | while( d!= 59) { |
| 431 | if( j ) { |
| 432 | G=G +4; |
| 433 | *(int*) d=-G; |
| 434 | } |
| 435 | else { |
| 436 | *(char**) d = v; |
| 437 | v=v +4; |
| 438 | } |
| 439 | ad(); |
| 440 | if( d == 44)ad(); |
| 441 | } |
| 442 | ad(); |
| 443 | } |
| 444 | else { |
| 445 | A(*(int*)(d +4)); |
| 446 | *(int*) d=q; |
| 447 | ad(); |
| 448 | ad(); |
| 449 | m= 8; |
| 450 | while( d!= 41) { |
| 451 | *(int*) d=m; |
| 452 | m= m +4; |
| 453 | ad(); |
| 454 | if( d == 44)ad(); |
| 455 | } |
| 456 | ad(); |
| 457 | K=G=0; |
| 458 | ae( 15042901); |
| 459 | m= s(60545,0); |
| 460 | I(0); |
| 461 | A(K); |
| 462 | ae( 50121); |
| 463 | *(int*) m= G; |
| 464 | } |
| 465 | } |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 466 | } |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 467 | |
| 468 | int main( int argc, char** argv) { |
| 469 | Q = stdin; |
| 470 | if (argc-- > 1) { |
| 471 | char* file = argv[1]; |
| 472 | argv += 1; |
| 473 | Q = fopen(file, "r"); |
| 474 | if (Q == NULL) { |
| 475 | fprintf(stderr, "Could not open file \"%s\"\n", file); |
| 476 | return -1; |
| 477 | } |
| 478 | } |
| 479 | D = strcpy(R = calloc(1, 99999), |
| 480 | " int if else while break return for define main ") + 48; |
| 481 | v = calloc(1, 99999); |
Jack Palevich | d160530 | 2009-05-08 15:26:24 -0700 | [diff] [blame^] | 482 | ac = calloc(1, 99999); |
| 483 | q = (int) ac; |
Jack Palevich | ae54f1f | 2009-05-08 14:54:15 -0700 | [diff] [blame] | 484 | P = calloc(1, 99999); |
| 485 | o(); |
| 486 | ad(); |
| 487 | ab(0); |
| 488 | #if 1 |
| 489 | fwrite(R, 1, 99999, stdout); |
| 490 | fwrite(ac, 1, 99999, stdout); |
| 491 | fwrite(P, 1, 99999, stdout); |
| 492 | return 0; |
| 493 | #else |
| 494 | return (*(int(*)()) *(int*) (P + 592))(argc, argv); |
| 495 | #endif |
Jack Palevich | 8831148 | 2009-05-08 13:57:37 -0700 | [diff] [blame] | 496 | } |
| 497 | |