Compdigitec Labs

CUPS web interface not working

By admin | August 17, 2013

CUPS seems to be working fine – documents can be printed and everything seems to work fine, but the web interface at http://localhost:631/ doesn’t work, returning something like:

Firefox can’t establish a connection to the server at localhost:631.

Solution:

Open /etc/cups/cupsd.conf as root and ensure that the line:

Listen 631

Exists somewhere in the file. Then save it and close it. Finally, restart CUPS:

sudo /etc/init.d/cups restart

Then fire up your web browser and head to http://localhost:631/ and enjoy the CUPS web interface.

Topics: Linux | No Comments »

OpenGL acceleration in Debian/Ubuntu

By admin | June 20, 2013

Getting “Error:  couldn’t get an RGB, Double-buffered visual“?

1) Install video driver

Example:

sudo apt-get install xserver-xorg-video-intel # or whatever nvidia package for your card

2) Install OpenGL and related libraries/tools:

sudo apt-get install libgl1-mesa-dri libgl1-mesa-glx mesa-utils

3) Restart X server or restart computer:

sudo shutdown now -r

4) Test acceleration:

glxgears
glxinfo

Sample working output:

name of display: :0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
    GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer,
    GLX_OML_swap_method, GLX_SGI_swap_control, GLX_SGIS_multisample,
    GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
    GLX_INTEL_swap_event
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
client glx extensions:
    GLX_ARB_create_context, GLX_ARB_create_context_profile,
    GLX_ARB_create_context_robustness, GLX_ARB_framebuffer_sRGB,
    GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_EXT_framebuffer_sRGB,
    GLX_EXT_create_context_es2_profile, GLX_MESA_copy_sub_buffer,
    GLX_MESA_multithread_makecurrent, GLX_MESA_swap_control,
    GLX_OML_swap_method, GLX_OML_sync_control, GLX_SGI_make_current_read,
    GLX_SGI_swap_control, GLX_SGI_video_sync, GLX_SGIS_multisample,
    GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
    GLX_EXT_texture_from_pixmap, GLX_INTEL_swap_event
