Git Product home page Git Product logo

chapter17's Introduction

Chapter17

该项目展示了如何使用 PLT Hook 技术来获取网络请求相关信息。

运行环境

AndroidStudio3.2 NDK16~19 支持 x86 armeabi-v7a

说明

运行项目后点击开启 Socket Hook按钮,然后点击请求按钮。

整个实现与ThreadHook基本一样,大家可以参考之前的文档

实现差异

不过跟ThreadHook相比,整体实现还有略有差异,这一次我们增加了一个hook_plt_method_all_lib方法

int hook_plt_method_all_lib(const char* exclueLibname, const char* name, hook_func hook) {
  if (refresh_shared_libs()) {
    // Could not properly refresh the cache of shared library data
    return -1;
  }

  int failures = 0;

  for (auto const& lib : allSharedLibs()) {
      if (strcmp(lib.first.c_str(), exclueLibname) != 0) {
        failures += hook_plt_method(lib.first.c_str(), name, hook);
      }
  }

  return failures;
}

它的作用是不仅仅hook某个so,而是hook内存中的所有so。但是要排除掉方法本身定义的so,不然运行期间会出问题。

我们可以通过sa_family来判断类型,需要过滤掉local socket

if (serv_addr->sa_family == AF_INET) {
   // ipv4地址

} else if(serv_addr->sa_family == AF_INET6) {
   // ipv6地址

} else if (serv_addr->sa_family == AF_LOCAL) {
   // local socket
}

通过connect函数的hook,我们可以做的东西很多,例如:

  1. 禁用应用网络访问
  2. 过滤广告ip
  3. 禁用定位功能

chapter17's People

Contributors

shwenzhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.