Android ls and df parsing - Android Software/Hacking General [Developers Only]

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{0,}(?<INCLUDES>([0-9]){1,}\s{1,})?(?<OWNER>.*?)\s{1,}(?<GROUP>.*?)\s{0,}(?<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}(\e\[([0-9]{1,};)?[0-9]{1,}m){0,}(?<NAME>.*?)(\e\[([0-9]{1,};)?[0-9]{1,}m){0,}(\s{1,}->\s{1,}(\e\[([0-9]{1,};)?[0-9]{1,}m){0,}(?<SYMLINK>.*?)(\e\[([0-9]{1,};)?[0-9]{1,}m){0,})?(?<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{0,}(?<INCLUDES>([0-9]){1,}\s{1,})?(?<OWNER>.*?)\s{1,}(?<GROUP>.*?)\s{0,}(?<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}(\e\[([0-9]{1,};)?[0-9]{1,}m){0,}(?<NAME>.*?)(\e\[([0-9]{1,};)?[0-9]{1,}m){0,}(\s{1,}->\s{1,}(\e\[([0-9]{1,};)?[0-9]{1,}m){0,}(?<SYMLINK>.*?)(\e\[([0-9]{1,};)?[0-9]{1,}m){0,})?(?<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

Related

MediaPlayer.setDataSource(url) not working

MediaPlayer.setDataSource(url) is not working in my app.
Im puttin the file "hello.mp3" in the assets-folder, and Im using the following
Code:
String soundUrl = "file:///android_asset/hello.mp3";
mp = new MediaPlayer();
try {
mp.setDataSource(soundUrl);
mp.prepare();
mp.start();
}
catch (IOException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalStateException e) {}
This code works when I put the "hello.mp3" in the res/raw-folder:
Code:
mp = new MediaPlayer();
mp = MediaPlayer.create(getBaseContext(), R.raw.hello);
mp.start();
Problem with the last code is that I need to load the sound-files dynamically, and apparently you cant create a string or a uri with the correct sound-file at the end and insert that as the second parameter in the MP.create()-function.
Pseudocode - NOT WORKING
Code:
String mySound = "hello";
Uri myUri = "R.raw." + mySound;
...
mp = MediaPlayer.create(getBaseContext(), myUri);
Any ideas?
Amazing, several months later and still no one is able to realte how to play a local sound dynamically.
An issue with what you are trying to do is that there are multiple versions of MediaPlayer.create() and MediaPlayer.setDataSource() which take different types of parameters.
R.raw.hello is NOT a string. It is an int. Look in the gen directory to find the generated file R.java and in this file you will find raw which has a public static final int definition for R.raw.hello
R.raw.hello has to be passed to one of the routines which takes an int for the parameter and not a string.

Dynamically reference the R.raw.-content?

Is it possible to dynamically reference a specific resource in the R.raw.-folder?
For instance, if I have an mp3 in the raw-foler named "hello.mp3" I can reference it in the code with:
Code:
mp = MediaPlayer.create(getBaseContext(), R.raw.hello);
But how do I replace the last "hello" with the content of a variable, so that I can load different mp3's from R.raw with the same code?
Code:
// CODE NOT WORKING
String soundFile = "helloagain";
String mpPath = "R.raw." + soundFile;
mp = MediaPlayer.create(getBaseContext(), mpPath);

Automates patcher tool

Hi,
I've been looking for a tool or script to replace hex sequence in binary file in Windows. Indeed, i found this script :
Code:
Imports System.Runtime.CompilerServices
Imports System.IO
Public Class FinduReplaceHex
Private Shared ReadOnly FindHex As Byte() = {&H75, &HF6, &HF3}
Private Shared ReadOnly ReplaceHex As Byte() = {&HA2, &HE3, &H4B}
<MethodImpl(MethodImplOptions.NoInlining)> Private Shared Function DP(sequence As Byte(), position As Integer) As Boolean
If position + FindHex.Length > sequence.Length Then
Return False
End If
For i As Integer = 0 To FindHex.Length - 1
If FindHex(i) <> sequence(position + i) Then
Return False
End If
Next
Return True
End Function
Private Sub Patch_Click(sender As Object, e As EventArgs) Handles Patch.Click
Dim DT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim FD As Byte() = File.ReadAllBytes(DT & "\App.dll")
For F As Integer = 0 To FD.Length - 1
If Not DP(FD, F) Then
Continue For
End If
For R As Integer = 0 To FindHex.Length - 1
FD(F + R) = ReplaceHex®
Next
Next
If System.IO.File.Exists(DT & "\App.dll") Then
System.IO.File.Move(DT & "\App.dll", DT & "\App.dll.backup")
File.WriteAllBytes(DT & "\App Method 3.dll", FD)
Else
'Write Other Codes
End If
End Sub
End Class
The only problem is that I want to be able to use wildcards like this :
Search for F4 B3 ?? 12 and replace F4 BE 65 EA
Thanks in advance

Extracting many "long key name" = "value" pairs from DB2's log files

Extracting many "long key name" = "value" pairs from DB2's log files
Hello Team!
I have a problem go through it!
Working on extracting some Key/Value pairs out of DB2's log files. I have a file like this:
Code:
[...snip...]
Buffer pool xda writes = 0
Asynchronous pool xda page writes = 0
Total buffer pool read time (millisec) = 66
Total buffer pool write time (millisec) = 0
Total elapsed asynchronous read time = 46
Total elapsed asynchronous write time = 0
Asynchronous data read requests = 3
Asynchronous index read requests = 0
[...snip...]
While I can go and use EXTRACT commands/regexes for only the specific ones I want, it would be extremely tedious to do so. Especially since this spans across various sourcetypes.
Ideally, I'd like to be able to make use of Splunk's(Learnt splunk from mindmajix) "CLEAN_KEYS" setting and have things come out extracted so I can do a search like this without having to configure anything else:
Code:
search {stuff} | timechart avg(Total_buffer_pool_read_time_millisec)
I have this so far.. (copied some values from other pre-packaged transforms.conf files)
props.conf:
Code:
[db2dynsql]
BREAK_ONLY_BEFORE=Number of executions
SHOULD_LINEMERGE=true
KV_MODE=none
REPORT-kv = db2_kv
transforms.conf:
Code:
[db2_kv]
CAN_OPTIMIZE = True
CLEAN_KEYS = True
DEFAULT_VALUE =
DEST_KEY =
FORMAT = $1::$2
KEEP_EMPTY_VALS = False
LOOKAHEAD = 4096
MV_ADD = False
REGEX = ([^=]+)\s+=\s+(.*?)
SOURCE_KEY = _raw
WRITE_META = False
Help me on this!
Thanks
Gnanasekar

How and where my device store fingerprint results and matches with my next attempt ?

MAIN QUESTION IS AT BOTTOM
Where my android devices stores scanned fingerprint data and in what format and how it matches with new scanned.
I also know this: :the scan of fingertip is analysed for certain control points and generates a token which is like a password hash.
It generates hash via this:
Code:
KeyStore mKeyStore;
String KEY_NAME = UUID.randomUUID().toString();
Cipher mCipher;
mKeyStore = KeyStore.getInstance("AndroidKeyStore");
keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
keyGenerator.init(new
KeyGenParameterSpec.Builder(KEY_NAME,
KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(
KeyProperties.ENCRYPTION_PADDING_PKCS7)
.build());
keyGenerator.generateKey();
mCipher = Cipher.getInstance(
KeyProperties.KEY_ALGORITHM_AES + "/"
+ KeyProperties.BLOCK_MODE_CBC + "/"
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);
SecretKey key = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
mCipher.init(Cipher.ENCRYPT_MODE, key);
Is editing/extracting or using this hash and storing somewhere else and try to match the newly generated hash with this while storing that security key of android(assuming same for all), is it possible OR ANY OTHERWAY ROUND?
ALSO
Code:
KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
KeyStore.Entry entry = ks.getEntry(alias, null);
if (!(entry instanceof PrivateKeyEntry)) {
Log.w(TAG, "Not an instance of a PrivateKeyEntry");
return null;
}
Signature s = Signature.getInstance("SHA256withECDSA");
s.initSign(((PrivateKeyEntry) entry).getPrivateKey());
s.update(data);
byte[] signature = s.sign();
boolean valid = s.verify(signature);
I saw this, but can't say helpful or not

Categories

Resources