Q:xposed hook all methods of an app and the impact of the performance - Xposed Framework Development

I developed a module to monitor the performance of an app (for example: wechat , whatsapp, any app is ok), my motivation is to get the delay of all the methods of the app. So first I get all the classes list and save as a txt file in sdcard, then in my module I read the class name one by one and get declaredmethods and hook every method of the class.
Actually this module successed, but the app (wechat app) crashed (NO RESPONSE) , the app is very complicated and the large amount of classes,methods hook impact the app's normal running.
Q: I want to know tracking and hooking all methods of an app is possible? HOW TO FIX THIS PROBLEM THAT THE APP DO NOT RESPONSE?

wendy_1805 said:
I developed a module to monitor the performance of an app (for example: wechat , whatsapp, any app is ok), my motivation is to get the delay of all the methods of the app. So first I get all the classes list and save as a txt file in sdcard, then in my module I read the class name one by one and get declaredmethods and hook every method of the class.
Actually this module successed, but the app (wechat app) crashed (NO RESPONSE) , the app is very complicated and the large amount of classes,methods hook impact the app's normal running.
Q: I want to know tracking and hooking all methods of an app is possible? HOW TO FIX THIS PROBLEM THAT THE APP DO NOT RESPONSE?
Click to expand...
Click to collapse
I don't think the hooking is the issue there, but what you do in your methods. I guess this must be quite computationally expensive (maybe not just one method, but if one of your method adds a small delay, and if all your multiple methods do the same, the sum of small delays will add up to a very huge global delay).
A few common ways to alleviate the time required for computations is to either pre-compute and store in persistent, static variables and limit the number of input/output requests (so that you compute/get from Android libs once most of the stuff you need, and then you share this data between different methods), and to use more efficient algorithms (in term of computational complexity, see Wikipedia) if available.
If this doesn't fix your issues, you should post some code snippets so that people here can better see what kind of job your methods are doing.

lrq3000 said:
I don't think the hooking is the issue there, but what you do in your methods. I guess this must be quite computationally expensive (maybe not just one method, but if one of your method adds a small delay, and if all your multiple methods do the same, the sum of small delays will add up to a very huge global delay).
A few common ways to alleviate the time required for computations is to either pre-compute and store in persistent, static variables and limit the number of input/output requests (so that you compute/get from Android libs once most of the stuff you need, and then you share this data between different methods), and to use more efficient algorithms (in term of computational complexity, see Wikipedia) if available.
If this doesn't fix your issues, you should post some code snippets so that people here can better see what kind of job your methods are doing.
Click to expand...
Click to collapse
Thank you for your answer. Actually I just print a log after the hooking. "System.out.println("packagename: "+param.thisObject.getClass().getPackage()+" classname: "+param.thisObject.getClass().getName()+" method name: "+param.method.getName());" I choose the simple log to test if hooking all methods of an app is possible. But after I hooking every methods of the wechat app, I click the icon of wechat and the phone showing blank screen then pop up dialog box "No responsing!"

wendy_1805 said:
Thank you for your answer. Actually I just print a log after the hooking. "System.out.println("packagename: "+param.thisObject.getClass().getPackage()+" classname: "+param.thisObject.getClass().getName()+" method name: "+param.method.getName());" I choose the simple log to test if hooking all methods of an app is possible. But after I hooking every methods of the wechat app, I click the icon of wechat and the phone showing blank screen then pop up dialog box "No responsing!"
Click to expand...
Click to collapse
System.out.println is an I/O so if it often gets called, this will hugely slow down your app. You should rather use Log.d("YourAppName", "Your debug message here"), which will only print when connected to a debugger (so if you disconnect your phone from your IDE, you should get an app with full speed since the debug statements will be ignored).

Related

[APP] Resident Mort - Scary Good, not Scary Evil