GLX version: 1.4
GLX extensions:
    GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_import_context,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer,
    GLX_MESA_multithread_makecurrent, GLX_MESA_swap_control,
    GLX_OML_swap_method, GLX_OML_sync_control, GLX_SGI_make_current_read,
    GLX_SGI_swap_control, GLX_SGI_video_sync, GLX_SGIS_multisample,
    GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, GLX_SGIX_visual_select_group,
    GLX_EXT_texture_from_pixmap, GLX_INTEL_swap_event
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) 915GM x86/MMX/SSE2
OpenGL version string: 1.4 Mesa 9.1.3
OpenGL extensions:
    GL_ARB_multisample, GL_EXT_abgr, GL_EXT_bgra, GL_EXT_blend_color,
    GL_EXT_blend_minmax, GL_EXT_blend_subtract, GL_EXT_copy_texture,
    GL_EXT_polygon_offset, GL_EXT_subtexture, GL_EXT_texture_object,
    GL_EXT_vertex_array, GL_EXT_compiled_vertex_array, GL_EXT_texture,
    GL_EXT_texture3D, GL_IBM_rasterpos_clip, GL_ARB_point_parameters,
    GL_EXT_draw_range_elements, GL_EXT_packed_pixels, GL_EXT_point_parameters,
    GL_EXT_rescale_normal, GL_EXT_separate_specular_color,
    GL_EXT_texture_edge_clamp, GL_SGIS_generate_mipmap,
    GL_SGIS_texture_border_clamp, GL_SGIS_texture_edge_clamp,
    GL_SGIS_texture_lod, GL_ARB_multitexture, GL_IBM_multimode_draw_arrays,
    GL_IBM_texture_mirrored_repeat, GL_3DFX_texture_compression_FXT1,
    GL_ARB_texture_cube_map, GL_ARB_texture_env_add, GL_ARB_transpose_matrix,
    GL_EXT_blend_func_separate, GL_EXT_fog_coord, GL_EXT_multi_draw_arrays,
    GL_EXT_secondary_color, GL_EXT_texture_env_add,
    GL_EXT_texture_filter_anisotropic, GL_EXT_texture_lod_bias,
    GL_INGR_blend_func_separate, GL_NV_blend_square, GL_NV_light_max_exponent,
    GL_NV_texgen_reflection, GL_NV_texture_env_combine4, GL_S3_s3tc,
    GL_SUN_multi_draw_arrays, GL_ARB_texture_border_clamp,
    GL_ARB_texture_compression, GL_EXT_framebuffer_object,
    GL_EXT_texture_compression_s3tc, GL_EXT_texture_env_combine,
    GL_EXT_texture_env_dot3, GL_MESA_window_pos, GL_NV_packed_depth_stencil,
    GL_NV_texture_rectangle, GL_ARB_depth_texture, GL_ARB_shadow,
    GL_ARB_texture_env_combine, GL_ARB_texture_env_crossbar,
    GL_ARB_texture_env_dot3, GL_ARB_texture_mirrored_repeat,
    GL_ARB_window_pos, GL_EXT_stencil_two_side, GL_EXT_texture_cube_map,
    GL_APPLE_packed_pixels, GL_APPLE_vertex_array_object, GL_ARB_draw_buffers,
    GL_ARB_fragment_program, GL_ARB_fragment_shader, GL_ARB_shader_objects,
    GL_ARB_vertex_program, GL_ARB_vertex_shader, GL_ATI_draw_buffers,
    GL_ATI_texture_env_combine3, GL_EXT_shadow_funcs, GL_EXT_stencil_wrap,
    GL_MESA_pack_invert, GL_MESA_ycbcr_texture, GL_ARB_half_float_pixel,
    GL_ARB_point_sprite, GL_ARB_shading_language_100, GL_ARB_sync,
    GL_ARB_texture_non_power_of_two, GL_ARB_vertex_buffer_object,
    GL_ATI_blend_equation_separate, GL_EXT_blend_equation_separate,
    GL_OES_read_format, GL_ARB_pixel_buffer_object, GL_ARB_texture_rectangle,
    GL_EXT_pixel_buffer_object, GL_EXT_texture_compression_dxt1,
    GL_EXT_texture_rectangle, GL_ARB_framebuffer_object,
    GL_EXT_framebuffer_blit, GL_EXT_framebuffer_multisample,
    GL_EXT_packed_depth_stencil, GL_APPLE_object_purgeable,
    GL_ARB_vertex_array_object, GL_ATI_separate_stencil,
    GL_EXT_gpu_program_parameters, GL_OES_EGL_image, GL_ARB_copy_buffer,
    GL_ARB_map_buffer_range, GL_EXT_separate_shader_objects,
    GL_ARB_ES2_compatibility, GL_ARB_debug_output,
    GL_ARB_draw_elements_base_vertex, GL_ARB_explicit_attrib_location,
    GL_ARB_provoking_vertex, GL_ARB_sampler_objects, GL_EXT_provoking_vertex,
    GL_ARB_get_program_binary, GL_ARB_robustness,
    GL_ANGLE_texture_compression_dxt3, GL_ANGLE_texture_compression_dxt5,
    GL_ARB_internalformat_query, GL_ARB_texture_storage,
    GL_ARB_invalidate_subdata

Topics: Linux | 1 Comment »

Check if an Intent can be used in Android

By admin | June 15, 2013

Intent intent = new Intent("org.openintents.action.PICK_FILE"); // or any other intent
// add other intent options here

if(context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
    // we can use this intent
} else {
    // we can't use this intent
}

From: http://www.curious-creature.org/2008/12/15/android-can-i-use-this-intent/ [Romain Guy]

Topics: Mobile | 1 Comment »

Generating slope fields / direction fields with python and gnuplot

By admin | April 21, 2013

Slope field of (dy/dx) = x/y

Slope field of (dy/dx) = x/y

slopefields.py (1.9 KB)

Now you can generate your own slope field / vector field / direction field of a differential equation using open source python and gnuplot!

Topics: Linux | 1 Comment »

Techniques for testing Android fragments

By admin | March 4, 2013

How to test a fragment-based Android application:

Preferably test in the “don’t keep activities” mode, as this will root out a ton of bugs related to the Android lifecycle – i.e. when Android decides to kill an old activity of yours.

Case Study:

User complaint: http://forum.videolan.org/viewtopic.php?f=35&t=108743

The story so far… old versions of the VLC for Android beta, up to 0.0.10, suffer from a bug, where trying to delete something in another fragment causes the other (non-visible) fragment to receive the onContextItemSelected() call. After setting user visibility hints for that bug, a series of fragment related bugs appeared, mostly involving IllegalStateException in android.support.v4.app.FragmentManager because of duplicate fragments being added.

