pages tagged hackingrohieb.namehttps://rohieb.name/blag/tag/hacking/rohieb.nameikiwiki2019-05-05T21:56:21ZChange partition type without reformattinghttps://rohieb.name/blag/post/change-partition-type-without-reformatting/rohieb
CC-BY-SA 3.0
2013-09-19T05:04:01Z2011-01-02T16:29:00Z
<p>Note to myself: it is possible to change the partition type of a already
formatted (and used) partition. For example, if you have already
formatted the partition with NTFS, but accidentally had created it with
partition type <code>0x83</code> (Linux), so Windows can’t read it, since it expects
<code>0x07</code> (HPFS/NTFS). On Linux, you can use sfdisk for that purpose:</p>
<pre><code># Be root
# dd if=/dev/sdb of=sdb-bootsector count=1 # backup boot sector
# sfdisk -d /dev/sdb | sed -e 's/Id=83/Id=07/' > /tmp/sdb.txt
# sfdisk /dev/sdb < /tmp/sdb.txt
</code></pre>
<p>(fill in the right values for your case)</p>
<p>Of course, good old fdisk works also, use the <code>t</code> command.</p>
<p><a href="http://serverfault.com/questions/46758/can-you-change-the-partition-type-on-a-linux-server-without-starting-up-fdisk/46840#46840">(Source)</a></p>
ZSNES on AMD64 Ubuntuhttps://rohieb.name/blag/post/zsnes-on-amd64-ubuntu/rohieb
CC-BY-SA 3.0
2019-05-05T21:56:21Z2010-10-05T22:00:00Z
<p><strong>[ Update, 2013-10:</strong> This post post is not up to date anymore. On newer
Debians (since 7.0/wheezy) and Ubuntus (at least since 12.04, Precise Pangolin),
you should be able to install zsnes out of the box: <code>sudo apt-get install
zsnes:i386</code>. For details see the MultiArch documentation for
<a href="https://wiki.debian.org/Multiarch/">Debian</a> and <a href="https://help.ubuntu.com/community/MultiArch">Ubuntu</a>. <strong>]</strong></p>
<p>Before I bought my current hardware, I was working on a 32-bit-based
system, and I really appreciated ZSNES as an SNES emulator. But
unfortunately, my new hardware was an AMD64 system, and there is
currently no ZSNES package for 64-bit Ubuntu or Debian <img src="https://rohieb.name/smileys/sad.png" alt=":(" /> So I decided
to google a bit about the issue, but it took me until now (a year later)
to get ZSNES finally working on my machine. The problem is, if you build
ZSNES on a 64-bit machine, all the application does is segfault at
start, and if you <a href="http://board.zsnes.com/phpBB3/viewtopic.php?p=118067&sid=dd9a2a54d9178eb5009c33586aea703c#p118067">try to compile for 32-bit systems</a>, you get errors
about missing 32-bit libs (in particular, configure does not find a
suitable <code>libsdl</code>). Instead, if you just take the binary which was
compiled on a 32-bit system, and install the <code>ia32-libs</code> package,
everything seems to work—at least I was able to play a few levels of
Super Mario World succesfully <img src="https://rohieb.name/smileys/smile.png" alt=":-)" /> </p>
<p>So here was my idea: take the 32-bit package from the Ubuntu repository,
and just change the Architecture control field, and by this fool dpkg :P
And as it turned out, this idea worked great. You can get the Debian
package here if you want, it <em>should</em> work for Ubuntu Karmic and Lucid,
as well as for Debian testing (<strong>but</strong> I only tested it on Lucid, so
there is no warranty here—but I’m happy to hear if it works :-)):</p>
<ul>
<li><a href="http://rohieb.name/stuff/zsnes_1.510-2.2ubuntu3~ppa1_amd64.deb">zsnes_1.510-2.2ubuntu3~ppa1_amd64.deb</a></li>
<li>SHA1: <code>716bbd37267b477ef02961a7727212619309b83f</code></li>
<li>MD5: <code>452ea5230ad17df1dee649ab4cc6c8c0</code></li>
</ul>
<h2 id="howtoreproduceit">How to Reproduce It</h2>
<p>For the curious people reading here, here is what I actually did:</p>
<ol>
<li><code>wget http://archive.ubuntu.com/ubuntu/pool/universe/z/zsnes/zsnes_1.510-2.2ubuntu3_i386.deb</code></li>
<li><code>ar x zsnes_1.510-2.2ubuntu3_i386.deb</code></li>
<li><code>tar xzf data.tar.gz</code></li>
<li><p>Edit <code>usr/share/applications/zsnes.desktop</code> and added <code>-ad sdl</code> to the
<code>Exec:</code> field, otherwise it would just segfault on the first run:</p>
<pre><code>Exec=zsnes -ad sdl
</code></pre></li>
<li><p>Edit <code>usr/share/doc/zsnes/changelog.Debian.gz</code> and added a new
changelog entry for the version (just copy one of the previous
entries and adapt it)</p></li>
<li><code>tar xzf control.tar.gz</code></li>
<li><p>Edit the <code>control</code> file, changed the <code>Version:</code> and <code>Architecture:</code>
field to <code>amd64</code>, added the <code>ia32-libs</code> dependency, and set myself as
maintainer:</p>
<pre><code>Package: zsnes
Version: 1.510-2.2ubuntu3~ppa1
Architecture: amd64
Maintainer: Roland Hieber <foobar@example.org>
Installed-Size: 4160
Depends: ia32-libs, libao2 (>= 0.8.8), libc6 (>= 2.4), libgcc1 (>= 1:4.1.1),
libgl1-mesa-glx | libgl1, libpng12-0 (>= 1.2.13-4),
libsdl1.2debian (>= 1.2.10-1), libstdc++6 (>= 4.1.1), zlib1g (>= 1:1.2.2.3)
[...]
</code></pre></li>
<li><p>Change the <code>md5sums</code> file for the right values for
<code>usr/share/applications/zsnes.desktop</code> and
<code>usr/share/doc/zsnes/changelog.Debian.gz</code> (I used the <code>md5sum</code>
command and copy-pasted it)</p></li>
<li><code>tar czf control.tar.gz control md5sums postrm postinst</code></li>
<li><code>tar czf data.tar.gz usr/</code></li>
<li><code>ar r zsnes_1.510-2.2ubuntu3~ppa1_amd64.deb debian-binary
control.tar.gz data.tar.gz</code></li>
</ol>
<p>I’m afraid that I can’t put the package into <a href="https://launchpad.net/~rohieb/+archive/ppa">my PPA</a>, Launchpad only
accepts source packages for uploads, and builds the binary packages
itself, both for i386 and AMD64. This approach can not be used here,
since we needed the i386 binary for AMD64.</p>
GNU screen: start with multiple windows and commandshttps://rohieb.name/blag/post/gnu-screen-start-with-multiple-windows-and-commands/rohieb
CC-BY-SA 3.0
2013-09-19T05:04:01Z2010-07-29T22:00:00Z
<p>I wanted to restart my IRC bot on reboot, but I also wanted to have
control over it and see its log output, so I wanted to start it inside a
<code>screen</code> session. This is nearly trivial, <code>screen -dmS yoursessionname
yourcommand</code> is your friend, and you can later on reattach using <code>screen
-r yoursessionname</code>.</p>
<p>But what if I want to start multiple commands, each in its own screen
window? My first solution used <code>screen -dmS</code> followed by something like
<code>screen -r sessionname -X screen; screen -r sessionname -X next; screen
-r sessionname -X title "my window title"; screen -r sessionname -X exec
"my command line"</code>, but it seems that the <code>next</code> command fails in this
context, and I ended up with all the mess in one single window.</p>
<p>My next approach (okay, it took me half an hour of reading <a href="http://www.gnu.org/software/screen/manual/">the
manual</a> until here ;-)) was more succesful: I created a session
command file which contained screen commands like this:</p>
<pre><code>screen
select 1
title "my window title"
exec mycommand arguments ...
</code></pre>
<p>And, voilà, I could paste the single command line into my crontab:
<code>screen -dmS sessionname && screen -r sessionname -X source
sessioncommandfile</code></p>
netcat, your friendly network snifferhttps://rohieb.name/blag/post/netcat-your-friendly-network-sniffer/rohieb
CC-BY-SA 3.0
2013-09-19T05:04:01Z2009-09-23T22:00:00Z
<p>I was bored today and started to play around with this Windows Mobile
Messaging application (I think it’s called Outlook Mobile or sort of
thing), and I found out that I was not able to connect to my IMAP
mailbox on my root server, though it worked with my Freemail account. So
I wanted to see what makes Outlook Mobile bother about my IMAP server.</p>
<p>If you are familiar with Linux (which I suppose you are ;-)), you
certainly know <code>netcat</code>. With this little tool, you can talk directly to
servers on a byte-oriented basis, and this can be very useful if you
have to debug programs which use character-oriented protocols like IMAP,
SMTP, IRC and so on.</p>
<p>But I’ve realised that I can not only use <code>netcat</code> to talk to a server
myself, but even to build a transparent proxy server that displays all
the data that comes over it. After a while — okay, it was about 2 hours
— I got the following nice command:</p>
<pre><code>$ mkfifo pipe
$ tty=`tty`; netcat -l 1234 < pipe | tee $tty |
netcat myserver.com 143 | tee pipe
</code></pre>
<p>I could now set up Outlook Mobile to talk to port 1234 on my home
computer and the bytes went straight to my console and also to port 143
(the IMAP port) on my server.</p>
<p>The first direction was straightforward: the first <code>netcat</code> process
listens to the local port and pipes its output first to the console
(using <code>tee</code>) and then to a second <code>netcat</code> instance that does the
communication with the remote server. Now, the commands from the server
have to get back to the client, so I created a named pipe using <code>mkfifo</code>
(of course, your filesystem has to support it, so you better not do this
on FAT) and used this as the input to the first <code>netcat</code> process that
sends it back to the original client.</p>
<p>Of course, I could have used Wireshark, but I hate that it does not
allow to copy&paste the contents of a packet so I have only the bytes of
the protocol that I need — which can be quite useful if you want to
reuse parts of the content, especially in character-oriented protocols.
Also, the filter settings in Wireshark can be annoying, there is no
simple way to only have packets from one network connection (or I
haven’t found it yet).</p>
<p>So, finally I found out that is has something to do with the IMAP
capabilities that Outlook Mobile bothers about. I suppose I will write
something about it if I have traced the problem back.</p>
<p><strong>Update:</strong> Note: You can also rewrite the server and/or client messages
using <code>sed</code>, but be sure to use unbuffered output with <code>-u</code> like that:</p>
<pre><code>$ tty=`tty`; netcat -l 143 < pipe | tee $tty | netcat myserver.com 143 |
sed -u 's/^\* CAPABILITY.*/* CAPABILITY IMAP4 STARTTLS/' | tee pipe
</code></pre>