Thursday, March 12, 2015

How to install Python3 with brew(mac)

$brew install python3

You will see below process:
==> Installing dependencies for python3: xz, pkg-config, readline, sqlite, gdbm, openssl
==> Installing python3 dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.1.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.2.1.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/xz/5.2.1: 59 files, 1.7M
==> Installing python3 dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.28.yosemite.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.28.yosemite.bottle.2.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.28: 10 files, 612K
==> Installing python3 dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-6.3.8.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.3.8.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X provides similar software, and installing this software in
parallel can cause all kinds of trouble.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
🍺  /usr/local/Cellar/readline/6.3.8: 40 files, 2.1M
==> Installing python3 dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.8.8.3.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring sqlite-3.8.8.3.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include

==> Summary
🍺  /usr/local/Cellar/sqlite/3.8.8.3: 9 files, 2.1M
==> Installing python3 dependency: gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.11.yosemite.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring gdbm-1.11.yosemite.bottle.2.tar.gz
🍺  /usr/local/Cellar/gdbm/1.11: 17 files, 532K
==> Installing python3 dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2: 459 files,  18M
==> Installing python3
==> Downloading https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/python3/3.4.3 --enable-ipv6 --datarootdir=/usr/local/Cellar/python3/3.4.3/share --datadir=/u
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python3/3.4.3
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python3/3.4.3/share/python3
==> Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-12.2.tar.gz
######################################################################## 100.0%
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-6.0.8.tar.gz
######################################################################## 100.0%
==> Caveats
Pip and setuptools have been installed. To update them
  pip3 install --upgrade pip setuptools

You can install Python packages with
  pip3 install <package>

They will install into the site-package directory
  /usr/local/lib/python3.4/site-packages

See: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md

.app bundles were installed.
Run `brew linkapps python3` to symlink these to /Applications.
==> /usr/local/Cellar/python3/3.4.3/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar
==> /usr/local/Cellar/python3/3.4.3/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar
==> Summary
🍺  /usr/local/Cellar/python3/3.4.3: 5899 files, 100M, built in 2.7 minutes
Andress-MBP:~ andres$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> 

Add django:
Andress-MBP:/ andres$ open usr/local/Cellar/python3.4.3
location:
$open /usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4

Wednesday, March 11, 2015

Handy ADB commands

More cool adb tricks here
  • Command to find location of apk for specific appName
$adb shell pm list packages -f | grep AppName
output:
package:/data/app/com.packageName.AppName-2/base.apk=com.packageName. AppName
  • Pull App apk
$adb pull /data/app/com.packageName.AppName-2/base.apk /Download/Location 

ADB root access:
$adb shell
$su //now you have adb root access

Android 6.0 Permissions:
Granting and revoking runtime permissions:
$adb shell pm grant/revoke my.package.name some.permission.NAME

Installing an app with all permissions granted:
$adb install -g my.package.name

Dumping app permission state:
$adb shell dumpsys package my.package.name

Show all Android permissions:
adb shell pm list permissions -d -g


To display ADB commands:
open terminal and type $adb help

AndroidSs-MacBook-Air:~ android$ adb help
Android Debug Bridge version 1.0.32

 -a                            - directs adb to listen on all interfaces for a connection
 -d                            - directs command to the only connected USB device
                                 returns an error if more than one USB device is present.
 -e                            - directs command to the only running emulator.
                                 returns an error if more than one emulator is running.
 -s <specific device>          - directs command to the device or emulator with the given
                                 serial number or qualifier. Overrides ANDROID_SERIAL
                                 environment variable.
 -p <product name or path>     - simple product name like 'sooner', or
                                 a relative/absolute path to a product
                                 out directory like 'out/target/product/sooner'.
                                 If -p is not specified, the ANDROID_PRODUCT_OUT
                                 environment variable is used, which must
                                 be an absolute path.
 -H                            - Name of adb server host (default: localhost)
 -P                            - Port of adb server (default: 5037)
 devices [-l]                  - list all connected devices
                                 ('-l' will also list device qualifiers)
 connect <host>[:<port>]       - connect to a device via TCP/IP
                                 Port 5555 is used by default if no port number is specified.
 disconnect [<host>[:<port>]]  - disconnect from a TCP/IP device.
                                 Port 5555 is used by default if no port number is specified.
                                 Using this command with no additional arguments
                                 will disconnect from all connected TCP/IP devices.