The problems were caused when Android decided to kill unused background activities. The interface code would try to recreate and re-add() fragments, even though Android had automatically recreated them via “android.support.fragments” in the onCreate() bundle. This would manifest after opening another activity, shutting the screen off, or having a system popup appear.

The solution was to keep better track of currently-added fragments, as member variables of the main activity may not necessarily be kept after the activity was hidden. To solve the problem, a check was implemented in onRestoreFragments() to ‘recall’ fragments that were already added. This fixed the problem permanently.

The moral of the story: watch and manage fragments very carefully in order to prevent problems.

Topics: Mobile | 3 Comments »

Compiling mingw-w64 with GCC 4.8

By admin | February 7, 2013

You need at least mingw-w64 rev 5579, build-essential, and a working compiler. Be sure to have installed flex and bison.

Replace the demo prefix /usr/i686-w64-mingw32 with whatever you feel like, if you want to.

Extract the gcc tarball, and pull in mpfr, mpc, and and gmp tarballs under the extracted gcc root.

sudo mkdir /usr/i686-w64-mingw32

../binutils-2.22/configure --disable-multilib --target=i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32
make -j4
sudo make install

ln -s /usr/i686-w64-mingw32/i686-w64-mingw32 /usr/i686-w64-mingw32/mingw

../mingw-w64/mingw-w64-headers/configure --build=i686-linux-gnu --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32/i686-w64-mingw32 # notice the extra i686-w64-mingw32
make
sudo make install

../gcc-4.8-20130120/configure --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++  --with-system-zlib --enable-shared --prefix=/usr/i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32
make all-gcc -j4
sudo make install-gcc

../mingw-w64/configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32
make -j4
sudo su
export PATH=/usr/i686-w64-mingw32/bin:$PATH
make install
exit

cd ../gcc-4.8-20130120-build
make -j4
# /usr/i686-w64-mingw32/i686-w64-mingw32/bin/ld: cannot find dllcrt2.o: No such file or directory
sudo ln -s /usr/i686-w64-mingw32/lib/dllcrt2.o /usr/i686-w64-mingw32/mingw/lib/
make
# checking for ld that supports -Wl,--gc-sections... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
# dig into i686-w64-mingw32/libstdc++-v3/config.log, you find this:
# /usr/i686-w64-mingw32/i686-w64-mingw32/bin/ld: cannot find crt2.o: No such file or directory
# solution:
sudo ln -s /usr/i686-w64-mingw32/lib/crt2.o /usr/i686-w64-mingw32/mingw/lib/
make
sudo make install

../../../mingw-w64/mingw-w64-libraries/winstorecompat/configure --prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32
make
sudo su
export PATH=/usr/i686-w64-mingw32/bin:$PATH
make install
exit

And just for fun, let’s test it:

i686-w64-mingw32-gcc --version
# i686-w64-mingw32-gcc (GCC) 4.8.0 20130120 (experimental)
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions.  There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

i686-w64-mingw32-gcc ~/c/hello.c

file a.exe
# a.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

wine a.exe
# Hello, World!

Bibliography:

Topics: Linux | 3 Comments »

Android DTS benchmark – libavcodec vs libdca

By admin | January 4, 2013

Galaxy Nexus with Android 4.1, ARMv7+NEON, VLC for Android 0.0.9-git (libdca 0.0.5 and libav revision 53c25ee), and OpenSL ES audio output

See previous audio benchmark for method

Summary/Conclusion: On an ARMv7 processor with NEON, libavcodec is faster by about 7% CPU-wise.

libdca libavcodec
Mean 18.326% 11.193%
Median 17.7% 9.4%
Mode 17.5% 9%
DTS benchmark - libdca vs libavcodec

DTS benchmark – libdca vs libavcodec

Raw data:

===libdca===
D/VLC     (15980): [0x5c6299b4]: main decoder using decoder module "dts"
  PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
