Wednesday, May 27, 2015

Joomla - How to easily add Javascript snippets

If you're into analyzing the traffic of your Joomla website (as you should be IMHO), you will probably need to add some tracking software to your site. The most obvious one is Google Analytics. Other choices can be Crazyegg, GoingUp or other solutions.
All of these, as well as other solutions, require that you add a Javascript snippet to your site. In this post I'll show you how to add some module positions to your template. This will make it easier to add the required scripts to your website.

Module position basics

If you've been working with Joomla, you know that a Joomla template consists of HTML and some PHP snippets.
For one, it contains a component area where the output from the different components are shown (articles, blog lists, third-party components etc). A Joomla template also contains several PHP snippets, which are called module positions. You can assign modules to these positions and they will appear in the given position in your template.

Easier way to insert scripts

Of course, you can use an extension for each third-party script you want to enter. Probably there is one available (isn't there for almost anything?). The problem with this approach, though, is that you need to keep track of X number of extensions and their updates. And for each extension you add to your site, the chance of being hacked increases. After all, code is made by humans, and humans make mistakes.
For those reasons, I prefer using the 'Custom HTML' module when I need to insert code snippets. For best results, you should have special module positions for the JavaScript snippet modules. That way, you can control where in the source code the snippets appear, something which can be crucial for the workings of the snippet.
The method is simple, but effective.
You will need three module positions, and as many Custom HTML modules as you need (one for each snippet).

Inserting the module positions in your template

In order to make this as flexible as possible, you need three module positions:
  • endhead
  • topbody
  • endbody
Now you're ready to insert the module positions. You will need to enter the following code into your template index.php file. You'll find it here: /templates/yourtemplatename/index.php.

Make sure to create a backup of your index.php file before messing with it.
Enter this just before the </head> tag.
<jdoc:include type="modules" name="endhead" />
Enter this just after the <body> tag:
<jdoc:include type="modules" name="topbody" />
Enter this just before the </body> tag:
<jdoc:include type="modules" name="endbody" />
Save your template.
The next step is to add the actual modules that will hold your JavaScript. But before that, we need to do some adjustments to the text editor settings.

Allowing JavaScript in your editor

To be able to add the JavaScript to the Custom HTML module, you need to allow Javascript in your text editor. If you use TinyMCE, you find this setting in Extensions -> Plugin Manager -> Editor - TinyMCE 2.0. Make sure you have the setting for 'Code Cleanup on Startup' set to 'Off' and the 'Code Cleanup on Save' to 'Never'.
code-cleanup-tinymce
If you're using JCE, go to Groups -> Default (or other group you're using) -> Editor Parameters. Make sure the 'Allow Javascript' setting is set to 'Yes'.
allow-js-yes

Adding the script to the Custom HTML module


Now, you need to add the actual Javascript snippet to a Custom HTML module and assign it to the appropriate module position.

I'll use Google Analytics as an example. Go to the Module Manager and click New. Choose the 'Custom HTML' module type. You will see the module parameters.

Enter a title for the module, for instance 'Google Analytics code', enable the module, choose not to show the module title.

For the Google Analytics code, we assign the module to the newly created 'endhead' position. This has the Google Analytics snippet appear just before the closing HEAD tag (</head>). As you have not entered the new module positions to the template XML file, they will not appear in the module position drop-down. Not to worry: You can simply enter the position name 'endhead' in the field directly.
mod-custom-analytics
Lastly, enter the HTML mode of your editor and paste the Google Analytics code into the window. You can now save the module.
Reload your website frontend and look for the snippet.

Adding more snippets

Using this method, you can add as many Javascript snippets as you like. You can control the order of the snippets by altering the order of the modules in the module manager.
I find this method easy to use and flexible. Hope you enjoy it and that it saves you some time and frustration

Saturday, May 16, 2015

Joomla 3.x. - How to edit registration page

Changing registration form fields titles

In order to change Registration page title, follow the steps below:
  1. Log into your Joomla admin panel.
  2. Open User Registration menu item under Menus > System Menu tab:
    Joomla-3.x.-How-to-edit-registration-page-1
  3. Change menu item title. Save the change and check your site:
    Joomla-3.x.-How-to-edit-registration-page-2
