rubenv / node-apk-parser

Extract Android Manifest info from an APK file.
MIT License
79 stars 25 forks source link

Cannot parse file #7

Closed bigbn closed 9 years ago

bigbn commented 9 years ago

I use your example:

var parseApk = require('apk-parser');
parseApk('app-debug.apk', function (err, data) {
    console.log(data)
    console.log(err)
    // Handle error or do something with data.
});

and have this:

[bigbn@bigbn apkTest]$ node i 
undefined
[Error: Cannot parse value: =(type 0x10)0x15 (Raw: "21")]

and listing look's like that:

[bigbn@bigbn apkTest]$ ./node_modules/apk-parser/tools/aapt l -a app-debug.apk 
AndroidManifest.xml
res/drawable-hdpi-v4/ic_launcher.png
res/drawable-mdpi-v4/ic_launcher.png
res/drawable-xhdpi-v4/ic_launcher.png
res/drawable-xxhdpi-v4/ic_launcher.png
res/layout/activity_main.xml
res/raw/promo.mp4
resources.arsc
classes.dex
META-INF/MANIFEST.MF
META-INF/CERT.SF
META-INF/CERT.RSA

Resource table:
Package Groups (1)
Package Group 0 id=127 packageCount=1 name=me.about.bigbn.promostack
  Package 0 id=127 name=me.about.bigbn.promostack typeCount=9
    type 0 configCount=1 entryCount=2
      spec resource 0x7f010000 me.about.bigbn.promostack:attr/metaButtonBarStyle: flags=0x00000000
      spec resource 0x7f010001 me.about.bigbn.promostack:attr/metaButtonBarButtonStyle: flags=0x00000000
      config (default):
        resource 0x7f010000 me.about.bigbn.promostack:attr/metaButtonBarStyle: <bag>
        resource 0x7f010001 me.about.bigbn.promostack:attr/metaButtonBarButtonStyle: <bag>
    type 1 configCount=4 entryCount=1
      spec resource 0x7f020000 me.about.bigbn.promostack:drawable/ic_launcher: flags=0x00000100
      config mdpi-v4:
        resource 0x7f020000 me.about.bigbn.promostack:drawable/ic_launcher: t=0x03 d=0x00000002 (s=0x0008 r=0x00)
      config hdpi-v4:
        resource 0x7f020000 me.about.bigbn.promostack:drawable/ic_launcher: t=0x03 d=0x00000003 (s=0x0008 r=0x00)
      config xhdpi-v4:
        resource 0x7f020000 me.about.bigbn.promostack:drawable/ic_launcher: t=0x03 d=0x00000004 (s=0x0008 r=0x00)
      config xxhdpi-v4:
        resource 0x7f020000 me.about.bigbn.promostack:drawable/ic_launcher: t=0x03 d=0x00000005 (s=0x0008 r=0x00)
    type 2 configCount=1 entryCount=1
      spec resource 0x7f030000 me.about.bigbn.promostack:layout/activity_main: flags=0x00000000
      config (default):
        resource 0x7f030000 me.about.bigbn.promostack:layout/activity_main: t=0x03 d=0x00000000 (s=0x0008 r=0x00)
    type 3 configCount=1 entryCount=1
      spec resource 0x7f040000 me.about.bigbn.promostack:raw/promo: flags=0x00000000
      config (default):
        resource 0x7f040000 me.about.bigbn.promostack:raw/promo: t=0x03 d=0x00000001 (s=0x0008 r=0x00)
    type 4 configCount=1 entryCount=5
      spec resource 0x7f050000 me.about.bigbn.promostack:color/black: flags=0x00000000
      spec resource 0x7f050001 me.about.bigbn.promostack:color/black_overlay: flags=0x00000000
      spec resource 0x7f050002 me.about.bigbn.promostack:color/blue: flags=0x00000000
      spec resource 0x7f050003 me.about.bigbn.promostack:color/green: flags=0x00000000
      spec resource 0x7f050004 me.about.bigbn.promostack:color/red: flags=0x00000000
      config (default):
        resource 0x7f050000 me.about.bigbn.promostack:color/black: t=0x1c d=0xff000000 (s=0x0008 r=0x00)
        resource 0x7f050001 me.about.bigbn.promostack:color/black_overlay: t=0x1c d=0xff000000 (s=0x0008 r=0x00)
        resource 0x7f050002 me.about.bigbn.promostack:color/blue: t=0x1c d=0xff0000ff (s=0x0008 r=0x00)
        resource 0x7f050003 me.about.bigbn.promostack:color/green: t=0x1c d=0xff00ff00 (s=0x0008 r=0x00)
        resource 0x7f050004 me.about.bigbn.promostack:color/red: t=0x1c d=0xffff0000 (s=0x0008 r=0x00)
    type 5 configCount=1 entryCount=1
      spec resource 0x7f060000 me.about.bigbn.promostack:dimen/large: flags=0x00000000
      config (default):
        resource 0x7f060000 me.about.bigbn.promostack:dimen/large: t=0x05 d=0x00001401 (s=0x0008 r=0x00)
    type 6 configCount=1 entryCount=3
      spec resource 0x7f070000 me.about.bigbn.promostack:string/app_name: flags=0x00000000
      spec resource 0x7f070001 me.about.bigbn.promostack:string/dummy_button: flags=0x00000000
      spec resource 0x7f070002 me.about.bigbn.promostack:string/dummy_content: flags=0x00000000
      config (default):
        resource 0x7f070000 me.about.bigbn.promostack:string/app_name: t=0x03 d=0x00000006 (s=0x0008 r=0x00)
        resource 0x7f070001 me.about.bigbn.promostack:string/dummy_button: t=0x03 d=0x00000007 (s=0x0008 r=0x00)
        resource 0x7f070002 me.about.bigbn.promostack:string/dummy_content: t=0x03 d=0x00000008 (s=0x0008 r=0x00)
    type 7 configCount=3 entryCount=5
      spec resource 0x7f080000 me.about.bigbn.promostack:style/AppTheme: flags=0x00000400
      spec resource 0x7f080001 me.about.bigbn.promostack:style/ButtonBar: flags=0x00000000
      spec resource 0x7f080002 me.about.bigbn.promostack:style/ButtonBarButton: flags=0x00000000
      spec resource 0x7f080003 me.about.bigbn.promostack:style/FullscreenTheme: flags=0x00000400
      spec resource 0x7f080004 me.about.bigbn.promostack:style/FullscreenActionBarStyle: flags=0x00000000
      config (default):
        resource 0x7f080000 me.about.bigbn.promostack:style/AppTheme: <bag>
        resource 0x7f080001 me.about.bigbn.promostack:style/ButtonBar: <bag>
        resource 0x7f080002 me.about.bigbn.promostack:style/ButtonBarButton: <bag>
        resource 0x7f080003 me.about.bigbn.promostack:style/FullscreenTheme: <bag>
      config v11:
        resource 0x7f080003 me.about.bigbn.promostack:style/FullscreenTheme: <bag>
        resource 0x7f080004 me.about.bigbn.promostack:style/FullscreenActionBarStyle: <bag>
      config v21:
        resource 0x7f080000 me.about.bigbn.promostack:style/AppTheme: <bag>
    type 8 configCount=1 entryCount=4
      spec resource 0x7f090000 me.about.bigbn.promostack:id/fullscreen_content_controls: flags=0x00000000
      spec resource 0x7f090001 me.about.bigbn.promostack:id/videoView: flags=0x00000000
      spec resource 0x7f090002 me.about.bigbn.promostack:id/listView: flags=0x00000000
      spec resource 0x7f090003 me.about.bigbn.promostack:id/webView: flags=0x00000000
      config (default):
        resource 0x7f090000 me.about.bigbn.promostack:id/fullscreen_content_controls: t=0x12 d=0x00000000 (s=0x0008 r=0x00)
        resource 0x7f090001 me.about.bigbn.promostack:id/videoView: t=0x12 d=0x00000000 (s=0x0008 r=0x00)
        resource 0x7f090002 me.about.bigbn.promostack:id/listView: t=0x12 d=0x00000000 (s=0x0008 r=0x00)
        resource 0x7f090003 me.about.bigbn.promostack:id/webView: t=0x12 d=0x00000000 (s=0x0008 r=0x00)

