Objection to Tutorials

Search This thread

mohamedrashad

Senior Member
Nov 15, 2012
1,087
618
26
ismailia
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
 

mohamedrashad

Senior Member
Nov 15, 2012
1,087
618
26
ismailia
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
 

Jonny

Retired Forum Moderator
Jul 22, 2011
9,293
9,616
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.
 

mohamedrashad

Senior Member
Nov 15, 2012
1,087
618
26
ismailia
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.

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
 

Jonny

Retired Forum Moderator
Jul 22, 2011
9,293
9,616
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

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.
 

mohamedrashad

Senior Member
Nov 15, 2012
1,087
618
26
ismailia
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.

Simpler than Java :D I should learn it soon
 

Jonny

Retired Forum Moderator
Jul 22, 2011
9,293
9,616
Simpler than Java :D I should learn it soon

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();
                }
            });
        }
    }
 
Last edited:

mohamedrashad

Senior Member
Nov 15, 2012
1,087
618
26
ismailia
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();
                }
            });
        }
    }


i'm just wondering why apk tool don't give us Java code :p The development would be easier :D:D
 

Jonny

Retired Forum Moderator
Jul 22, 2011
9,293
9,616
i'm just wondering why apk tool don't give us Java code :p The development would be easier :D:D

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:
 

Jonny

Retired Forum Moderator
Jul 22, 2011
9,293
9,616
@Jonny


Have a look at this tool I found - maybe useful maybe not

http://xdaforums.com/showthread.php?p=52853769

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.
 

TheFixItMan

Senior Member
Jul 8, 2012
7,844
4,052
London
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

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
 

mohamedrashad

Senior Member
Nov 15, 2012
1,087
618
26
ismailia
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

You should learn programming, for pc or android, you are missing a lot of fun here :D
 

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    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

    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.
    2
    Simpler than Java :D I should learn it soon

    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();
                    }
                });
            }
        }
    2
    i'm just wondering why apk tool don't give us Java code :p The development would be easier :D:D

    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:
    1
    The thread is in its right place....

    ya GUIDE Codes shoul be explaind