To change registration form fields, please modify en-GB.com_users.ini file located in language/en-GB folder on your server. Use CTRL+F how keys to search for the text you would like to change. You can change titles listed below in en-GB.com_users.ini file:
  • Required field
  • Name
  • Username
  • Password
  • Confirm Password
  • Email Address
  • Confirm email Address
  • optional
Edit en-GB.plg_user_profile.ini file, located in administrator/language/en-GB folder on your server to change the titles listed below:
  • Address 1
  • Address 2
  • City
  • Region
  • Country
  • Postal / ZIP Code
  • Phone
  • Web site:
  • Favourite Book
  • About Me
  • The date of birth entered should use the format Year-Month-Day, i.e. 0000-00-00
  • Date of Birth
In order to change Registration and Cancel buttons titles, please edit en-GB.ini file from language/en-GB folder on your server.

Removing registration form fields

In order to disable some fields in your registration form, make the following changes:
  1. Log into your Joomla backend.
  2. Navigate to Extensions > Plugins Manager.
  3. Edit User – Profile plugin:
    Joomla-3.x.-How-to-edit-registration-page-3
  4. Select Disabled option from the drop down menu next to the field title. You can chose Optional or Required item in case you would like the form field be required or optional when submitting the form:
    Joomla-3.x.-How-to-edit-registration-page-4

Adding registration form fields

In order to add new fields to the registration form, database and files update is required. The following database changes are required:
  1. Access the database assigned to your site using PhpMyAdmin tool on your hosting Cpanel.
  2. Browse XXX_users table. XXX is your the database table prefix:
    Joomla-3.x.-How-to-edit-registration-page-5
  3. Click on the Structure button.
  4. Choose elements between which you would like to paste a new field.
  5. Specify columns number under Add section. Add chose database ID after which new item will be shown.
  6. Click on Go button:
    Joomla-3.x.-How-to-edit-registration-page-6
  7. Specify Name, Type and Length settings on the next screen.
  8. Save changes:
    Joomla-3.x.-How-to-edit-registration-page-7
In order to make a new field appear on your site, modify the following files:
  1. Edit user.php file from the libraries/joomla/user folder. Find code for the field after which your new section should come:
    public $name = null;
    Add code for your new field just under the code above:
    public $field_lable_here= null;
    Where field_lable_here is your new field title.
  2. Modify users.xml file from administrator/components/com_users/models/forms directory.
    Find code for the field after which your new field will be shown:
    ?
    1
    2
    3
    4
    5
    6
    <field name="name" type="text"
            description="COM_USERS_USER_FIELD_NAME_DESC"
            label="COM_USERS_USER_FIELD_NAME_LABEL"
            required="true"
            size="30"
    />
    Add code for your field just under the code below:
    ?
    1
    2
    3
    4
    5
    6
    <field name="field_lable_here" type="text"
            description="Your description"
            label="field_lable_here"
            required="true"
            size="30"
    />
    Replace field_lable_here with your new field label. Change Your description text to your description.
  3. Edit registration.xml file from the components/com_users/models/forms folder on your server. Add code for your field under the code used for the field after which you would like to show your new field:
    ?
    1
    2
    3
    4
    5
    6
    <field name="field_lable_here" type="text"
            description="Your description"
            label="field_lable_here"
            required="true"
            size="30"
    />
Upload the modified files on your server. Refresh your site to see the change.
Feel free to check the detailed video tutorial below:

Thursday, May 14, 2015

Android studio - “Cannot start internal HTTP server”

Android studio is also starting without any problems. But then I get two messages:
  • Internal HTTP server disabled: Cannot start internal HTTP server. Git integration, JavaScript debugger and LiveEdit may operate with errors. Please check your firewall settings and restart Android Studio
  • Gradle 'Nieuwproject' project refresh failed: Connection refused: connect
  1. cmd -- 'Run as administrator'.
  2. cmd> netsh winsock reset
  3. Restart PC
  4. That's worked

Friday, May 1, 2015

Android - Decompile APK + eclipse to debug SmalI

Never thought of APK decompiler is so convenient, and also can be modified to compile and run, this is easier than modifying the PE in win much, thanks to apktool and SmalI tools the author provides such a good tool.

