Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Frida获取ANDROID_ID_Java_Android_Frida - Fatal编程技术网

Java 如何使用Frida获取ANDROID_ID

Java 如何使用Frida获取ANDROID_ID,java,android,frida,Java,Android,Frida,Android中的每个应用程序都有其独特之处 要使用以下代码获取ANDROID I amd内部Java的ANDROID\u ID: import android.content.Context; import android.content.ContentResolver; import android.provider.Settings; protected void onCreate(...) { context = (Context)this; String androidId =

Android中的每个应用程序都有其独特之处

要使用以下代码获取ANDROID I amd内部Java的
ANDROID\u ID

import android.content.Context;
import android.content.ContentResolver;
import android.provider.Settings;
protected void onCreate(...) {
  context = (Context)this;
  String androidId = Settings.Secure.getString((ContentResolver)context.getContentResolver(), (String)"android_id");
}
但我想在我的andoird手机上的其他应用程序中运行它。
我想用这个

我正在用Python加载注入脚本:

import frida
device = frida.get_usb_device()
pid = device.spawn(["com.target.app"])
device.resume(pid)
time.sleep(1) #Without it Java.perform silently fails
session = device.attach(pid)
script = session.create_script(open("jsfrida.js").read())
script.load()

#prevent the python script from terminating
raw_input()
但在我的脚本中,我不知道如何称呼它,这就是我尝试的:

Java.perform(function (){
  console.log("Inside java perform function");
  var ActivityThread = Java.use('android.app.ActivityThread');
  var Context = Java.use('android.content.Context');
  var settings = Java.use('android.provider.Settings.Secure');
  var ctx = Java.cast(ActivityThread.currentApplication().getApplicationContext(), Context);
  //console.log(ctx.getPackageName());
  //console.log(ctx.getContentResolver());
  var androidId = settings.Secure.getString(ctx.getContentResolver(), "android_id");
  console.log(androidId);
  console.log("END");
 });
但它不打印Android,它只打印:

Script loaded successfully 
Inside java perform function
  • 是内部类,因此需要使用
    $
    • 将被编译为ClassName$InnerClassName
  • 要获取
    coentresolver
    ,您可以调用
    getContentResolver
    ,而无需强制转换

我认为你的问题在于背景。不能创建新的上下文,必须使用现有上下文。若要获取现有上下文,您需要挂接一个函数,该函数将上下文作为参数检索。@Robert您是对的。我修复了上下文问题,现在我有了上下文(我用注释行验证了它),但
设置
类仍然有问题。我记得一些子类的问题,如
设置。安全
在frida中,类名可能不同。打印名称以android.provider开头的类的完整类列表,查看类名是否正确:
$ frida -Uf com.app.example --no-pause
     ____
    / _  |   Frida 12.1.2 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
Spawned `com.app.example`. Resuming main thread!                    
[Android::com.app.example]-> 
function getContext() {
  return Java.use('android.app.ActivityThread').currentApplication().getApplicationContext().getContentResolver();
}                                         
function logAndroidId() {
  console.log('[?]', Java.use('android.provider.Settings$Secure').getString(getContext(), 'android_id'));
}
undefined
[Android::com.app.example]-> Java.perform(logAndroidId)
[?] 52d1497b52bf8a11
undefined
[Android::com.app.example]->