+ Reply to Thread
Page 2 of 5 FirstFirst 1 2 3 4 5 LastLast
Results 11 to 20 of 46
Like Tree3Likes

Thread: [DEV] Reversing the compiled scripts

  1. #11
    Currently Offline Android 1.0 ***
    Join Date
    Jan 2012
    Posts
    48
    Quote Originally Posted by A6PAMOB View Post
    My mistake, the size of script.exe must be 24576 bytes.
    I have reuploaded the unscript.zip.
    No problem, may I ask where did you get that exe? If we have sources of script.exe, or any other tools (mostly edragonex), it would come handy. I'm trying to remake the whole process in C#, in an easier way.



  2. #12
    Currently Offline Beta
    Join Date
    Jan 2012
    Location
    Moscow, Russia
    Posts
    5
    I have no sources of any tools.

    The source of my utility is in the jar file. :-)
    C source - https://github.com/allwinner/linux-2...mach-sun4i/pin
    Last edited by A6PAMOB; 01-26-2012 at 05:57 PM.

  3. #13
    Currently Offline Android 1.0 ***
    Join Date
    Jan 2012
    Posts
    48
    Quote Originally Posted by A6PAMOB View Post
    I have no sources of any tools.

    The source of my utility is in the jar file. :-)
    C source - https://github.com/allwinner/linux-2...mach-sun4i/pin
    Yes I saw your source. And thanks for the source of script.exe, it will definitely come handy

  4. #14
    Currently Offline Android 1.0 ***
    Join Date
    Jan 2012
    Posts
    48
    A6PAMOB:

    I'm sorry to tell you but found a bug in your code. There are a few values, what aren't used as normal int values, but hex formatted addresses. Their extraction isn't perfect.

    See this:
    extracted code
    Code:
    ctp_twi_addr = 85
    input code
    Code:
    ctp_twi_addr = 0x85
    Any way to have an automatized part of the script, what transforms every the value of every field what got "_addr" in its name into hex format? Basically it's just adding "0x" to the int

  5. #15
    Currently Offline Beta
    Join Date
    Jan 2012
    Location
    Moscow, Russia
    Posts
    5
    1. Create misc.fex:
    [misc]
    ctp_twi_addr = 0x85
    2. script.exe misc.fex
    3. unscript.bat misc.bin
    4. the output:
    [misc]
    ctp_twi_addr = 133

    Could you plese send my your original fex and bin file ...

    In my last version I'm trying convert to hex a values more then 0xFFFF.
    Yes I can that do with a value of every field with "_addr" in its name.

  6. #16
    Currently Offline Android 1.0 ***
    Join Date
    Jan 2012
    Posts
    48
    oops, sorry, my mistake, it was different bin and fex But right, there's no conversion done between hex and dec numbers.
    Any way, translated your Java lib to C#, here's the code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Runtime.InteropServices;
    
    
    namespace ConfigLib
    {
        public class Script
        {
            public static int INT_SIZE = 4;
            public static int START_MAIN = 4 * INT_SIZE;
            public static int MAIN_NAME_SIZE = 32;
            public static int MAIN_SIZE = MAIN_NAME_SIZE + INT_SIZE + INT_SIZE;
            public static int SUB_NAME_SIZE = 32;
            public static int SUB_SIZE = SUB_NAME_SIZE + INT_SIZE + INT_SIZE;
    
            static byte[] buffer;
    
            public static int Decompile(string inBin, string outScript)
            {
                List<string> cache = new List<string>();
                
    
    
                if (!File.Exists(inBin))
                    return 0;
    
    
                if (File.Exists(outScript))
                    File.Delete(outScript);
    
                FileStream stream = new FileStream(outScript, FileMode.OpenOrCreate);
                StreamWriter write = new StreamWriter(stream);
    
    
                FileInfo f = new FileInfo(inBin);
                int fSize = (int)f.Length;
    
                buffer = new byte[fSize];
    
                try
                {
                    FileStream fs = new FileStream(inBin, FileMode.Open);
                    fs.Read(buffer, 0, fSize);
                    fs.Close();
    
                }
                catch (FileNotFoundException e)
                {
                    return 0;
                }
                catch (IOException e)
                {
                    return -1;
                }
    
                int countMain = readInt(0);
    
                for (int main = 0; main < countMain; main++)
                {
                    String name = readString(START_MAIN + main * MAIN_SIZE, MAIN_NAME_SIZE);
                    int countSub = readInt(START_MAIN + main * MAIN_SIZE + MAIN_NAME_SIZE);
                    int offset = readInt(START_MAIN + main * MAIN_SIZE + MAIN_NAME_SIZE + INT_SIZE);
    
                    offset = offset * 4;
    
                    if (main > 0)
                    {
                        write.WriteLine('\n' + "[" + name.TrimEnd('\0') + "]");
                    }
                    else
                    {
                        write.WriteLine("[" + name.TrimEnd('\0') + "]");
                    }
    
                    for (int sub = 0; sub < countSub; sub++)
                    {
                        String nameSub = readString(offset + sub * SUB_SIZE,
                                SUB_NAME_SIZE).TrimEnd('\0');
                        int offsetSub = readInt(offset + sub * SUB_SIZE + SUB_NAME_SIZE);
                        offsetSub = offsetSub * 4;
                        int aTwoValue = readInt(offset + sub * SUB_SIZE + SUB_NAME_SIZE
                                + INT_SIZE);
                        int pattern = (aTwoValue >> 16) & 0xFFFF;
                        int wordCount = (aTwoValue) & 0xFFFF;
    
                        String aValue;
                        switch (pattern)
                        {
                            case 1: // Int
                                if (nameSub.Contains("_addr"))
                                {
                                    aValue = ToHex(readInt(offsetSub)).ToString().TrimEnd('\0');
                                }
                                else
                                {
                                    aValue = readInt(offsetSub).ToString().TrimEnd('\0');
                                }
                                break;
    
                            case 2: // String
                                aValue = "\"" + readString(offsetSub, wordCount * 4).TrimEnd('\0') + "\"";
                                break;
    
                            case 4:  // GPIO word
                                char v1;
                                String v2,
                                v3,
                                v4,
                                v5,
                                v6;
                                int val;
                                v1 = (char)(readInt(offsetSub + INT_SIZE * 0) + 64);
                                v2 = readInt(offsetSub + INT_SIZE * 1).ToString();
    
                                val = readInt(offsetSub + INT_SIZE * 2);
                                if (val == -1)
                                    v3 = "default";
                                else
                                    v3 = val.ToString();
    
                                val = readInt(offsetSub + INT_SIZE * 3);
                                if (val == -1)
                                    v4 = "default";
                                else
                                    v4 = val.ToString();
    
                                val = readInt(offsetSub + INT_SIZE * 4);
                                if (val == -1)
                                    v5 = "default";
                                else
                                    v5 = val.ToString();
    
                                val = readInt(offsetSub + INT_SIZE * 5);
                                if (val == -1)
                                    v6 = "default";
                                else
                                    v6 = val.ToString();
    
                                aValue = "port:P" + v1 + "" + v2 + "<" + v3 + "><" + v4
                                        + "><" + v5 + "><" + v6 + ">";
                                break;
                            default:
                                break;
                        }
    					
    					write.WriteLine(nameSub.Trim() + " = " + aValue.TrimEnd('\0'));
                    }
                }
    
                write.Close();
                stream.Close();
    
                return 1;
            }
    
    
    
            private static string ToHex(int value)
            {
                return String.Format("0x{0:X}", value);
            }
    
    		private static int readInt(int pos)
    		{
    			byte b1 = buffer[pos];
    			byte b2 = buffer[pos + 1];
    			byte b3 = buffer[pos + 2];
    			byte b4 = buffer[pos + 3];
    			
    			return (b4 << 24) + ((b3 & 0xFF) << 16) + ((b2 & 0xFF) << 8) + (b1 & 0xFF);
    		}
    		
    		private static string readString(int pos, int size)
    		{
    			byte[] cache = new byte[size];
    
                for (int i = 0; i < size; i++)
                {
                    cache[i] = buffer[pos + i];
                }
    
                return System.Text.Encoding.Default.GetString(cache);
    		}	
    	}
    }
    It's a library, not an exe, so just create the new project and class, copy the code, and make your executable call it It also converts the hex addresses properly.

    EDIT:
    A6PAMOB, if you could rewrite the script.c in Java, I would gladly add it to this library, and as an ultimate goal, make a new build system what does everything natively, without external executables, but using a nice and clean, open source C# based library for this. Biggest problem so far is recreating the way how edragonex works, plus fsbuild
    Last edited by fonix232; 01-29-2012 at 01:32 PM.

  7. The Following User Says Thank You to fonix232 For This Useful Post:

    A6PAMOB (01-29-2012)

  8. #17
    Currently Offline Android 1.0 ***
    Join Date
    Jan 2012
    Posts
    48
    Just made some further progress on the ultimate A10 tool, now (I think) we can create the bootloader/bootfs FAT images

  9. #18
    Currently Offline Beta *
    Join Date
    Feb 2012
    Posts
    14
    Quote Originally Posted by fonix232 View Post
    Just made some further progress on the ultimate A10 tool, now (I think) we can create the bootloader/bootfs FAT images
    Nice! Is the C# code in the post above the latest version or are there any more recent updates?

  10. #19
    Currently Offline Android 1.0 ***
    Join Date
    Jan 2012
    Posts
    48
    Quote Originally Posted by FezzFest View Post
    Nice! Is the C# code in the post above the latest version or are there any more recent updates?
    I did not really change the script decompiling part, but added a new class for BootFS/bootloaderfs handling. Also it's me (ainolmodder) from SLD ;D

  11. #20
    Currently Offline Beta *
    Join Date
    Feb 2012
    Posts
    14
    Quote Originally Posted by fonix232 View Post
    I did not really change the script decompiling part, but added a new class for BootFS/bootloaderfs handling. Also it's me (ainolmodder) from SLD ;D
    I didn't expect that!
    Going to sharpen my C# skills to get this thing working (shouldn't be too difficult )
    Last edited by FezzFest; 02-02-2012 at 07:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts