How to decode the application extension block of GIF? - decode

How to decode the application extension block of GIF?
0000300: 73e7 d639 bdad 10ad 9c08 b5a5 0021 ff0b s..9.........!..
0000310: 4e45 5453 4341 5045 322e 3003 0100 0000 NETSCAPE2.0.....
0000320: 21f9 0409 1900 f600 2c00 0000 0016 01b7 !.......,.......
this "
21 ff0b s..9.........!..
0000310: 4e45 5453 4341 5045 322e 30
" is known, but what is "03 0100 0000"?

The following describes GIF Netscape Application extension, taken from here.
The block is 19 bytes long. First 14 bytes belongs to general
Application Extension format, syntax is described in GIF89a
Specification, section "26. Application Extension".
Syntax
0 | 0x21 | Extension Label
+---------------+
1 | 0xFF | Application Extension Label
+---------------+
2 | 0x0B | Block Size
+---------------+
3 | |
+- -+
4 | |
+- -+
5 | |
+- -+
6 | |
+- NETSCAPE -+ Application Identifier (8 bytes)
7 | |
+- -+
8 | |
+- -+
9 | |
+- -+
10 | |
+---------------+
11 | |
+- -+
12 | 2.0 | Application Authentication Code (3 bytes)
+- -+
13 | |
+===============+ --+
14 | 0x03 | Sub-block Data Size |
+---------------+ |
15 | 0x01 | Sub-block ID |
+---------------+ | Application Data Sub-block
16 | | |
+- -+ Loop Count (2 bytes) |
17 | | |
+===============+ --+
18 | 0x00 | Block Terminator
You already know the data up to NETSCAPE2.0. The next byte 0x03 tells us the next data sub-block length which is always 3 bytes. The following 0x01 is the sub-block ID. For Netscape block, there is only one data sub-block and the ID is 1.
The following 2 bytes specifies the loop count in little endian — how many times the image frames should be looped, which is 0, and 0 means loop forever.
The last byte 0x00 is used to terminate the data block. So when we meet a 0x00 where data sub-block length should be, we know there are no sub-blocks left and we need to stop reading the block.

Related

How to evaluate BOOTP chaddr by mac address?

In dhcp packet, a field means client hardware address, but it's not the same as mac address like "fa:16:3e:6f:1a:9d".
If I have known a interface's mac address "fa:16:3e:6f:1a:9d", how to evaluate chaddr by mac address?
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| op (1) | htype (1) | hlen (1) | hops (1) |
+---------------+---------------+---------------+---------------+
| xid (4) |
+-------------------------------+-------------------------------+
| secs (2) | flags (2) |
+-------------------------------+-------------------------------+
| ciaddr (4) |
+---------------------------------------------------------------+
| yiaddr (4) |
+---------------------------------------------------------------+
| siaddr (4) |
+---------------------------------------------------------------+
| giaddr (4) |
+---------------------------------------------------------------+
| |
| chaddr (16) |
| |
| |
+---------------------------------------------------------------+
| |
| sname (64) |
+---------------------------------------------------------------+
| |
| file (128) |
+---------------------------------------------------------------+
| |
| options (variable) |
+---------------------------------------------------------------+
See https://www.ietf.org/rfc/rfc2131.txt
4.4.1 Initialization and allocation of network address
...
The client MUST include its hardware address in the 'chaddr'
field, if necessary for delivery of DHCP reply messages.
First six bytes contain the hardware address, the rest are zeros. One can inspect the contents of bootp/dhcp packets for example in Linux with dhcpdump.

Calculation of Battery Consumption of each running mobile application

Is it possible to find out how much each mobile application consumes the battery per day (using R language) , where I have data collection of the following fields
record_id ,
date_time,
application_name,
battery_level,
battery_status
battery_level (It is a number represents the available percentage of the battery)
battery_status ( status of the battery : charging , discharging , full)
This calculation is based on the collected data.
example of such data :
+-----------+------------------+---------------------+---------------+----------------+
| record_id | application_name | date_time | battery_level | battery_status |
+-----------+------------------+---------------------+---------------+----------------+
| 473849 | viber | 2015-09-01 21:34:01 | 7 | Charging |
| 473850 | watsup | 2015-09-01 21:34:01 | 7 | Charging |
| 473851 | AccuWeather | 2015-09-01 21:34:01 | 7 | Charging |
+-----------+------------------+---------------------+---------------+----------------+
as I understood that it is not possible to calculate battery Consumption of
each running mobile application using data collected in my first post.
Let us have another data collection .
assuming that we have the following data ,
cpu usage per each running application and
memory usage per each running application
as the following
+-----------+------------------+---------------------+---------------------------------+------------------------------------+
| record_id | application_name | date_time | cpu_usage_per_app_in_percentage | memory_usage_per_app_in_percentage |
+-----------+------------------+---------------------+---------------------------------+------------------------------------+
| 473849 | viber | 2015-09-06 19:23:13 | 5 | 2 |
| 473850 | watsup | 2015-09-06 19:23:13 | 9 | 2 |
| 473851 | AccuWeather | 2015-09-06 19:23:13 | 8 | 4 |
| 473980 | viber | 2015-09-06 19:23:14 | 4 | 1 |
| 474254 | watsup | 2015-09-06 19:23:14 | 9 | 1 |
| 474323 | AccuWeather | 2015-09-06 19:23:14 | 9 | 2 |
| 474533 | viber | 2015-09-06 19:23:15 | 5 | 2 |
| 474536 | watsup | 2015-09-06 19:23:15 | 8 | 3 |
| 474537 | AccuWeather | 2015-09-06 19:23:15 | 5 | 3 |
| 474538 | calendar | 2015-09-06 19:23:15 | 7 | 3 |
+-----------+------------------+---------------------+---------------------------------+------------------------------------+
you can suggest any other way of data collection , the key question is that is it possible to make calculation of Battery Consumption of earch running mobile application ? if so how and what the data to be collected?

