After a long period with no Qt4 support for Ruby 1.9, the qtbindings gem has stepped in to fill the void. This project packages the qtruby4-qtruby library from the korundum project, so the API is unchanged.
Installation is straightforward:
sudo gem install qtbindings
or for rvm users:
sudo rvm gem install qtbindings
Compatible with 1.8 as well.
Monday, September 26, 2011
Sunday, September 25, 2011
Determining installed version of Ubuntu
Neither uname nor motd are of much use in determining the version of Ubuntu installed on a third-party system, and searching launchpad.net for version details of key packages in dpkg is annoying.
Fortunately there is a utility called lsb_release that provides this information:
bash$ lsb_release -si
Ubuntu
bash$ lsb_release -sr
11.04
bash$ lsb_release -sc
natty
Fortunately there is a utility called lsb_release that provides this information:
bash$ lsb_release -si
Ubuntu
bash$ lsb_release -sr
11.04
bash$ lsb_release -sc
natty
Complete all the way down to the silly nickname for each release.
Since this is an LSB utility, it's probably been in place for some time, silently waiting to provide more detail than uname. Seriously, would a mention in the SEE ALSO section of the uname manpage be *so* hard to add?
Wednesday, September 21, 2011
First impressions, redux
The R500 bit the dust over a year and a half ago. Most PC manufacturers were busy trying to crank out netbooks or a Macbook Air ripoff at the time, so there was no suitable replacement -- had to limp along with a Macbook Pro (ugh!) running Ubuntu until spring of this year.
What replaced the R500? A Thinkpad X1. It weighs twice as much, has no transreflective screen, and is a bit bulkier, but it is paradise after using that Macbook Pro for a year. Dedicated pageup/down keys! Home and End keys! A Delete key! THREE mouse buttons! A hardware kill switch for wifi and bluetooth! A freaken eSATA connector!
But why no grumpy install post detailing how to get Linux speaking to all the hardware? Because everything just works! Even the volume control buttons and the fingerprint reader. No joke. You can thank IBM's interest in Linux for that.
On top of the compatibility, it's a nice looking machine, powerful (64-bit debian runs great on a dual-core i5 with 8 GB of RAM), and tough -- GorillaGlass over the display, MILSPEC (assuming 810) shock and spill resistance (including a keyboard that drains *through* to the bottom of the laptop), the works.
The one caveat: it's best to use non-standard video drivers, as the standard debian/ubuntu Intel video driver became a bit crashy. Easily fixed, though, by adding the xorg-edgers PPA.
What replaced the R500? A Thinkpad X1. It weighs twice as much, has no transreflective screen, and is a bit bulkier, but it is paradise after using that Macbook Pro for a year. Dedicated pageup/down keys! Home and End keys! A Delete key! THREE mouse buttons! A hardware kill switch for wifi and bluetooth! A freaken eSATA connector!
But why no grumpy install post detailing how to get Linux speaking to all the hardware? Because everything just works! Even the volume control buttons and the fingerprint reader. No joke. You can thank IBM's interest in Linux for that.
On top of the compatibility, it's a nice looking machine, powerful (64-bit debian runs great on a dual-core i5 with 8 GB of RAM), and tough -- GorillaGlass over the display, MILSPEC (assuming 810) shock and spill resistance (including a keyboard that drains *through* to the bottom of the laptop), the works.
The one caveat: it's best to use non-standard video drivers, as the standard debian/ubuntu Intel video driver became a bit crashy. Easily fixed, though, by adding the xorg-edgers PPA.
Sunday, September 18, 2011
.vimrc and UTF-8
Quick .vimrc config to display UTF-8 characters correctly:
" support UTF-8 automatically when not on console
if has('gui_running') && has('multi_byte')
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8
endif
" support UTF-8 automatically when not on console
if has('gui_running') && has('multi_byte')
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8
endif
Note that the gui_running requirement ensures that this will be used by gvim and by vim run from a terminal emulator (such as urxvt or mlterm), not by vim running from a virtual terminal or console.
Wednesday, September 7, 2011
Fixing strings(1)
The first step in any examination of a binary is to run strings(1) on it.
This usually results in output like the following:
bash$ strings /bin/ls
FXL9GX
Directions for improvement: load one or more dictionary files and perform lookups on them in Ruby. Search for english-like words by taking 4-letter prefixes and suffixes of each 'word' in the string and searching for dictionary words that start or end with that prefix/suffix. Provide early-exit from the inner field look when a match is found. Allow matches of sprintf formatting strings, URIs ('http://'), etc.
This usually results in output like the following:
bash$ strings /bin/ls
FXL9GX
|"H9
GXL9FX
|"H9
F@L9G@
...which, needless to say, sucks.
The problem here is that a 'string' is any sequence of printable ASCII characters of a minimum length (usually 4).
The output of strings(1) can be made a bit more usable by discarding any string that does not contain a word in the system dictionary.
An off-the cuff implementation of such a filter in Ruby would be:
#!/usr/bin/env ruby
DICT='/usr/share/dict/american-english-insane'
ARGF.lines.each do |line|
is_str = false
line.gsub(/[^[:alnum:]]/, ' ').split.each do |word|
next if word.length < 4
is_str = true if (`grep -Fxc '#{word}' #{DICT}`.chomp.to_i > 0)
end
puts line if is_str
end
This would then be passed the output of strings(1):
bash$ strings /bin/ls | ./strings.rb
__gmon_start__
_fini
clock_gettime
acl_get_entry
acl_get_tag_type
...
This is super-slow for large executables, and will miss sprintf-style formatting strings that contain only control characters (e.g. "%p\n"), but for the general case it produces useful output.
Directions for improvement: load one or more dictionary files and perform lookups on them in Ruby. Search for english-like words by taking 4-letter prefixes and suffixes of each 'word' in the string and searching for dictionary words that start or end with that prefix/suffix. Provide early-exit from the inner field look when a match is found. Allow matches of sprintf formatting strings, URIs ('http://'), etc.
Labels:
binary analysis,
programming,
ruby,
shell
Thursday, August 11, 2011
Ruby __END__ and DATA
The __END__ keyword in Ruby causes the parser to stop executing the source file; it is often used for appending documentation such as a LICENSE file to the end of a source code file.
More interesting is the fact that the contents of the file following the __END__ keyword are available via the global IO object named DATA.
This means that it is possible to include test data -- even binary data -- at the end of a Ruby source file:
bash$ cat od.rb
#!/usr/bin/env ruby
if __FILE__ == $0
offset = 0
while (buf = DATA.read(16)) do
bytes = buf.unpack 'C*'
puts "%08X: %s\n" % [ offset, bytes.map { |b| " %03o" % b } ]
offset += 16
end
end
__END__
bash$ cat /bin/true >> od.rb
bash$ ./od.rb
00000000: 177 105 114 106 002 001 001 000 000 000 000 000 000 000 000 000
00000010: 002 000 076 000 001 000 000 000 220 044 100 000 000 000 000 000
00000020: 100 000 000 000 000 000 000 000 060 226 001 000 000 000 000 000
...
More interesting is the fact that the contents of the file following the __END__ keyword are available via the global IO object named DATA.
This means that it is possible to include test data -- even binary data -- at the end of a Ruby source file:
bash$ cat od.rb
#!/usr/bin/env ruby
if __FILE__ == $0
offset = 0
while (buf = DATA.read(16)) do
bytes = buf.unpack 'C*'
puts "%08X: %s\n" % [ offset, bytes.map { |b| " %03o" % b } ]
offset += 16
end
end
__END__
bash$ cat /bin/true >> od.rb
bash$ ./od.rb
00000000: 177 105 114 106 002 001 001 000 000 000 000 000 000 000 000 000
00000010: 002 000 076 000 001 000 000 000 220 044 100 000 000 000 000 000
00000020: 100 000 000 000 000 000 000 000 060 226 001 000 000 000 000 000
...
Labels:
ruby
Monday, August 8, 2011
knotify4 uses 100% CPU
This is true, and has been for awhile. It tends to occur when a laptop is suspended while online, then resumed while offline. A nice side effect is that battery life gets reduced by about 75% while offline, which is generally when one wants the longest battery life.
There are plenty of bug reports open on this, but it's pretty clear that the KDE/Kubuntu guys either have no clue how to fix this, or cannot be bothered.
Since knotify4 isn't really all that useful (especially when using E17 for a WM), there is a brutal hack that will effectively silence it:
sudo mv /usr/bin/knotify4 /usr/bin/knotify4.orig
There are plenty of bug reports open on this, but it's pretty clear that the KDE/Kubuntu guys either have no clue how to fix this, or cannot be bothered.
Since knotify4 isn't really all that useful (especially when using E17 for a WM), there is a brutal hack that will effectively silence it:
sudo mv /usr/bin/knotify4 /usr/bin/knotify4.orig
sudo cp /bin/true /usr/bin/knotify4
Needless to say, the original file should be restored before doing an upgrade.
Subscribe to:
Posts (Atom)