device commands:
  adb push [-p] <local> <remote>
                               - copy file/dir to device
                                 ('-p' to display the transfer progress)
  adb pull [-p] [-a] <remote> [<local>]
                               - copy file/dir from device
                                 ('-p' to display the transfer progress)
                                 ('-a' means copy timestamp and mode)
  adb sync [ <directory> ]     - copy host->device only if changed
                                 (-l means list but don't copy)
                                 (see 'adb help all')
  adb shell                    - run remote shell interactively
  adb shell <command>          - run remote shell command
  adb emu <command>            - run emulator console command
  adb logcat [ <filter-spec> ] - View device log
  adb forward --list           - list all forward socket connections.
                                 the format is a list of lines with the following format:
                                    <serial> " " <local> " " <remote> "\n"
  adb forward <local> <remote> - forward socket connections
                                 forward specs are one of: 
                                   tcp:<port>
                                   localabstract:<unix domain socket name>
                                   localreserved:<unix domain socket name>
                                   localfilesystem:<unix domain socket name>
                                   dev:<character device name>
                                   jdwp:<process pid> (remote only)
  adb forward --no-rebind <local> <remote>
                               - same as 'adb forward <local> <remote>' but fails
                                 if <local> is already forwarded
  adb forward --remove <local> - remove a specific forward socket connection
  adb forward --remove-all     - remove all forward socket connections
  adb reverse --list           - list all reverse socket connections from device
  adb reverse <remote> <local> - reverse socket connections
                                 reverse specs are one of:
                                   tcp:<port>
                                   localabstract:<unix domain socket name>
                                   localreserved:<unix domain socket name>
                                   localfilesystem:<unix domain socket name>
  adb reverse --norebind <remote> <local>
                               - same as 'adb reverse <remote> <local>' but fails
                                 if <remote> is already reversed.
  adb reverse --remove <remote>
                               - remove a specific reversed socket connection
  adb reverse --remove-all     - remove all reversed socket connections from device
  adb jdwp                     - list PIDs of processes hosting a JDWP transport
  adb install [-lrtsd] <file>
  adb install-multiple [-lrtsdp] <file...>
                               - push this package file to the device and install it
                                 (-l: forward lock application)
                                 (-r: replace existing application)
                                 (-t: allow test packages)
                                 (-s: install application on sdcard)
                                 (-d: allow version code downgrade)
                                 (-p: partial application install)
  adb uninstall [-k] <package> - remove this app package from the device
                                 ('-k' means keep the data and cache directories)
  adb bugreport                - return all information from the device
                                 that should be included in a bug report.

  adb backup [-f <file>] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]
                               - write an archive of the device's data to <file>.
                                 If no -f option is supplied then the data is written
                                 to "backup.ab" in the current directory.
                                 (-apk|-noapk enable/disable backup of the .apks themselves
                                    in the archive; the default is noapk.)
                                 (-obb|-noobb enable/disable backup of any installed apk expansion
                                    (aka .obb) files associated with each application; the default
                                    is noobb.)
                                 (-shared|-noshared enable/disable backup of the device's
                                    shared storage / SD card contents; the default is noshared.)
                                 (-all means to back up all installed applications)
                                 (-system|-nosystem toggles whether -all automatically includes
                                    system applications; the default is to include system apps)
                                 (<packages...> is the list of applications to be backed up.  If
                                    the -all or -shared flags are passed, then the package
                                    list is optional.  Applications explicitly given on the
                                    command line will be included even if -nosystem would
                                    ordinarily cause them to be omitted.)

  adb restore <file>           - restore device contents from the <file> backup archive

  adb help                     - show this help message
  adb version                  - show version num

scripting:
  adb wait-for-device          - block until device is online
  adb start-server             - ensure that there is a server running
  adb kill-server              - kill the server if it is running
  adb get-state                - prints: offline | bootloader | device
  adb get-serialno             - prints: <serial-number>
  adb get-devpath              - prints: <device-path>
  adb status-window            - continuously print device status for a specified device
  adb remount                  - remounts the /system and /vendor (if present) partitions on the device read-write
  adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
  adb reboot-bootloader        - reboots the device into the bootloader
  adb root                     - restarts the adbd daemon with root permissions
  adb usb                      - restarts the adbd daemon listening on USB
  adb tcpip <port>             - restarts the adbd daemon listening on TCP on the specified port
networking:
  adb ppp <tty> [parameters]   - Run PPP over USB.
 Note: you should not automatically start a PPP connection.
 <tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
 [parameters] - Eg. defaultroute debug dump local notty usepeerdns

adb sync notes: adb sync [ <directory> ]
  <localdir> can be interpreted in several ways:

  - If <directory> is not specified, /system, /vendor (if present), and /data partitions will be updated.

  - If it is "system", "vendor" or "data", only the corresponding partition
    is updated.

environmental variables:
  ADB_TRACE                    - Print debug information. A comma separated list of the following values
                                 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
  ANDROID_SERIAL               - The serial number to connect to. -s takes priority over this if given.
  ANDROID_LOG_TAGS             - When used with the logcat option, only these debug tags are printed.


Monday, March 9, 2015

apktool usage: Decompile and Compile APK (in mac)

A. Installation:
1. Install Apktool

B. Process to Decompile APK(Android Package):
1. Open terminal and cd to apktool directory
2. $./apktool d <../../pathToMyAPK> 



3. Command generates a folder with all app resources and smali files

4. Now go to smali folder and you can make changes to the behavior of the app.

-->After you made changes to the app, you have to compile the source and then signed your app to work in a device(steps below)