Android manifest:
N: android=http://schemas.android.com/apk/res/android
  E: manifest (line=2)
    A: android:versionCode(0x0101021b)=(type 0x10)0xd
    A: android:versionName(0x0101021c)="0.93.0" (Raw: "0.93.0")
    A: package="me.about.bigbn.promostack" (Raw: "me.about.bigbn.promostack")
    A: platformBuildVersionCode=(type 0x10)0x15 (Raw: "21")
    A: platformBuildVersionName="5.0.1-1624448" (Raw: "5.0.1-1624448")
    E: uses-sdk (line=7)
      A: android:minSdkVersion(0x0101020c)=(type 0x10)0xf
      A: android:targetSdkVersion(0x01010270)=(type 0x10)0x15
    E: uses-permission (line=11)
      A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
    E: uses-permission (line=12)
      A: android:name(0x01010003)="android.permission.ACCESS_NETWORK_STATE" (Raw: "android.permission.ACCESS_NETWORK_STATE")
    E: uses-permission (line=13)
      A: android:name(0x01010003)="android.permission.ACCESS_WIFI_STATE" (Raw: "android.permission.ACCESS_WIFI_STATE")
    E: uses-permission (line=14)
      A: android:name(0x01010003)="android.permission.WRITE_EXTERNAL_STORAGE" (Raw: "android.permission.WRITE_EXTERNAL_STORAGE")
    E: uses-permission (line=15)
      A: android:name(0x01010003)="android.permission.WAKE_LOCK" (Raw: "android.permission.WAKE_LOCK")
    E: uses-permission (line=16)
      A: android:name(0x01010003)="android.permission.RECEIVE_BOOT_COMPLETED" (Raw: "android.permission.RECEIVE_BOOT_COMPLETED")
    E: uses-permission (line=17)
      A: android:name(0x01010003)="android.permission.ACCESS_FINE_LOCATION" (Raw: "android.permission.ACCESS_FINE_LOCATION")
    E: application (line=19)
      A: android:theme(0x01010000)=@0x7f080000
      A: android:label(0x01010001)=@0x7f070000
      A: android:icon(0x01010002)=@0x7f020000
      A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
      A: android:allowBackup(0x01010280)=(type 0x12)0xffffffff
      E: meta-data (line=26)
        A: android:name(0x01010003)="PackageVersion" (Raw: "PackageVersion")
        A: android:value(0x01010024)=(type 0x10)0xd
      E: activity (line=30)
        A: android:theme(0x01010000)=@0x1030007
        A: android:label(0x01010001)=@0x7f070000
        A: android:name(0x01010003)="me.about.bigbn.promostack.MainActivity" (Raw: "me.about.bigbn.promostack.MainActivity")
        A: android:screenOrientation(0x0101001e)=(type 0x10)0x0
        A: android:configChanges(0x0101001f)=(type 0x11)0x4a0
        E: intent-filter (line=36)
          E: action (line=37)
            A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
          E: category (line=39)
            A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
      E: receiver (line=43)
        A: android:name(0x01010003)="me.about.bigbn.promostack.recievers.BootUpReceiver" (Raw: "me.about.bigbn.promostack.recievers.BootUpReceiver")
        A: android:permission(0x01010006)="android.permission.RECEIVE_BOOT_COMPLETED" (Raw: "android.permission.RECEIVE_BOOT_COMPLETED")
        A: android:enabled(0x0101000e)=(type 0x12)0xffffffff
        E: intent-filter (line=47)
          E: action (line=48)
            A: android:name(0x01010003)="android.intent.action.BOOT_COMPLETED" (Raw: "android.intent.action.BOOT_COMPLETED")
          E: category (line=50)
            A: android:name(0x01010003)="android.intent.category.DEFAULT" (Raw: "android.intent.category.DEFAULT")
      E: receiver (line=53)
        A: android:name(0x01010003)="me.about.bigbn.promostack.recievers.PowerConnectedReceiver" (Raw: "me.about.bigbn.promostack.recievers.PowerConnectedReceiver")
        E: intent-filter (line=54)
          E: action (line=55)
            A: android:name(0x01010003)="android.intent.action.ACTION_POWER_DISCONNECTED" (Raw: "android.intent.action.ACTION_POWER_DISCONNECTED")

