Tclsh convert base64 dump into zip file - zip

I have written a Tclsh code that will fetch a zip file content in base64 format through xml-rpc method. I am dumping that base64 data into a file using the following snippet:
#!/usr/bin/tclsh
...
set mybase64Dump [myXmlRpcCallToReturnThisDump]
set zipFilePtr [open "xyz.zip" "w"]
puts $zipFilePtr $mybase64Dump
close $zipFilePte
Zip file was getting generated with XKbytes of size, but when trying to open using 7zip it says, Is not Archive. But I copy pasted the same base64 dump in a online converter. It was giving me a proper extractable zip file.
Is it something I am doing wrongly?

You probably need to configure the output file to be binary, not ascii. The default translation for a newly opened file is "auto", which does system-specific translation of the end-of-line characters, which is not what you want for a .zip file. Configure this using fconfigure on the handle after opening it or by adding the BINARY access flag to the open command.
See http://www.tcl.tk/man/tcl8.5/TclCmd/open.htm and http://www.tcl.tk/man/tcl8.5/TclCmd/fconfigure.htm for details on the syntax.

Related

Steganography with Microsoft Word - DOCX

I write a application hide a of string within a .docx file.
A Docx file comprises of a collection of XML files that are contained inside a ZIP archive. So, My program treat that file like a zip file and hide secret string in it.
After research, I found a way to insert data to ZIP archive.
A Secret String is injected after a file section right before the 1st central directory header. After that, a pointer in an end of central directory record is updated to compensate the shift of the central directory header.
My output docx file work fine with typical file archivers (7-zip, WinRAR, File Roller, &c) or file managers (Windows Explorer).
But when I open my output docx file with Microsoft Word it said:
Here is link for input and output file
What step did I wrong or missing?

writefile-write-file-to-workspace Groovy Jenkins step looks to be corrupting size & content of Binary file

In course of uploading binary file with few attempts per file parameter uploaded file in Jenkins is missing & Fetching binary or zipped uploaded files in Jenkins - Windows cannot open the folder . The Compressed(zipped) Folder is invalid noticed, writeFile Groovy used as part of Jnekins pipeline is corrupting content of file along with its size - worried more from Binary file perspective.
Per the documentation, https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#writefile-write-file-to-workspace , it's mentioned to support base64 encoding for binary data for writing files, but looks like it's bug as written file is with wrong size (exceeds..) & corrupt, as one can't open zip or binary file as highlighted in post linked above.
writeFile: Write file to workspace Write the given content to a named
file in the current directory.
file Type: String text Type: String
encoding (optional) The target encoding for the file. If left blank,
the platform default encoding will be used. If the text is a
Base64-encoded string, the decoded binary data can be written to the
file by specifying "Base64" as the encoding. Type: String
Any work-around is present or is there a way to raise bug-fix request?
Here is line of code which looks to be causing problem from groovy Jenkins pipeline script
// Read contents and write to workspace
writeFile(file: filename, encoding: 'Base64', text: filedata.read().getBytes().encodeBase64().toString())

Cat output different from redirect output

I have a ".msg" file, and I wanted to do some textual parsing on it. I have not installed any package to convert a .msg file to any other kind of format.
When I do :
cat testing.msg <--- Shows up correctly and whatever in the screen is what I want
However when I do:
cat testing.msg > file <---- The file seems to be encoded when I do vi and look into the file.
testing.msg: CDF V2 Document, No summary info
How can I correctly to read the msg file so that I get the correct textual data?
I have tried changing the $LANG variables but that doesn't seem to work.

NodeJS - Reading image source returns incorrect file size

This could be a basic question, but wanted to understand why the size of the file being read using fs.readFileSync is incorrect if the source is referring to an 'image' or non-text file path.
Example:
fs.writeFileSync(outputPath, fs.readFileSync(source, 'utf8'));
Because you are calling fs.readFileSync(source, 'utf8').
The important part is utf8, you are telling it to decode the file as if it is utf8 text. If it is a non-text file then it will not work properly and thus produce the incorrect file size.

How to get the content from an uncompressed .docx file by using ifstream.open() and read() methods. office open xml, vc++

I'm trying to build a suffix tree from a .docx file.
So first I unzipped the .docx file and then again created a .docx file with out compressing it. I used ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetLevel(0) method. Here I used C#.
This uncompressed .docx files can be opened without any error.
For the next step I used vc++. By using ifstream.open ("uncompressed.docx", ios::binary ); method I tried to open the file and store the content in a char array by using ifstream.read ( (char *)T, MAX_LENGTH - 1 ) method. But I could not get the actual content of uncompressed.docx file. When I tried to print the content of the char array(T) it printed some formatting tags rather than printing the actual text content of the uncompressed.docx.
I could not figure out what is the actual file that ifstream.open() method opens.It is not the document.xml file.
Please tell me how to get the actual text content from the uncompressed.docx file using VC++.

Resources