C. Process to Compile APK(Android Package):

1. Open terminal and cd to apktool directory
2. $./apktool b <../../pathToMyAPK>
3. New apk is generated in  ./tool/out_decompile/dist/NewAPP.apk
->Now we need to sign the apk to be able to port to device.

D. Sign APK:
1. Generate release key using below command.
$keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
2. Enter password for key.

>creates key: /Users/android/my-release-key.keystore

2. Generate new apk(done in above step C. 2).
3. Sing your app
$jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore /Users/android/Desktop/tools/apktool/tool/compile_apk/myAPK-1.apk alias_name
4. Done. Signs apk, saved in the same location.
5. Install apk to device: $adb install /Users/android/Desktop/tools/apktool/tool/compile_apk/myAPK-1.apk   

Reference:
https://www.youtube.com/watch?v=XbvyqpnP1-E
https://code.google.com/p/android-apktool/downloads/list
Signing apk manually: 
http://developer.android.com/tools/publishing/app-signing.html

Sublime Text 3. Great code editor.

Download from here:
http://www.sublimetext.com/3

View/Edit code:
1. Just drag and drop file to the Sublime icon. And sublime will open it.

To Install package:
1. Install Package Control, go to:
https://packagecontrol.io/installation
2. Copy code, now open 'Sublime' go to 'View' -> 'Show Console', paste code and enter. Done.
3. Cmd+ Shift + P , type "Install Package"
4. For ex: Dayle Rees (to add color schemes)

Some cool packages to install:
-predwan (nicer tabs)
-Dayle Rees (color scheme)
-Brackethighlighter (highlights brackets)
-SideBarEnhancement (more sideBar options)
-sublimecodeIntel (code completion)
more.....

To Remove package:
1. Cmd+ Shift + P , type "Remove Package"
2. Select package to remove



Reference:
https://www.youtube.com/watch?v=zVLJfrIwEP8

You can google and find different plugins for Sublime. I highly recommended :)

Friday, March 6, 2015

Reverse Engineer Android App. Decompile with dex2jar(using Mac)

Work in progress....

Setup:
1. First download dex2jar fille from:
http://karanbalkar.com/2014/05/convert-apk-file-to-jar-using-dex2jar/

2. Download JD-GUI:
http://jd.benow.ca/

3. Pull apk from device to machine.


How to use:
1. Now run Dex2jar, drag and drop file "MyApp.apk" to the dex2jar directory(terminal)
Command:
/Dex2-jar/dex2jar-0.0.9.15$ sh d2j-dex2jar.sh '/home/andsand/Desktop/dex2jar_Dir/apk_location/MyApp.apk'

Output:
dex2jar /home/andsand/Desktop/dex2jar_Dir/apk_location/MyApp-1.apk -> MyApp-1-dex2jar.jar


6. Output will generate a jar file in the dex2jar directory...
In this case is name: MyApp-1-dex2jar.jar


Next step:
1. open MyApp-1-dex2jar.jar with JD-GUI  to see code.
2. Click on icon  JD-GUI
3. Now select and open the MyApp-1-dex2jar.jar file, you can  see the code. You can drag and drop jar file to JD-GUI.
4. File -> Save all Sources (this will create a zip file with all the source code)
5. PS. You can open the source code file with sublime or any other code editor, to analyze the code.

And done now you can analyze the code of the app, make changes, compile and sign manually the app.


Thursday, March 5, 2015

Activator



Start:
Andress-MBP:~ andres$ cd /Users/andres/Development/Activator/activator-1.2.12/

Andress-MBP:activator-1.2.12 andres$ ./activator new

Fetching the latest list of templates...

Browse the list of templates: http://typesafe.com/activator/templates
Choose from these featured templates or enter a template name:
  1) minimal-akka-java-seed
  2) minimal-akka-scala-seed
  3) minimal-java
  4) minimal-scala
  5) play-java
  6) play-scala
(hit tab to see a list of all templates)



refrence:
https://www.youtube.com/watch?v=eNCerkVyQdc

Add "adb" to your PATH (using a Mac)

ADB- Android Debug Bridge

1. Find the path to your Android/sdk/platform-tools
$pwd to get the full location path
Location: Users/android/Library/Android/sdk/platform-tools

2. Now open bash_profile,
$vi ~/.bash_profile
enter: export PATH=${PATH}:/((pathToyour_AndroidSDK))

export PATH=${PATH}:/Users/android/Library/Android/sdk/platform-tools

and save.

3. Quit terminal and Done. Now when you type $adb, the tool will work from any /dir in your mac



Reference:
adb:
http://developer.android.com/tools/help/adb.html
https://seo-michael.co.uk/how-to-setup-adb-on-os-x/

Install Android Studio:
https://developer.android.com/sdk/installing/index.html?pkg=studio

Install Java JDK, if not installed, check with $jave -version
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Add adb to path:
http://www.android.gs/install-set-up-adb-mac-os-x-linux/