And this is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="me.about.bigbn.promostack">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <!-- -->
        <meta-data android:name="PackageVersion" android:value="13" />

        <activity
            android:screenOrientation="landscape"
            android:name="me.about.bigbn.promostack.MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <receiver android:enabled="true" android:name=".recievers.BootUpReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <receiver android:name=".recievers.PowerConnectedReceiver">
            <intent-filter>
                <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
jeduan commented 9 years ago

:+1: having the same problem

boulaycote commented 9 years ago

Same here.

id0Sch commented 9 years ago

same issue here... is the repo still maintained?

boulaycote commented 9 years ago

The issue is easy to fix:

The malformed part is =(type 0x10)0x15 (Raw: "21"). You can add a function like so

ParseApk.prototype.extractRawType = function (string) {
    var matches = string.match(/\(Raw:\s\"(.+)\"\)/);

    if (matches && matches.length > 1) 
        return matches[1];
    return null;
}

And call it when rest.substring(0, 12) === "=(type 0x10)" inside the parseOutput. Like so;

else if (rest.substring(0, 12) === "=(type 0x10)") {
    // Raw
    value = self.extractRawType(rest);
}
rubenv commented 9 years ago

I'll happily accept a pull request for this!

rubenv commented 9 years ago

published version 0.1.4 to npm