Compiling UnrealIRCD on an iPod Touch 2G

Note: This is an old post, from an old blog far, far away

Prerequisites

wget "http://www.unrealircd.com/downloads/Unreal3.2.10.1.tar.gz" | tar -xvzf -

Configuring

For some reason I had to run the ./configure as root after cd’ing into the directory where I extracted the files as the mobile user; perhaps due to an inability to run unsigned applications?

checking whether we are cross compiling… configure: error: in /var/mobile/Unreal3.2.10.1': configure: error: cannot run C compiled programs. If you meant to cross compile, use–host’.

After running as root, everything went rather smoothly. Edit dpath and spath as you wish.

1
./configure --with-showlistmodes --enable-ssl --enable-ziplinks --enable-inet6 --with-listen=5 --with-dpath=/var/mobile/UnrealIRCD-build --with-spath=/var/mobile/UnrealIRCD-build/src/ircd --with-nick-history=2000 --with-sendq=3000000 --with-bufferpool=18 --with-permissions=0600 --with-fd-setsize=1024 --enable-dynamic-linking

I forgot to use ‘time’ but estimate it perhaps took around 20 minutes. After make && make install:

1
2
3
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.cert.pem -days 1826
cp server.key server.key.pem

to generate the certificate and key needed for the SSL connection. After running ./unreal start ; it required some source modules in the build folder and the config file for the IRCD.

1
2
cp -r /var/mobile/Unreal3.2.10.1/src/ ../UnrealIRCD-build/
cp /var/mobile/UnrealIRCD-build/src/example.conf /var/mobile/UnrealIRCD-build/unrealircd.conf

Edit the config file as you wish!…

How I understand RSA

wpid-wp-1402514522645-1024x735.jpeg Euler’s totient function is defined as the number of positive integers relatively prime to n (including 1). E.g. φ(12) = 4 ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), and φ(15) = 8. http://www.thescienceforum.com/mathematics/14111-modular-multiplicative-inverse-context-rsa.html https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Extended_Euclidean_algorithm https://docs.google.com/viewer?url=www.math.utah.edu/~fguevara/ACCESS2013/Euclid.pdf as to why the extended Euclid’s algo can be used to find the modular multiplicative inverse wpid-wp-1402514649564-1024x767.jpeg wpid-wp-1402514730357-1024x491.jpeg https://docs.google.com/viewer?url=ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf https://docs.google.com/viewer?url=ftp://ftp.rsasecurity.com/pub/rsalabs/rsa_algorithm/rsa-oaep_spec.pdf In particular, ^ page 9. OAEP is the padding scheme ( http://crypto.stackexchange.com/questions/10145/rsa-pcks1-v2-1-rsaes-oaep-algorithm http://crypto.stackexchange.com/questions/2074/rsa-oaep-input-parameters ) , whereas I2OSP and OS2IP (on page 4); what really helped things come full circle for me is realizing how they represent arbitrary data as an integer (first converting it to an octet string). Without further do, let’s test our generated keys by encrypting and decrypting the number 521 (any number smaller than 527, our modulus, will do. ( http://stackoverflow.com/questions/10061626/message-length-restriction-in-rsa ) )

1
2
3
4
5
6
7
8
$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 521**41 % 527
346
>>> print 346**281 % 527
521

Note that if we try with a larger number…

1
2
3
4
>>> print 1000**41 % 527
411
>>> print 411**281 % 527
473

Nope. What really helped things come full circle once again (or full sphere..) http://en.wikipedia.org/wiki/Pretty_Good_Privacy#Confidentiality http://superuser.com/questions/383732/how-does-ssh-encryption-work It makes more sense to use a symmetric encryption algorithm with high throughput to encrypt the data first, then use PKI to encrypt and transfer the key. And that is how the world works.

Good First Bug

https://wiki.mozilla.org/Good_first_bug So!… I realize the change isn’t as trivial in FF 29+ since the switch to the nasty curved tabs. Regardless, here’s my solution: http://forums.mozillazine.org/viewtopic.php?f=38&t=2799203 and add the code to remove sidebars and this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.tabbrowser-tab {
-moz-binding: url("chrome://browser/content/tabbrowser.xml#tabbrowser-tab");
}
.tabbrowser-tab[selected="true"] {
font-weight: bold !important;
color: rgba(255,255,255,1) !important;
background-image: linear-gradient(rgba(102,51,102,.85), rgba(102,51,102,.85) 50%),
linear-gradient(-moz-dialog, -moz-dialog) !important;
}
tab:not([selected="true"]) {
background-color: #2F0 !important;
color: gray !important;
}

