Async Download with Curl in Irssi Perl Scripting

Uncategorized

When downloading a file from Perl, there’s many ways to go about it. You can use LWP, libcurl, wget, curl the program, etc. My shell hoster doesn’t include many perl binding so I can’t use LWP or libcurl. I use `curl -s $url` to download urls. The only problem with using any of the above mentioned methods is that they all block Irssi until the page is downloaded. That means the client freezes and doesn’t respond to pings during this time. To remedy this, fork can be used. But fork is rather screwey in Irssi; if you use it wrong, it will create 2 instances of Irssi.

The fix? Use someone else’s code that works. Here’s mine, released under the GNU GPL. It can easily be adapted, and should be, to use LWP or libcurl if your client supports those.

use strict;
use Irssi;
use POSIX;
 
sub async_curl ($$$) {
        my ($geturl, $callback, $argref) = @_;
        my ($reader, $writer);
        pipe($reader, $writer);
        my $pid = fork();
        if ($pid > 0) {
                close($writer);
                Irssi::pidwait_add($pid);
                my $pipetag;
                my @pargs = ($reader, \$pipetag, $callback, $argref);
                $pipetag = Irssi::input_add(fileno($reader), INPUT_READ, \&pipe_input, \@pargs);
        } else {
          my $content;
          eval {
                my $data = `curl -s "$geturl"`;
                print($writer $data);
                close($writer);
          };
          POSIX::_exit(1);
        }
}
 
sub pipe_input ($$$$) {
        my ($reader, $pipetag, $callback, $argref) = @{$_[0]};
        my @lines = <$reader>;
        close($reader);
        Irssi::input_remove($$pipetag);
        my $text = join("", @lines);
        $callback->($text, $argref);
}

Using this code is very simple. Here’s a quick example:

sub callback_method {
        my ($content, $argref) = @_;
        my ($arg1, $arg2) = @{$argref};
        # Here we have the $content from the url
        # and the two args we wanted back
}
 
# Gather up any arguments we want to piggy-back onto the callback
my @args = ('test1', 'test2');
# Call async_curl with a reference to our callback method
# and a reference to our piggy-back args
async_curl("http://www.google.com/", \&callback_method, \@args);
1 Comment

Google Docs lets websites grab your email address

Software

When a user clicks an invite link to join as a collaborator on a Google Docs document, his or her information is automatically added to the document without any confirmation. Using frames, this can allow websites to automatically add you to their Google Document without your knowledge, giving them your email address and name (if you have it set on your account). This is a huge security risk. Don’t believe me? Check your Google Docs account.

Live attack link, right-click save as:
http://odie5533.com/attackexample.html

No Comments

DeSmuME SVN 1212

Software

Here’s the latest changes:

------------------------------------------------------------------------
r1212 | luigi__ | 2008-12-22 04:45:25 -0600 (Mon, 22 Dec 2008) | 2 lines

Fixed 16-bit and 32-bit accesses to the VRAM regs
Added basic support for the VRAMSTAT, WRAMCNT, WRAMSTAT and EXMEMCNT regs (writes to these regs now write the appropriate values at the other side)
------------------------------------------------------------------------

Download DeSmuME SVN 1212 here

No Comments

DeSmuME SVN 1211

Software

Mostly fixes included in this one. Here’s the changes since my last build:

