Memfetch with Android Samsung Galaxy Nexus - android

So I'm trying to use memfetch to dump the memory of a particular process from my Samsung Galaxy Nexus.
I downloaded memfetch from http://lcamtuf.coredump.cx/
Extracted out its contents using the following command:
tar -xvf memfetch.tgz
Ran an ls on my memfetch directory:
ls
COPYING Makefile memfetch.c mffind.pl README
At this stage i'm supposed to run the make command to get my memfetch executable.
Editing the memfetch.c file, i removed the #include page.h line
So first i downloaded the Android ARM Architecture it with the following command. This was for static cross-compilation for the memfetch:
apt-get install gcc-arm0-linux-gnueabi
Then i edited Makefile at the following areas:
FILE = memfetch
CFLAGS = -Wall -09 -static
CC = arm-linux-gnueabi-gcc
So success, i had my memfetch executable:
make
arm-linux-gnueabi-gcc -Wall -09 -static memfetch.c -o memfetch
ls
COPYING Makefile memfetch memfetch.c mffind.pl README
Then i pushed the memfetch executable into my Android phone:
adb push memfetch /sdcard/memfetch
Now from here i worked things from my phone. I ran executed the adb shell command and created a directory to store the memfetch exectable, ideally to run it from there:
adb shell
su
cd /sdcard
mkdir tmp
mount -t tmpfs tmpfs tmp
cp memfetch tmp
cd tmp
chmod 6755 memfetch
Now here's where the problem comes. When i executed the memfetch, i was getting the following error:
./memfetch 1197
memfetch 0.05b by Michal Zalewski <lcamtuf#coredump.cx>
Usage ./memfetch [ -sawn ] [ -S xxx ] PID
-s - wait for fault signal before generating a dump
-a - skip non-anonymous maps (libraries etc)
-w - write index file to stdout instead of mfetch.lst
-m - avoid mmap(), helps to prevent hanging on some 2.2 boxes
-S xxx - dump segment containing address xxx (hex) only
No matter what PID i tried to dump, i always got the same error. I even tried with various flag combinations but none of them worked :(
Thanks for any help in advanced, let me know if any additional information is required.

That is because of stupidity of Windows Command Line, that make some null characters as input to linux commands.
the solution is, if you don't use other inputs "samwS" comment this lines,
while ((opt=getopt(argc,(void*)argv, "+samwS:h"))!=EOF)
switch(opt) {
case 's': waitsig=1; break;
case 'a': skipmap=1; break;
case 'w': textout=1; break;
case 'm': avoid_mmap=1; break;
case 'S': if (sscanf(optarg,"%x",&onlyseg)!=1)
fatal("Incorrect -S syntax (hex address expected).\n");
break;
default: usage(argv[0]);
}
it you use them just comment
default: usage(argv[0]);

Related

Issues with building Android native executable programs through CMake and arm-linux-gnueabi-gcc

CMakeLists.txt
STRING( REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} )
SET(TARGET ${CURRENT_FOLDER})
PROJECT (${TARGET})
add_compile_options(-static -march=armv7-a)
aux_source_directory(./src SRCS)
add_executable(${TARGET} ${SRCS})
hello.c
#include <stdio.h>
int main(void)
{
printf("hello ARM!!!");
return 0;
}
adb push '.\Desktop\hello' /data/local/tmp
adb shell chmod 777 /data/local/tmp/hello
adb shell /data/local/tmp/hello
/system/bin/sh: /data/local/tmp/hello: No such file or directory
adb shell ls -l /data/local/tmp/
-rwxrwxrwx root root 10652 2021-01-21 17:03 hello
When I compile by the following command
arm-linux-gnueabi-gcc -static -march=armv7-a hello.c -o hello
adb push '.\Desktop\hello' /data/local/tmp
adb shell chmod 777 /data/local/tmp/hello
adb shell /data/local/tmp/hello
hello ARM!!!
I found that the compile_commands.json generated by cmake is
"command": "/bin/arm-linux-gnueabi-gcc-8 -g -static -march=armv7-a -o CMakeFiles/hello.dir/src/hello.c.o -c /home/dev/workspace/ASM/Projects/hello/src/hello.c",
I don't know how to solve this problem.
CMake use two steps to generate executable. The first step it compiles the source files ( c or c++) to object file. then it links the file needed to generate the executable(s).
The compile_commands.json will contain only the commands used to compile and not to link. normally you can find the command used to link in link.txt. this file can be found in CMakeFiles/<name>.dir/link.txt.
You can also , directly run your make commad with VERBOSE=1 to see the executed command on live.
For your problem, i think there is a problem with your TARGET variable, but without more information i can not be sure.