into browser.css ](/wp-content/uploads/2014/05/green_tabs-150x91.jpg)

The Strong Induction Axiom

These are notes taken from the Lec 3 | MIT 6.042J Mathematics for Computer Science, Fall 2010 video lecture, which can be found at https://www.youtube.com/watch?v=NuGDkmwEObM#t=4658

What exactly does the Strong in Strong Induction mean? Let $P(n)$ be any predicate. if $P(0)$ is true then $\forall n (P(0) \wedge P(1) \wedge \ldots \wedge P(n)) \Rightarrow P(n+1)$ is true, then $\forall n : P(n)$ is true. Remember the normal induction axiom? Let $P(n)$ be a predicate. If $P(0)$ is True and $\forall n \in \mathbb{N} : (P(n) \Rightarrow P(n+1))$ is True, then $\forall n \in \mathbb{N}$ $P(n)$ is True. The difference is that you’re assuming that all the cases starting from the base case til $n$ are true, in order to prove that $P(n+1)$ is true. The Unstacking game is demonstrated: here’s a brief recap (no, actually, this is just another LaTex exercise for me)

The score one would get is (4*4)+(2*2)+(3*1)+(1*1)+(1*1)+(2*1)+(1*1) = 28. There must be a strategy to beat this, is there?

(7*1)+(6*1)+(5*1)+(4*1)+(3*1)+(2*1)+(1*1) = 28. Now one should immediately jump to the conclusion (if one is an MIT student) that all combinations lead to a score of 28. But one is not if one is reading this, so: Theorem: All strategies $S(n)$ for the Unstacking Game with $n$ starting blocks lead to the same score. Proof by strong induction: Inductive Hypothesis: $P(n)$ is the Theorem. Base Case: $S(1)$ is zero (One can’t play the game with 0 blocks). Inductive step: Assume $P(1), P(2), \ldots, P(n)$ in order to prove $P(n+1)$. With $(n+1)$ blocks, for $1 \leq k \leq n$:

Our score for $P(n+1)$ is $k(n+1-k)+P(k)+P(n+1-k)$ (think recursion, after each division of blocks each block is an instance of the Game). One has hit a dead end here, as one is trying to prove that $P(n+1)$ is dependent on $n$, not $k$. Honestly this example (IMHO) is rather haphazard, as the next step, which not so intuitively, is to make a good guess as to what $S(n)$ might be, and in classic MIT intuition style, our first guess yields $\frac{n(n-1)}{2}$. Testing a few values of $n$.. $S(2) = 1$, $S(3) = 3$, $S(4) = 6$, $S(8) = 28$. Let’s put $P(n)$ through its runs again…. Base case, where $P(n) = \frac{n(n-1)}{2}$: $P(1) = 0$. Going back to the previous expression which we derived for the score, now that we have an expression for $P(n)$: $k(n+1-k) + \frac{k(k-1)}{2} + \frac{(n+1-k)(n-k)}{2}$ Simplifying this expression (aka plugging it into WolframAlpha…) results in $\frac {n(n+1)}{2}$, which is $S(n+1)$. In the words of the professor, “The $k$ disappears.“ We have worked backwards (to my understanding), deriving an expression for the score, reaching a dead end, where we have to stop assuming ($k$), come up with an expression for $P(n)$, and filling in the blank to prove $P$(or $S$)$(n+1)$.

Proof by contradiction (aka a LaTeX test)

What is a proof by contradiction? A proof by contradiction is if $\neg P \Rightarrow F$ is true.

One assumes that a proposition P is False, and uses that to derive until a contradiction is reached, which can’t be True.

