frida cannot create instance of class com.android.okhttp.Request$Builder with android 11 - httprequest

I want to create a simple http request with frida while hooking the function. With android 6, everything is ok, but when I try with android 11, there's a big prolem here:
Error: no supported overloads
at U (frida/node_modules/frida-java-bridge/lib/class-factory.js:484)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:800)
at get (frida/node_modules/frida-java-bridge/lib/class-factory.js:696)
at get (frida/node_modules/frida-java-bridge/lib/class-factory.js:681)
at <anonymous> (/inject.js:52)
at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:16)
at perform (frida/node_modules/frida-java-bridge/index.js:193)
at make_custom_request (/inject.js:55)
at onEnter (/inject.js:42)
Here is the code:
var req = _uri + param;
Java.perform(function(){
var OkHttpClient = Java.use("com.android.okhttp.OkHttpClient");
var Builder = Java.use("com.android.okhttp.Request$Builder").$new(); //error here
var request = Builder.url(Java.use("java.lang.String").$new(req)).build();
OkHttpClient.$new().newCall(request).execute();
});
I'm new with frida. Help me please.
Update
I know this issue due to restriction on non-sdk interface mechanic in android 9+.
So, how can i bypass this mechanic with frida?

Related

Running data downloading on background thread

Im building a new app and since i want it to be smooth as everyone, I want to use a background thread that would be responsible for all the data downloading using restsharp. Im also following the MVVM pattern.
I've been reading a lot about task.run and how to use it properly and the whole async-await topic. But since Im new to all this, Im not sure how I should procceed to do things right. I have a lot of code so I will breifly try to explain what Im doing and then put a snippet.
So I started with creating a service class that contains all the functions that are using restsharp to get the data. And inside my ViewModel Im calling those functions in the very begining. Im trying to use tasks and run those functions on the background thread but the app get blocked on the splash screen. And abviously thats because Im doing things wrong ... so I decided to ask you guys.
I have this function for exemple :
public string GetResPor()
{
var restClient = new RestClient { BaseUrl = new Uri("http://xxx.xxx.xxx.xxx:xxxx") };
var request = new RestRequest
{
Resource = "getCliPor",
Method = Method.GET
};
request.AddParameter(new Parameter { Name = "idt", Value = GetImAsync().GetAwaiter().GetResult(), Type = ParameterType.GetOrPost });
var result = restClient.Execute(request);
Port = result.Content;
return Port;
}
When I convert this on a Task :
public async Task<string> GetResPor()
{
var restClient = new RestClient { BaseUrl = new Uri("http://xxx.xxx.xxx.xxx:xxxx") };
var request = new RestRequest
{
Resource = "getCliPor",
Method = Method.GET
};
request.AddParameter(new Parameter { Name = "idt", Value = GetImAsync().GetAwaiter().GetResult(), Type = ParameterType.GetOrPost });
var result = await restClient.ExecuteTaskAsync(request);
Port = result.Content;
return Port;
}
on the ViewModel I start by creating a new instance of my service class and then:
Port = RD.GetRestauPort().GetAwaiter().GetResult();
And this is where the app get blocked, no exceptions no nothing.
To keep things simple, let's start with the basics. The easiest thing to do, in order to run something in a background thread, is to call it inside a Task.Run(). What this does is:
Queues the specified work to run on the ThreadPool and returns a task or Task<TResult> handle for that work.
Basically, you are delegating your work to the TreadPool and it handles everything for you - looks for a worker, waits for the worker to finish its job (on a new thread) and then notifies you of the result.
So, basically, whatever you want to be in a background thread, the simples solution will be to wrap it inside a Task.Run() and await its result, in case you need it.
Also, avoid using GetAwaiter().GetResult(). The simple rule in asynchronous programming is - if you can await, await all the way up.
You can read more about the topics in
this SO post
Advanced Tips for Using Task.Run With Async/Await
Using Task.Run in Conjunction with Async/Await

React Native - Wrapping native objects created in native modules