Running C++ program in android device

I am writing a C++ code to execute 'top' command in android device. This is the code I use.
using namespace std;
int main()
{
char buffer[1024];
string result;
system("top -n 1 | head -n 4 | tail -n 3");
FILE *memcpu= popen("top -n 1 | head -n 4 | tail -n 3","r");
while (!feof(memcpu)) {
if (fgets(buffer, 1024, memcpu) != NULL)
result+=buffer;
}
cout<<"result you need\n"<<result;
}
I want to run this file in adb device. Hence I build the program using command
arm-linux-gnueabi-g++ -static -march=armv7-a name.cpp -o test
When I run the program, the string result is empty.
I tested the program by including system("top -n 1"); line in the program. But I am not getting any output from adb shell (empty string).
I build the same program using g++ and run in linux pc. And at that time I am getting the correct output. What might be the reason that I am not getting desired output in adb shell from android device?
When you build the program using command
arm-linux-gnueabi-g++ -static -march=armv7-a name.cpp -o test
a static binary is created. In order to link the libraries in android, the program must be built using android ndk build. And that solved the problem for me.

Rsync and ssh on android: No such file or directory

I'm trying to write an android app that backs up data from selected directory of an android device to a remote host using rsync and ssh. When I run the rsync command from adb shell as follows, it works:
rsync -rvz -e "/system/xbin/ssh -y -p 22" "/mnt/sdcard/" "rajeesh#10.0.2.2:backup/"
But my java code using Runtime.exec fails with an error that says:
Error: rsync: failed to exec /system/xbin/ssh -y -p 22: No such file or directory (2)
The code I used is as follows:
String[] commands = {
"rsync", "-rvz", "-e", "\"/system/xbin/ssh -y -p 22\"",
"\"/mnt/sdcard/\"", "\"rajeesh#10.0.2.2:backup/\""
};
Process process = Runtime.getRuntime().exec(commands);
Both rsync and ssh have been placed at /system/xbin and chmoded to 755. Tried replacing "rsync" with "/system/xbin/rsync" also but the issue remains. What would be the issue here?
Found out the issue myself.
When run directly from the shell, quotes have specific meaning and they are required here as follows:
rsync -rvz -e "ssh -y -p 22" "/path/to/src/" "/path/to/dest"
My java snippet above was trying to run the command with the quotes escaped, like "\"arg\"". But quotes not required when used outside shell. The correct usage is:
String[] commands = {
"/system/xbin/rsync", "-rvz", "-e", "/system/xbin/ssh -y -p 22",
"/mnt/sdcard", "rajeesh#10.0.2.2:backup/"
};
I'm not sure but maybe problem is that the destination path (rajeesh#10.0.2.2:backup/) is not absolute?
Also if you what to sync your files in the same device, maybe you should try to not use ssh? And do something like that:
rsync -rvz /mnt/sdcard/some_directory /backup

GCC thinks I'm running x86

I am trying to compile Cyanogenmod on Linux Mint 15. And receive the following error.
host StaticLib: libmincrypt (/home/benji/Source/out/host/linux-x86/obj/STATIC_LIBRARIES/libmincrypt_intermediates/libmincrypt.a)
ERROR: prebuilts/tools/gcc-sdk/../../gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin/x86_64-linux-ar only run on 64-bit linux
make: *** [/home/benji/Source/out/host/linux-x86/obj/STATIC_LIBRARIES/libmincrypt_intermediates/libmincrypt.a] Error 1
make: *** Waiting for unfinished jobs....
# In case value of PACKAGES is empty.
-
benji#ultranoid ~/Source/prebuilts/tools/gcc-sdk $ ./gcc
ERROR: ./../../gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin/x86_64-linux-gcc only run on 64-bit linux
I can't figure out what is causing this. I am on a 64 bit install. Please advise.
benji#ultranoid ~/Source $ uname -p
x86_64
Workaround
Comment out lines 23-38 of prebuilts/tools/gcc-sdk/gcc
Example: http://pastebin.com/qH0BYcSF
As pointed out here, within Android build system the test for x32 vs x64 host is based on the output of file -L "$SHELL" | grep -q "x86[_-]64". In other words it tests whether or not current shell is a 64 bit binary.
So a possible answer is : check out if value of environmental variable $SHELL is a valid path to a shell executable.
You may try to change shell with chsh or
create a link to your favorite shell so that $SHELL is satisfied. The latter did the trick for me - I've simply linked /bin/bash to where $SHELL pointed.
use uname -m to check system.
#file -L "$SHELL" | grep -q "x86[_-]64"
#if [ $? != 0 ]; then
# $SHELL is not a 64-bit executable, so assume our userland is too.
# echo "ERROR: $MY_TOOL only run on 64-bit linux"
# exit 1
#fi
changed to:
ARCH_OS=uname -m | tr '[:upper:]' '[:lower:]'
if [ "$ARCH_OS" != "x86_64" ] ; then
echo "ERROR: $MY_TOOL only run on 64-bit linux from uname -m"
exit 1
fi

