Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae54f1fb authored by Jack Palevich's avatar Jack Palevich
Browse files

Continue deobfuscation.

Add a license.

Indent the code.
Add includes for external functions.
Improve function prototypes.
Start adding the correct type to things that are pointers.
Start fixing compiler warnings.

Instead of directly executing the compiled code (which only works on x86 Linux),
write the internal compiler state to stdout. This makes it easier to test whether
or not our refactoring is breaking anything.

Return a zero status on success.

Add error checking for a missing input file.
parent 88311486
Loading
Loading
Loading
Loading
+472 −407
Original line number Diff line number Diff line
/*
 **
 ** Copyright 2009, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 **
 **     http://www.apache.org/licenses/LICENSE-2.0
 **
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.
 */

/* Based upon the freeware version of the Obfuscated Tiny C Compiler
 * by Francis Bellard.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int d, z, C, h, P, K, q, G, L, W;
char* ac;
char* v;
char* D;
char* M;
char* R;
FILE* Q;

int d,z,C,h,P,K,ac,q,G,v,Q,R,D,L,W,M;
E(e){
void ab (int j);
void w();

void E(e) {
    *(char*) D++=e;
}

o() {
    if (L) {
        h = *(char*) L++;
@@ -11,20 +45,24 @@ if( h == 2){
            L = 0;
            h = W;
        }
    } else
        h = fgetc(Q);
}
else h=fgetc(Q);
}

X() {
    return isalnum(h) | h == 95;
}

Y() {
    if (h == 92) {
        o();
if( h == 110)h=10;
        if (h == 110)
            h = 10;
    }
}
ad(){
int e,j,m;

void ad() {
    int j, m;
    while (isspace(h) | h == 35) {
        if (h == 35) {
            o();
@@ -33,7 +71,7 @@ if( d == 536){
                ad();
                E(32);
                *(int*) d = 1;
*(int*)(d +4)=D;
                *(int*) (d + 4) = (int) D;
            }
            while (h != 10) {
                E(h);
@@ -56,8 +94,7 @@ o ();
        if (isdigit(d)) {
            z = strtol(M, 0, 0);
            d = 2;
}
else{
        } else {
            *(char*) D = 32;
            d = strstr(R, M - 1) - R;
            *(char*) D = 0;
@@ -72,8 +109,7 @@ ad();
                }
            }
        }
}
else{
    } else {
        o();
        if (d == 39) {
            d = 2;
@@ -81,23 +117,24 @@ Y ();
            z = h;
            o();
            o();
}
else if( d == 47&h == 42){
        } else if (d == 47 & h == 42) {
            o();
            while (h) {
while( h!=42)o ();
                while (h != 42)
                    o();
                o();
if( h == 47)h=0;
                if (h == 47)
                    h = 0;
            }
            o();
            ad();
}
else{
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";
        } else {
            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";
            while (j = *(char*) e++) {
                m = *(char*) e++;
                z = 0;
while((C=*(char*) e++-98)<0)z=z*64+C+64;
                while ((C = *(char*) e++ - 98) < 0)
                    z = z * 64 + C + 64;
                if (j == d & (m == h | m == 64)) {
                    if (m == h) {
                        o();
@@ -109,13 +146,15 @@ break;
        }
    }
}
ae( g){

void ae( g) {
    while( g&&g!=-1) {
        *(char*) q++=g;
        g=g>>8;
    }
}
A(e){

void A(e) {
    int g;
    while( e) {
        g=*(int*) e;
@@ -123,35 +162,42 @@ g=*(int*) e;
        e=g;
    }
}
s(g,e){

int s( g, e) {
    ae(g);
    *(int*) q = e;
    e = q;
    q = q + 4;
    return e;
}
H(e){

int H(e) {
    s(184,e);
}
B(e){

int B(e) {
    return s(233,e);
}

S( j, e) {
    ae(1032325);
    return s(132 + j, e);
}
Z(e){

void Z(e) {
    ae( 49465);
    H(0);
    ae( 15);
    ae( e+144);
    ae( 192);
}
N(j,e){

void N( j, e) {
    ae(j + 131);
    s((e < 512) << 7 | 5, e);
}
T (j){

void T (j) {
    int g,e,m,aa;
    g=1;
    if( d == 34) {
@@ -162,7 +208,7 @@ Y ();
            o ();
        }
        *(char*) v=0;
v=v +4&-4;
        v= (char*) (((int)v) +4&-4);
        o ();
        ad();
    }
@@ -260,7 +306,8 @@ s(232,g-q-5);
        if( j)s(50305,j);
    }
}
O (j){

void O (j) {
    int e,g,m;
    if( j--== 1)T(1);
    else {
@@ -296,14 +343,17 @@ H(e);
        }
    }
}
w (){

void w() {
    O(11);
}

U() {
    w();
    return S(0, 0);
}
I (j){

void I (j) {
    int m,g,e;
    if( d == 288) {
        ad();
@@ -370,7 +420,8 @@ else if( d!= 59)w ();
        ad();
    }
}
ab (j){

void ab (int j) {
    int m;
    while( d == 256 | d != -1 & !j ) {
        if( d == 256) {
@@ -381,7 +432,7 @@ G=G +4;
                    *(int*) d=-G;
                }
                else {
*(int*) d=v;
                    *(char**) d = v;
                    v=v +4;
                }
                ad();
@@ -412,19 +463,33 @@ ae( 50121);
        }
    }
}
main(g,e){
Q=__stdinp;
if( g-->1){
e=e +4;
Q=fopen(*(int*) e,"r");
}
D=strcpy(R =calloc(1,99999)," int if else while break return for define main ")+48;

int main( int argc, char** argv) {
    Q = stdin;
    if (argc-- > 1) {
        char* file = argv[1];
        argv += 1;
        Q = fopen(file, "r");
        if (Q == NULL) {
            fprintf(stderr, "Could not open file \"%s\"\n", file);
            return -1;
        }
    }
    D = strcpy(R = calloc(1, 99999),
            " int if else while break return for define main ") + 48;
    v = calloc(1, 99999);
    q = ac = calloc(1, 99999);
    P = calloc(1, 99999);
    o();
    ad();
    ab(0);
return(*(int(*)())*(int*)(P+592))(g,e);
#if 1
    fwrite(R, 1, 99999, stdout);
    fwrite(ac, 1, 99999, stdout);
    fwrite(P, 1, 99999, stdout);
    return 0;
#else
    return (*(int(*)()) *(int*) (P + 592))(argc, argv);
#endif
}