Tracking APK general practice is to insert the log output in the anti compiled SmalI code, then recompile and run output log, this method is time-consuming and laborious, if can real-time debugging is the best. Search, the better method is to use the NetBeans+DDMS. I tried to debug, but had little understanding of the operation of NetBeans, eclipse estimated that many people will, in fact more or less the same settings with NetBeans.
Debugging steps:
1 on the APK using the apktool anti compile debug SmalI code to the out folder, the current version of apktool is 2.0.0b7.
java -jar apktool_2.0.0b7.jar d -d test.apk -o out
Here you must use the -d parameter, the code suffix such anti compiler is Java, because only java files can only be recognized by the eclipse/netbeans debugging.
2 set debug mark and find the main class
In the output of the out folder, open the AndroidManifest.xml with a text editor, set the android:debuggable attribute in the application node="true".
In AndroidManifest.xml, the keyword search
<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Find the activity node containing the above information, record the value of the android:name property, the value is the main class of the application. As shown in the examples below, the main class for the com.acids.helloworld.MainActivity.
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.acids.helloworld">
    <application android:debuggable="true" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
        <activity android:label="@string/app_name" android:name="com.acids.helloworld.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
3 in the main class of the onCreate event to add debug wait.
Open the main class file in a text editor, find onCreate method, insert the invoke-static {}, in the first sentence of Landroid/os/Debug; -> waitForDebugger (V), remember to add a=0; // prefix maintains a consistent, the results are as follows:
a=0;// # virtual methods
a=0;// .method protected onCreate(Landroid/os/Bundle;)V
a=0;//     invoke-static {}, Landroid/os/Debug;->waitForDebugger()V
a=0;// 
a=0;//     .locals 1
a=0;//     .param p1, "savedInstanceState"    # Landroid/os/Bundle;
a=0;// 
a=0;//     .prologue
a=0;//     .line 11
a=0;//     invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
4 save file, recompile using apktool package for debug.apk
java -jar apktool_2.0.0b7.jar b -d out -o debug.apk
5 on the debug.apk signature (need to download signature tool), I put it in the signapk folder under the signature tool, debug.sign.apk generation
java -jar .\signapk\signapk.jar .\signapk\testkey.x509.pem .\signapk\testkey.pk8 .\debug.apk .\debug.sign.apk
6 upload debug.sign.apk to mobile phone or simulator, and then installed and running. Can you see the program running in the white screen, then don't move equipment and exit the program, because the program is now running to just add the waitForDebugger code, this code means has been suspended, waiting for the debugger.

The following set up real-time debugging environment.
7 enter the first step of the out folder, the build and dist inside the folder to delete, this is a apktool compiler apk.
8 start eclipse, building Java projects
  1) File -> New -> Project -> Java Project -> Next
2) Project Name at Use default location, remove the Location option, select the out folder, and then Next
3) The SmalI folder for the Source Folder, and Finish
In eclipse 9, the main class open second step to find, and find the onCreate method, the first method in waitForDebugger to add breakpoints later. The following diagram

10 open DDMS (path in%android-sdks%\tools\ddms.bat), if in the sixth step operation of the modified program, display can debug program in the DDMS equipment list.

The last column corresponding to the program for 8600/8700, of which 8600 is the debugging the program port.
11 now to do is put the association can code and debugging program. Back in eclipse, configure the remote debugging
1) Menu Run> Debug -> Debug Configurations
2) Double click the Remote Java Application, Host the default localhost on the line, 8600 Port in tenth steps to get, and then Apply> Debug.

12 then eclipse automatically switch to the debug view, and see the program is already running and interrupt can be executed on the next line of code, you can directly see the relevant variables.

Have you can debug SmalI with eclipse, the above example is from a program where we start debugging to debug, but to the code they concerned local indeed trouble. It is recommended to use jd-gui software directly view the compiled Java code debugging, to determine the location, and then enter the SmalI location breakpoint and real-time debugging, can be twice the result with half the effort.
Related tools inHere to download
  apktool: https://code.google.com/p/android-apktool/
  jd-gui

Source: http://www.programering.com/a/MjM5UTMwATg.html

