Related
Hi there,
I'm having a big issue, when trying to remove an XElement from an XML file created in IsolatedStorage.
--------------------------------------------------------------------------------------------
Code to CREATE the XML file
Dim File_to_Create As String = "Tracks.xml"
Dim file As XDocument = <?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlnsd="urn:schemas-microsoft-comfficedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Cartridges.xsd" generated="2010-11-23T14:26:55">
<Carts>
<CART_NAME>First</CART_NAME>
<CART_COLOR>White</CART_COLOR>
</Carts>
<Carts>
<CART_NAME>Second</CART_NAME>
<CART_COLOR>Black</CART_COLOR>
</Carts>
</dataroot>
Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Try
If isoStore.FileExists(File_to_Create) Then
MessageBox.Show(File_to_Create + " TRUE")
Else
MessageBox.Show(File_to_Create + " FALSE")
Dim oStream As New IsolatedStorageFileStream(File_to_Create, FileMode.Create, isoStore)
Dim writer As New StreamWriter(oStream)
writer.WriteLine(file)
writer.Close()
MessageBox.Show("OK")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'open selected file
Dim isoStream As IsolatedStorageFileStream
isoStream = New IsolatedStorageFileStream(File_to_Create, System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore)
Dim XML_File As XDocument = XDocument.Load(isoStream)
Dim Cart_Query As System.Collections.IEnumerable = From query In XML_File.Descendants("Carts") Order By _
CStr(query.Element("CART_NAME")) Descending, CStr(query.Element("CART_NAME"))
Select New Class_Cartridge_Data With {.Cart_Name = CStr(query.Element("CART_NAME")), _
.Cart_Color = CStr(query.Element("CART_COLOR"))}
Me.ListBox_Cartridges.ItemsSource = Cart_Query
isoStore.Dispose()
isoStream.Close()
End Try
--------------------------------------------------------------------------------------------
Code to ADD / EDIT XElement
Dim File_to_Create As String = "Tracks.xml"
Dim XML_IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()
' Check that the file exists if not create it
If Not (XML_IsolatedStorage.FileExists(File_to_Create)) Then
Return
End If
Dim XML_StreamReader As New StreamReader(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Read))
Dim XML_Document As XDocument = XDocument.Parse(XML_StreamReader.ReadToEnd())
XML_StreamReader.Close()
' Update the element if it exist or create it if it doesn't
Dim XML_XElement As XElement = XML_Document.Descendants("Carts").Where(Function(c) c.Element("CART_NAME").Value.Equals("First")).FirstOrDefault()
If XML_XElement IsNot Nothing Then
XML_XElement.SetElementValue("CART_NAME", "Third")
Else
' Add new
Dim newProgress As New XElement("Cartridges", New XElement("CART_NAME", "Fourth"), New XElement("CART_COLOR", "Blue"))
Dim rootNode As XElement = XML_Document.Root
rootNode.Add(newProgress)
End If
Using XML_StreamWriter As New StreamWriter(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Write))
XML_StreamWriter.Write(XML_Document.ToString())
XML_StreamWriter.Close()
End Using
--------------------------------------------------------------------------------------------
Now my issue and request for some help!
If I use
XML_XElement.Remove
then the following exception is raised whenever I try to "refresh" the bounded ListBox
System.Xml.XmlException was unhandled
LineNumber=37
LinePosition=12
Message=Data at the root level is invalid. Line 37, position 12.
SourceUri=""
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(Int32 res, String resString, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 res, String resString)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream)
at ListBox_Data_from_XML_LINQ.MainPage.Button_Create_XML_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:
--------------------------------------------------------------------------------------------
In short, I can add or edit, but cannot DELETE an XElement...
Any ideas?
Thanks in advance!
Can you post the code you are using for XElement.Remove and use code tags so the formatting is right. Its the # button on the post toolbar.
Ren13B said:
Can you post the code you are using for XElement.Remove and use code tags so the formatting is right. Its the # button on the post toolbar.
Click to expand...
Click to collapse
Well, I did nothing special, just the XML_Element.remove, instead of adding a new xelement.
Then the error raises whenever I try to reopen the XML file.
My point is, how can I delete an specific xelement?
As far as I know, the following code should work
Code:
Dim XML_XElement As XElement = XML_Document.Descendants("Carts").Where(Function(c ) c.Element("CART_NAME").Value.Equals("First")).Firs tOrDefault()
If XML_XElement IsNot Nothing Then
XML_XElement.SetElementValue("CART_NAME", "Third")
Else
' remove the selected record
XML_XElement.Remove
End If
Honestly I don't know if the foregoing code is correct or if the issue is related to how WP7 handles the removal thus corrupting the original file.
Please let me know if you need anything else.
Any help is very appreciated!
PS: Thanks for the other replies, helped a lot!
Here's how I did it in c#. My xml file is very different than yours so the query will be different but the important parts are where you load and close the file streams and then write.
Code:
//Get users private store info
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
//open selected file
isoStream = new IsolatedStorageFileStream(list, System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
XDocument xml = XDocument.Load(isoStream);
isoStream.Close();
//Find section
XElement sectionElement = xml.Descendants("section").Where(c => c.Attribute("name").Value.Equals(groupn)).FirstOrDefault();
//Find item and remove it
sectionElement.Elements("setting").Where(c => c.Attribute("name").Value.Equals(litem)).FirstOrDefault().Remove();
isoStream.Close(); //Seems unnecessary but it's needed.
//Write xml file
isoStream = new IsolatedStorageFileStream(list, FileMode.Create, FileAccess.Write, isoStore);
xml.Save(isoStream);
isoStream.Close();
Thanks again for your help, greatly appreciated.
However I'm still getting the same error.
Sorry for asking, but are you getting any errors when deleting in WP7 ?
My knowledge on XML is extremely new and I'm sure that I'm making some mistakes somewhere...
But so far, I cannot get past the same exception.
Seems that the XML gots "corrupted" after the delete operation.
On the other hand, if is not too much to ask for, using my current code, how will handle the delete of the selected record?
Thanks!
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Ren13B said:
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Click to expand...
Click to collapse
Problem is my country is not listed so I cannot register...
Here is the C# version of my current code for adding/editing
Code:
public static void ADD_XML_Record()
{
string File_to_Create = "Tracks.xml";
var XML_IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
// Check that the file exists if not create it
if (! (XML_IsolatedStorage.FileExists(File_to_Create)))
{
return;
}
StreamReader XML_StreamReader = new StreamReader(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Read));
XDocument XML_Document = XDocument.Parse(XML_StreamReader.ReadToEnd());
XML_StreamReader.Close();
// Update the element if it exist or create it if it doesn't
XElement XML_XElement = XML_Document.Descendants("Carts").Where((c) => c.Element["CART_NAME"].Value.Equals("dd")).FirstOrDefault();
if (XML_XElement != null)
{
XML_XElement.SetElementValue("CART_NAME", "bbbbb");
}
else
{
// Add new
XElement newProgress = new XElement("Carts", new XElement("CART_NAME", "dd"), new XElement("CART_COLOR", "ff"));
XElement rootNode = XML_Document.Root;
rootNode.Add(newProgress);
}
using (StreamWriter XML_StreamWriter = new StreamWriter(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Write)))
{
XML_StreamWriter.Write(XML_Document.ToString());
XML_StreamWriter.Close();
}
}
I tried your code but I'm having a bad time making it to work.
If not a big deal, please could you tell me how to modify it ?
I mean, if a record is found, instead of editing, to remove it?
Honestly I'm stuck and any help is more than apprecisted!
Ren13B said:
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Click to expand...
Click to collapse
Ren,
Just to say thank you for your last code. I made a little mod and now it works ok!
Thanks a lot for helping me out!
So I don't know if this is an obvious question or not. There's something I want to change in the NetworkController.java class in the SystemUI.apk. I found what I need to do by looking at the Android source code. So after much research I downloaded APK manager and decompiled the apk. But now I have these smali files which I've read are the assembler for the dex format produced by the dalvik vm. So I don't know what to do now? Is this what I have to try to edit? Because I have no idea what's going on in NetworkController.smali. I know what I need to change in the java code... But I'm clueless with the smali? Is there another step here I missing that turns the smali into java code I can edit? Or is this really how people edit this stuff?!
Thanks!
Edit: So from more research it looks like the only way to edit the actual java code of the SystemUI.apk is to do it in the source and then compile my own rom. That's a lot of work for about 5 lines of a code I need to change. Is this really the case?
Edit 2: I've been doing a lot of research into this and I now know the exact lines that need to be changed to make this possible. Within com.android.systemui.statusbar.policy.NetworkController (In SystemUI.apk) there is a switch statement that decides the icon to be displayed based on the network. Part of this switch is as follows:
Code:
521 case TelephonyManager.NETWORK_TYPE_HSDPA:
522 case TelephonyManager.NETWORK_TYPE_HSUPA:
523 case TelephonyManager.NETWORK_TYPE_HSPA:
524 case TelephonyManager.NETWORK_TYPE_HSPAP:
525 if (mHspaDataDistinguishable) {
526 mDataIconList = TelephonyIcons.DATA_H[mInetCondition];
527 mDataTypeIconId = R.drawable.stat_sys_data_connected_h;
528 mContentDescriptionDataType = mContext.getString(
529 R.string.accessibility_data_connection_3_5g);
530 } else {
531 mDataIconList = TelephonyIcons.DATA_3G[mInetCondition];
532 mDataTypeIconId = R.drawable.stat_sys_data_connected_3g;
533 mContentDescriptionDataType = mContext.getString(
534 R.string.accessibility_data_connection_3g);
535 }
536 break;
So as you can see, the switch statement puts all the types of HSPA together into one case (by not breaking it falls through all of them to the last one), which is why it shows H no matter what. All that needs to be done here is to change it so HSPAP has its own case in which it uses the 4G icon (or an added H+ icon if so desired). I've actually been doing a lot of research today to see if I could just pull the SystemUI.apk from my rom, decompile it, make this modification, recompile, and push it back to do this myself... But I've now learned lots about how android (or the dalvik vm) compiles the java into smali assembly code and that's what I get from decompiling the apk. Not the java code. So this is not just a simple edit .
So is there any chance this could be added? Or could someone point me in a better direction as to how to make this modification myself? The smali code is extremely confusing. I'm not sure if it's even possible to edit the smali to do this, not that I would know where to start. It seems this has to be done before the ROM is compiled?
Thanks for the consideration! And I welcome any help!
BraydenJames said:
So I don't know if this is an obvious question or not. There's something I want to change in the NetworkController.java class in the SystemUI.apk. I found what I need to do by looking at the Android source code. So after much research I downloaded APK manager and decompiled the apk. But now I have these smali files which I've read are the assembler for the dex format produced by the dalvik vm. So I don't know what to do now? Is this what I have to try to edit? Because I have no idea what's going on in NetworkController.smali. I know what I need to change in the java code... But I'm clueless with the smali? Is there another step here I missing that turns the smali into java code I can edit? Or is this really how people edit this stuff?!
Thanks!
Edit: So from more research it looks like the only way to edit the actual java code of the SystemUI.apk is to do it in the source and then compile my own rom. That's a lot of work for about 5 lines of a code I need to change. Is this really the case?
Edit 2: I've been doing a lot of research into this and I now know the exact lines that need to be changed to make this possible. Within com.android.systemui.statusbar.policy.NetworkController (In SystemUI.apk) there is a switch statement that decides the icon to be displayed based on the network. Part of this switch is as follows:
Code:
521 case TelephonyManager.NETWORK_TYPE_HSDPA:
522 case TelephonyManager.NETWORK_TYPE_HSUPA:
523 case TelephonyManager.NETWORK_TYPE_HSPA:
524 case TelephonyManager.NETWORK_TYPE_HSPAP:
525 if (mHspaDataDistinguishable) {
526 mDataIconList = TelephonyIcons.DATA_H[mInetCondition];
527 mDataTypeIconId = R.drawable.stat_sys_data_connected_h;
528 mContentDescriptionDataType = mContext.getString(
529 R.string.accessibility_data_connection_3_5g);
530 } else {
531 mDataIconList = TelephonyIcons.DATA_3G[mInetCondition];
532 mDataTypeIconId = R.drawable.stat_sys_data_connected_3g;
533 mContentDescriptionDataType = mContext.getString(
534 R.string.accessibility_data_connection_3g);
535 }
536 break;
So as you can see, the switch statement puts all the types of HSPA together into one case (by not breaking it falls through all of them to the last one), which is why it shows H no matter what. All that needs to be done here is to change it so HSPAP has its own case in which it uses the 4G icon (or an added H+ icon if so desired). I've actually been doing a lot of research today to see if I could just pull the SystemUI.apk from my rom, decompile it, make this modification, recompile, and push it back to do this myself... But I've now learned lots about how android (or the dalvik vm) compiles the java into smali assembly code and that's what I get from decompiling the apk. Not the java code. So this is not just a simple edit .
So is there any chance this could be added? Or could someone point me in a better direction as to how to make this modification myself? The smali code is extremely confusing. I'm not sure if it's even possible to edit the smali to do this, not that I would know where to start. It seems this has to be done before the ROM is compiled?
Thanks for the consideration! And I welcome any help!
Click to expand...
Click to collapse
It's as simple as you think. Add a new case (removing the HSPAP case from the existing one) and use syntax as per the code snippet above. You'll need add the drawable or reuse an existing one. Keep the 'else' condition as well for fallback.
I'd reuse an existing drawable first (even a random WiFi or roaming one) just to check that your actual smali edit is good, then trace back the drawable requirements and add the image. You'll need to update the string as well if you want it distinguishable (wherever it's used).
If the edit is really a dud apktool will throw errors when you re-encode it.
You can just compile that systemUI apk, no need to do the whole rom.
Read this thread to do the same thing, first post.
http://forum.xda-developers.com/showthread.php?t=1409540&goto=newpost
RogerPodacter said:
You can just compile that systemUI apk, no need to do the whole rom.
Read this thread to do the same thing, first post.
http://forum.xda-developers.com/showthread.php?t=1409540&goto=newpost
Click to expand...
Click to collapse
Oh okay. So I do need to sync with the source. But I can just build the SystemUI.apk?
Yes you can. It should be spelled out in that link in the first post.
I canĀ“t find the text in: com.android.systemui.statusbar.policy.NetworkController
Any idea?
Great developers all over xda make good guides and awesome mods.but all they do is writing the mod and say copy to bla bla and you are done. This don't create a real developer. I think you should explain the codes to us. If you don't mind some people wanna learn here
True but you should move the thread to the General section.
Deleted
The thread is in its right place....
ya GUIDE Codes shoul be explaind
I know java well, but most of Guides are on Smali language, I don't like copy paste cause I wanna learn it right, So what's the problem in explaining mods
@Jonny pls move this to general section, thanks
If you want to know what smali functions do then download Virtuous Ten Studio by Diamondback and the rest of the Virtuous team then look in the included smali help section.
Jonny said:
If you want to know what smali functions do then download Virtuous Ten Studio by Diamondback and the rest of the Virtuous team then look in the included smali help section.
Click to expand...
Click to collapse
I don't mean the smali basics, I meant explaining mods in depth instead of this Copy-Paste, I will check VTS asap, thanks for suggestion
mohamedrashad said:
I don't mean the smali basics, I meant explaining mods in depth instead of this Copy-Paste, I will check VTS asap, thanks for suggestion
Click to expand...
Click to collapse
With smali you are basically just moving numbers around and calling other methods (invoke and invoke-virtual) - usually you store the result in a register for example v0. Then you've got you're comparison statements like if-ne (if not equal), if-eq (if equal), if-nez (if not equal to zero) etc. Then you can also call resources by using the hex values in public.xml, eg const v4, "0x070000" for example.
Once you know the basic functions and principals of the language then its fairly easy to follow the code of the mods to find out what they're doing and what they're changing.
Jonny said:
With smali you are basically just moving numbers around and calling other methods (invoke and invoke-virtual) - usually you store the result in a register for example v0. Then you've got you're comparison statements like if-ne (if not equal), if-eq (if equal), if-nez (if not equal to zero) etc. Then you can also call resources by using the hex values in public.xml, eg const v4, "0x070000" for example.
Once you know the basic functions and principals of the language then its fairly easy to follow the code of the mods to find out what they're doing and what they're changing.
Click to expand...
Click to collapse
Simpler than Java I should learn it soon
mohamedrashad said:
Simpler than Java I should learn it soon
Click to expand...
Click to collapse
Ha! I wish, to do for example the following in java
Code:
Integer i = 1;
if (i = 0) {
return "wtf is happening!";
} else {
return "everything is normal";
}
in smali would be something like:
Code:
const v1, 0x1
const-string v2, "wtf is happening"
const-string v3, "everything is normal"
if-eqz v1 :cond_0
return v3
:cond_0
return v2
My syntax is probably not correct but this was just something wrote off the top of my head so... :highfive: Point is what you can do relatively easily in java with a couple of lines of code can be a pain in the neck and take up a lot of lines to do in smali - especially with more complex functions.
For example I'd hate to have to try and do something like this in smali (code snippet from an app I've made for my school).
Code:
class LoadNews extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgress = new ProgressDialog(getSherlockActivity());
mProgress.setMessage("Loading news, Please wait...");
mProgress.setIndeterminate(false);
mProgress.setCancelable(true);
mProgress.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(AllNewsItemsURL, "GET", params);
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
newsItems = json.getJSONArray(NEWS);
for (int i = 0; i < newsItems.length(); i++) {
JSONObject obj = newsItems.getJSONObject(i);
Integer id = i + 1;
String title = obj.getString(TITLE);
String story = obj.getString(STORY);
String imageSrc = IMAGE_DIR_URL + obj.getString(IMAGE_SRC);
String date = obj.getString(DATE);
story = replace(story, imageSrc);
date = buildDate(date);
if (id > dbhandler.getNewsCount()) {
dbhandler.addNews(new News(id, title, story, imageSrc, date));
} else {
dbhandler.updateNews(new News(id, title, story, imageSrc, date));
}
if (isCancelled() || FlagCancelled) break;
}
} else {
Log.e("JSON Response", "success == 0");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
mProgress.dismiss();
getSherlockActivity().runOnUiThread(new Runnable() {
public void run() {
getNewsList();
}
});
}
}
Jonny said:
Ha! I wish, to do for example the following in java
Code:
Integer i = 1;
if (i = 0) {
return "wtf is happening!";
} else {
return "everything is normal";
}
in smali would be something like:
Code:
const v1, 0x1
const-string v2, "wtf is happening"
const-string v3, "everything is normal"
if-eqz v1 :cond_0
return v3
:cond_0
return v2
My syntax is probably not correct but this was just something wrote off the top of my head so... :highfive: Point is what you can do relatively easily in java with a couple of lines of code can be a pain in the neck and take up a lot of lines to do in smali - especially with more complex functions.
For example I'd hate to have to try and do something like this in smali (code snippet from an app I've made for my school).
Code:
class LoadNews extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgress = new ProgressDialog(getSherlockActivity());
mProgress.setMessage("Loading news, Please wait...");
mProgress.setIndeterminate(false);
mProgress.setCancelable(true);
mProgress.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(AllNewsItemsURL, "GET", params);
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
newsItems = json.getJSONArray(NEWS);
for (int i = 0; i < newsItems.length(); i++) {
JSONObject obj = newsItems.getJSONObject(i);
Integer id = i + 1;
String title = obj.getString(TITLE);
String story = obj.getString(STORY);
String imageSrc = IMAGE_DIR_URL + obj.getString(IMAGE_SRC);
String date = obj.getString(DATE);
story = replace(story, imageSrc);
date = buildDate(date);
if (id > dbhandler.getNewsCount()) {
dbhandler.addNews(new News(id, title, story, imageSrc, date));
} else {
dbhandler.updateNews(new News(id, title, story, imageSrc, date));
}
if (isCancelled() || FlagCancelled) break;
}
} else {
Log.e("JSON Response", "success == 0");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
mProgress.dismiss();
getSherlockActivity().runOnUiThread(new Runnable() {
public void run() {
getNewsList();
}
});
}
}
Click to expand...
Click to collapse
i'm just wondering why apk tool don't give us Java code The development would be easier
mohamedrashad said:
i'm just wondering why apk tool don't give us Java code The development would be easier
Click to expand...
Click to collapse
That's to do with the Dalvik VM android apps run on. If you compiled standard java files (.java) for a standard java applet then those files would be compiled into .class files (which can be "reverse engineered" - though not particularly well and all reverse engineer software available for java currently should be used for guidance only as the code they output is nowhere near the original.
For android apps, these .class files are further compiled into a dalvik executable file with extension .dex - in an apk file this is called classes.dex. You can think of a classes.dex file as a compiled .exe file - you can't easily get readable/correct source of it. Exe files are therefore reverse engineered into their byte-code which is in a low-level language called Assembly Language (ASM).
Dalvik executables work in much the same way that they can be decompiled to their byte-code, which allows them to be edited without having the full source - unlike using a java decompiler, they give correct code for the language they are written in. The dalvik byte-code is the smali language so you can think of smali as the dalvik equivalent of ASM.
In short term, smali is editable and can be recompiled and run with no problems whereas code produced by current java decompilers cannot be used to make changes and then recompiled due to incorrect code given, so in this instance it was better for apktool to give a smali output :good:
mohamedrashad said:
i'm just wondering why apk tool don't give us Java code The development would be easier
Click to expand...
Click to collapse
@Jonny
Have a look at this tool I found - maybe useful maybe not
http://forum.xda-developers.com/showthread.php?p=52853769
marcussmith2626 said:
@Jonny
Have a look at this tool I found - maybe useful maybe not
http://forum.xda-developers.com/showthread.php?p=52853769
Click to expand...
Click to collapse
That doesn't seem too bad considering the likes of JAD and JD-GUI, however, I can still 100% guarantee that if you put that into Android Studio (or Eclipse but I prefer AS), it would not compile
Best to use decompiled java as a guideline or to search for methods you want to make mods out of - eg increasing the maximum number of pages in the HTC Sense 6.0 launcher (Prism.apk) you search for the method getMaxPageCount() in the decompiled java code, have a look at what the java was like then find out where to change the values and then do the actual mod in smali.
marcussmith2626 said:
@Jonny
Have a look at this tool I found - maybe useful maybe not
http://forum.xda-developers.com/showthread.php?p=52853769
Click to expand...
Click to collapse
These apps (java decompiler) are good to learn some tricks in apps but non give a ready-to-import Eclipse project which make them 75% useless
mohamedrashad said:
These apps (java decompiler) are good to learn some tricks in apps but non give a ready-to-import Eclipse project which make them 75% useless
Click to expand...
Click to collapse
I dont have any experience of programming so I dont know the use of these things but I spose Its interesting to compare
My main expertise is end user software/hardware support and repair for pcs/laptops - I just look at android as a hobby for fun as something different
marcussmith2626 said:
I dont have any experience of programming so I dont know the use of these things but I spose Its interesting to compare
My main expertise is end user software/hardware support and repair for pcs/laptops - I just look at android as a hobby for fun as something different
Click to expand...
Click to collapse
You should learn programming, for pc or android, you are missing a lot of fun here
Hello all,
Just curious about some general knowledge (salute; reference: HIMYM) on whether or not it's possible to see what an app is doing (during installation, in the background, app initialization, and foreground usage)
It's not my own app in question so I understand physically seeing the code is out of the question; however I'm more concerned about what the app is doing and the files/directories it accesses, and whether or not there's a way for me to view these activities.
If you must know, the app in question is the Adidas Confirmed app as RootCloak (and various other apps) DO NOT WORK. I'm attempting to isolate the issue, and I'm fairly certain it has to do with an external resource (within the device; i.e. different partition, files, folders, etc.) that permanently marks the device 'rooted' during initial installation. Maybe if I can see exactly what the app reaches out to, I can then come up with a fix action.
Any input would be greatly appreciated.
You could try to decompile this app, but it might not work very well if the app obfuscates the code http://decompileandroid.com/
Rijul.A said:
You could try to decompile this app, but it might not work very well if the app obfuscates the code http://decompileandroid.com/
Click to expand...
Click to collapse
This actually worked PERFECTLY. I was able to go inside the src and see exactly the commands the app calls for to check root.
If anyone is interested...I'm going to try a few things out, play with some variables and see if I can't allow the app access on my rooted device.
Code:
// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: braces fieldsfirst space lnc
package com.gpshopper.adidas.objects;
import android.os.Build;
import java.io.File;
// Referenced classes of package com.gpshopper.adidas.objects:
// ExecShell
public class Root
{
private static String LOG_TAG = com/gpshopper/adidas/objects/Root.getName();
public Root()
{
}
public static boolean checkRootMethod1()
{
String s = Build.TAGS;
return s != null && s.contains("test-keys");
}
public static boolean checkRootMethod2()
{
label0:
{
label1:
{
boolean flag = false;
boolean flag1;
try
{
File file = new File("/system/app/Superuser.apk");
File file1 = new File("/system/app/SuperSU/SuperSU.apk");
if (file.exists())
{
break label1;
}
flag1 = file1.exists();
}
catch (Exception exception)
{
return false;
}
if (!flag1)
{
break label0;
}
}
flag = true;
}
return flag;
}
public static boolean checkRootMethod3()
{
return (new ExecShell()).executeCommand(ExecShell.SHELL_CMD.check_su_binary) != null;
}
public static boolean isDeviceRooted()
{
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
}
}
There is a similar file also in the src using a different language I've not yet been able to comprehend. I'm really new at this in case you couldn't already figure lol...is it possible to view my device's database where apps store variables? It may be possible the app is permanently storing the variable even after its removal so best case would be to start from a fresh ROM install. Just a theory.
The other language is generally irrelevant
Delete /data/data/<packagename>/ or clear app data normally, that will work, no need for a fresh install.
If you need help hooking this method, please quote me in a reply.
I am trying to change the emojies inside of Facebook Messenger by the ones from EmojiOne.
In the first place, I decompiled through dex2jar the messenger APK and did quite a bit of search but no luck, it is obfuscated and pretty hard to read.
So my second guess was to replace each emoji in the resources. To do that, I used aapt to get one and try it:
HTML:
> aapt dump resources msg.apk | grep 1f60f
resource 0x7f020eca com.facebook.orca:drawable/messenger_emoji_1f60f_32: t=0x03 d=0x000017b3 (s=0x0008 r=0x00)
resource 0x7f020ecb com.facebook.orca:drawable/messenger_emoji_1f60f_64: t=0x03 d=0x000017b2 (s=0x0008 r=0x00)
resource 0x7f0c2086 com.facebook.orca:string/emoji_1f60f: t=0x03 d=0x00003439 (s=0x0008 r=0x00)
I tried this :
HTML:
public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable {
if (!resparam.packageName.equals("com.facebook.orca"))
return;
XModuleResources modRes = XModuleResources.createInstance(MODULE_PATH, resparam.res);
resparam.res.setReplacement("com.facebook.orca", "drawable", "messenger_emoji_1f60f_32", modRes.fwd(R.drawable.emojione_emoji_1f60f_32));
resparam.res.setReplacement("com.facebook.orca", "drawable", "messenger_emoji_1f60f_64", modRes.fwd(R.drawable.emojione_emoji_1f60f_64));
}
and quite a few other things, but nothing seems to work. My drawable is working since I tried it in an Activity.
Even though I can get this working, would this be a proper solution to my original problem ?
Will I need to replace EACH emoji one by one in the two sizes ?
Thanks in advance
Bump please, no one?
Up for this thanks
This doesn't solve your problem, but I recently decompiled a proguarded apk too, and couldn't find the right resources easily. I found a method too do so though.
First, install xinstaller, then under misc enable debugging apps (allows debugging any app).
Next, connect your phone, make sure adb is on and connected, open Facebook and go to a conversation. Send some emoji too.
In Android studio, go into Android device monitor (ddms), tools -> Android -> Android device monitor. MAKE SURE YOU SET DDMS UP first
Now, find the button in the toolbar that says something like ui automator dump . This will take a layout dump of your displayed screen and give you a screenshot that you can use to click on various layout objects. You will be able to select the emoji and see what resource id is associated with it.
Or at least, it will give you a method to start looking for the resource id's. Combined with a tool like grep for windows, checking out public.xml for the ID's (they're in hex, but if you want to search in code for the ID, convert it to decimal). And you can pretty much find where the code and resource ID's are now !