Nidelven IT - All about Python, Zope & Plone - and Open Source!

Here you'll find issues related to our services. Mostly about Python, Zope and Plone, as well as hosting-related issues.

"Keeping IT real"






Older entries



Atom - Subscribe - Categories
Previous | Next

Learning things the hackish way

I've been studying more Spanish the last couple of months, and take it as I guess a part of the job, to increase our website reach and open up opportunities in one of the major world languages.

So, I've been using various places, products and services to learn Spanish. One of the most recent services I've started to use is Livemocha, and signed up for one of their new year offers for cheap access.

Well, all is good. But then I accessed the website and remembered that, ah, they *require* version 11.3 of the Flash Player, not 11.2 which is the highest version that will be available on Linux.

OK, so after some quick thinking, I thought I could edit the flash player binary plug-in using emacs, because the version string is available in the browser about:plugins page. So searching for the last part of the version string (version was 11.2 r202), r202 through emacs and replacing the 2 with 3 where I could see the 11.2 or 11,2 was, did the trick. I was able to fool the flash plugin and Livemocha that I was indeed running 11.3 and videos etc. worked fine. I read somewhere that Adobe were abandoning Flash but can see now that they have grand plans, just for fewer platforms. It's interesting to see how they are basically shafting a lot of the customers that were depending on Flash as a true cross-platform, browser-based development and runtime environment.

http://www.w3schools.com/browsers/browsers_os.asp shows that Linux is at 4-5%, alone for Linux the numbers are significant, including Android they are staggering.

Anyway, enough about that, I think it's safe to assume they won't be changing Flash or adding new features on minor versions (so 11.<whatever> should be safe). Just fixing bugs, improving performance perhaps.

But, this is a Python post, so to the point. I searched for binary diff for Linux on Google but couldn't find anything useful.

Thinking this was a simple, byte-by-byte comparison I decided I could write my own script, as shown here:

"""
#!/usr/bin/env python
import sys

try:
    script, first, second = sys.argv
except ValueError:
    print 'diff.py firstfile secondfile'

first_data, second_data = open(first, 'r').read(), open(second, 'r').read()

first_size = len(first_data)
second_size = len(second_data)

if first_size != second_size:
    print 'Files differ in size', first_size, second_size

for index in range(first_size):
    first_ = first_data[index]
    second_ = second_data[index]
    if first_ != second_:
        print 'differing in position %s, first has %s, second has %s' % (index, ord(first_), ord(second_))

print 'finished'
"""

When running this script, it gives:

morphex@laptop:/usr/lib/flashplugin-installer$ ./diff.py libflashplayer.so libflashplayer.so.bak
differing in position 21225, first has 51, second has 50
differing in position 15618949, first has 51, second has 50
differing in position 15957965, first has 51, second has 50
differing in position 16008569, first has 51, second has 50
differing in position 16008652, first has 51, second has 50
finished

a list of the differences between the two files. I dropped handling files of different size, as I guess it is a point that things in the file need to be in the same place. Replacing one byte one place in the file with two for example seems like a bad idea, the OS or program using the binary file could depend on correct positions throughout the file.

You can see that the script reads up both files into memory, it would probably be better to read byte-by-byte but file reading, blocking etc. were a bit too much to go into for a simple comparison script, so another argument for skipping files of different size.

So there you go, hope you found this interesting and fun. :)

[Permalink] [By morphex] [Python-only or > 0.5 Python related (Atom feed)] [2013 10 Jan 19:32 GMT+2]

Add comment (text format)

Passphrase

A passphrase is required to comment on this weblog. It is required to make sure that bots aren't doing automatic spamming. It is: nit is the best!.

Title

Name

Email

Comment