unpack

How can I replicate Perl's unpack functionality in C#?

Hi, I am trying to recreate a Perl script in C# but have a problem creating a checksum value that a target system needs. In Perl this checksum is calculated using the unpack function: while (<PACKAGE>) { $checksum += unpack("%32C*", $_); } $checksum %= 32767; close(PACKAGE); where PACKAGE is the .tar file input stream I need to...

Python: unpack to unknown number of variables?

How could I unpack a tuple of unknown to, say, a list? I have a number of columns of data and they get split up into a tuple by some function. I want to unpack this tuple to variables but I do not know how many columns I will have. Is there any way to dynamically unpack it to as many variables as I need? Thanks for your help :) ...

In Perl, how can I unpack to several variables?

I have a struct wich contains: struct mystruct{ int id[10]; char text[40]; unsigned short int len; }; And I'm trying to unpack it in a single line, something like this: my(@ids,$text,$length) = unpack("N10C40n",$buff) ; But everything is going to the first array(@ids), i've tried templates as "N...

Unpacked gem in vendor/gems not in a versioned directory

I unpacked a gem into my vendor/gems directory and tried to run my Rails app. I got this message: Unpacked gem in vendor/gems not in a versioned directory I don't understand this error and judging by the Google search results for this error there are not many people who have experienced this problem. Could this mean I also need to v...

C/C++ Date Solution/Conversion

I need to come up with a way to unpack a date into a readable format. unfortunately I don't completely understand the original process/code that was used. Per information that was forwarded to me the date was packed using custom C/Python code as follows; date = year << 20; date |= month << 16; date |= day << 11; date |= hour <...

Can I use Perl's unpack to break up a string into vars?

I have an image file name that consists of four parts: $Directory (the directory where the image exists) $Name (for a art site, this is the paintings name reference #) $File (the images file name minus extension) $Extension (the images extension) $example 100020003000.png Which I desire to be broken down accordingly: $dir=1000 $...

How can I speed up Perl's processing of fixed-width data?

We've got a mature body of code that loads data from files into a database. There are several file formats; they are all fixed-width fields. Part of the code uses the Perl unpack() function to read fields from the input data into package variables. Business logic is then able to refer to these fields in a 'human-readable' way. The file...

Lua unpack bug?

I Have stumbled on a weird behavior in Lua unpack function table1 = {true, nil, true, false, nil, true, nil} table2 = {true, false, nil, false, nil, true, nil} a1,b1,c1,d1,e1,f1,g1 = unpack( table1 ) print ("table1:",a1,b1,c1,d1,e1,f1,g1) a2,b2,c2,d2,e2,f2,g2 = unpack( table2 ) print ("table2:",a2,b2,c2,d2,e2,f2,g2) Output: table1:...

Decoding packed data into a structure

Hi What would the best way of unpacking a python string into fields I have data received from a tcp socket, it is packed as follows, I believe it will be in a string from the socket recv function It has the following format uint8 - header uint8 - length uint32 - typeID uint16 -param1 uint16 -param2 uint16 -param3 uint16 -param4 char[...

hoptoad_notified gem won't unpack into vendor

I think this should be working. environment.rb config.gem "hoptoad_notifer", :version => '=2.1.2' list of installed gems: $ gem list hoptoad_notifier *** LOCAL GEMS *** hoptoad_notifier (2.1.2) Output of rake:gems $ rake gems (in /rails/appdir) - [R] hoptoad_notifier = 2.1.2 I = Installed F = Frozen R = Framework (loaded befo...

How to fix "can't adapt error" when saving binary data using python psycopg2

I ran across this bug three times today in one of our projects. Putting the problem and solution online for future reference. impost psycopg2 con = connect(...) def save(long_blob): cur = con.cursor() long_data = struct.unpack('<L', long_blob) cur.execute('insert into blob_records( blob_data ) values (%s)', [long_data...

How can I handle packed data from Perl/PHP in C++?

I got a problem implementing a PHP programm in C++. It is about the PHP/Perl function unpack. I don't know how to do the follwing in C++ (no problem in reading a file... but how do i unpack("C*") the read contents). <?php $file = fopen("bitmaskt.dat", "rb"); //create the data stream $matrix_x = unpack("C*", fread($file, 286));...

How can I parse space separated STDIN hex strings unpacked in Perl?

I have a Java program that spits out, in space-separated hexadecimal format, 16 bytes of raw packet received over the network. Since I dont want to change that code, I am piping the result to a Perl script that, theoretically, can simply unpack this from STDIN into recognizable variables. The following is a sample of the line input to my...

how to unpack the contents of a javascript file?

Hi all! You know how those packed js files look like, right? eval(function(p,a,c,k,e,d){ ... } ('obfuscated-string'.split('|'),0,{})) It just so happens to be that i have to tweak some large legacy code that looks like that and i want to find a way to turn this into a more readable version. If that's not possible, can i at least get ...

Python: How to transfer varrying length arrays over a network connection

Hi, I need to transfer an array of varying length in which each element is a tuple of two integers. As an example: path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] I am trying to use pack and unpack, however, since the array is of varying length I don't know how to create a format such that both know the format. I was trying to turn...

PHP String Split

I need to split a string into chunks of 2,2,3,3 characters and was able to do so in Perl by using unpack: unpack("A2A2A3A3", 'thisisloremipsum'); However the same function does not work in PHP, it gives this output: Array ( [A2A3A3] => th ) How can I do this by using unpack? I don't want to write a function for it, it should be...

Can I use unpack to split a string into characters in Perl?

A common 'Perlism' is generating a list as something to loop over in this form: for($str=~/./g) { print "the next character from \"$str\"=$_\n"; } In this case the global match regex returns a list that is one character in turn from the string $str, and assigns that value to $_ Instead of a regex, split can be used in the same way or ...

How do I unpack a binary string in PHP?

How can I do this Perl code in PHP? print unpack ("H*", pack ("B*", "00000000100000012000000" )); ...

Obfuscated Javascript Code from Facebook Application?

This is the code that was copied and pasted into my address bar: javascript:(function() {a='app117970624901700_jop';b='app117970624901700_jode';ifc='app117970624901700_ifc';ifo='app1179 70624901700_ifo';mw='app117970624901700_mwrapper';eval(function(p,a,c,k,e,r){e=function(c){return (c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCh...

How to download and unpack .ZIP folder using Adobe Air?

How to download and unpack .ZIP folder using Adobe Air? So I have http link onto that zip file example.com/zip.zip I need a function to download it onto users hard drive and unpack it into some folder on filesystem. How to do such thing? (code example, please) ...