*Anyone get the reference? Haha*
Resident Mort
The Scripter's Companion​
Current News / Status:
Resident Mort is currently Under Development
Resident Mort is planned to be a background EXE that will extend the functionality of MortScript available to developers through the usage of the "PostMessage" function.
Resident Mort is planned to extend functionality by adding extra, possibly more complex, functions or even adding in the ability for more complex GUIs.
Features (Green = Implemented, Blue = In Testing, Orange = Planned, Red = Failed):
GetProcessList - Gets a list of Running Programs
GetRecentApps - Gets a list of Recent Apps (10)
CreateScript - Creates a MortScript with the provided info
MakeFile - Makes a file of any kind with the provided info
MakeFolder - Makes a folder at the specified location
RegToEvent - Registers a File to an event​
UnRegFromEvent - Unregisters a File from an event
IsIdEventRegistered - Checks to see if a File is registered to an event.
DispImg - Displays an Image to the screen [and gets where the user Presses]
MakeForm - The Initial call for setting up an 'advanced GUI' form
FormAddObject -A Call that will add one of the predefined objects to the form being created
DeployForm - The Final call for setting up an 'advanced GUI' form, displays it to the user
This application is being made for MortScripters, to possibly make some projects easier. Since I don't use MortScript so much any more, I do rely on you the developers who use MortScript, to tell me what you want in the program.
Since I have a good deal of Functions there, I will commence work on a primary release
Saved For Future Use - Features and Screenshots
like the idea! advanced guis would be very useful
so this is a compiler? I am not sure what this is about
-sorry
No, this is a Resident App, an EXE that is always running in the background. It will have certain functions in it which can be accessed by MortScripters.
All the functions can be called with PostMessage ( I will provide documentation on how to do so, when I make a first release ). Then the results will either be written in the REGISTRY, written to a FILE, or copied to the CLIPBOARD (depending on how the scripter wants to handle the task).
Does this clarify it a bit?
Thanks for sharing!
A small update:
I am using this 'decent' planning utility, to help me keep track of my growing projects. According to this utility, the program is close to 30% complete. Then again, this is just a 'decent' utility haha. I would say, in my estimation (since some Code is "Copy + Paste"), I am close to 60% to 75% done.
A small change in my plans:
While I originally had the intentions of making this program as simple as a PostMessage in MortScript, I found out the following two Limitations:
1) MortScript's PostMessage/SendMessage only support(s) sending Numbers in the wParam and lParam parameters...very disheartening.
2) Due to #1, I made an assistant EXE, which would be run instead of calling PostMessage [this way I could do it Natively in my own control], but it is MUCH harder to transfer data between two applications that I would have thought! Due to Virtual Stacks and Memory Allocation 'rules', I couldn't EASILY do this.
So Here is my change:
In order to use Resident Mort, scripters will have to do about 3 or 4 commands to run. The only real commands that need to be used are PostMessage and RegWriteString (Did I get those right?).
In any case, my Resident Mort will read the Registry for corresponding wParam and lParam values and use those [in the future I will attempt Clipboard integration, to avoid Registry Interfacing].
When I release this program to the public, I will try to include a MortScript file that shows how to use all the functions. I don't remember much of MortScript [unfortunately], but I was thinking it could be helpful to make a "Library" of MortScript functions so a script will only have to call that function. But that is if some kind dev. would like to help out later on
Anyways, Thats that for this update. Expect a result in the coming week.
That sounds interesting for adv. gui functions.
Cyclonezephyrxz7 said:
1) MortScript's PostMessage/SendMessage only support(s) sending Numbers in the wParam and lParam parameters...very disheartening.
Click to expand...
Click to collapse
That's not MortScript's fault, it is design of whole Windows CE kernel, more here
I'd go with background EXE, that would listen to messages WM_USER+somenumber, maybe even region (for different actions, so you'd have both lParam and wParam free for another parameters). If you need help with this part, drop me PM on MSN, I had to study this a bit in the PinchToZoom project myself.
@OndraSter : Yeah, I know that Windows CE has limitations, however it is not impossible. Such an ability could be implemented in a code-update to MortScript. I did my reseach (if you look at #2, I mention that I found it much harder to transfer data between exe's that I had hoped) and found that you can transfer data via SendMessage (the Synchronous method) using a TRANSFERDATASTRUCT and WM_COPYDATA. If MortScripts interpreter could identify a SendMessage with a String value in either wParam or lParam, then it would create such a structure and transfer it, the receiving app would HAVE to take care of deleting the data though, or you have mis-used RAM.
As for how it is going to work now, I did not consider using WM_USER + a value, mainly because my program won't be using other Messages, and will only act if the correct wParam/lParam are provided (preventing accidental execution if the System decides to post a message with the same ID). I have it mostly covered, and I am closing in on finishing (currently with Reg data retrieval only, no Clipboard yet). I have completed 3 of the 7 Proposed Functions (MakeFile, MakeFolder, CreateScript) and I would have finished RegToEvents, but I got sorta lazy hehe. DispImg shouldn't take me more than a few minutes when I get to it, and once I get the API calls for Processes and figure out how to read the MRU reg-entry, I will have the last 3 complete!
As for Clipboard data retrieval, unless I am using the entirely wrong API calls, MortScript has an interesting way of using the Clipboard...I tried copying simple strings like "hello world" to the clipboard using MortScript, then trying to retrieve them in my Resident Mort, but the clipboard always comes up empty... Any ideas anyone?
Thats that for now I am about ready to release....any other functions you want implemented?
As for how it is going to work now, I did not consider using WM_USER + a value, mainly because my program won't be using other Messages, and will only act if the correct wParam/lParam are provided (preventing accidental execution if the System decides to post a message with the same ID).
Click to expand...
Click to collapse
http://msdn.microsoft.com/en-us/library/ms644947(v=VS.85).aspx
Good idea, the only downside being that it will generate the Message Numbers each time it is run... It is not assured that the Post / Send Message MsgIDs will remain constant.
Thanks for the link however
Cyclone,
Sorry about taking so long to post here...
How about, when the BT is on, this reports what is "out there" based on what the BT stack is telling you.
That is, it should read the surrounding area, then report that is saw my BT dongle. In the car, it should report that it saw my BT GPS unit.
Then, I can use that information to change my profile. That is, when it sees the BT dongle, regular phone calls. When it sees the BT GPS unit, run speaker mode, or connect to the GPS unit for phone calls.
Thanks!
--Ironhead
P.S. it would need to support the Touch Pro 2, Rhodium (my understanding is that it is Widcomm BT stack)
I"ll see what I can manage. I am really 'grid-locked' in my work on a couple of projects already So a release of this may have to wait a while....Sorry
I wish I had caught you a little sooner...
AutohotkeyCE may be a better base to work from than Mortscript...
http://www.autohotkey.net/~Micha/AutohotkeyCE/html/index.htm
In fact... AHKCE should be able to cater to all of your needs without the separate resident app
Yeah, I have seen that before. This project is really just a little challenge for myself to expand upon MortScript [because I know it is widely used].
Thank you for the link/suggestion however
I've been playing with Mortscripts for a while, I'm really thinking I can do everything I want, right from there...
EXCEPT:
Actually getting the information from the BT stack. I just need to see if there are any registered BT devices around my phone (so I can tell if I am in my car, at home, at work, etc.).
--Ironhead
Bumpity bump!
Hehe...Yeah, sorry for the lack of work on this. Check out FFP_LockScreen. I am working on a new release. I have very little time now, and I can't manage more than just one or two projects at a time. Once I release FFP_LS 3.0, I can devote some time MAYBE to this project. It all depends on how quickly the XDA-Marketplace idea takes off.
Sorry =\
I you can add a tool to make an GUI... it s must be soo cool...

[TOOL] AppThwack - Easily test apps on real devices we host

Hi, I'm Trent and I co-created AppThwack, a service for on-demand automated testing of Android apps on real devices. Basically, you upload an apk and a couple minutes later you get screenshots and logcat dumps from actual phones and tablets we host.
Beta Users Needed
We're currently looking for devs to join our private beta. You can message me or sign up on our website and I'll get a beta code to you shortly. We're trying to stress the system and make additions/adjustments so the service is as useful as possible for developers.
Current Features
Real phones and tablets: About 20 high- and low-end devices and we add a few more every week.
Fast: See results in real time. Full test runs on all devices takes a minute or two to complete.
Selectable default tests: Install, launch, UI Monkey, Cleanup
Configurable tests: For example, specify the number of UI Monkey events and seed the randomizer
JUnit including Robotium support via uploaded test packages
Screenshots in portrait and landscape on all devices
Logcat and filterable logcat viewer
High-level results sortable by device or test
Full stack-traces for any exception that occurs
Future
We're working on adding more test frameworks like monkeyrunner and more default tests, particularly performance tests that measure battery consumption, CPU usage, etc. We're also adding more data visualization and charting so it's easy to see what some of the gathered statistics mean.
We plan to launch soon, but the beta program will remain in effect even after that. The service will follow a freemium model. Again, the beta is free and we're going to keep it in place even after we eventually launch.
Inter-device automation
Our back-end supports device-to-device automation, so if you have an app or scenario that you'd like to test that involves multiple devices or interaction with other devices, even non-Android devices, let me know. We're looking for people to help us develop how this service will be exposed.
Edit: I can't post links, but if you search for "appthwack" you'll find it. Btw, I've apparently lurked since October, 2008. Yikes.
Just wondering will this support of testing apps that require root?
Also any chance we can see like a live pic of the device when it installs the app and opens it?
Sent from my VS910 4G using xda premium
motodroidfreak said:
Just wondering will this support of testing apps that require root?
Click to expand...
Click to collapse
Right now it does not and all of our phones are as close to stock as possible. I'll look into making it an option so we automatically root before your app installs and then un-root after the tests are complete. Root opens up some new possibilities, both good and bad, so I'll need to think about it.
motodroidfreak said:
Also any chance we can see like a live pic of the device when it installs the app and opens it?
Click to expand...
Click to collapse
Yes! The launch test takes a screenshot in both landscape and portrait. You can see all screenshots sorted by device by clicking "By Device" or "By Test" and clicking the "Screenshots" link in the blue box at the top.
Screenshots also show up in each launch test log so you can see the context as the shot was captured. Logcat dumps show up in the same place (Link from the blue box at the top will open a filterable and highlighted log viewer).
Alright thanks I'll try it out tonight
Sent from my VS910 4G using xda premium
Holy cow. Didn't realize such web service existed.
I just signed up and currently having a look around. Is it possible for me to join the beta? Thanks!
Is it possible for a "free" upgrade for my account? Heh just asking
EDIT : Created a new project. Then I'm stuck. The "Runs" tab is empty.
EDIT again : Oh.. uploading had error previously. Uploading again.
Very interesting project. Good luck to your team and I hope I can be a good beta tester
Realy interesting, for us, almost of our apps needs root access, so please think about adding root to your service
Test on my Sensation
Will test on my sensation
test
nullFactory said:
Hi, I'm Trent and I co-created AppThwack, a service for on-demand automated testing of Android apps on real devices. Basically, you upload an apk and a couple minutes later you get screenshots and logcat dumps from actual phones and tablets we host.
Beta Users Needed
We're currently looking for devs to join our private beta. You can message me or sign up on our website and I'll get a beta code to you shortly. We're trying to stress the system and make additions/adjustments so the service is as useful as possible for developers.
Current Features
Real phones and tablets: About 20 high- and low-end devices and we add a few more every week.
Fast: See results in real time. Full test runs on all devices takes a minute or two to complete.
Selectable default tests: Install, launch, UI Monkey, Cleanup
Configurable tests: For example, specify the number of UI Monkey events and seed the randomizer
JUnit including Robotium support via uploaded test packages
Screenshots in portrait and landscape on all devices
Logcat and filterable logcat viewer
High-level results sortable by device or test
Full stack-traces for any exception that occurs
Future
We're working on adding more test frameworks like monkeyrunner and more default tests, particularly performance tests that measure battery consumption, CPU usage, etc. We're also adding more data visualization and charting so it's easy to see what some of the gathered statistics mean.
We plan to launch soon, but the beta program will remain in effect even after that. The service will follow a freemium model. Again, the beta is free and we're going to keep it in place even after we eventually launch.
Inter-device automation
Our back-end supports device-to-device automation, so if you have an app or scenario that you'd like to test that involves multiple devices or interaction with other devices, even non-Android devices, let me know. We're looking for people to help us develop how this service will be exposed.
Edit: I can't post links, but if you search for "appthwack" you'll find it. Btw, I've apparently lurked since October, 2008. Yikes.
Click to expand...
Click to collapse
I would like to test the tool, can you share with me..
Tested
Tested the tool, seems too good..
Suggestion : In-case if you want to reach maximum number of developer. Allow developer to use has free.
IDEA : You can request developer to post about you're tool on there app page, website & play store... As you're giving the tool as free you will get enough number of people to view & use the tool.. if the developer agree then you will allow him to use the tool for free of cost..
As a developer am ready to use the tool & post about you in my app & other places too...
This is a great tool, just uploaded an apk of my app that's in my signature and it worked, with a couple of NullPointers from the Play Store's licence service. That shouldn't happen, and doesn't on any of my devices, so I suspect it's an issue on your end. Any idea why?
HTML:
java.lang.NullPointerException at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:99) at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:228) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.os.HandlerThread.run(HandlerThread.java:60)
HTML:
FATAL EXCEPTION: background thread java.lang.NullPointerException at com.google.android.vending.licensing.LicenseValidator.verify(LicenseValidator.java:99) at com.google.android.vending.licensing.LicenseChecker$ResultListener$2.run(LicenseChecker.java:228) at android.os.Handler.handleCallback(Handler.java:608) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:156) at android.os.HandlerThread.run(HandlerThread.java:60)
Borland
We are using Silk Mobile for end to end applications testing. Do you ever used this tool?
What an interesting service! I'll look into this from work tomorrow.
Not having used this at all, the first things which do spring to mind are:
-streaming realtime logcat
-a (skype?) connection with live streaming video of the app running, so you can see layouts/animations etc.
Anyway, I'm going to check this out tomorrow!
Quinny899 said:
This is a great tool, just uploaded an apk of my app that's in my signature and it worked, with a couple of NullPointers from the Play Store's licence service. That shouldn't happen, and doesn't on any of my devices, so I suspect it's an issue on your end. Any idea why?
Click to expand...
Click to collapse
Thanks for checking out the service. My immediate guess it that this is caused by the absence of a default Play account. Many devices have no account as one of our supported frameworks, calabash, removes accounts upon cleanup after script completion. On the plus-side, if you were to write scripts you should be able to add a temporary account from the test itself.
Highly unlikely you'd hit this bug in a real world situation, but it is a bug nonetheless.
Really awesome service! Can't test it for the moment as it doesn't support root apps, but this is really a great concept :good:
Maybe you could build a superuser permissions manager which would grant root access but makes sure to keep /system mounted as read-only, this way no harm could be done to the devices and us root apps devs could use your awesome service.
I actually got quite a few ideas, you could delete the mount binary in /system/xbin and use it in an internal appthwack app's private data, so that it's the only app able to call this binary and thus to mount /system.
I'd definitely subscribe to AppThwack if it had root support.
If you want help with developing this kind of secure root environment for the testing, I'd gladly contribute.
EDIT : Strangely enough, I just tested it with my app (which asks for root in the launcher activity, so I really didn't expect it to work) and had 0 failures, 75 pass.
How comes ? Have you already added root support ?^^
Either way this is really cool, I'm going to spread the words and most likely subscribe a paid account :good:
Is there somewhere we can see pictures of your device lab? Gotta be one hell of a device museum you got over there^^
Androguide.fr said:
Really awesome service! Can't test it for the moment as it doesn't support root apps, but this is really a great concept :good:
Click to expand...
Click to collapse
Awesome, thanks for the kind words!
EDIT : Strangely enough, I just tested it with my app (which asks for root in the launcher activity, so I really didn't expect it to work) and had 0 failures, 75 pass.
How comes ? Have you already added root support ?^^
Click to expand...
Click to collapse
This is pretty interesting. The only two rooted devices are a couple running CM. I'll look into this further, and if you have any ideas I'd love to hear them as well.
Either way this is really cool, I'm going to spread the words and most likely subscribe a paid account :good:
Is there somewhere we can see pictures of your device lab? Gotta be one hell of a device museum you got over there^^
Click to expand...
Click to collapse
Sweet, I really appreciate it. As soon as I have the number of posts to do so I'll post a pic of the lab.
Some things can not be automated, like scanning a QR code or reading/writing to an NFC tag. Do you plan on adding "manual tests" for a fee?
This would be really great to test apps on specific hardware.
worldtiki said:
Some things can not be automated, like scanning a QR code or reading/writing to an NFC tag. Do you plan on adding "manual tests" for a fee?
This would be really great to test apps on specific hardware.
Click to expand...
Click to collapse
Thanks for the question! Our primary focus is on automation. There are existing test houses and services that will execute manual tests like those you describe, but of course because of the manual component they're slow and expensive.
We often push folks to break their testing down into more granular chunks. For instance, verify you can take a picture and deal with the image, even if it's not the QR code or whatever your app usually consumes. This will find problems with simply using the camera and resulting image location. Now, have a separate test that processes a photo of a QR code, but feed the image in as part of the test. This removes the camera component from the analysis part, meaning it's now possible to benchmark the image analysis algorithm on all devices.
With a combination of a service like ours where you test very, very quickly on tons of devices, you can now do some more UX/end-to-end tests on a handful of devices yourself. This hybrid approach is great for finding the vast majority of issues before release.
nice post
Realy interesting, for us
Awesome tool !
No Developer can test his/her app on many devices. But your tool ... A W E S O M E ! ... I Used it yesterday to test two of my new apps ... Found some error is my app on certain devices which i'd have never found without AppThwack .. :good: :good:

Include local JavaScript within PhoneGap on Windows Phone 7

I have a PhoneGap application designed to work on multiple mobile platforms. I'm loading a dynamic HTML content from an external page on the Internet using jQuery Mobile. The problematic system is Windows Phone 7.
This is what I get from the external page, with the URL of the script tag already replaced to load from the phone instead of from the net to save bandwidth:
HTML:
<script type="text/javascript" charset="utf-8" src="x-wmapp1:/app/www/test.js"></script>
This works fine on Android, iPhone and even BlackBerry when I replaced the x-wmapp1: part by a respective counterpart (e.g. file:///android_asset/www/ on Android). However, on Windows Phone 7 it doesn't seem to work at all.
When I try to load the same URL via $.getScript function, it always returns a 404 eror, even if I try and load it with a relative path only.
Any suggestions?
First of all, this type of question may be better suited to the Software Development or Apps and Games sub-forums, as a lot of the people who hang out here are more familiar with homebrew hacks. I'll give it a shot, though.
First of all, what kind of path are you trying to use? I haven't tried loading scripts or images in HTML or JS, but to dynamically load content within the app itself typically requires some care with regard to the path. For example, is the JS file being built into the assembly (as a resource) or included alongside it (as content)? How about the HTML page?
This is a kind of lame approach, but one option that's sure to work is just inlining the scripts in the page, directly. That won't increase the total app size or load time at all, although it might make maintaining the app take a little bit more effort.
Thanks for the reply, I will try to post this into the more appropriate forum.
With regards to paths - you can see the path in the HTML snippet I provided in the original question. It's all a bit specific and we cannot afford to load JS directly from page, since that does increase the size of the resulting HTML, sent from an external PHP page, thus increasing bandwidth. This is the first reason why we chose to have all JS and CSS files directly bundled with the application and load them internally rather than from Internet.
Also, all of JS files are included alongside the application as content. I'm using the same approach for all images, since if they were included as a resource, they would not show in the application.
GoodDayToDie said:
First of all, this type of question may be better suited to the Software Development or Apps and Games sub-forums, as a lot of the people who hang out here are more familiar with homebrew hacks. I'll give it a shot, though.
First of all, what kind of path are you trying to use? I haven't tried loading scripts or images in HTML or JS, but to dynamically load content within the app itself typically requires some care with regard to the path. For example, is the JS file being built into the assembly (as a resource) or included alongside it (as content)? How about the HTML page?
This is a kind of lame approach, but one option that's sure to work is just inlining the scripts in the page, directly. That won't increase the total app size or load time at all, although it might make maintaining the app take a little bit more effort.
Click to expand...
Click to collapse
First question: have you set the IsScriptEnabled proerty on the control to True? It defaults to False, preventing scripting within the control. Also, changing it only takes effect
on navigation, so if you already loaded the page and then set this property, it still won't work.
Anyhow, I missed that your HTML was coming externally, and only the scripts and stylesheets were local. That's... interesting, and seems reasonable enough, and I can't find any info online that exactly matches your use case. The way you're structuring the script src URI looks weird to me, but I haven't messed with the WebBrowserControl very much at all.
One solution, though a bit hacky:
Use the WebBrowserControl's InvokeScript function to dynamically load scripts into your pages. To do this, you would first need to load the script file content into a .NET String object. The GetResourceStream function is probably your best friend here, combined with ReadToEnd(). Then, just invoke the eval() JS function, which should be built-in, and pass it the JS file content. That will load the JS into the web page, creating objects (including functions) and executing instructions as the files are eval()ed.
Of course, you'd need to do this on every page navigation, but you can actually automate it such that the page itself requests that the app load those scripts. In your app, bind the script-loading function to the ScriptNotify event handler, probably with some parameter such as the name of the script to load. Then, on each page served from your server to the app, instead of including standard <script src=...> tags, use <script>window.external.notify('load localscript1.js')</script> and so on; this will trigger the app's ScriptNotify function for you.
I hope that helps. I can see your use case, but somewhat surprisingly, I couldn't find anybody else online who had either run into your problem or written a tutorial on doing it your way.
Thank you for your reply, it was very informative. One question though - why do you think the way I'm structuring the SCRIPT URI is wierd? I tried to mess around with relative URIs and the such, however those would load the JavaScript file from Internet rather than from the application itself.
The problem I'm running into with your proposed solutions, however is that:
1. the project is a PhoneGap/Cordova application, using its own components, so I have no idea where I would look for IsScriptEnabled here (although this all worked on an older PhoneGap release, so I'm guessing they have it set up correctly)
2. injecting a script programmatically on each navigation would require me to rewrite much of the code we already use for other platforms, not to mention those custom Cordova components, which I don't even know if they can handle such thing
As for my user case - I was surprised to be the only guy on the internet with this methodology in place as well. So it either works for everyone else or nobody really thought of doing it my way, since it's basically an Internet application (maybe the don't want to disclose their sources, who knows).
CyberGhost636 said:
1. the project is a PhoneGap/Cordova application, using its own components, so I have no idea where I would look for IsScriptEnabled here (although this all worked on an older PhoneGap release, so I'm guessing they have it set up correctly)
Click to expand...
Click to collapse
In the WebBrowser properties.
CyberGhost636 said:
As for my user case - I was surprised to be the only guy on the internet with this methodology in place as well.
Click to expand...
Click to collapse
Of course you not "the only guy". I've tried to port/run a few HTML java-script based games on WP7 (Digger and couple more) more then year ago; they runs well with one HUGE exception - touch screen events are freezing scripts execution and make games not playable.
The "x-wmapp1:" URI scheme was what I was referring to. Not sure where that comes from, but I haven't done anything really with the WebBrowser control.
I have no knowledge of PhoneGap or Cordova; I assume they're "we write your app for you" frameworks? One would assume that such tools would know to set IsScriptEnabled, but you may have to do so manually. A bit of web searching on that direction may be fruitful - maybe earlier versions enabled scripting by default, and now it's disabled by default so you have to specify an option somewhere?
Injecting the script on navigation really doesn't require any major change to the server-side code. I mean, is sending
<script>window.external.notify('load localscript1.js')</script>
really much different from sending
<script type="text/javascript" charset="utf-8" src="x-wmapp1:/app/www/test.js"></script>
? If that's too different, you could instead send
<script src="http://yourserver.com/LoadLocalScripts.js"></script>
and put "LoadLocalScripts.js" on your server with the following code:
window.external.notify('load localscript1.js');
This has only a trivial increase in server traffic and load time, but lets you continue using external scripts instead of inline ones. Very little server-side change needed at all.
Now, the additional client-side code to support the window.external.notify and call InvokeScript... normally I'd say that's dead easy, because it is if you have any experience with the .NET framework, but in your case I get the feeling that this isn't so? I code to the framework, or to the underlying native code, and I tend to code "raw" (very little auto-generated code), so I'm not going to be able to help you solve the problems with a "make me an app" wizard unless I can see the code it generates for you.
For what it's worth, here's the approximate raw code that I'd use (it's over-simplified, but close enough):
void HandleNotify (String param) {
String[] parts = param.split(" ");
if (parts[0] == "load") LoadScript(parts[1]);
}
void LoadScript (String script) {
String content = Application.GetResourceStream(new Uri(script, UriType.Absolute)).ReadToEnd();
theBrowserControl.InvokeScript("eval", content);
}
void theBrowserControl_Loaded (...event handler args here...) {
theBrowserControl.IsScriptEnabled = true;
theBrowserControl.ScriptNotify += HandleNotify;
theBrowserControl.Navigate("http://yoursite.com");
}
the URI comes from Windows Phone itself, with this code, you can see for yourself:
var a = document.createElement('a');
a.setAttribute('href', '.');
alert(a.href);
also, I've been informed that this works in Cordova 2.0, so it might be a 1.8.1 bug... will try and see how it goes
thanks for your help so far!
Looks like it was a problem with PhoneGap 1.8.1 - after upgading to Cordova 2.0 (PhoneGap got renamed) it all works now... thanks for all the help!

HashMap<> not updated fast enough

Hi there, I have strange problem with my Xposed code.
I use a static HashMap to store unlock timestamps for Applock application, first I add the entry with put, and 200ms later I call get at another location. The thing is: the HashMap isn't updated yet. A few hundred milliseconds later, it is, but not before. And that's strange, as HashMaps should be VERY fast, I read somewhere about 50ms for a HashMap with 10 000 or even more entries, and mine has 300 maximum while in use, while testing it maybe had 15..
Is there a way to force an update of that HashMap?
Kind regards,
Max
@rovo89, @romracer, @C3C076
There is no delay, once the put call returns, you can get the item again. If you're calling from a different thread, make sure to synchronize properly. The relevant excerpts of your code would be necessary to say more.
rovo89 said:
There is no delay, once the put call returns, you can get the item again. If you're calling from a different thread, make sure to synchronize properly. The relevant excerpts of your code would be necessary to say more.
Click to expand...
Click to collapse
Of course, sorry, forgot to add link: https://github.com/Maxr1998/MaxLock...ain/java/de/Maxr1998/xposed/maxlock/Main.java
Should I create my own implementation of HashMap and make put and get snychronized?
Maxr1998 said:
Of course, sorry, forgot to add link: https://github.com/Maxr1998/MaxLock...ain/java/de/Maxr1998/xposed/maxlock/Main.java
Should I create my own implementation of HashMap and make put and get snychronized?
Click to expand...
Click to collapse
No reason for own implementation. Surround hashmap operations with synchronized block.
E.g.
synchronized (TEMPS) {
TEMPS.put(...);
}
C3C076 said:
No reason for own implementation. Surround hashmap operations with synchronized block.
E.g.
synchronized (TEMPS) {
TEMPS.put(...);
}
Click to expand...
Click to collapse
Tried it, but it didn't work. I already pushed the changes, could you take a look if I did something wrong?
Sent using my nexus⁴ running Euphoria 1.1 with Xposed and hells-Core B80
@rovo89 @C3C076 I also tried a ConcurrentHashMap without synchronizing like described here/Concurrent Collections, doesn't work as well.
When I get and log the value again 2 seconds later via Handler.postDelayed, it was updated..
Sent using my nexus⁴ running Euphoria 1.1 with Xposed and hells-Core B80
One possible reason is you are putting items to map within one process (belonging to your MY_PACKAGE_NAME) and
attempting to read map from different process (e.g. "android.app.Activity"). I believe you cannot see items put to map from one process to be "visible" by different process. Each process has its own instance of TEMPS map with own items in it. The contents of map is not shared across processes.
You have to think about using different approach.
Instead of memory store, use file system or DB which all processes you are hooking would have access to.
C3C076 said:
One possible reason is you are putting items to map within one process (belonging to your MY_PACKAGE_NAME) and
attempting to read map from different process (e.g. "android.app.Activity"). I believe you cannot see items put to map from one process to be "visible" by different process. Each process has its own instance of TEMPS map with own items in it. The contents of map is not shared across processes.
You have to think about using different approach.
Instead of memory store, use file system or DB which all processes you are hooking would have access to.
Click to expand...
Click to collapse
It actually is shared. I used a few handler().postDelayed() to read the value in periodic time segments and the value is updated maybe 500ms after first check were it isn't.
Sent using my nexus⁴ running Euphoria 1.1 with Xposed and hells-Core B80
Hit thanks if I helped!
Maxr1998 said:
…but I still get lockscreen looping because my Map isn't updated fast enough.
I already tried synchronizing the critical blocks on Map itself, on Main class, used ConcurrentHashMap, Collections.synchronizedMap(), created baclground Threads for put(), used delays to wait for update, etc. bla bla. I just can't get it to work.
It always updates the Map a few hundred milliseconds after polling, when I use delay, it still does.
If there's anyone who can help me on that issue, it would be highly appreciated.
Click to expand...
Click to collapse
@rovo89 @C3C076
Sent using my nexus⁴ running Euphoria 1.1 with Xposed and hells-Core B80
Hit thanks if I helped!
Again, a map is updated immediately. You can verify this by getting the value immediately after putting it into the map, from the same place. For accessing the values from other threads, you use synchronization, but with the methods you tried, this doesn't seem to be the problem. So it's probably something else in your code, like trying to access the variable from a different process. You could log pid and tid for debugging whenever you access the map.
rovo89 said:
Again, a map is updated immediately. You can verify this by getting the value immediately after putting it into the map, from the same place. For accessing the values from other threads, you use synchronization, but with the methods you tried, this doesn't seem to be the problem. So it's probably something else in your code, like trying to access the variable from a different process. You could log pid and tid for debugging whenever you access the map.
Click to expand...
Click to collapse
Ok, thanks. I now found out the Map updating happened at the onPause logic in the same process, my LockActivity uses another Map, like you said.
Could you point me to an easy and fast database solution? Maybe something like XSharedPreferences at public storage with write support? Could you maybe even create such thing for XposedBridge?
C3C076 said:
One possible reason is you are putting items to map within one process (belonging to your MY_PACKAGE_NAME) and
attempting to read map from different process (e.g. "android.app.Activity"). I believe you cannot see items put to map from one process to be "visible" by different process. Each process has its own instance of TEMPS map with own items in it. The contents of map is not shared across processes.
You have to think about using different approach.
Instead of memory store, use file system or DB which all processes you are hooking would have access to.
Click to expand...
Click to collapse

How to hook all * extends java.io.Reader|Writer

I am trying to write a module that hooks (first off all, later only specific) in/output streams and readers/writers to analyze the content.
First try was to hook java.io.Reader.read with all 3 read method signatures - this didn't show very much, so I guess it only hooks real java.io.Reader, and every method who overrides the specific method without calling super will not get hooked.
So I tried to just get all classes and look, if they are java.io.Reader.class.isAssignableFrom(every_single_class) //all classes that extend Reader, or a check if Reader r = new c();
- it turned out it is harder than i thought to get all loaded classes from a classloader.
Tried so far:
1. In desktop-oracle-java you could, via reflection, make the classes-field of a classloader (from the LoadPackageParam lpparam) visible, and it would contain an array of all classes. Android Java does not have this - this field simply doesn't exist.
2. Digging deeper into the android source, it seems like the VMClassLoader inside the normal classloader handles this, but it internally it calls a native loadclass method, so I can't access this data here.
3. My next try was to use the reflections.org lib (pulled via maven) - and every suggested method like getSubTypesOf(Object.class) and many others.
4. Now i tried to hook loadClass of classLoader, but this seemed to lead to an stackoverflow or something like that, i think.
5. I also tried to hook findClass of classLoader, but it seemingly never gets called?
So, what is the correct way to get all subclasses of java.io.Reader (inside a specific classloader) in XPosed framework? To me, it doesn't seem to be a too weird feature to have.
Also: Is there a way that I don't have to restart my phone after every new app version? Or to at least disable the "optimizing 100 apps" on every third boot. (Carbon rom, Android 5.1)
bump. im also interested in this
Very interestd topic!
I found a github project that should be able to do this, and I think I also found the according class.
github.com/baer-devl/DAMN/blob/master/src/at/fhooe/mcm14/damn/xposed/XHookAll.java (i'm currently not allowed to post real links because <10 posts)
There is also a 90-pages master thesis with about ~10 pages about hooking. If someone is interested, I can ask if the author allows to publish/upload it.

Categories

Resources