I'm trying to reverse engineer a proprietary scripting compiled bytecode So I can recover source codes of contractor who has gone.While I worked out the majority of it, I'm trying to work out how to translate expressions back into code. Wondering if anyone may have some ideas from the patterns below the sort of logic that might be used to rebuild the equations. In particular how operators may be applied back to the components of the expression.Specifically I'm trying to work out how to decompile these two expressions:A = B * C+D/E-FA = B * (C+D)/E-FOperation Codes ,this was worked out from examples provided below22 04 >2B 04 <32 04 *01 04 +17 04 /55 04 -25 00 AND27 00 OR26 04 end of statementType of assignment:3D 40 xx xx       = Variable xx xx 3D 45 xx xx xx xx = 4 byte number4B xx             = One byte value48 xx             = One byte value38 40 xx xx       = Assign result to variable xx xxIn this example the variables are:A = 00 00B = 00 04C = 00 08D = 00 0CE = 00 10F = 00 14Example:A = 10*20+30/40-50/24B AF       ; 175 38 40 00 00 ; Assign result to AA = 10*B+30/40-50/248 0A       ; 103D 40 00 04 ; B 32 04       ; *48 00       ; 001 04       ; +48 19       ; 2555 04       ; -38 40 00 00 ; assign result to AA = B+C3D 40 00 04 ; B3D 40 00 08 ; C01 04       ; +38 40 00 00 ; assign result to AA = B*C3D 40 00 04 ; B3D 40 00 08 ; C32 04       ; *38 40 00 00 ; assign result to AA = B-C3D 40 00 04 ; B3D 40 00 08 ; C55 04       ; -38 40 00 00 ; Assign result to AA = B/C3D 40 00 04 ; B3D 40 00 08 ; C17 04       ; / 38 40 00 00 ; Assign result to AA = B*C+D-E/F3D 40 00 04 ; B3D 40 00 08 ; C32 04       ; *3D 40 00 0C ; D01 04       ; +3D 40 00 10 ; E3D 40 00 14 ; F17 04       ; /55 04       ; -38 40 00 00 ; Assign result to AA = B*C+D/E-F3D 40 00 04 ; B3D 40 00 08 ; C32 04       ; *3D 40 00 0C ; D3D 40 00 10 ; E17 04       ; / 01 04       ; +3D 40 00 14 ; F55 04       ; -38 40 00 00 ; Assign result to AA = B*(C+D)/E-F3D 40 00 04 ; B3D 40 00 08 ; C3D 40 00 0C ; D01 04       ; +32 04       ; *3D 40 00 10 ; E17 04       ; /3D 40 00 14 ; F55 04       ; -38 40 00 00 ; Assign result to AA = B+C * D3D 40 00 04 ; B3D 40 00 08 ; C 3D 40 00 0C ; D32 04       ; * 01 04       ; +38 40 00 00 ; assign result to AA=(B+C) * D3D 40 00 04 ; B3D 40 00 08 ; C01 04       ; +3D 40 00 0C ; D32 04       ; *38 40 00 00 ; assign result to AA=B+C+D * E3D 40 00 04 ; B3D 40 00 08 ; C01 04       ; +3D 40 00 0C ; D3D 40 00 10 ; E32 04       ; *01 04       ; +38 40 00 00 ; assign result to AA=(B+C+D) * E3D 40 00 04 ; B3D 40 00 08 ; C01 04       ; +3D 40 00 0C ; D01 04       ; +3D 40 00 10 ; E32 04       ; *38 40 00 00 ; assign result to AA=A+B * C+D+E * F3D 40 00 00 ; A3D 40 00 04 ; B3D 40 00 08 ; C32 04       ; *01 04       ; +3D 40 00 0C ; D01 04       ; +3D 40 00 10 ; E3D 40 00 14 ; F32 04       ; *01 04       ; +38 40 00 00 ; Assign result to AA=(A+B) * (C+D)+E * F3D 40 00 00 ; A3D 40 00 04 ; B01 04       ; + 3D 40 00 08 ; C3D 40 00 0C ; D01 04       ; +   32 04       ; *3D 40 00 10 ; E3D 40 00 14 ; F32 04       ; *01 04       ; +38 40 00 00 ; Assign result to AA=A+B+(C * D)+E3D 40 00 00 ; A3D 40 00 04 ; B01 04       ; +3D 40 00 08 ; C3D 40 00 0C ; D32 04       ; *01 04       ; +3D 40 00 10 ; E01 04       ; + 38 40 00 00 ; assign result to AA=A+B+(C* D *E)+F3D 40 00 00 ; A3D 40 00 04 ; B01 04       ; +3D 40 00 08 ; C3D 40 00 0C ; D32 04       ; *3D 40 00 10 ; E32 04       ; *01 04       ; +3D 40 00 14 ; F01 04       ; +38 40 00 00 ; assign result to AA=B-C3D 40 00 04 ; B3D 40 00 08 ; C55 04       ; -38 40 00 00 ; assign result to AA=B*C+D-E/F3D 40 00 04 ; B3D 40 00 08 ; C32 04       ; *3D 40 00 0C ; D01 04       ; +3D 40 00 10 ; E3D 40 00 14 ; F17 04       ; -55 04       ; /38 40 00 00 ; Assign result to ABoolean Expressions512 < A3D 45 00 00 02 00 ; 5123D 40 00 00       ; variable A2B 04             ; <26 00             ; end of expression00 7E             ; ?a>B and b128 or d>1024 or e>1283D 40 00 00 ; A3D 40 00 04 ; B22 04       ; >25 00       ; AND00 CC       ;3D 40 00 04 ; B3D 40 00 08 ; C2B 04       ; <25 00       ; AND00 CC       ;3D 40 00 08 ; C4B 80       ; 12822 04       ; >27 00       ; OR 00 E8       ;3D 40 00 0C ; D 3D 45 00 00 04 00 ; 102422 04       ; >27 00       ; OR 00 E8       ; 3D 40 00 10 ; E4B 80       ; 12822 04       ; >26 00       ; end of expression01 14       ; ?
reversing bytcode - trying to work decompiling expression
file format
Thanks to response from Jongware who correctly identified this as reverse polish notation, which needed to be converted to infixTested on some samplesOriginal:1) A=B * C+D-E/F2) A=B * C+D/E-F3) A=B * (C+D)/E-FDecompiled:1) A=(((B * C)+D)-(E/F))2) A=(((B * C)+(D/E))-F)3) A=(((B* (C+D))/E)-F)If this helps anyone else this is the prototype processing code in C#, which I've verified works correctly. This code needs further improvement, but it does work for this scenario described.    // instruction is a byte[] array containing the code to decode    Stack<string> stack = new Stack<string>();    string op;    byte[] bit32=new byte[4];    string result;    for (int i = 0; i < instruction.Length;i++ )    {        op=;        switch (instruction[i])        {            case 0x22:                op=>;                i++;                break;            case 0x2B:                op=<;                i++;                break;            case 0x32:                op=*;                i++;                break;        case 0x01:            op=+;            i++;            break;        case 0x17:            op=/;            i++;            break;        case 0x55:            op=-;            i++;            break;        case 0x38:            i++;            if (instruction[i]==0x40)            {                // builds the final result, and adds it to textboxDecompiledText                i++;                result = string.Format({0}={1}, string.Format(S{0:X2}{1:X2}, instruction[i], instruction[i + 1]),                stack.Pop());                i++;                textBoxDecompiled.Text += result;                break;            }            break;        case 0x4B: // 1 byte integer        case 0x48:            i++;            stack.Push(((int)instruction[i]).ToString());            break;        case 0x3D:            i++;            switch (instruction[i])            {                case 0x40: // variable                    i++;                    string currentVariable= string.Format(S{0:X2}{1:X2}, instruction[i], instruction[i + 1]);                    stack.Push(currentVariable);                    i += 1;                    break;                case 0x45: // 4 byte integer                    i++;                    Buffer.BlockCopy(instruction,i,bit32,0,4);                    Array.Reverse(bit32);                    int bit32result = BitConverter.ToInt32(instruction, 0);                    stack.Push(bit32result.ToString());                    i+=3;                    break;            }            break;    }    // check if we have an operator    if (!string.IsNullOrEmpty(op))    {        if (stack.Count >= 2)        {            string op2 = stack.Pop();            string op1 = stack.Pop();            stack.Push(string.Format(({0}{1}{2}), op1, op, op2));        }        else        {            // something wrong here!            throw new InvalidOperationException();        }    }}