0

I have a process that attempts to get the package name from another process. I am using C++ code and compiling it using Android toolchain. I have its socket fd and ip address, however, I didn't find in the api a function that will return a string containing the package name. I have the socket fd and the address, if it helps:

uid_t GetSocketID(int sockfd)
{
    int err;
    socklen_t len;
    struct sockaddr_in addr;
    len = sizeof(addr);
    int res = getpeername(sockfd, (struct sockaddr*)&addr, &len);

    if (res < 0)
    {
        err = errno;
        return -1;
    }

    int iSockIp = addr.sin_addr.s_addr;
    int iSockPort = ntohs(addr.sin_port);
    int iUid = -1;

    if (iSockIp == 0 || iSockPort == 0)
    {
            return -1;

    }
}

example taken from: https://github.com/android/platform_system_core/blob/master/libcutils/qtaguid.c

Does anybody know how can I get the package name?

Thanks!

4

1 回答 1

0

分 3 步完成:

  • 用于netstat从套接字中查找进程
  • 用于ps从进程信息中查找可执行文件
  • 在应用程序的根目录中搜索AndroidManifest.xml以找到拥有可执行文件的 APK。
于 2016-04-24T14:47:35.793 回答