How do you create a loadable kernel module for Android?

I know there a number of walkthroughs and tutorials floating around out there which describe this activity, but after having read many of them I still can't get this working. If anyone has the patience to wade through the steps I've taken (posted below) and suggest where I may have gone off track I'd be very appreciative. I've spent about a day and a half staring at make files and reading walkthroughs so literally any suggestions would be helpful.
Environment:
I'm using an Ubuntu 10.04 32 bit vm.
I'm hosting from a 64 bit windows 7
My Core 2 Duo does not have the hardware support for 64 bit VMs so i'm trying to compile against Android 2.1 kernel
I have installed Java 1.5 from the Dapper repo and removed my 1.6 installation
The rest of the tooling has been acquired according the Android dev documentation...
As per Initializing a Build Environment:
Java:
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk
Other required:
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline5-dev libz-dev libgl1-mesa-dev
$ sudo apt-get install gcc-multilib g++-multilib libc6-i386 libc6-dev-i386
Then from Downloading the Source Tree:
Repo:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
$ repo init -u https://android.googlesource.com/platform/manifest -b eclair
$ repo sync
$ gpg --import (imported the huge key)
And from Building the System:
Initialize:
$ source build/envsetup.sh
Choose a Target:
$ lunch generic-user
Build the Code:
$ make -j4
Added!
Output of make -j4:
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
Install: out/host/linux-x86/bin/acp
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
target Generated: libclearsilver-jni <= out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
host C++: aapt <= frameworks/base/tools/aapt/AaptAssets.cpp
host C++: aapt <= frameworks/base/tools/aapt/Command.cpp
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; error in opening zip file
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; error in opening zip file
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; cannot read zip file
error: cannot access org.clearsilver.HDF
class file for org.clearsilver.HDF not found
javadoc: error - Class org.clearsilver.HDF not found.
Error: No classes were specified on the command line. Try -help.
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h] Error 15
make: *** Waiting for unfinished jobs....
error: error reading out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar; cannot read zip file
error: cannot access org.clearsilver.CS
class file for org.clearsilver.CS not found
In file included from frameworks/base/tools/aapt/AaptAssets.h:18,
from frameworks/base/tools/aapt/AaptAssets.cpp:5:
frameworks/base/tools/aapt/ZipFile.h:65: warning: ‘typedef’ was ignored in this declaration
javadoc: error - Class org.clearsilver.CS not found.
Error: No classes were specified on the command line. Try -help.
In file included from frameworks/base/tools/aapt/AaptAssets.h:18,
from frameworks/base/tools/aapt/Main.h:14,
from frameworks/base/tools/aapt/Command.cpp:6:
frameworks/base/tools/aapt/ZipFile.h:65: warning: ‘typedef’ was ignored in this declaration
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_CS.h] Error 15
Added!
So it turns out i've got some problems here. I assume that once i've overcome these issues, i'll have an environment capable of compiling kernel modules. Please do correct me if I'm wrong.
Next I head into my directory containing my module.c file and it's makefile. Contents of makefile below:
obj-m += mymodule.o
CROSS_COMPILE=~/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
KERNEL_DIR ?= /home/<myuser>/WORKING_DIRECTORY
VERSION = v1.1
all:
make -C $(KERNEL_DIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
rm -rf *.c~
rm -rf *.mod*
rm -rf *.o
clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
I have very little experience with make and makefiles, but this looked reasonable to me. My main concern with this file is the KERNEL-DIR variable. I tried a few different values for that variable, but got all sorts of errors where I do not with it's current value. Of course, it could still be wrong, so any comments here are welcome.
So, as far as I know, I should be able to execute make with no args or anything and will figure out what it needs to do. I have tried make, make -f both with and without sudo. All four permutations yield the same results:
make -C /home/<myuser>/WORKING_DIRECTORY M=/home/<myuser>/Desktop/<MyModuleDir> ARCH=arm CROSS_COMPILE=~/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- modules
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.1-update1
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ECLAIR
============================================
make[1]: Entering directory `/home/<myuser>/WORKING_DIRECTORY'
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
Available sub-modules:
01-test dumpsys libminui LotsOfApps
20-dns.conf dvz libminzip lowstoragetest
95-configured dx libmp4recognizer_utility lsd
aapt dx-tests libmtdutils LunarLander
acc edify libnativehelper LunarLanderTests
AccountAndSyncSettings Email libneo_cgi MagicSmokeWallpapers
accRuntimeTest EmailTests libneo_cs make_cfst
acp emma libneo_util makedict
adb emmalib libnetutils make_g2g
adbd emulator libocr makekeycodes
add-property-tag emulator-arm libomx_aac_component_lib make_ve_grammar
afar emulator-hw libomx_aacdec_sharedlibrary mediaframeworktest
aidl emulator-tcg libomx_amr_component_lib MediaProvider
AlarmClock EnabledTestApp libomx_amrdec_sharedlibrary mediaserver
AliasActivity etc1tool libomx_amrenc_component_lib memtest
am eventanalyzer libomx_amrenc_sharedlibrary minigzip
android event-log-tags libomx_avc_component_lib mkbootfs
android.core.tests.annotation exc_dump libomx_avcdec_sharedlibrary mkbootimg
android.core.tests.archive ext libomx_baseclass_lib mksdcard
android.core.tests.concurrent Fallback libomx_common_lib mkstubs
android.core.tests.crypto fastboot libomx_m4v_component_lib mkyaffs2image
android.core.tests.dom FixedGridLayout libomx_m4vdec_sharedlibrary Mms
android.core.tests.logging flash_image libomx_mastercore_lib MmsTests
android.core.tests.luni.io FontLab libomx_mp3_component_lib monkey
android.core.tests.luni.lang framework libomx_mp3dec_sharedlibrary monkeyrunner
android.core.tests.luni.net FrameworkPermissionTests libomx_queue_lib mtpd
android.core.tests.luni.util framework-res libomx_sharedlibrary MultiResolution
android.core.tests.math FrameworkTest libop Music
android.core.tests.nio framework-tests libopencore_author MusicTests
android.core.tests.nio_char FrameworkTestTests libopencore_common nc
android.core.tests.prefs fsck_msdos libopencore_download netcfg
android.core.tests.regex fs_config libopencore_downloadreg netperf
android.core.tests.runner fs_get_stats libopencore_mp4local netserver
android.core.tests.security Gallery libopencore_mp4localreg ninepatch
android.core.tests.sql Gallery3D libopencore_net_support NinePatchLab
android.core.tests.text GalleryTests libopencore_player NoShareUidApp
android.core.tests.xml gdbserver libopencore_rtsp NotePad
android.core.tests.xnet genext2fs libopencore_rtspreg NotePadTests
android.cts.dpi GestureBuilder libosclbase opcontrol
android.cts.refapp GL2JNI libosclerror openssl
android.policy GLJNI libosclio OpenWnn
android.policy_mid GlobalSearch liboscllib oprofiled
android.policy_phone GlobalSearchBenchmarks libosclmemory org.eclipse.core.commands_3.4.0.I20080509-2000
androidprefs GlobalSearchPermissionTests libosclproc org.eclipse.equinox.common_3.4.0.v20080421-2006
android.test.runner GlobalSearchTests libosclregcli org.eclipse.jface_3.4.2.M20090107-0800
AndroidTests GlobalTime libosclregserv org-netbeans-api-visual
angeles GoogleContactsProvider libosclutil org-openide-util
ant GoogleContactsProviderTests libpagemap osgi
antlr-2.7.7 google-framework libpassthru_oma1 PackageInstaller
anttasks googlelogin-client libpcap parseStringTest
apicheck GoogleSearch libpixelflinger perm_checker
ApiDemos gpustate libpixelflinger_armv6 perm_checker.conf
ApiDemosReferenceTest gralloc.default libpixelflinger_static Phone
ApiDemosTests groovy-all-1.6.5 libplatform_library_jni PicoTts
apkbuilder grxmlcompile libpng ping
ApplicationsProvider gtest-filepath_test libpopt PinyinIME
applypatch gtest-linked_ptr_test libprotocolenginenode_base PlatformLibraryClient
applypatch_static gtest-message_test libprotocolenginenode_common platform.xml
app_process gtest-options_test libprotocolenginenode_download_common pm
AppWidgetHostTest gtest-port_test libprotocolenginenode_pdl post_trace
AppWidgetProvider gtest_pred_impl_unittest libprotocolenginenode_ps pppd
apriori gtest_prod_test libpv_aac_dec preload
archquery gtest-test-part_test libpvaacffparsernode ProcessTests
asm-3.1 gtest-typed-test2_test libpvaacffrecognizer procmem
atree gtest-typed-test_test libpvaacparser procrank
AudioHardwareRecord gtest_unittest libpvamrffparsernode profile_pid
AudioHardwareRecordLoop gzip libpvamrffrecognizer profile_trace
AudioInRecord HelloActivity libpv_amr_nb_common_lib Provision
backup_helper_test HelloActivityTests libpvamrwbdecoder pvplayer
BackupTest hierarchyviewer libpvauthorengine q2dm
BatteryWaster hist_trace libpv_avc_common_lib q2g
bb2sym Home libpvavcdecoder qemud
bb_dump hosttestlib libpvavifileparser qemu-props
bbprof hprof-conv libpv_config_parser qwerty2.kcm
bison HTMLViewer libpvdecoder_gsmamr qwerty.kcm
Bluetooth icache libpvdownloadinterface racoon
BluetoothChat icudata libpvdownloadmanagernode radiooptions
BluetoothDebug idegen libpvdownloadreginterface read_addr
bmgr ime libpvencoder_gsmamr read_method
bookmarks.xml ImfTest libpvfileoutputnode read_pid
bootanimation ImfTestTests libpvfileparserutils read_trace
Browser imgdiff libpvframemetadatautility recovery
BrowserPowerTests init libpvgendatastruct required_hardware.xml
BrowserTestPlugin input libpvgsmamrparser rgb2565
BrowserTests installd libpv_http_parcom rild
bsdiff invoke_mock_media_player libpvid3parcom rsg-generator
bspatch iptables libpvjitterbuffer RSSReader
btool ip-up-vpn libpvjitterbuffernode run-core-tests
bugreport iself libpvjitterbufferrtp run-core-tests-on-ri
BusinessCard isprelinked libpvlatmpayloadparser safe_iop_test
Calculator jarjar libpvmediadatastruct SampleBrowserPlugin
CalculatorTests jarutils libpvmediainputnode schedtest
Calendar jasmin libpvmedialayernode scp
CalendarProvider jasmin.jar libpvmediaoutputnode screenshot2
CalendarProviderTests javax.obex libpvmf sdklib
CalendarTests jcommon-1.0.12 libpvmfrecognizer sdkmanager
Camera jdiff libpvmimeutils SdkSetup
CameraTests jdwpspy libpvmioaviwavfileinput sdkstats
CertInstaller JETBoy libpvmiofileinput sdkuilib
cfassembler jfreechart-1.0.9 libpvmiofileoutput sdutil
check-lost+found jfreechart-1.0.9-swt libpvmp3 SearchableDictionary
check_prereq junit libpvmp3ff sensors.goldfish
check_stack jython libpvmp3ffparsernode service
check_trace kcm libpvmp3ffrecognizer servicemanager
clearsilver keystore libpvmp4decoder services
cmu2nuance keystore_cli libpvmp4ff Settings
com.android.inputmethod.pinyin.lib KeyStoreTests libpvmp4ffcomposer SettingsProvider
com.example.android.platform_library kxml2-2.3.0 libpvmp4ffcomposernode SettingsTests
commons-compress-1.0 latencytop libpvmp4ffparsernode sh
Compass LatinIME libpvmp4ffrecognizer ShareUidApp
ContactManager Launcher libpvmp4interface showlease
Contacts Launcher2 libpvmp4reginterface showmap
ContactsProvider launchperf libpvomxaudiodecnode showslab
ContactsProviderTests layoutlib libpvomxbasedecnode sig
ContactsTests layoutlib_api libpvomxencnode sig-check
core layoutlib_create libpv_omx_interface sig-create
core-tests layoutlib_utils libpvomx_proxy_lib signapk
CoreTests layoutopt libpvomxvideodecnode SignatureTest
coverage libabi libpvplayer_engine SignatureTestTests
cpueater libacc libpvpvxparser signature-tools
cpufeatures libaes libpvrtsp_cli_eng_node SimpleJNI
crasher libandroidpv libpvrtspinterface SkeletonApp
create_test_dmtrace libandroidpvauthor libpv_rtsp_parcom SkeletonAppTests
cts libandroid_runtime libpvrtspreginterface skia_bench
CtsAccessibilityServiceTestCases libandroid_servers libpvsdpparser skia_gm
CtsAccountManagerTestCases libapplypatch libpvsocketnode SlowSuggestions
CtsAppAccessData libarity libpvstreamingmanagernode SmokeTest
CtsAppSecurityTests libastl libpvthreadmessaging SmokeTestApp
CtsAppTestCases libaudioflinger libpvwav Snake
CtsAppWithData libaudiointerface libpvwavffparsernode SnakeTests
CtsBluetoothTestCases libaudiopolicygeneric libpvwavffrecognizer SoftKeyboard
CtsContentTestCases libbinder librank soslim
cts-dalvik-buildutil libbz libreference-cdma-sms sound
CtsDatabaseTestCases libc libreference-ril SoundRecorder
CtsDelegatingAccessibilityService libcameraservice libril SpammySuggestions
CtsDpiTestCases libcamerastub libRS SpareParts
CtsDpiTestCases2 libc_common librs_jni spec-progress
CtsExampleTestCases libc_debug librtppayloadparser sqlite3
CtsGestureTestCases libclearsilver-jni librtprtcp SRecTest
CtsGraphicsTestCases libc_nomalloc libsafe_iop SRecTestAudio
CtsHardwareTestCases libcolorconvert libsampleplugin ssh
CtsInstrumentationAppDiffCert libcpm libSDL SslLoad
CtsJniTestCases libcrypto libSDLmain stack_dump
CtsLocationTestCases libctest libsimplejni StatusBarTest
CtsMediaTestCases libcts_jni libskia Stk
CtsNetTestCases libctspermission_jni libskiagl strace
CtsOsTestCases libcutils libsonivox stringtemplate
CtsPerformance2TestCases libdb libsoundpool su
CtsPerformance3TestCases libdbus libspeex surfaceflinger
CtsPerformance4TestCases libdbus-tools-common libsqlite svc
CtsPerformance5TestCases libdex libsqlite3_android swing-worker-1.1
CtsPerformanceTestCases libdl libsqlite3_phone_number_utils_test swt
CtsPermission2TestCases libdrm1 libsqlite3_phonetic_string_utils_test system_server
CtsPermissionDeclareApp libdrm1_jni libSR_AcousticModels tcpdump
CtsPermissionTestCases libdrm2 libSR_AcousticState TelephonyProvider
CtsProviderTestCases libdvm libSR_AudioIn telephonytest
CtsSharedUidInstall libebl libSR_Core temp_layoutlib
CtsSharedUidInstallDiffCert libebl_arm libsrec_jni Term
CtsSimpleAppInstall libedify libSR_EventLog test_defs.xml
CtsSimpleAppInstallDiffCert libEGL libSR_G2P TestDeviceSetup
CtsSpeechTestCases libelf libSR_Grammar test-fb-refresh
CtsTargetInstrumentationApp libelfcopy libSR_Nametag test-fb-simple
CtsTelephonyTestCases libembunit libSR_Recognizer test_g2g
CtsTestStubs libemoji libSR_Semproc test-mdp
CtsTextTestCases libESR_Portable libSR_Session test-opengl-codegen
CtsUsePermissionDiffCert libESR_Shared libSR_Vocabulary test-opengl-fillrate
CtsUtilTestCases libETC1 libssl test-opengl-filter
CtsViewTestCases libexif libstagefright test-opengl-finish
CtsWebkitTestCases libexpat libstagefright_omx test-opengl-gl2_basic
CtsWidgetTestCases libext libstdc++ test-opengl-gl_basic
CubeLiveWallpapers libfdlibm libsurfaceflinger test-opengl-gralloc
CustomLocale libFFTEm libsvoxpico test-opengl-linetex
daemonize libfst libsystem_server test-opengl-swapinterval
dalvikvm libft2 libsysutils test-opengl-textures
dasm libgetactualaacconfig libterm test-opengl-tritex
dbus-daemon libgif libtestplugin test-progress
dbus-monitor libgl2jni libthread_db test-progress-new
dbus-send libGLES_android libthreadsafe_callback_ao test_swiarb
ddmlib libGLESv1_CM libtinyxml test_zipfile
ddms libGLESv2 libtomcrypt timeinfo
ddmuilib libgljni libtommath timetest
debuggerd libgoogleclient libttspico toolbox
DensityTest libgtest libttssynthproxy traceview
descGen libgtest_main libui TransformTest
DeskClock libhardware libunz TtsService
Development libhardware_legacy libutil tuttle2.kcm
dexdeps libhost libutils uix
dexdump libicudata-default libvorbisidec updater
dexlist libicudata-eu libwbxml UpgradeExample
dexopt libicudata-jp libwbxml_jni usbtest
dexopt-wrapper libicudata-large libwebcore UserDictionaryProvider
dexpreopt libicudata-us libwnndict VisualizationWallpapers
dex-tools libicui18n libWnnEngDic vm-tests
dhcpcd libicuuc libWnnJpnDic VoiceDialer
dhcpcd-run-hooks libiptc libwpa_client Voiper
dictTest libjavacore libxml2 vold
DisabledTestApp libjni_latinime libxml2wbxml VpnServices
dmtracedump libjni_pinyinime libz wbxmltest
DownloadProvider libjnitest libzipfile wdsclient
draw9patch libjpeg LightingTest webkitmerge
DrmProvider liblog line_endings Wiktionary
droiddoc libm linker WiktionarySimple
dumpeventlog libm4v_config LiveWallpapers xmlwriter
dumpkey libmedia LiveWallpapersPicker yuv420sp2rgb
dump_regions libmedia_jni localize zipalign
DumpRenderTree libmediaplayerservice logcat
dumpstate libmincrypt logwrapper
make[1]: Leaving directory `/home/<myuser>/WORKING_DIRECTORY'
rm -rf *.c~
rm -rf *.mod*
rm -rf *.o
You'll notice a few screwy warnings, but as best as I can tell, they are not real problems. If anyone feels differently about these, please say so.
make[1]: Entering directory `/home/<myuser>/WORKING_DIRECTORY'
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
/bin/bash: line 0: cd: sdk/layoutopt/app/src/resources: No such file or directory
I guess that last line sounds pretty suspicious but I have no idea what to do about it. Apart from the few strange things i've mentioned, it would appear that this all went smoothly. However, after the whole thing completes, I can't find the *.ko file anywere. I did a ls -alRg | grep *.ko on my home directory and it turns up nothing. I'm stumped. If I can provide any more information or run any tests or try anything differently i'll be checking in frequently.
Sorry for being late, but hope it helps:
http://tthtlc.wordpress.com/2011/12/29/how-to-write-a-kernel-module-on-android-sony-ericsson-xperia-arc-s/
I wrote and tested the code on my Sony Ericsson Xperia Arc S and it works (in general in should work for any Android phone).
Connecting via adb and USB, and “su” to root, the “lsmod” listed all the kernel module (in general, the article at
http://web.archive.org/web/20121106004141/http://developer.sonymobile.com/2011/05/06/how-to-build-a-linux-kernel gave a very good coverage of what to do in Linux kernel compilation for SonyEricsson phone):
lsmod
android_module 654 0 - Live 0x7f007000 (P)
sdio 16532 0 - Live 0x7f000000
“android_module” was the one I had inserted via insmod android_module.ko.
Here’s how to do it:
First the original program was copied from:
http://rechtzeit.wordpress.com/2011/03/21/77/
Or reproduced as follows:
android_module.c:
#include"linux/module.h"
#include"linux/kernel.h"
//replace the "" with angular brackets
int init_module(void)
{
printk(KERN_INFO "Hello android kernel...\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye android kernel...\n");
}
Makefile:
obj-m += android_module.o
all:
make -C /home/tteikhua/android/sony_ericsson_src/58/kernel/ M=$(PWD) modules
clean:
make -C /home/tteikhua/android/sony_ericsson_src/58/kernel/ M=$(PWD) clean
The directory where the kernel is located (“-C” above) is where kernel is located.
And the following command will use the Makefile from above:
ARCH=arm CROSS_COMPILE=/opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- make
As shown above, the cross compiler I had used is from CodeSourcery.
And after insmod android_module.ko you can see the debugging message in dmesg output:
<6>[11184.063507] Hello android kernel...
<7>[11619.209655] msmrtc_timeremote_set_time: 11/29/2011 10:09:36 (04)
<6>[11619.210418] RPC CALL -- TOD TIME UPDATE: ttick = 404244221
<6>[11619.210418] stamp=52910543933046785, freq = 0
<7>[11619.211578] msmrtc_tod_proc_result: 12/29/2011 10:09:36 (03)
<6>[11619.211578] rs30000048 rs30000048.262144: setting system clock to 2011-12-29 10:09:36 UTC (1325153376)
<6>[11662.112365] device rmnet0 left promiscuous mode
<6>[11662.112579] device rmnet0 entered promiscuous mode
<6>[11669.958221] device rmnet0 left promiscuous mode
<6>[11669.958435] device rmnet0 entered promiscuous mode
<7>[11698.181060] msmrtc_timeremote_set_time: 11/29/2011 10:10:55 (04)
<6>[11698.187622] RPC CALL -- TOD TIME UPDATE: ttick = 406832008
<6>[11698.187652] stamp=52910548228014081, freq = 0
<7>[11698.193939] msmrtc_tod_proc_result: 12/29/2011 10:10:55 (03)
<6>[11698.194030] rs30000048 rs30000048.262144: setting system clock to 2011-12-29 10:10:55 UTC (1325153455)
<6>[11814.442901] bq27520 0-0055: bq27520_handle_soc_worker() capacity=97 (100) flags=0x229 ctrl_status=0x28b soh_state=0x3, valid=1
<6>[11984.057373] Goodbye android kernel...
And the “Goodbye” is when rmmod android_module is executed. In between are debugging message from other components in the kernel.
Final words:
The above are written in 2011, for more modern resources, please refe to the following to get started:
https://source.android.com/docs/core/architecture/kernel/modular-kernels
https://source.android.com/docs/core/architecture/kernel
https://source.android.com/docs/setup/build/building-kernels
https://source.android.com/docs/core/architecture/kernel/loadable-kernel-modules
I think I've red that emulator kernel does not support module, so you must compile also the kernel with modules support.
I hope that this link will help you
There are two things you'll need to do. Firstly, create an emulator kernel that supports loadable kernel modules.
There's a comprehensive post here covering the process of setting up the emulator kernel.
There are 2 parts of the instructions to alter:
I find it easiest to keep the kernel within the repo area (in this case, ~/WORKING_DIRECTORY), like so:
cd ~/WORKING_DIRECTORY
mkdir kernel
cd kernel
git clone git://android.git.kernel.org/kernel/common.git
The branch information is no longer correct, however, so where it says:
git checkout -t origin/android-goldfish-2.6.29 -b goldfish
use this instead:
git checkout -t archive/android-gldfish-2.6.29 -b goldfish
As you've found out, the kernel by default is not configured with loadable module support. Enable before compiling. After, this step:
make ARCH=arm goldfish_defconfig
do this:
make ARCH=arm menuconfig
A text-based menu will show up. Use the Up/Down arrow keys to navigate, Space to select an option, Enter to expand a menu (menus have --->) at the end of the line, and Esc-Esc to go back a menu.
Select "Enable loadable module support" by scrolling down and hitting Space
Hit Esc-Esc to exit, and hit Enter to save the new configuration
Now build. Using your setup, it would be:
make ARCH=arm CROSS_COMPILE=/home/<myuser>/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
Now that that's done you can do the second part, which is making a loadable kernel module. You were almost there, but because you didn't have the kernel source for the emulator, it didn't work. Just take the makefile you have and change KERNEL_DIR to:
KERNEL_DIR ?= /home/<myuser>/WORKING_DIRECTORY/kernel/common

Categories

Resources