使用Bashregex?从AIDL文件中提取方法

问题描述

我想提取所有方法包括它们的参数并返回数据类型。 (每行一个

这是一个示例文件IPackageManager.aidl

我已经这样尝试过了:

wget -qO - "https://raw.githubusercontent.com/LineageOS/android_frameworks_base/7fc95f204527ee079c5891d56c969668f0b35a0b/core/java/android/content/pm/IPackageManager.aidl" | \
sed -e '1,/interface/d' \
-e '/^$/d' \
-e 's/^[[:space:]]*//' \
-e '/^[^a-zA-Z]/d' \
-e '/^[^;]*$/{$!N}' \
-e '$d' \
-e 's/\(^\|\n\)[[:space:]]*\|\([[:space:]]\)\{2,\}/\2/g'

但不幸的是,它仍然不能解决所有情况。例如,它无法将queryIntentActivityOptions放在一行中(与setPackagesSuspendedAsUser相同)。

以下是一些示例输出

ParceledListSlice queryIntentActivities(in Intent intent,String resolvedType,int flags,int userId);
ParceledListSlice queryIntentActivityOptions(in ComponentName caller,in Intent[] specifics,in String[] specificTypes,in Intent intent,int userId);
ParceledListSlice queryIntentReceivers(in Intent intent,int userId);

这应该是3行,而不是4行,因为只有3种方法

有什么想法吗?

解决方法

要再次执行sed命令以删除没有\n的行上的;

wget -qO - "https://raw.githubusercontent.com/LineageOS/android_frameworks_base/7fc95f204527ee079c5891d56c969668f0b35a0b/core/java/android/content/pm/IPackageManager.aidl" | \
sed -e '1,/interface/d' \
-e '/^$/d' \
-e 's/^[[:space:]]*//' \
-e '/^[^a-zA-Z]/d' \
-e '/^[^;]*$/{$!N}' \
-e '$d' \
-e 's/\(^\|\n\)[[:space:]]*\|\([[:space:]]\)\{2,\}/\2/g' | \
sed -e ':x;N;s/\([^;]\)\n/\1/;bx'