Jump to content

Snippet: Difference between revisions

From LabVIEW Wiki
No edit summary
mNo edit summary
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{TOCright}}<br>
{{TOCright}}
A '''Snippet''' is an image of LabVIEW code.  [[LabVIEW 2009]] added native support to embed actual code inside a [[wikipedia:Portable_Network_Graphics|PNG]] image. With this functionality it is possible to distribute code on a website, inside of a PNG image, and use the image to import the code into a [[VI]].


A snippet is in the [[LabVIEW|LabVIEW]] context an image of LabVIEW code.<br>
== Creation ==
===Native===
Starting with [[LabVIEW 2009]], to create a '''snippet''':
# Select the code to include on the [[Block Diagram]].
# Sselect '''Create Snippet from selection''' from the '''Edit''' menu. [http://zone.ni.com/reference/en-XX/help/371361G-01/lvhowto/create_visnippet/]


[http://zone.ni.com/devzone/cda/tut/p/id/9330 LabVIEW 2009 introduced] the embedding of the actual code inside a [http://en.wikipedia.org/wiki/Portable_Network_Graphics PNG] image.<br>
===Advanced===
With the [[Code Capture Tool|Code Capture Tool]] version 2.0 it's possible to create a snippet in any version from [[LabVIEW 7 Express|LabVIEW 7.0]] and up.


With this functionality it is possible to expose your code on a website, and with the same file import the code into a LabVIEW [[VI|VI]].<br>
== Importing ==


= Creation<br>  =
=== LabVIEW 2009 ===


LabVIEW 2009 has native support to create a snippet.<br>
To import the actual code into a VI, just drag and drop the image onto the block diagram of a VI. With [http://www.microsoft.com/Windows/internet-explorer/ Internet Explorer] it's possible to drag and drop the image from a web-page directly into a VI's [[Block Diagram]].


With the [[Code Capture Tool|Code Capture Tool]] version 2.0 it's possible to create a snippet in any LabVIEW version from 7.0 and up.<br>
For [http://www.mozilla.com/firefox/ Firefox] and [http://www.google.com/chrome Google Chrome] it's necessary to drop the image in an OS folder or use a plugin [http://addons.mozilla.org/firefox/addon/1419 IETab] (for Firefox).  


= Importing<br>  =
=== LabVIEW 8.2, 8.5 and 8.6===


== LabVIEW 2009<br>  ==
To import a snippet into [[LabVIEW 8.20]] it's possible if the snippet is created with the [[Code Capture Tool|Code Capture Tool]] in the same (or an older) version of LabVIEW. Second you need a special tool developed by [http://lavag.org/user/7534-jcarmody/ JCarmody]. This tool is available for [http://lavag.org/index.php?app=downloads&showfile=118 download] in the LAVA Uncertified Code Repository.


To import the actual code into a VI, just drag and drop the image onto the block diagram of a VI. With [http://www.microsoft.com/Windows/internet-explorer/ Internet Explorer] it's possible to drag and drop the image for a web-page into a VI&nbsp;directly.<br>
== Technique ==


For [http://www.mozilla.com/firefox/ Firefox] and [http://www.google.com/chrome Google Chrome] it's necessary to drop the image in an OS folder or use a plugin [http://addons.mozilla.org/firefox/addon/1419 IETab] (for Firefox).<br>
The code of a LabVIEW snippet is stored inside a [http://en.wikipedia.org/wiki/Portable_Network_Graphics#.22Chunks.22_within_the_file PNG Chunk] named 'niVI'. The capitalization of this chunkname makes sure the code is removed if someone alters the image, thus preventing the creation of malicious snippets.<br>  


== LabVIEW 8.2, 8.5 and 8.6<br> ==
Inside this chunk a filestream representing a VI is stored. LabVIEW interprets this as a normal VI to be embedded.<br>  


To import a snippet into LabVIEW 8.2 it's possible if the snippet is created with the [[Code Capture Tool|Code Capture Tool]] in the same (or an older) version of LabVIEW. Second you need a special tool developed by [http://lavag.org/user/7534-jcarmody/ JCarmody]. This tool is available for [http://lavag.org/index.php?app=downloads&showfile=118 download] in the LAVA Uncertified Code Repository.<br>
=== Code integrity===


= Technique<br> =
Technically it's possible to have a different codeset embedded than represented by the PNG image chunk. This is proven by [http://forums.ni.com/ni/view_profile?user.id=134255 Darin.K] on the [[NI Forums|NI Forum]] with the following snippet:<br>  


The code of a LabVIEW snippet is stored inside a [http://en.wikipedia.org/wiki/Portable_Network_Graphics#.22Chunks.22_within_the_file PNG Chunk] named 'niVI'. The capitalization of this chunkname makes sure the code is removed if someone alters the image, thus preventing the creation of malicious snippets.<br>
[[Image:MerrimanSnippet.png]]


Inside this chunk a filestream representing a VI is stored. LabVIEW interprets this as a normal VI to be embedded.<br>
[http://forums.ni.com/ni/board/message?board.id=BreakPoint&view=by_date_ascending&message.id=8610#M8610 Source ]<br>  


== Code integrity<br>  ==
Upon dropping this image on a LabVIEW diagram another image was placed.


Technically it's possible to have a different codeset embedded than represented by the PNG image chunk. This is proven by [http://forums.ni.com/ni/view_profile?user.id=134255 Darin.K] on the [[NI Forums|NI Forum]] with the following snippet:<br>
The name of the Snippet Chunk (niVI), describes this chunk as [http://www.w3.org/TR/2003/REC-PNG-20031110/#5Chunk-naming-conventions unsave to copy], tests with Paint.net shows that indeed the chunk is removed when the image is altered. However usage of Microsoft Paint show that the snippet is not removed upon editing of the image.
 
[[Image:MerrimanSnippet.png]]<br>
 
[http://forums.ni.com/ni/board/message?board.id=BreakPoint&view=by_date_ascending&message.id=8610#M8610 Source ]<br>


Upon dropping this image on a LabVIEW diagram another image was placed.
== References ==


The name of the Snippet Chunk (niVI), describes this chunk as [http://www.w3.org/TR/2003/REC-PNG-20031110/#5Chunk-naming-conventions unsave to copy], tests with Paint.net shows that indeed the chunk is removed when the image is altered. However usage of Microsoft Paint show that the snippet is not removed upon editing of the image.
[[Category:Code distribution]]

Latest revision as of 20:12, 12 March 2021

A Snippet is an image of LabVIEW code. LabVIEW 2009 added native support to embed actual code inside a PNG image. With this functionality it is possible to distribute code on a website, inside of a PNG image, and use the image to import the code into a VI.

Creation

Native

Starting with LabVIEW 2009, to create a snippet:

  1. Select the code to include on the Block Diagram.
  2. Sselect Create Snippet from selection from the Edit menu. [1]

Advanced

With the Code Capture Tool version 2.0 it's possible to create a snippet in any version from LabVIEW 7.0 and up.

Importing

LabVIEW 2009

To import the actual code into a VI, just drag and drop the image onto the block diagram of a VI. With Internet Explorer it's possible to drag and drop the image from a web-page directly into a VI's Block Diagram.

For Firefox and Google Chrome it's necessary to drop the image in an OS folder or use a plugin IETab (for Firefox).

LabVIEW 8.2, 8.5 and 8.6

To import a snippet into LabVIEW 8.20 it's possible if the snippet is created with the Code Capture Tool in the same (or an older) version of LabVIEW. Second you need a special tool developed by JCarmody. This tool is available for download in the LAVA Uncertified Code Repository.

Technique

The code of a LabVIEW snippet is stored inside a PNG Chunk named 'niVI'. The capitalization of this chunkname makes sure the code is removed if someone alters the image, thus preventing the creation of malicious snippets.

Inside this chunk a filestream representing a VI is stored. LabVIEW interprets this as a normal VI to be embedded.

Code integrity

Technically it's possible to have a different codeset embedded than represented by the PNG image chunk. This is proven by Darin.K on the NI Forum with the following snippet:

Source

Upon dropping this image on a LabVIEW diagram another image was placed.

The name of the Snippet Chunk (niVI), describes this chunk as unsave to copy, tests with Paint.net shows that indeed the chunk is removed when the image is altered. However usage of Microsoft Paint show that the snippet is not removed upon editing of the image.

References