I'm interested in wrapping some C++ libraries as react-native modules but I'm hitting a bit of a conceptual wall. Very new to this stuff so bear with me!
I want to wrap something like the AudioProcessorGraph functionality of Juce https://juce.com/doc/classAudioProcessorGraph_1_1AudioGraphIOProcessor
However a big component of the api is connecting audio node objects to each other to form an audio processing graph. You can imagine something very similar to the web audio api:
const audioCtx = new AudioContext();
const oscillator = new OscillatorNode(audioCtx);
const gainNode = new GainNode(audioCtx);
oscillator.connect(gainNode).connect(audioCtx.destination);
The problem I'm seeing, before I even write a single line of code, is that I don't see a way with the RCT_EXPORT_METHOD macro to pass an instance of a native object as an argument to a method call of another native object. https://nodejs.org/api/addons.html#addons_wrapping_c_objects I've done similar things with native node addons using the ObjectWrap functionality. Is there anyway to accomplish something similar with react-native?
RCT_EXPORT_METHOD is used to export a function to the JS side in IOS. The caveat here is that the arguments you pass via JS to Native or from Native to JS should be serializable. This is because the communication happens via the RN Bridge in async manner.
This is what I would do in your case. Lets take the example:
Lets say you have a function in native module
//Initialise a list to store audioContexts
ArrayList<AudioContext> audioCtxList = new ArrayList<AudioContext>();
#ReactMethod
public void createAudioContext(Callback cb){
AudioContext audioCtx = new AudioContext();
audioCtxList.add(audioCtx);
cb.invoke(//...index of the newly created audioCtx)
}
Now in the JS side you have a reference that u can use to talk to native module
so next function would look something like
#ReactMethod
public void createOscillator(int audioCtxId){
AudioCtx actx = // Get the audioContext from the list using the audioCtxId
const oscillator = new OscillatorNode(audioCtx);
const gainNode = new GainNode(audioCtx);
oscillator.connect(gainNode).connect(audioCtx.destination);
}
As a result you would not need to export any native object to JS side and you can accomplish the functionality u need too.

Can't get SignalR client events published with Aurelia Event Aggregator

I have a single page app based on Aurelia and I'm trying to get it to work with an existing SignalR backend. I've downloaded the SignalR javascript client and integrated it with the Aurelia app manually (i.e. I'm not using a proxy file). I'm able to connect to the SignalR hub and see the arrvive messages in the console.... so far so good. Now, I'm trying to use the Aurelia Event Aggregator so that when a new hub message arrives an event is fired and any components of the app subscribed to that particular event will do some work. The issue is that the SignalR event callback doesn't seem to be able to access the Event Aggregator object. Here's the code to illustrate the issue:
//Import statements omitted for brevity
#inject (EventAggregator)
export class MyService{
constructor(eventAggregator) {
this.ea = eventAggregator;
this.connection = $.hubConnection("http://localhost:8080/signalr", { useDefaultPath: false });
this.hub = this.connection.createHubProxy("myHub");
//Register a callback function to fire when a new hub message arrives
this.hub.on("sendMessage", this.processHubMessage);
//No issues so far - all this constructor code works fine
}
processHubMessage(message) {
// This doesn't work - this.ea is undefined in the scope of this function
this.ea.publish('deviceStatusUpdate', message);
}
}
The event aggregator object referenced within the callback function is not defined - I assume because it's not being called within the scope of the class. Is there a way to resolve this? How do I give the callback function access to the class properties (this.ea in my example).
Try using
this.hub.on("sendMessage", (message) => this.processHubMessage(message));
It's failing on you due to how this isn't what you're expecting it to be. By using a fat arrow function, this is what you expect it to be. This is a really frustrating part of JavaScript, but fat arrows provide a simple workaround for it.
I think you are missing the 'start' for your Proxy, also you may need to alias your view model to pass to the HubProxy.
This works for me:
constructor(eventAggregator){
this.eventAggregator = eventAggregator;
var signalrAddress = 'https://pathToYouServer';
var hubName = 'yourHubsName';
var connection = $.hubConnection(signalrAddress);
var eventHubProxy = connection.createHubProxy(hubName);
var vm = this;
eventHubProxy.on('yourBroadcastMessage', function(data) {
vm.eventAggregator.publish(data);
});
connection.start();
}

How to trigger Cortana Programmatically?

Is there a way to use VoiceCommand methods used to programaticlly trigger Cortana as if the Cortana has registered "Hey Cortana" to begin listening?
I had this same question, but for Windows 10. Found a solution: on Windows 10, you can trigger Cortana with Win + C key stroke combination. To get this working programmatically, you would need interop with the Win32 SendInput method. Fortunately there is a NuGet package Windows Input Simulator, that does just this:
Install-Package InputSimulator
With that installed I was able to trigger Cortana from a WPF app using:
var sim = new InputSimulator();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_C);
It is not possible the closest you can get is using something like this:
async static void LaunchCortana(bool untrusted, string searchText)
{
// The URI to launch
string uriToLaunch = #"http://www.bing.com/";
searchText = "search?q=" + searchText.Replace(" ", "+");
var uri = new Uri(uriToLaunch + searchText);
// Set the option to show a warning
var options = new Windows.System.LauncherOptions();
options.TreatAsUntrusted = untrusted;
// Launch the URI with a warning prompt
var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
or
await Launcher.LaunchUriAsync(new Uri("bing://home"));
It works in Windows Phone 8.x only and utilizes the fact that Cortana disables Bing.com , but you can't use it to launch Cortana commands. It will just starts a Web search.

How can I set up expectations for event registration on a multimock

I am using RhinoMocks 3.6 and would like to use the multimock feature to implement both a class and a interface.
var mocks = new MockRepository();
var project = mocks.StrictMultiMock(
typeof(Project),
typeof(INotifyCollectionChanged));
using (mocks.Record())
{
((INotifyCollectionChanged)project).CollectionChanged += null;
LastCall.Constraints(Is.NotNull()).Repeat.Any();
}
The LastCall is working though. I get this message :
System.InvalidOperationException : Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).
What am I doing wrong here??
Have you actually checked that the Project class has methods you can override as the error message indicates? I'll assume you have. :-)
I'd suggest you switch to using the AAA syntax instead of record/replay as shown here:
I assume you're wanting to know if the class under test reacts the right way when the CollectionChanged event is fired? If that's the case, you can do it something like this:
var project = MockRepository.GenerateMock<Project, INotifyPropertyChanged>();
project.Expect(p => p.SomeMethod())
.Repeat.Any()
.Raise(p => ((INotifyCollectionChanged)p).CollectionChanged += null,p,new NotifyCollectionChangedEventArgs());