11 February 2013

How to decompile apk from Play Store

No comments:

This is how you can decompile an application you have installed on your phone.

My phone is rooted, uses RootBox 3.5 and has BusyBox installed. You may need to have that too if you want to follow my steps completly.

Let's start:

1. Install application from market

2. Download apk to computer

First you need to locate the apk on the phone.

Connect to the phone:

 adb shell

Find the apk in the folder the apk are downloaded to. It is ussualy in '/data/app/' or '/system/app/'. The apk is called as the id from the Play Store, for example 'com.something.someapp.apk'. You can see this in the url from Play.

Next you need to pull it to the computer. Once you have located the apk and know it's name exit adb.

On your PC execute:

 adb pull /data/app/com.something.someapp.apk 

3. Transform apk to jar

I use dex2jar
dex2jar-0.0.9.11/d2j-dex2jar.sh com.something.someapp.apk

4. See the code inside the jar

I use Java Decompiler

Just open the program and open the jar.

5. Get the resources

You can just unzip the apk. This will allow you to get the images but not the xml and layouts.

Instead you could use android-apktool. After you download and install it, just run:
apktool d com.something.someapp.apk

I know it's not very complicated but I needed a place to put this so I can remember the details.

Enjoy!

Update: Intellij 12 + Android Annotations 2.7 + maven

3 comments:
This is my previous post updated for the new versions of intelliJ Idea 12 and Android Annotations 2.7

1. Create your project with Android Maven Plugin

Read the GettingStarted

You can run this command to get the basic structure:

mvn archetype:generate \
  -DarchetypeArtifactId=android-quickstart \
  -DarchetypeGroupId=de.akquinet.android.archetypes \
  -DarchetypeVersion=1.0.9 \
  -DgroupId=com.tagonsoft \
  -DartifactId=ExampleApp

Add/Edit the dependency to android:

With android from central mvn repository:

  com.google.android
  android
  4.1.1.4

Or with android from maven-android-sdk-deployer:

  android
  android
  4.2_r1
  provided

Run 'mvn idea:idea' to get the basic idea project to start with.

2. Add AndroidAnnotations to maven pom.xml

  

  com.googlecode.androidannotations
  androidannotations
  2.7.1
  provided



  com.googlecode.androidannotations
  androidannotations-api
  2.7.1
                                          

3. Configure Idea compiler

Like so:
I couldn't get it to work with processor from classpath, so I use the path from maven repo. For intelliJ Idea 12 you have to add 3 jars like so (the path are from my own mvn repo):
/work/libs/mvnrepo/com/googlecode/androidannotations/androidannotations/2.7.1/androidannotations-2.7.1.jar:/work/libs/mvnrepo/com/googlecode/androidannotations/androidannotations-api/2.7.1/androidannotations-api-2.7.1.jar:/work/libs/mvnrepo/com/sun/codemodel/codemodel/2.4.1/codemodel-2.4.1.jar

The jars are androidannotations-2.7.1.jar, androidannotations-api-2.7.1.jar and codemodel-2.4.1.jar. The separator is ':'.

Add as processor FQ name:

com.googlecode.androidannotations.AndroidAnnotationProcessor

4. Tweak your module to regenerate R file in the new location:


I use <project path> + /target/generated-sources/r
Hope someone else finds this useful. Feel free to add or correct me.

30 September 2012

How I configure Intellij Idea 11 for Android, AndroidAnnotations 2.6 and maven

No comments:
I know there are many many posts about this. This is a summary of how I do, so I can have a place for copy paste.

1. Create your project with Android Maven Plugin

Read the GettingStarted

You can run this command to get the basic structure:

mvn archetype:generate \
  -DarchetypeArtifactId=android-quickstart \
  -DarchetypeGroupId=de.akquinet.android.archetypes \
  -DarchetypeVersion=1.0.8 \
  -DgroupId=com.tagonsoft \
  -DartifactId=ExampleApp

Add/Edit the dependency to android:

 
    com.google.android
    android
    4.0.1.2
    provided
 

2. Add AndroidAnnotations to maven pom.xml

  
                                             
    com.googlecode.androidannotations 
    androidannotations          
    2.6                               
    provided                              
                                            
                                                         
                                             
    com.googlecode.androidannotations 
    androidannotations          
    api                         
    2.6                               
                                            

3. Configure Idea compiler