15980   124 10079    R     527m 75.7   1 26.0 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 21.4 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 17.5 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 17.6 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 17.4 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 18.4 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 17.7 org.videolan.vlc
15980   124 10079    S     531m 76.4   0 17.5 org.videolan.vlc
15980   124 10079    S     531m 76.4   1 17.3 org.videolan.vlc
15980   124 10079    S     531m 76.4   0 17.1 org.videolan.vlc
D/VLC     (16769): [0x5bf9e44c]: main decoder using decoder module "dts"
16769   124 10079    S     524m 75.3   1 20.8 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 25.0 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 17.2 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 17.6 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 18.0 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 17.7 org.videolan.vlc
16769   124 10079    S     531m 76.4   0 18.2 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 17.8 org.videolan.vlc
16769   124 10079    S     531m 76.4   1 17.9 org.videolan.vlc
16769   124 10079    S     531m 76.4   0 17.5 org.videolan.vlc
D/VLC     (16840): [0x5c64fc54]: main decoder using decoder module "dts"
16840   124 10079    S     523m 75.3   0  9.3 org.videolan.vlc
16840   124 10079    S     531m 76.4   1 24.1 org.videolan.vlc
16840   124 10079    S     531m 76.4   0 17.9 org.videolan.vlc
16840   124 10079    S     531m 76.4   0 16.8 org.videolan.vlc
16840   124 10079    S     531m 76.4   1 17.7 org.videolan.vlc
16840   124 10079    S     531m 76.4   0 17.5 org.videolan.vlc
16840   124 10079    S     531m 76.4   1 17.8 org.videolan.vlc
16840   124 10079    S     531m 76.4   0 18.2 org.videolan.vlc
16840   124 10079    S     531m 76.4   1 17.7 org.videolan.vlc
16840   124 10079    S     531m 76.4   0 17.2 org.videolan.vlc

=====libavcodec=====
D/VLC     (17167): [0x5c43802c]: main decoder using decoder module "avcodec"
  PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
17167   124 10079    S     523m 75.3   0 20.2 org.videolan.vlc
17167   124 10079    S     532m 76.4   0 16.0 org.videolan.vlc
17167   124 10079    S     532m 76.4   0  9.4 org.videolan.vlc
17167   124 10079    S     532m 76.4   1  8.8 org.videolan.vlc
17167   124 10079    S     532m 76.4   0  9.0 org.videolan.vlc
17167   124 10079    S     532m 76.4   1  9.3 org.videolan.vlc
17167   124 10079    S     532m 76.4   0  9.6 org.videolan.vlc
17167   124 10079    S     532m 76.4   1  9.7 org.videolan.vlc
17167   124 10079    S     532m 76.4   1  9.4 org.videolan.vlc
17167   124 10079    S     532m 76.4   0  7.9 org.videolan.vlc
D/VLC     (17276): [0x5c4add84]: main decoder using decoder module "avcodec"
17276   124 10079    S     522m 75.1   0 20.0 org.videolan.vlc
17276   124 10079    S     530m 76.2   1 14.2 org.videolan.vlc
17276   124 10079    S     530m 76.2   0  8.7 org.videolan.vlc
17276   124 10079    S     530m 76.2   0  9.4 org.videolan.vlc
17276   124 10079    S     530m 76.2   0  9.9 org.videolan.vlc
17276   124 10079    S     530m 76.2   0  9.9 org.videolan.vlc
17276   124 10079    S     530m 76.2   1  9.0 org.videolan.vlc
17276   124 10079    S     530m 76.2   0  9.2 org.videolan.vlc
17276   124 10079    S     530m 76.2   0  9.7 org.videolan.vlc
17276   124 10079    S     530m 76.2   1  9.3 org.videolan.vlc
D/VLC     (17340): [0x5c657204]: main decoder using decoder module "avcodec"
17340   124 10079    S     522m 75.1   1 27.6 org.videolan.vlc
17340   124 10079    S     530m 76.3   0 14.5 org.videolan.vlc
17340   124 10079    S     530m 76.2   0  9.5 org.videolan.vlc
17340   124 10079    S     530m 76.2   0  9.4 org.videolan.vlc
17340   124 10079    S     530m 76.2   0  9.0 org.videolan.vlc
17340   124 10079    S     530m 76.2   1  9.4 org.videolan.vlc
17340   124 10079    S     530m 76.2   0  9.0 org.videolan.vlc
17340   124 10079    S     530m 76.2   0 10.0 org.videolan.vlc
17340   124 10079    S     530m 76.2   0  9.0 org.videolan.vlc
17340   124 10079    S     530m 76.2   0  9.8 org.videolan.vlc

Topics: Mobile | 3 Comments »

Compose key not working with iBus

By admin | December 8, 2012

The iBus input method does not work with the compose key – see Debian bug #591459 and Ubuntu bug #493766. It seems that iBus is intercepting all keystrokes and substituting its own instead, even though xev shows the Multi_key and accent being produced. For example, Multi_Key + ‘ + e leads to ‘e instead of é.