r1211 core: - fixed silly bug in VRAM mapping (typo)
r1210 Corrected a small mistake with WFC profile #3.
r1209 core: - temporally fix in VRAM mapping and add BGx scroll;
r1208 Added the 3 WFC profiles with their CRC16's, now Mario Kart boots a bit more (the next problem for it seems to be a DMA timing problem).
r1207 Added the flag OFN_NOCHANGEDIR when opening a file (prevents changing the working directory). This prevents the config file from being exported to the ROM folder, resulting in config saving problems.
r1206 Added more values to the default firmware (mostly Wifi settings)
r1205 core: - fixed Master Brightness (this is fix games with black screens ex. "Pirates of the Caribbean At Worlds End");
r1204 core: - fix capture display (fixed blinking with both 3D screens ex.Sonic Rush, Metroid Prime etc)
r1203 Added the movie thing and its dependencies into autotools scripts.
r1202 typo fix
r1201 core: - fixed in 3D render and added simulation Geometry FIFO;
r1200 Make functions without declaration static and remove unused i variables.
r1199 core: - cleanup gfx3d.cpp;
r1198 Removing credits for a persons work is something that I won't tolerate, more when it's my work. It's OK to add more people, but not removing them. Also, as a general comment, that speed "improvement" is completely stupid.
r1197 minor optimization to lighting formula
r1196 core: - 1st step for MMU split for procs (speedup); - some changes in FIFO;
r1195 change arm9 sqrt and div. sqrt should be more precise, and the register access is more straightforward.
r1194 Fixed ARM9 hardware division when the denom is zero (see http://nocash.emubase.de/gbatek.htm#dsmaths)
r1193 Fixed a few bugs with looping feature (looped sounds now play corectly when using PAlib) Changed interpolation to cosine interpolation (makes transitions smoother)

Download DeSmuME SVN 1211 here

No Comments

Twisted FTP Upload

Python

Here’s a snippet for uploading a file via FTP using the Twisted Python library.

from twisted.protocols.basic import FileSender
from twisted.protocols.ftp import FTPClient
from twisted.internet.protocol import ClientCreator
from twisted.internet import reactor
 
def fileTransferFail(failure):
    failure.printTraceback()
    reactor.stop()
 
def cbStore(consumer, filename):
    fs = FileSender()
    d = fs.beginFileTransfer(open(filename, 'r'), consumer)
    d.addCallback(lambda _: consumer.finish()).addErrback(fileTransferFail)
    return d
 
def connectionMade(ftpClient, filename, uploadpath = None):
    if uploadpath is None:
        uploadpath = filename
    d1, d2 = ftpClient.storeFile(uploadpath)
    d1.addCallback(cbStore, filename).addErrback(fileTransferFail)
    d2.addCallback(lambda _: reactor.stop())
    return d2
 
def sendFile(host, port, username, password, filename, uploadpath):
    creator = ClientCreator(reactor, FTPClient, username, password)
    d = creator.connectTCP(host, port)
    d.addCallback(connectionMade, filename, uploadpath).addErrback(fileTransferFail)
    return d
 
if __name__ == '__main__':
    username = 'GoogleUser'
    password = 'GoogleSuperSecretPassword'
    host = 'google.com'
    port = 21
    filename = 'index.html'
    uploadto = '/public_html/index.html'
    sendFile(host, port, username, password, filename, uploadto)
    reactor.run()
No Comments

PCSX2 Compile Guide

Programming

I get hits for people trying to compile PCSX2 from SVN, so I thought I’d make the shortest tutorial in the world on how to do it (it’s VERY easy…).

Steps: 1. Prerequisites 2. SVN Checkout 3. Compiling in Visual Studio 4. Distribution 5. Improve PCSX2

Step 1. Prerequisites
In order to compile PCSX2, you need:

  1. Microsoft Visual Studio 2003/2005/2008
  2. Nvidia Cg Toolkit
  3. SVN Checkout of the PCSX2 code

Step 2. SVN Checkout.
If you already have the current version checked out, go to step 3. I use SVN via Cygwin. TortoiseSVN is an alternative and won’t be covered.

First, you need Cygwin. Head over to the Cygwin website and download the setup file (or just right-click save as the download link from here). Run the setup, hit next 5 times, wait, hit next again, wait, and a package list should now appear. Under Devel find “subversion: A version control system.” Click the Skip text once and it should change to 1.5.4-1 or something similar. Hit next and wait for the install to finish. Tell the setup to make an icon on the desktop and hit finish. Open up the Cygwin shell (icon on desktop) and type in the following:
svn co http://pcsx2.googlecode.com/svn/trunk/ pcsx2

Step 3. Compiling in Visual Studio
Now navigate to C:\cygwin\home\your username\pcsx2\pcsx2\windows\VCprojects and open your project of choice (I use pcsx2_2008.vcproj). In the top of Visual Studio, next to the green arrow, is a drop-down menu currently set to “Debug”. Choose “Release.” With pcsx2 selected in the Solution Explorer, press [SHIFT]+[F6] to build pcsx2. It should take about a minute to compile. Your compiled pcsx2 should be available in C:\cygwin\home\your username\pcsx2\bin.

Step 4. Distribute your build!
Developers love nothing more than sharing their creation with the world. Attach it to emails, send it through IRC, post it on message boards, IM it to your friends, and start a website where you post your builds for the world!

Step 5. Improve PCSX2
This step is often-overlooked because for the typical gamer it seems too hard. But it’s not! Improvements to PCSX2 come not only through rigorous development, but also through documentation, dissemination, and thorough testing. Test PCSX2 and post your results. Make a website that lists results of your test. Write documentation on how to use PCSX2 and how to configure it properly.

No Comments

DeSmuME SVN 1193

Programming

Development on this project has really picked up in the past few months. They’ve also switched from CVS to SVN since my last snapshot. Maybe they’ll start using GIT soon?

Changes for this release are far too numerous to name here. Check the SVN repo on SourceForge if you want the full list.

Download DeSmuME SVN 1193 Here

No Comments

HaloHBF v1.08-0.1

C# .NET

There’s been a modified version of my HaloHBF aimbot floating around that works with Halo v1.08. It violates the GNU GPL, so I’m “freeing” it and releasing it here. The only changes made to the program were to allow it to work on Halo v1.08. Any bugs or defects in the last version are still present in this one. I have no actually tested this version out (*hehe*), but it should work. Someone, please test it out and post a comment if it works or if it doesn’t. I’d like to know.

Halo HBF v1.08-0.1


Download HaloHBF v1.08-0.1 Here

*EDIT* Fixed download link. Try it again.

12 Comments

PCSX2 SVN 396

Software

It’s been a while since I released a PCSX2 build. Here’s the latest SVN snapshot Win32 build compiled in Microsoft Visual Studio 2008. Full change log is included in the SFX archive.

Here’s the changes:
r396 fixes for gcc 4.3.2. Gcc now checks the argument pointer size for mmx instructions in intel mode. It never used to so movq with incorrect xmmword pointer arguments were allowed. With 4.3.2, these need to be corrected to qword.
r395 Moving stuff to /trunk/. Step 1: create /trunk
r394 compilation problem
r393 changed qword to xmmword to fix gcc errors on newer distros
r392 got rid of abs error
r390 commenting out unneeded rpsxBASIC
r385 Different version of pcsx2 with recompiler only. Supported compilers include VS 2008 and up. WIP
r384 fixed a typo which could have potentially slowed down the emu. Thanks goes to cottonvibes for that one!
r383 tiny bug
r382 allow also changing "inis" path.
r381 Added some source-level configurability to the paths... hope didn't break anything ;)
r380 updated some more licenses.
r379 Sorry I had DAZ enabled in my local copy and it slipped in.
r378 Massive update of the GPL license headers. I don't know if I missed something, but I hope not.

PCSX2 SVN Revision 396

Download PCSX2 SVN 396 here

No Comments

HaloHBF v0.1

C# .NET

I get so many hits to my site every day from people looking for it, so here it is.

HaloHBF v0.1


Download HaloHBF v0.1

6 Comments
« Older Posts