Like so:
I couldn't get it to work with processor from classpath, so I use the path from maven repo:
/work/libs/mvnrepo/com/googlecode/androidannotations/androidannotations/2.6/androidannotations-2.6.jar
Add as processor FQ name:
com.googlecode.androidannotations.AndroidAnnotationProcessor
Add your module to the Processed modules section. Set Generated Sources Directory Name to:
target/generated-sources/annotations

4. Tweak your module to regenerate R file in the new location:


I use <project path> + /target/generated-sources/r
Remove the normal R folder from sources.
Sometimes Idea thinks it knows better and when it updates the maven project it overwrites your changes. The solution I found on the internet is to leave gen as sources and to exclude the folders beneath it. Like so:
Hope someone else finds this useful. Feel free to add or correct me.

13 February 2010

Groovy way to see if thread execution had errors

1 comment:
I had to write a script that did something and for a faster run I decided to use threads.
I needed to start a thread to do some task and then to be able to check that it had finished without an error/exception.
In Java if the code executed in a new thread throws an error, it doesn't matter that much, it just executes the next instruction after thread.join().
Some solutions found on the internet were
  • to put all the code inside the thread in a try-catch block and in the catch block populate a map with the thread name and status. Then you could get the status by querying statusMap[threadName]
  • add a status status field to your class witch is a subclass of Thread. Then you do the same thing as above and in the catch block modify the status to failed (status is successfull in the begining). You get get the status by thread.status
Luckily in  groovy we have dynamic object behaviour.
So my solution is to add a new field to the Thread class, and use Thread.setDefaultUncaughtExceptionHandler to populate it.
It looks something like
Thread.metaClass.failed = false

Thread.setDefaultUncaughtExceptionHandler(
        {t, ex ->
          t.failed = true
        } as Thread.UncaughtExceptionHandler)

def th= Thread.start {
  println ' in thread 1'
  throw new RuntimeException("thread exception")
  println ' in thread 2'

}
th.join()

assert th.failed

And now I can see if any exception/error has been thrown. And all the threads I start will have this property.

04 February 2010

Religions with a sense of humor

No comments:
I just love it when a religion has a sense of humor.
Discordianists are my favorite.
Today I came across The TriPrimality from subgenius:

The TriPrimality:
"Bob" is.
"Bob" becomes.
"Bob" is not.
Nothing is; Nothing becomes; Nothing is not. Thus: Nothing Is Everything.
  Therefore: Everything is "Bob."
Abracadabra.

"I don't practice what I preach, because I'm not the kind of person I'm preaching to."--Bob
You have to admit that is funny.
And I can't close without mentioning my favorite religious person, Robert Anton Wilson.

"Spectacles, testicles, brandy, cigars -- you're all popes! You're all absolutely infallible. I have the authority to appoint anyone a Discordian Pope, because I'm a Discordian Pope. The first rule after you become a Discordian Pope is to excommunicate every Discordian Pope you meet. This is based on the basic Discordian principle that we Discordians must stick apart."  - RAW

so, what can I say ?

"Spectacles, testicles, brandy, cigars -- you're all popes! "

09 December 2009

Mohana- the witch of bring-a-thing

No comments:
This week we were asked something to bring a thing for "Bring A Thing", a kind of charity activity at work.
I brought a kind of jack in the box witch. Then I was asked to write a  story about it.
I thing it got out pretty well and I wanted to share it with you
To fully understand the story you should watch South Park , listen to some Manowar and live in Romania. It is still funny if you haven't done any of this, but...

Here it is:

Once upon a time in the land of far away yet so close you could feel it lived little Timmy.
He was a handicapped kid walking around in his wheel chair and singing Abba all day.
Timmy’s life was quite boring and ordinary, except when playing tanki online. He was a true champion then.
One day his parents wanted to surprise Timmy. So they sent little Timmy to leave with aunt whom he had never seen or heard of, Florgonzola.
Oh boy, finally an adventure, thought the child.
And finally he arrived. The weather was not so nice. It was autumn and raining, but hey, the tickets were cheaper because it was off-season.
So T is now with his ugly, quite stupid aunt. No adventure here, disappointed.
But wait, there is a forest near by. So, putting his off-road tires on his wheel chair the boy sets up for a quest.
In the middle of the forest there was an old house, seemed quite deserted.
The boy rushed in. After an hour he finally made it in to find an empty poor house.
“I’ll come at night, there must be a ghost here, or at least a spider, or a possessed squirrel, or maybe the wind will blow through the window to make buhuhu”. So the boy went every night, but still nothing special.
So the sixth night he arrived at his aunt home yet again disappointed, with his off-road tires torn apart by the sharp rocks of reality.
He entered the house to find what?
Florgonzola had transformed into an uglier, stupider witch, making soup out of weed and a bleeding deer leg.
“Come in, welcome desert”, she said. The boy understood that it made sense, it was also the sixth hour and the sixth minute, almost as much as some presidency lasted in some countries.
The boy was now terrified. He started to cry and swirl around until his tires caught fire. Then he decided to call his friends.
So he started his mp3 player and the “kings of metal” appeared from their kingdom of steel.
Using their sharp minds and their powerful guitars they enslaved the witch. Their music was not so good, but at least they were loud.
With her last words she promised that if she were to live she will only do good and change her name and looks to more nicer things.
The kings accepted with their kind minds.
Florgonzola was baptized under the sign of Odin all-powerful. Now she is named “MOHANA”. The kings of metal were pleased with yet another successful mission and the boy was given a steel horse called Pegus (because Pegas was a bike).
But she was still punished to live in a box.

From time to time she appears from the box to scare the bad thoughts and the bad enchantments around people, bringing luck and fortune.

BTW
Did you hear about the witch who was ashamed of her long black hair?
She always wore long gloves to cover it up.


18 November 2009

Ways to map and query many-to-many in GORM

3 comments:
I played with many-to-many relations in grails and found some interesting ways to work with them.
First the domain definitions.
For the purpose of this demo I chose the classic example with books and authors. A book may have many authors and an author may have many books.

class Author {
String name
}

class Book {
String name
}

What I consider the silliest way to define your domains I found here http://www.grails.org/Many-to-Many+Mapping+without+Hibernate+XML
They suggest mapping the join table using a domain object and creating the links by hand.
On 'books and authors' it would look like

class Book {
String name
static hasMany = [ memberships: Membership]

List authors() {
return memberships.collect {it.author}
}

List addToAuthors(Author author) {
Membership.link(this, author)
return authors()
}

List removeFromAuthors(Author author) {
Membership.unlink(this, author)
return authors()
}
}

class Author {
String name
static hasMany = [memberships: Membership]

List books() {
return memberships.collect {it.book}
}

List addToBooks(Book book) {
Membership.link(book, this)
return books()
}

List removeFromBooks(Book book) {
Membership.unlink(book, this)
return books()
}
}

class Membership {
Book book
Author author
static Membership link(book, author) {
def m = Membership.findByBookAndAuthor(book, author)
if (!m) {
m = new Membership()
book?.addToMemberships(m)
author?.addToMemberships(m)
m.save()
}
return m
}

static void unlink(book, author) {
def m = Membership.findByBookAndAuthor(book, author)
if (m) {
book?.removeFromMemberships(m)
author?.removeFromMemberships(m)
m.delete()
}
}
}

While this works it doesn't seam very elegant to me.
So, moving on, I found a better way to do it.

class Author {
String name

static hasMany = [books:Book]
}

class Book {
String name

static belongsTo = Author
static hasMany = [authors: Author]
}

This seems the best way. Or you could use hibernate annotations, but I won't treat that.
Now let's see how we can query these.
Let's say I want to get all the books written by an author.
First dynamic finders. This is done in 2 steps:

def author = Author.findByName(a_Name)
def books = author ? Book.findAllByAuthor(author) : []

With Hql it would look something like:

Book.executeQuery("from Book as b join b.authors a where a.name = :name order by b.name", [name: a_Name, max: max, offset: offset])
Book.findAll("from Book as b join b.authors a where a.name = :name order by b.name desc", [name: a_Name, max: max, offset: offset]);

This returns a list of arrays containing book and author
To get only the books use:

Book.executeQuery("select b from Book as b join b.authors a where a.name = :name order by b.name", [name: a_Name, max: max, offset: offset])

Finally, using criteria:

def criteria = Book.createCriteria()
def books = criteria.list {
authors {
eq('name', a_Name)
}
maxResults(max)
firstResult(offset)
order("name", "asc")
}

So these are some ways to query many-to-many relations with gorm, also using paging.
Hope it was helpful.