A popular example: Let’s prove that $\sqrt2$ is irrational. An irrational number is something that cannot be expanded into a fraction. (A common misconception is that Pi is $\frac{22}{7}$ and therefore rational; no it is not exactly $\frac{22}{7}$.

See http://mathworld.wolfram.com/PiFormulas.html

Assume that $\sqrt2$ is rational; such that we can represent it as $\frac{a}{b}$, where $\frac{a}{b}$ is a fraction in lowest terms.

$\Rightarrow \sqrt2 = \frac{a}{b}$ $\Rightarrow 2 = \frac{a^2}{b^2}$ $\Rightarrow 2b^2 = a^2$ $\Rightarrow 2 \mid a$ $\Rightarrow 4 \mid a^2$ $\Rightarrow 4 \mid 2b^2$ $\Rightarrow 2 \mid b^2$ $\Rightarrow 2 \mid b$ If both $a$ and $b$ are even, they are not in lowest terms, as both can be divided by 2 for further simplification. Hence we have a contradiction. $\square$

On calling su in an Android App

http://su.chainfire.eu/#how I noticed that https://github.com/koush/Superuser‘s su binary requires quotes around the target command, or else it won’t execute properly.

1
2
3
4
5
6
7
8
9
u0_a156@aries:/ $ su -c ping 8.8.8.8
su -c ping 8.8.8.8
Unknown id: 8.8.8.8
u0_a156@aries:/ $ su -c "ping 8.8.8.8"
su -c "ping 8.8.8.8"
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=3 ttl=39 time=262 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=39 time=271 ms

The “solution” is to write the intended su -c command to a shell script file and then call it with ProcessBuilder:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
try {
String samplePingCommand = new String("su -c ""+"ping 8.8.8.8"+""");
FileOutputStream fOut = getActivity().openFileOutput("test_ping.sh", MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(samplePingCommand);
osw.flush();
osw.close();
ProcessBuilder testPingCommand = new ProcessBuilder("sh", getActivity().getFilesDir()+"/test_ping.sh");
testPingCommand.redirectErrorStream(true);
Process startTestPingCommand = testPingCommand.start();
BufferedReader testPingCommandOut = new BufferedReader(new InputStreamReader(startTestPingCommand.getInputStream()));
String testPingCommandSingleLine;
while ((testPingCommandSingleLine = testPingCommandOut.readLine()) != null) {
/*Log.e("Ping Command Output", testPingCommandSingleLine); */
}
catch (Exception e) {
Log.e("Ping Command", "Error", e);
}

Unicode support nightmare

Compiling http://www.darwinsys.com/file/ for Android

Cross compiling is always a PITA, so here goes:

1
2
3
4
5
6
7
8
9
10
11
12
13
AR=arm-linux-androideabi-ar
OLDPWD=/home/transfusion/android-bash/fileutil
LD_LIBRARY_PATH=/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/usr/lib/
PATH=/home/transfusion/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
LD=arm-linux-androideabi-ld
PWD=/home/transfusion/android-bash/fileutil/bin
STRIP=arm-linux-androideabi-strip --strip-unneeded
CXX=arm-linux-androideabi-g++
CFLAGS=-L/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/usr/lib/ --sysroot=/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/ -I/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/usr/include/
RANLIB=arm-linux-androideabi-ranlib
ANDROID_NDK=/home/transfusion/android-ndk-r9c
CC=arm-linux-androideabi-gcc
READELF=arm-linux-androideabi-readelf

I have android-ndk-r9c extracted to my home directory.

1
2
3
4
5
6
cd file-5.11
cd src
ln -s $ANDROID_NDK/platforms/android-19/arch-arm/usr/lib/crtend_so.o
ln -s $ANDROID_NDK/platforms/android-19/arch-arm/usr/lib/crtbegin_so.o
./configure --prefix=/home/transfusion/file-android-build --host=arm-linux ---datarootdir=/system/share
make && make install

See https://stackoverflow.com/questions/6881164/crtbegin-so-o-missing-for-android-toolchain-custom-build as to why those two files need to be linked. The magic.mgc file is going to be placed in /system/share/misc/magic on the device. Copy all the files into /system on the device, and create the symlink to libmagic.so in /system/lib if it hasn’t been created

1
2
cd /system/lib
ln -s libmagic.so.1.0.0 libmagic.so.1

If all works well,

1
2
$ file /system/bin/file
/system/bin/file: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

Wikipedia jumps on the Helvetica bandwagon

Helvetica Scenario.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×