Giter Club home page Giter Club logo

pdvzip's Introduction

pdvzip

A simple command-line tool used to embed a ZIP file within a PNG image,
creating a tweetable and "executable" PNG-ZIP polyglot image file.

You can share your image on several *social media sites, which will preserve the embedded ZIP file.

Image size limits vary across platforms:

  • Flickr (200MB), ImgBB (32MB), PostImage (24MB), ImgPile (8MB), Twitter (5MB).

Demo Image
{Image credit: MΞV.ai / @aest_artificial}

Based on the similar idea by David Buchanan, from his original Python program tweetable-polyglot-png,
pdvzip uses different methods for storing and accessing embedded files within a PNG image.

Demo Videos: Twitter / Flickr

Compile and run the program under Windows or Linux.

Usage

user1@linuxbox:~/Desktop$ g++ pdvzip.cpp -O2 -s -o pdvzip
user1@linuxbox:~/Desktop$ ./pdvzip

Usage: pdvzip <cover_image> <zip_file>
       pdvzip --info

user1@linuxbox:~/Desktop$ ./pdvzip plate_image.png like_spinning_plates.zip

Reading files. Please wait...

Updating extraction script.

Embedding extraction script within the PNG image.

Embedding ZIP file within the PNG image.

Writing ZIP embedded PNG image out to disk.

Saved PNG image: pzip_55183.png 4038367 Bytes.

Complete!

You can now share your PNG-ZIP polyglot image on the relevant supported platforms.

After embedding the ZIP within an image, it can then be posted on a variety of social media/image hosting sites. "Execute" the image whenever you want to access the embedded file(s).

Extracting Your Embedded File(s)

Important: When saving images from Twitter, click the image in the post to fully expand it, before saving.

Linux (Make sure image file has executable permissions)

user1@linuxbox:~/Desktop$ chmod +x pzip_55183.png
user1@linuxbox:~/Desktop$ ./pzip_55183.png

Alternative execution (Linux). Using wget to download & run the image directly from the hosting site.
ImgBB wget example: Image with embedded python script.

$ wget "https://i.ibb.co/r6R7zdG/Fibonacci.png";chmod +x Fibonacci.png;./Fibonacci.png

Windows (Rename the image file extension to '.cmd')

G:\demo> ren pzip_55183.png pzip_55183.cmd
G:\demo> .\pzip_55183.cmd

Alternative execution (Windows). Using iwr to download & run the image directly from the hosting site.
Twitter iwr example: Image with embedded mp3 music file.

G:\demo> iwr -o img2.cmd "https://pbs.twimg.com/media/FsPOkPnWYAA0935?format=png";.\img2.cmd

Opening the cmd file from the desktop, on its first run, Windows may display a security warning.
Clear this by clicking 'More info' then select 'Run anyway'.

To avoid security warnings, run the image file from a Windows console, as shown in the above example.

For common video/audio files, Linux requires 'vlc (VideoLAN)', Windows uses the set default media player.
PDF '.pdf', Linux requires the 'evince' application, Windows uses the set default PDF viewer.
Python '.py', Linux & Windows use the 'python3' command to run these programs.
PowerShell '.ps1', Linux uses the 'pwsh' command, Windows uses 'powershell' to run these scripts.

For any other file type, Linux & Windows will rely on the operating system's set default application.
Obviously, the embedded file needs to be compatible with the operating system you run it on.

If the embedded media type is Python, PowerShell, Shell script or a Windows/Linux executable, you can provide optional command-line arguments for your file.

Here is a video example of using pdvzip with a simple Shell script (.sh) with arguments for the script file, that are also embedded within the PNG image along with the script file.

To just get access to the file(s) within the ZIP archive, rename the '.png' file extension to '.zip'. Treat the ZIP archive as read-only, do not add or remove files from the PNG-ZIP polyglot file.

PNG Image Requirements for Arbitrary Data Preservation

PNG file size (image + embedded content) must not exceed the hosting site's size limits.
The site will either refuse to upload your image or it will convert your image to jpg, such as Twitter.

Dimensions:

The following dimension size limits are specific to pdvzip and not necessarily the extact hosting site's size limits. These dimension size limits are for compatibility reasons, allowing it to work with all the above listed platforms.

PNG-32 (Truecolor with alpha [6])
PNG-24 (Truecolor [2])

Image dimensions can be set between a minimum of 68 x 68 and a maximum of 899 x 899.

Note: Images that are created & saved within your image editor as PNG-32/24 that are either black & white/grayscale, images with 256 colors or less, will be converted by Twitter to PNG-8 and you will lose the embedded content. If you want to use a simple "single" color PNG-32/24 image, then fill an area with a gradient color instead of a single solid color. Twitter should then keep the image as PNG-32/24. (Example).

PNG-8 (Indexed-color [3])

Image dimensions can be set between a minimum of 68 x 68 and a maximum of 4096 x 4096.

Chunks:

With Twitter, for example, you can overfill the following PNG chunks with arbitrary data,
in which the platform will preserve as long as you keep within the image dimension & file size limits.

bKGD, cHRM, gAMA, hIST,
iCCP, (Only 10KB max. with Twitter).
IDAT, (Use as last IDAT chunk, after the final image IDAT chunk).
PLTE, (Use only with PNG-32/24 images).
pHYs, sBIT, sPLT, sRGB,
tRNS. (Not recommended, may distort image).

Other platforms may differ in what chunks they preserve and which ones you can overfill.

pdvzip uses the iCCP (contains extraction script) and IDAT (contains ZIP file) chunk names for storing arbitrary data.

ZIP File Size & Other Important Information

To work out the maximum ZIP file size, start with the hosting site's size limit,
minus your PNG image size, minus 750 bytes (internal shell extraction script size).

Twitter example: (5MB) 5,242,880 - (307,200 + 750) = 4,934,930 bytes available for your ZIP file.

The less detailed your image, the more space available for the ZIP.

  • Make sure your ZIP file is a standard ZIP archive, compatible with Linux unzip & Windows Explorer.

  • Do not include other .zip files within the main ZIP archive. (.rar files are ok).

  • Do not include other pdvzip created PNG image files within the main ZIP archive, as they are essentially .zip files.

  • Use file extensions for your file(s) within the ZIP archive: my_doc.pdf, my_video.mp4, my_program.py, etc.

    A file without an extension will be treated as a Linux executable.

  • Paint.net application is recommended for easily creating compatible PNG image files.

My other programs you may find useful:-

pdvzip's People

Contributors

cleasbycode avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.