Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl to C++

0 views
Skip to first unread message

miztaken

unread,
May 18, 2008, 2:43:03 AM5/18/08
to
Hi there,
I dont know how to perl.
Can anybody convert this code (sub routine) from perl to C++.
I would be very much grateful

sub OleUnpackPackages {
my($this, $explodeinto, $parentname, @NativeFilenames) = @_;

my($infh, $byte, $number, $buffer, $outname);
my($finished);

OLEFILE: foreach my $inname (@NativeFilenames) {
$byte = "";
$buffer = "";
close $infh if $infh;
$infh = new FileHandle;
sysopen $infh, "$explodeinto/$inname", O_RDONLY; sysseek $infh,
6, SEEK_SET; # Skip 1st 6 bytes
$outname = "";
$finished = 0;
until ($byte eq "\0" || $finished) { # Read a C-string into
$outname
sysread($infh, $byte, 1) or $finished = 1;
$outname .= $byte;
}
# Then there is a null-terminated ASCII string which is the filename
of the object.
#print STDERR "Output filename is $outname\n";
$finished = 0;
$byte = 1;
until ($byte eq "\0" || $finished) { # Throw away a C-string
sysread($infh, $byte, 1) or $finished = 1;
}
# Throw away the next null-terminated ASCII string
sysseek $infh, 4, Fcntl::SEEK_CUR or next OLEFILE; # Skip next 4
bytes
# Throw away next 4 byte int
sysread $infh, $number, 4 or next OLEFILE;
$number = unpack 'V', $number;
# The next 4 bytes are an int giving the length of the next bit of the
header
#print STDERR "Skipping $number bytes of header filename\n";
sysseek $infh, $number, Fcntl::SEEK_CUR; # Skip the next bit of
header (C-string)
# Skip over the next bit of the header whose length we just read
sysread $infh, $number, 4 or next OLEFILE;
$number = unpack 'V', $number;
#print STDERR "Reading $number bytes of file data\n";
# Then you have a 4-byte int which is the length of the real embedded
original file
sysread $infh, $buffer, $number
if $number < -s "$explodeinto/$inname"; # Sanity check
# Read in all the data of the original embedded file
my $outfh = new FileHandle;
my $outsafe = $this->MakeNameSafe($outname, $explodeinto);
sysopen $outfh, "$explodeinto/$outsafe", (O_CREAT | O_WRONLY)
or next OLEFILE;
syswrite $outfh, $buffer, $number or next OLEFILE;
close $outfh;
# Set up MailScanner data structures
$this->{file2parent}{$outname} = $parentname;
$this->{file2parent}{$outsafe} = $parentname;
$this->{file2safefile}{$outname} = $outsafe;
$this->{safefile2file}{$outsafe} = $outname;

}
close $infh if $infh;
}

Please help me
miztaken

Ego

unread,
May 19, 2008, 10:12:30 AM5/19/08
to
miztaken wrote:
> Hi there,
> I dont know how to perl.
> Can anybody convert this code (sub routine) from perl to C++.
> I would be very much grateful
>
> [bunch of perl code]
>

www.rentacoder.com

regards, Michael

--
Michael K. [me...@moulinette.org]
http://moulinette.org/~meik/

s...@netherlands.co

unread,
May 19, 2008, 12:53:25 PM5/19/08
to


If you know C++, this should get you started. Otherwise my 5 minutes was wasted.
######################################################################################

sub OleUnpackPackages
{
my($this, $explodeinto, $parentname, @NativeFilenames) = @_;

my($infh, $byte, $number, $buffer, $outname);
my($finished);

OLEFILE:
foreach my $inname (@NativeFilenames)
{
$byte = "";
$buffer = "";
close $infh if $infh;
$infh = new FileHandle;
sysopen $infh, "$explodeinto/$inname", O_RDONLY;

Loop until all files are processed......

open infile, read in HdrOffset, any errors, close infile, continue on with next file
-------------------------------------------------------------------------------------

typedef unsigned char BYTE;

#pragma pack(push,1)
struct HdrOffset
{


# Skip 1st 6 bytes

sysseek $infh, 6, SEEK_SET;


$outname = "";
$finished = 0;

BYTE skip1[6];

# Read a C-string into $outname
until ($byte eq "\0" || $finished)
{
sysread($infh, $byte, 1) or $finished = 1;
$outname .= $byte;
}

CString strOutfile; (from ATL template class)

# Then there is a null-terminated ASCII string which is the filename

# of the object.


#print STDERR "Output filename is $outname\n";
$finished = 0;
$byte = 1;
until ($byte eq "\0" || $finished)
{
# Throw away a C-string
sysread($infh, $byte, 1) or $finished = 1;
}

??? # Throw away the next null-terminated ASCII string


sysseek $infh, 4, Fcntl::SEEK_CUR or next OLEFILE; # Skip next 4 bytes

BYTE skip2[4];

# Throw away next 4 byte int
sysread $infh, $number, 4 or next OLEFILE;

int number;
};
#pragma pack(pop)


$number = unpack 'V', $number;

# The next 4 bytes are an int giving the length of the next bit of the header
#print STDERR "Skipping $number bytes of header filename\n";
sysseek $infh, $number, Fcntl::SEEK_CUR; # Skip the next bit of header (C-string)

seek infile to HdrOffset::number, read in length
----------------------------------------------

# Skip over the next bit of the header whose length we just read
sysread $infh, $number, 4 or next OLEFILE;

int length;

$number = unpack 'V', $number;
#print STDERR "Reading $number bytes of file data\n";

read next BYTE[length] into buffer
-----------------------------------


# Then you have a 4-byte int which is the length of the real embedded original file
sysread $infh, $buffer, $number

byte *buffer = new BYTE[length];


close infile, open outfile
write buffer to outfile
close outfile
delete buffer;

s...@netherlands.co

unread,
May 19, 2008, 1:08:28 PM5/19/08
to
On Mon, 19 May 2008 09:53:25 -0700, s...@netherlands.co wrote:

>On Sat, 17 May 2008 23:43:03 -0700 (PDT), miztaken <justju...@gmail.com> wrote:
>

--snip--


>read next BYTE[length] into buffer
>-----------------------------------
> # Then you have a 4-byte int which is the length of the real embedded original file
> sysread $infh, $buffer, $number
>
>byte *buffer = new BYTE[length];

^
BYTE *pBuffer = new BYTE[length];


>
>
>close infile, open outfile
>write buffer to outfile
>close outfile
>delete buffer;

^
if (pBuffer)
delete pBuffer;

0 new messages