Questions tagged [unpack]

A function in several scripting languages for unpacking binary data into native types for the language in question. The opposite of the 'pack' function. For the Python concept, use 'iterable-unpacking'. This tag should be used with a programming language tag as well. While also used as directive or pragma in some compilers to ignore standard variable alignment for data aggregates (i.e. struct), do not use this tag for posts on that subject.

The unpack function parses a binary string into several variables with types that are native to the language in question. The binary string usually matches the machine-level representation that you would see in a C . The inverse operation is .

For Python use .

Most versions of unpack and pack functions use a format or template that specifies the byte by byte layout of the data being copied out of or put into the memory area containing the binary representation.

Both functions allow the use of C or C++ routines with complex data structures to be used with the scripting language in order to improve application performance or to perform operations and actions not available in the scripting language.

Documentation:

529 questions
60
votes
10 answers

git unpack error on push to gerrit

On push of a new branch to a gerrit server we encounter the following error: de@roma:~/git-hate/www$ git push origin landingpage Counting objects: 149, done. Delta compression using up to 2 threads. Compressing objects: 100% (73/73), done. Writing…
edlerd
  • 2,042
  • 1
  • 15
  • 22
44
votes
1 answer

How to unpack all objects of a git repository?

How can I unpack all objects of a pack file? I've just cloned a remote repository, so my local repository currently doesn't contain any loose object, only a .pack and a .idx files. I've tried running git unpack-objects <…
Chico Sokol
  • 1,074
  • 2
  • 15
  • 23
32
votes
3 answers

Python-like unpacking in JavaScript

I have the following string output_string = "[10, 10, [1,2,3,4,5], [10,20,30,40,50]]" Then I JSON.parse it my_args = JSON.parse(output_string) How do I unpack it in a Python-like way so that every element in my_args becomes an argument to a…
Kit
  • 26,307
  • 30
  • 94
  • 145
26
votes
3 answers

pack / unpack functions for node.js

Are there any modules that provide pack / unpack functionality for nodejs similar to python's struct module? I haven't found any specifically for node, and I'd assume that javascript implementations would be significantly slower. Thanks.
Adam M-W
  • 3,293
  • 7
  • 45
  • 66
20
votes
3 answers

Protobuf 3.0 Any Type pack/unpack

I would like to know how to transform a Protobuf Any Type to the original Protobuf message type and vice versa. In Java from Message to Any is easy: Any.Builder anyBuilder = Any.newBuilder().mergeFrom(protoMess.build()); But how can I parse that…
Overholt
  • 757
  • 1
  • 6
  • 22
20
votes
1 answer

analysing packed file of unknown format, how to continue?

Im interested in taking a deeper look into the firmware of my Behringer X32 mixing console, so i downloaded the actual file from (http://www.behringerdownload.de/X32/X32_Firmware_2.10.zip) and started IDA pro. The contained .update-file inside…
rhavin
  • 1,296
  • 1
  • 9
  • 30
18
votes
3 answers

Maven: How to unpack precise files from artifacts in the same output directory?

I have several artifacts from the same groupId (org.webjars), and I need to unpack them, and then copy all the contained js files into the same directory. The artifacts archives have a hierarchy (compressed as a jar) as follows: artifact1 -…
Rémi Doolaeghe
  • 2,034
  • 3
  • 26
  • 45
18
votes
2 answers

How do I unpack various form of integers in a byte buffer in Golang?

I need to extract various fields in a byte buffer. I came up with this solution: func (fs *FileSystem) readSB() { // fs.f is a *os.File buf := make([]byte, 1024) fs.f.ReadAt(buf, 1024) // Offset: type var p *bytes.Buffer //…
knarf
  • 2,530
  • 3
  • 24
  • 31
16
votes
4 answers

Default value in Python unpacking

Is there a way to have a default value if the number of values to unpack is too little compared to the variable list? For example: a, b, c = read_json(request) This works if read_json returns an array of three or more variable. If it only returns…
Laurent
  • 409
  • 4
  • 10
13
votes
3 answers

When would you use unpack('h*' ...) or pack('h*' ...)?

In Perl, pack and unpack have two templates for converting bytes to/from hex: h    A hex string (low nybble first). H    A hex string (high nybble first). This is best clarified with an example: use 5.010; # so I can use say my $buf =…
cjm
  • 59,511
  • 9
  • 121
  • 166
12
votes
2 answers

Why does unpacking a struct result in a tuple?

After packing an integer in a Python struct, the unpacking results in a tuple even if it contains only one item. Why does unpacking return a tuple? >>> x = struct.pack(">i",1) >>> str(x) '\x00\x00\x00\x01' >>> y = struct.unpack(">i",x) >>>…
Jedi
  • 2,473
  • 20
  • 39
12
votes
4 answers

How to unpack the contents of a JavaScript file?

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…
Valentin Brasso
  • 1,349
  • 5
  • 21
  • 39
12
votes
3 answers

Unpack binary data with python

I would like to unpack an array of binary data to uint16 data with Python. Internet is full of examples using struct.unpack but only examples dealing with binary array of size 4. Most of these examples are as follow (B is a binary array from a…
Alan Turing
  • 121
  • 1
  • 1
  • 5
11
votes
4 answers

Speed up python's struct.unpack

I am trying to speed up my script. It basically reads a pcap file with Velodyne's Lidar HDL-32 information and allows me to get X, Y, Z, and Intensity values. I have profiled my script using python -m cProfile ./spTestPcapToLas.py and it is spending…
Xavier Merino
  • 487
  • 4
  • 12
11
votes
2 answers

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…
Geggamojja
  • 145
  • 1
  • 6
1
2 3
35 36