Converting from ushort to RGB values

I'm trying to read an image file which has its colors stored in the following fashion:
Hex RGB
00 00 -> 0/0/0
01 00 -> 0/0/8
02 00 -> 0/0/16
...
20 00 -> 0/8/0
21 00 -> 0/8/8
22 00 -> 0/8/16
As you can see, it will increase the previous channel if the current one has a value of 256 or bigger.
I for the world can't seem to figure out a simple algorithm to calculate the appropriate color. If anyone can whip that for me I would be very thankful!
Update:
0x00 -> 0x1F == 0x20 -> 0x3F == 0/0/0 -> 0/0/248
0x40 -> 0x5F == 0x60 -> 0x7F == 0/8/0 -> 0/8/248
I just noticed that 32 ranges that follow up produce same color result... this is not some efficient RGB encoding, it's more like a protection if you ask me.
Another update:
I ended up making a colormap which I can use to lookup the right color for a specific number, you can see it's a pretty weird looking map. If someone can figure out an algorithm to get to the colors specified in this map I'd be very grateful as I'm really curious to how it works.
It looks to me as if they have done a 5-5-5 or a 5-6-5 bit level encoding to maximize the color capability within 16 bits. what this means is for lets say a 5-6-5 that the bit encoding would look like the below.
---------------------------------------------------------------------------------
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---------------------------------------------------------------------------------
| red | green | blue |
---------------------------------------------------------------------------------
However in your case it also looks as if they swapped byte order meaning that yours based upon the order you gave could actually look as follows (bytes ordered as you show them):
| byte 0 | byte 1 |
---------------------------------------------------------------------------------
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---------------------------------------------------------------------------------
| low green | blue | red | hi green |
---------------------------------------------------------------------------------
Disclaimer: This is a repost of an update to my original question for the sake of completion.
I ended up making a colormap which I can use to lookup the right color for a specific number, you can see it's a pretty weird looking map. If someone can figure out an algorithm to get to the colors specified in this map I'd be very grateful as I'm really curious to how it works.

Is there a way to show partitions on Cloudera impala?

Normally, I can do show partitions <table> in hive. But when it is a parquet table, hive does not understand it. I can go to hdfs and check the dir structure, but that is not ideal. Is there any better way to do that?
I am using Impala 1.4.0 and I can see partitions.
From the impala-shell give the command:
show partitions <mytablename>
I have something looking like this:
+-------+-------+-----+-------+--------+---------+--------------+---------+
| year | month | day | #Rows | #Files | Size | Bytes Cached | Format |
+-------+-------+-----+-------+--------+---------+--------------+---------+
| 2013 | 11 | 1 | -1 | 3 | 25.87MB | NOT CACHED | PARQUET |
| 2013 | 11 | 2 | -1 | 3 | 24.84MB | NOT CACHED | PARQUET |
| 2013 | 11 | 3 | -1 | 2 | 19.05MB | NOT CACHED | PARQUET |
| 2013 | 11 | 4 | -1 | 3 | 23.63MB | NOT CACHED | PARQUET |
| 2013 | 11 | 5 | -1 | 3 | 26.56MB | NOT CACHED | PARQUET |
Alternatively you can go to your table in HDFS . They are normally seen in this path:
/user/hivestore/warehouse/<mytablename> or
/user/hive/warehouse/<mytablename>
Unfortunately no. Issue is open though. So checking it manually seems to be the only option right now.

Hexadecimal Multiplication

Is there any shortcut or a some quick way of multiplying 2 small Hexadecimal numbers apart from converting into decimal ? Like in pen and paper method
Thanks,
Kiran
When you learn to multiply in base 10, you're taught to memorize multiplication-tables. The base 10 table is as follows:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
--+---+---+---+---+---+---+---+---
2 | 4 | 6 | 8 |10 |12 |14 |16 |18
--+---+---+---+---+---+---+---+---
3 | 6 | 9 |12 |15 |18 |21 |24 |27
--+---+---+---+---+---+---+---+---
etc...
When you're multiplying in other bases, you perform the same shortcuts, using a different multiplication-table (base 16):
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F
--+---+---+---+---+---+---+---+---+---+---+---+---+---+---
2 | 4 | 6 | 8 | A | C | E |10 |12 |14 |16 |18 |1A |1C |1E
--+---+---+---+---+---+---+---+---+---+---+---+---+---+---
3 | 6 | 9 | C | F |12 |15 |18 |1B |1E |21 |24 |27 |2A |2D
etc...
Long hand binary math is done the same way as longhand decimal for adding just carry the 2.
1010110 x 101
Add these numbers
1010110 ones column
00000000 tens column (or 2s column)
101011000 100s column (or 4s column)
=========
110101110
You didn't mention a platform/language/ect.
EDIT: OP clarified "pen and paper" after I wrote this.
Windows calculator has hex, octal, and binary modes.
But ultimately, numbers in a computer are base 2. Tools/languages which support decimal, hexidecimal, etc. are doing so for the convenience of the ape sitting at the keyboard, but in the computer's memory the number ends up being base 2.
For instance, in C the following two statements are the same (after lexing):
int x = 0xf * 0xf0; // hexidecimal
int x = 017 * 0360; // octal
int x = 15 * 240; // decimal
The different notations are for the convenience of the programmer, but in the machine these numbers are all represented the same way.
Using linux? You can use dc to do hex math. Set the input and output radix to 16 and you good to go.

Resources