A temporary solution is to export XMODIFIERS=”” to bypass iBus, freeing the keystrokes for compose. However, this disables the iBus input method as it prevents iBus from receiving the keystrokes. XMODIFIERS, however, can be set per application, so one can simply set XMODIFIERS=”” for the specific application that requires the compose key.

Topics: Linux | 2 Comments »

Exploring and rooting the iPPea TV

By admin | November 24, 2012

Skip to the rooting process, if you wish.

The iPPea TV is a pretty neat gadget, to say the least. The USB-stick sized device features a full Android 4.0.3 OS, a 1Ghz Ingenic JZ4770 MIPS processor (complete with FPU!), 512 MB of RAM, 2 GB flash storage, and about 800 MB of internal memory. Overall, it is pretty impressive for only $65. Having received it about three weeks ago for use in the development of the MIPS port of VLC Android, I’ve been meaning to write about this device. Now that I’ve received this device and have time to write, let’s take a look at what’s in it.

Unboxing the iPPea

Unboxing the iPPea

The iPPea comes in its own packaging, in addition to the 3D gyroscopic remote offered by Option B.

The iPPea's packaging

The iPPea’s packaging

The iPPea comes with some packaging.

The iPPea after unpacking

The iPPea after unpacking

So, after unpacking, we are ready to play with the iPPea. The iPPea simply “plugs in” to any HDMI-enabled TV, just like how a USB stick plugs into a computer. It doesn’t take too long to boot up, about 15-25 seconds-ish (I did not time this).

The iPPea's home screen after booting up

The iPPea’s home screen after booting up

Output of /proc/cpuinfo on the iPPea

Output of /proc/cpuinfo on the iPPea

Just a curious note here, the iPPea claims to support full 1080p, but my television reports it to be 720p. I did not notice any lack of quality though, the picture was still very clear and not pixellated.

The iPPea boots into a full Android 4.0.3 installation, as mentioned before, with the twist that it runs a MIPS processor. It also features full wifi, which we will use in some diagnostics. Here are the /proc/cpuinfo and Android Sysinfo dumps for the iPPea TV:

system type		: JZ4770
processor		: MIPS-compatible processor JZ4770
cpu model		: Ingenic XBurst
BogoMIPS		: 1001.88
wait instruction	: yes
microsecond timers	: no
tlb_entries		: 32
extra interrupt vector	: yes
hardware watchpoint	: yes, count: 1, address/irw mask: [0x0fff]
ASEs implemented	: mxu
shadow register sets	: 1
core			: 0
VCED exceptions		: not available
VCEI exceptions		: not available
Features		: fpu mxu
CPU implementer		: Ingenic
CPU architecture	: MIPS

Hardware		: linden
Revision		: 0005
Serial			: 0000000000000000

EFUSE0			: d075370b
EFUSE1			: 02c00811
EFUSE2			: fc460000
EFUSE3			: 8a54c84f
EFUSE4			: 00000000
EFUSE5			: 00000000
EFUSE6			: 00000000
EFUSE7			: 00000000

…and the Sysinfo dump:

ID=IML74K
Product=linden
Device=linden
Board=unknown
CPU ABI=mips
CPU ABI 2=mips-r2
Manufacturer=ingenic
Brand=Ingenic
Model=iPPea
Type=eng
Tags=test-keys
Finger Print=Ingenic/linden/linden:4.0.3/IML74K/eng.spark.20120901.003556:eng/test-keys
Time=1346431472000
User=spark
Host=spark
Hardware=linden
Radio=unknown
Bootloader=unknown
Incremental Version=eng.spark.20120901.003556
Release Version=4.0.3
SDK Version=15

Rooting the iPPea TV

Curiously, the iPPea comes with busybox built-in into the image. This will make working with the iPPea easier, as we don’t have to compile/download busybox and deploy it – full access to all the busybox tools is available by default.

But what makes rooting really easy is the fact that the makers of the iPPea handed the blessing of leaving ro.secure off. This means that a simple adb connection is enough to grant root access – all that we have to do is install a su binary.

Unfortunately, the busybox su requires too much baggage of the traditional Linux system – notably /etc/passwd, /etc/groups and friends to work. Since this is a MIPS system and Superuser.apk is contains an ARM binary, that approach cannot work either. In addition, compiling su-binary from Superuser.apk requires the entire AOSP tree, which is too much work and network bandwidth for us. So, we will use a portable C implementation of su instead.