Android - From APK to readable java source code in 3 easy steps

Android applications are packed inside a APK file, which is just a ZIP file containing among other things a compact Dalvik Executable (.dex) file.
First step is to extract the “classes.dex” file from the APK:
$ unzip program.apk classes.dex
Archive:  program.apk
  inflating: classes.dex
Now, we use the tool dex2jar to convert the classes.dex file to Java .class files:
$ bash dex2jar/dex2jar.sh ./classes.dex
version:0.0.7.8-SNAPSHOT
2 [main] INFO pxb.android.dex2jar.v3.Main - dex2jar ./classes.dex -> ./classes.dex.dex2jar.jar
Done.
From here we obtain the file “classes.dex.dex2jar.jar”, now we can use the java decompiler JD-GUI to extract the source code:
$ ./jd-gui classes.dex.dex2jar.jar
Now just go to “File -> Save all sources” and it will generate the zip file “classes.dex.dex2jar.src.zip” containing all the decompiled Java source code

Android - Decompiling DEX into Java sourcecode

decompiling DEX into Java sourcecode

1How can one decompile Android DEX (VM bytecode) files into corresponding Java sourcecode?
[Related]: android - decompiling DEX into Java sourcecode How can one decompile Android DEX (VM bytecode) files into corresponding Java sourcecode?
2

It's easy

Get these tools:
1) dex2jar, which is made by a Chinese student. It will translate dex files to jar files
2) jd-gui to view the java files in the jar
The source code is quite readable as dex2jar makes some optimizations.

Android - Decompile/Recompile an apk & basic editing

Android application package file (APK) is the package file format used to distribute applications for Google’s Android operating system.
An APK file is an archive that usually contains the following directories:
assets: a directory containing applications assets, which can be retrieved by AssetManager
res: the directory containing resources not compiled into resources.arsc
lib: the directory containing the compiled code that is specific to a software layer of a processor, the directory is split into more directories within it:
    armeabi: compiled code for all ARM based processors only
    armeabi-v7a: compiled code for all ARMv7 and above based processors only
    x86: compiled code for x86 processors only
    mips: compiled code for MIPS processors only
META-INF directory: a directory containing app certificate
    MANIFEST.MF: the Manifest file
    CERT.RSA: The certificate of the application.
    CERT.SF: The list of resources and thier SHA-1 digest
AndroidManifest.xml: Android manifest presents essential information about the app.
classes.dex: The executable code understood by the Dalvik VM
resources.arsc : a file containing precompiled resources

Different approaches to Decompile/Recompile an apk

a. apk
    1. apktool + Notepad++
    2. Virtuous Ten Studio
    3. AndroChef Java Decompiler
b. classes.dex
    1. smali/baksmali
    2. dex2jar + JD-GUI

Steps

1. download the app from phone/tab to computer using adb pull or and Android File manager (e.g. ES File Explorer)
adb devices – List all connected devices/emulator
adb push <local_path> <remote_path> – Copy file/dir to device/emulator
adb pull <remote_path> [<local_path>] – Copy file/dir from device/emulator
adb logcat – View device log
adb install [-l] [-r] [-s] <file> – push this package file to the device
adb uninstall [-k] <package> – remove this app package from the device
If using File manager, backup the app and copy it to sdcard to transfer it to computer
2. Now use any of the above approach as applicable

a. apk

apktool -> command line approach
install an apk            java -jar apktool.jar if app.apk
                          java -jar apktool.jar if framework-res.apk
decompiling an apk        java -jar apktool.jar d app.apk
recompile the folder      java -jar apktool.jar b appFolder


1. Install Framework file {only once}
2. Decompile the apk
3. Edit the code as required {using Notepad++, others}
4. Recompile the apk
5. Sign the apk {See Below}
6. ZipAlign the apk {See Below}
Virtuous Ten Studio -> GUI + very useful smali help {opcode details on hover} + drop smali files from other projects to understand the code
It automates the whole process. You only need to EDIT files and it does everything else.
AndroChef Java Decompiler -> very useful java decompiler to understand the code

b. classes.dex

