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