This step does require you to plug in the iPPea into a computer with ADB, so be prepared to do so. You will also need this prebuilt portable MIPS Android su binary. Skip over these steps if you are using the prebuilt binary (these are instructions to compile it yourself with the Android NDK):

export ANDROID_NDK=/opt/android-ndk-r8c # set as you need
$ANDROID_NDK/toolchains/mipsel-linux-android-4.6/prebuilt/linux-x86/bin/mipsel-linux-android-gcc --sysroot=$ANDROID_NDK/platforms/android-9/arch-mips -g su.c -o su

Now that you have the ‘su’ binary handy as well as your iPPea detected in adb (adb devices, you may need to chown it to make it visible), here we go:

adb push su /dev/
adb shell
# now we are on the iPPea
busybox mount -o remount,rw /system
busybox mv /dev/su /system/bin/su
busybox chmod 4755 /system/bin/su
busybox mount -o remount,ro /system
exit
# now we are back to our computer
adb reboot # to reboot

At this point we can put the iPPea back on the TV. If we open Term.apk and put in “su” and press Enter, we should have root:

Victory! Root access on the iPPea

Victory! Root access on the iPPea

And of course, once we have root access, the opportunities increase without bound – chrooted Debian/Linux, Android apps that require root, reformat and reflash with a custom ROM – the sky becomes the limit. We do, however, owe many thanks (and this is not meant to be sarcastic) to iPPea for leaving ro.secure at 0, allowing hobbyists to make better use of the hardware (which in itself is very neat).

Topics: Linux, Mobile | 19 Comments »

A simple su implementation in C

By admin | November 23, 2012

Sometimes, you might need to keep things simple. Here is a very simple su implementation written in portable C that can be used on almost any architecture – e.g. Embedded Linux, Android, Windows, etc as long as it supports C. It is licensed under the 3-clause BSD licence so any use is OK as long as credit is given:

/*
 * Simple su binary
 * Copyright (C) 2012 Compdigitec
 * http://www.compdigitec.com/labs/2012/11/23/a-simple-su-implementation-in-c/
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following disclaimer
 *   in the documentation and/or other materials provided with the
 *   distribution.
 * * Neither the name of Compdigitec nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>

#define SHELL "/system/bin/sh"

#define about() do { \
    printf("Simple crude su binary\n"); \
    printf("See http://www.compdigitec.com/labs/2012/11/23/a-simple-su-implementation-in-c/\n"); \
    printf("su [-c <command>] [-h] [-v] [user id to su to, must be integer]\n"); \
    } while(0)

int main(int argc, char* argv[]) {
    char* command = NULL;
    int user = 0; // root
    int group = 0;

    struct option long_opts[] = {
        { "command",	required_argument,		NULL, 'c' },
        { "help", 		no_argument,			NULL, 'h' },
        { "shell",		required_argument,		NULL, 's' },
        { "version",	no_argument,			NULL, 'v' },
        { NULL, 0, NULL, 0 },
    };

    int c;
    while((c = getopt_long(argc, argv, "+c:hsv", long_opts, NULL)) != -1) {
        switch(c) {
            case 'c':
                command = strdup(optarg);
                break;
            case 'h':
                about();
                exit(EXIT_SUCCESS);
                break;
            case 'v':
                about();
                exit(EXIT_SUCCESS);
            default:
                fprintf(stderr, "\n");
                about();
                exit(EXIT_SUCCESS);
        }
    }

    if(command == NULL)
        command = strdup(SHELL);

    if(optind < argc) {
        user = atoi( argv[optind++] );
    }

    // Let's get the group ID as well.
    struct passwd* tempPwdPtr;
#if 0
    struct passwd theentry;
    char* buf = malloc(sysconf(_SC_GETGR_R_SIZE_MAX));
    if(getpwuid_r(user, &theentry, buf, sysconf(_SC_GETGR_R_SIZE_MAX), &tempPwdPtr) == 0) {
        group = theentry.pw_gid;
        free(buf);
    }
#else
    if((tempPwdPtr = getpwuid(user)) != NULL) {
        group = tempPwdPtr->pw_gid;
    }
#endif

    //printf("Command: %s, User to run as: %i, GID = %i\n",command,user,group);
    setgid(group);
    setuid(user);
    system(command);

    free(command);
    return 0;
}

Topics: Linux | 3 Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries Newer Entries »