Sometimes apktool is not able do decompile an app because of DexGuard, Proguard, etc; in that case alternative is to extract classes.dex from the apk and go for any of the 2 below mentioned approaches
smali/baksmali
smali.jar        smali files to classes.dex
java -jar smali.jar OutputDir -o classes.dex

baksmali.jar     classes.dex to smali files
java -jar baksmali.jar classes.dex -o OutputDir


1. Install Framework file {only once}
2. Extract classes.dex from the apk
3. Decompile the classes.dex using baksmali.jar
4. Edit the code as required {using Notepad++, others}
5. Recompile the classes.dex using smali.jar
6. Replace original classes.dex in the apk with the new classes.dex
7. Sign the apk {See Below}
8. ZipAlign the apk {See Below}
dex2jar+JD-GUI
Convert .dex -> .jar using dex2jar.jar and open it in JD-GUI
3. Sign the apk
Every app needs to be signed before it can be installed on Android OS.
java -jar signapk.jar certificate.pem key.pk8 app.apk app_signed.apk
4. Zipalign the apk
is an archive alignment tool that provides important optimization to Android application (.apk) files
zipalign -fv 4 app_signed.apk app_final.apk
5. The modified app.apk is ready to by deployed.

Source: https://themasterofmagik.wordpress.com/2014/03/08/decompilerecompile-an-apk-basic-editing/

Android - MyMobiler - View, capture, control, and browse files of your Android device via USB/WiFi.



The MyMobiler desktop application controls your Android device through USB connection or WiFi. It allows you to see your mobile device remotely and capture the screen or video. What you see in the desktop application is mirroring your device screen and you can interact with your device using the mouse and keyboard.
  • Control your device using your desktop keyboard and mouse.
  • Capture the screen and video.
  • Copy/Cut/Paste text between device and desktop.
  • Transfer files between device and desktop.
  • USB / WiFi Connection.
  • Android OS version 2.2 or later.
 http://mymobiler.com/

Android - Use your Android from a web browser or desktop

How to Set Up and Use Mobizen Screen Recording


Your Android, Anywhere
https://www.mobizen.com/

Setup

1. Install Mobizen onto your Android device.
2. Run Mobizen. During the first run, you will need to create an account which allows you to connect to the device using a web browser. First, accept the “Term and conditions” and “Privacy policy”.
mobizen1
Then select the email address of one of the accounts you have configured on the phone.
mobizen2
Set your password.
mobizen3
Swipe through the tutorial and tap the “Start Mobizen” button.
mobizen5
Tap OK on this screen.
mobizen6
Application setup is ready.
mobizen7

Additional Phone Configuration

If you don’t have USB debugging enabled, go to device settings and enable developer options.
mobizen8
In Android 4.1 and below, the developer options can be found by:
1. Go to the settings menu, and scroll down to “About device.” Tap it.
2. Scroll down to the bottom again, where you see “Build number.” (Your build number may vary from ours here.)
3. Tap it seven (7) times. After the third tap, you’ll see a playful dialog that says you’re four taps away from being a developer. (If only it were that simple, eh?) Keep on tapping, and *poof*, you’ve got the developer settings back. (Source)
Open developer options, enable USB debugging.
mobizen9
(This step is not not required but it’s highly recommended.) Select “show touches.” Click will be visible on your recording, which makes videos easier to follow.
mobizen10
3. Install Mobizen on your PC by downloading the installer. Currently there is only a Windows version of the application, but a Mac version is planned. Installation is very easy. You don’t need to worry about a USB driver as it will be installed with this process.
4. Connect your device to your computer using USB. (You may also use a WiFi or 3G/LTE connection, but you won’t be able to use Mobizen built-in recording that way). Open the application on the device.
5. Open http://mobizen.com on your computer’s browser and log in using  the credentials you set up on your device earlier. Once you log in, you will see the list of the devices associated with the account.
mobizen12
Click on your device and you will see the screen of your phone.
mobizen13

Recording

In order to use Mobizen recording, you need to use a USB connection and have Android 4.2 or greater. To start recording, click record in the web interface and pause when you are done. Then click video and download the video.
What do you do if you have older version of Android? Use an external recording tool like Jing or Screencast-O-Matic.
 Source: http://university.utest.com/how-to-set-up-mobizen-screen-recording/