FORUMS

Android ls and df parsing

177 posts
Thanks Meter: 118
 
Post Reply Subscribe to Thread Email Thread
Hey all together,

after a lot of searching and using Google for days with no really good results i created now my own reg-ex functions to parse some Android shell outputs. So i only want to share my functions coz i dun found something like that.

If u create a Android File-Explorer or something else like this u'll have to get the ls and df output in some situations, if u use C# like me this will be great for u.

here are my functions:

(command) ls -l
(command) busybox ls -aFl

Code:
^(\s{0,}(?<INODE>[0-9]{1,})\s{1,})?(?<TYPE>(-|b|c|d|l|s|p){1})(?<PERM>((-|r|s|t|w|x){9}|[0-9]{4}))\s{1,}(?<INCLUDES>([0-9]){1,}\s{1,})?(?<OWNER>.*?)\s{1,}(?<GROUP>.*?)\s{1,}(?<ID>([0-9]){1,},)?\s{1,}(?<SIZE>([0-9]){1,})?\s{1,}(?<DATE>.*?)\s{1,}(?<TIME>([0-9]{2}.[0-9]{2}(:[0-9]{2})?|[0-9]{4}))\s{1}(?<NAME>.*?)(\s{1,}->\s{1,}(?<SYMLINK>.*?))?(?<SUBTYPE>(\*|/){1})?$
u can use it like

Code:
// INODE, TYPE, PERM, INCLUDES, OWNER, GROUP, ID, SIZE, DATE, TIME, NAME, SYMLINK, SUBTYPE
GroupCollection groups = Regex.Match("the ls -li or busybox -aFli output line by line", @"^(\s{0,}(?<INODE>[0-9]{1,})\s{1,})?(?<TYPE>(-|b|c|d|l|s|p){1})(?<PERM>((-|r|s|t|w|x){9}|[0-9]{4}))\s{1,}(?<INCLUDES>([0-9]){1,}\s{1,})?(?<OWNER>.*?)\s{1,}(?<GROUP>.*?)\s{1,}(?<ID>([0-9]){1,},)?\s{1,}(?<SIZE>([0-9]){1,})?\s{1,}(?<DATE>.*?)\s{1,}(?<TIME>([0-9]{2}.[0-9]{2}(:[0-9]{2})?|[0-9]{4}))\s{1}(?<NAME>.*?)(\s{1,}->\s{1,}(?<SYMLINK>.*?))?(?<SUBTYPE>(\*|/){1})?$").Groups;
            string INode = groups["INODE"].Value;
            string Type = groups["TYPE"].Value;
            string SubType = groups["SUBTYPE"].Value;
            string Perms = groups["PERM"].Value;
            string Includes = groups["INCLUDES"].Value;
            string Owner = groups["OWNER"].Value;
            string Group = groups["GROUP"].Value;
            string Id = groups["ID"].Value;
            string Size = groups["SIZE"].Value;
            string Date = String.Join(" ", groups["DATE"].Value, groups["TIME"].Value);
            string Name = groups["NAME"].Value;
            string[] extTmp = Name.Split('.');
            string FileExtension = extTmp[extTmp.Length - 1];
            string SymPath = groups["SYMLINK"].Value;

(command) df
(command) busybox df -Pakh

Code:
^(df:\s{1,})?(?<NAME>(.*?))(:\s{1,}(.*?))?(\s{1,}(?<SIZE>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<USED>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<FREE>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<BLOCKSIZE>([0-9]){1,}))?(\s{1,}(?<USE>([0-9]{1,})%))?(\s{1,}(?<PATH>(.*?)))?$
u can use it like

Code:
GroupCollection groups = Regex.Match("the df or df -Pakh output line by line", @"^(df:\s{1,})?(?<NAME>(.*?))(:\s{1,}(.*?))?(\s{1,}(?<SIZE>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<USED>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<FREE>([0-9]{1,}[a-zA-Z\.]?){1,}))?(\s{1,}(?<BLOCKSIZE>([0-9]){1,}))?(\s{1,}(?<USE>([0-9]{1,})%))?(\s{1,}(?<PATH>(.*?)))?$").Groups;
            string Name = groups["NAME"].Value;
            string Size = groups["SIZE"].Value;
            string Used = groups["USED"].Value;
            string Free = groups["FREE"].Value;
            string BlockSize = groups["BLOCKSIZE"].Value;
            string Use = groups["USE"].Value;
            string Path = groups["PATH"].Value;

Hope this helps someone

Regards,
k1ll3r8e
Last edited by k1ll3r8e; 19th February 2015 at 11:38 PM. Reason: forgot the 1 busybox line
 
 
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes