Why Frida (Inject) doesn't hook getPackageInfo and other methods? - javascript

I am having problems creating a script in JavaScript for Frida.
I want to hook the getPackageInfo method in order to log when it is called in the console, i have overloaded the old and the new version of it using this code:
jPM = Java.use('android.content.pm.PackageManager');
jPM.getPackageInfo.overload('java.lang.String','int').implementation=(pname,f)=>{
console.warn("Called => getPackageInfo ("+f+")");
return jPM.getPackageInfo.call(this,pname,f);
}
jPM.getPackageInfo.overload('android.content.pm.VersionedPackage','int').implementation=(vp,f)=>{
console.warn("Called => getPackageInfo [API level 33] ("+f+")");
return jPM.getPackageInfo.call(this,vp,f);
}
When i try to run the script I don't get any error, but I don't get any log in the console.
I am sure that the method that is being called is the first, because it's signature is this in smali:
Landroid/content/pm/PackageManager;->getPackageInfo(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;
I can't understand what am I doing wrong, if i use the same code to hook other methods it works. Please help me

I have solved this by using android.app.ApplicationPackageManager instead of android.content.pm.PackageManager.
Thanks to #Robert for giving me the link to this example code: https://codeshare.frida.re/#limyout/test/

Related

Storing typeorm repository function in a variable and calling doesn't works

I have a typeorm repository function called findOne in a repository called SampleRepository. I am using nestJS and injected the SampleRepository object in the service class. We can invoke that function like
function sample(){
this.sampleRepository.findOne(// relevant code)
}
But, when we store that function reference in a variable and use that variable to call findOne, it's throwing an error Cannot read properties of undefined (reading 'manager')
const ref = this.sampleRepository.findOne;
ref(// relevant code)
I understand this seems so weird and mindless. But, it's happening. Is there any other parsing happens or am I missing something?
I believe the issue here is that the context for the this of the findOne is being lost. I think you'd need to do const ref = this.sampleRepository.findOne.bind(this.sampleRepository) so that later when you call ref() you have the proper context. The other option is just don't set the method to a variable reference

TypeError: elem[prop] is not a function in Webdriveio

TypeError: elem[prop] is not a function
E2E testing in webdriveio. I want to click a button inside an iframe.
let iframe = browser.$('#fullmessage')
browser.pause(1000)
browser.switchToFrame(iframe)
browser.setTimeout({ implicit: 10000 })
let clickAgree = $('a[class="button is-success"]')
clickAgree.click()
browser.switchToParentFrame()
browser.pause(3000)
I was facing same error and when debug more using REPL found that the issue could be due to 2 reasons:
selector is returning array of elements and so it was not able to call the method used.
the method being called on element does not supports.
For example with following code:
$('.some_class').$$('input').getValue();
was getting error - Uncaught Error: elem[prop] is not a function. Using $('.auto_test_class').$$('input')[1].getValue(); works. But its better to use some Id or xpath.
Hope this might be useful for someone facing same issue :)
Hi i faced with the same problem, but in async. The reason is that you need
to await already defined element as parameter:
get iframe() { return $('.iframe'); }
await browser.switchToFrame(await this.iframe);
Because switchToFrame works only with element, not with promise.
Maybe for someone it will be useful.

Cannot get web component to work in codesandbox.io

I'm trying to get a customized built-in web component to work in codesandbox.io. This is the code:
class MyDiv extends HTMLDivElement {
constructor() {
super();
}
connectedCallback() {
this.innerHTML = "works!";
}
}
customElements.define("my-div", MyDiv, {extends: 'div'});
<div is="my-div"></div>
The error I'm getting:
Failed to construct 'HTMLDivElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
Tested in Chrome 67, Arch Linux. Here's the link: https://codesandbox.io/s/yqln560jzj
It does work here in a snippet, and it also works on codepen: https://codepen.io/connexo/pen/ZjEbqo
What am I missing here?
If it doesn't works it's because Codesandbox is using a kind a Javascript preprocessor (Typescript?) on external JS files, that will execute the code before (to detect syntaxt errors or so on).
The customElements.define() method is called twice, and fails the second time it is called because you can define a custom element only one time.
You can see it by calling customElements.get() inside your script, and see it's already defined.
console.log( customElements.get( 'my-div' ) )
If you put the Javascript inline (in the HTML file index.html) in a element it will work fine.
Note that the second error you get it's because you are using the Babel preprocessor in the Codeopen snippet. You must disable Babel and it will work.
What am I missing here?
Nothing. It's codesandbox.io that is missing Custom Elements support.

Invalid Chai property: called. Did you mean "all"?

I am trying to test my node.js code using Mocha, Sinon, and chai.
var callback = function (err, resultSet) {
should.exist(resultSet);
stubbedExecuteSqlQuery.should.be.called;
done();
};
stubbedExecuteSqlQuery.yields(null, expectedResultSet);
db.getResults(param1,param2, user, callback);
when the above code gets executed, it throws an error :
Invalid Chai property: called. Did you mean "all"?
The code used to work fine on chai version ^3.5.0 but after my recent package upgrade to ^4.1.2 the code has stopped working and has started throwing such errors.
I tried searching for it on the internet but could not find any useful information.
Any help will be appreciated. Thanks in advance!
I had a similar issue, I think it had something to do with using .yields
I ended up using .calledOnce . Try the following:
assert(stubbedExecuteSqlQuery.calledOnce);
The upside with this is that if needed you can do .calledTwice etc..

How to call a non-parameterised QML function from C++

I am trying to call a function in my QML:
function resetSomething() {
tempVar= undefined
}
I am not sure how to write the invokeMethod for this function.
I tried using something like that:
QQuickItem* qObj= findChild<QQuickItem>("temp");
if (qObj)
{
QVariant returnArg;
QMetaObject::invokeMethod(qObj, "resetSomething",Q_RETURN_ARG,QVariant,returnArg));
}
But it gives the error
no matching function resetSomething(QVariant) found.
As you can see in your error message Qt's Meta Object System is trying to find method resetSomething(QVariant), but your method doesn't have any parameters. I guess it's because of wrong Q_RETURN_ARG macro usage.
Seems that you can simply fix it like this:
QVariant returnArg;
QMetaObject::invokeMethod(qObj, "resetSomething", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnArg));
Also I suggest you to read official Qt documentation, it is brilliant.
BTW: Nice repo from Google with a lot of C++/JavaScript intercommunication. You can find a lot of useful patterns there.

Categories

Resources