Copy-pasting & Replacing NUL characters
I’m trying to edit files such as image files* which have the NUL \u0000 character & in my search found no present way to copy strings containing NULL or replace large amounts of spaces with NUL (because copying anything with NUL \u0000 replaces it with a space \u0020).
The 2 methods I have seen work is manually typing 00 repeatedly into the hex editor or manually counting how many spaces there are in a row & inserting NULL in the Character Panel for each instance (side note: the character panel doesn’t work after using the hex editor). HTML Tag, MIME Tools, & URL Plugin are unable to relace “\u0000” with the null character. Find and replacing with an extended or regex string doesn’t work. Neither does find/replacing 20 with 00 in the hex editor. None of the Edit > Paste Special options seem to do anything at all for me.
I’m running the most recent version of the Notepad++ (v8.2.1), 64-bit version on Windows 10.
*I’m trying to repair image files that have been partially overwritten & 1 thing I’ve been doing is trying to save headers & such to add to data I’ve recovered. I also want to try entering random data to see what kind of results I get. I’m mainly dealing with png, jpg, & bmp files, but occasionally find other types of non-images that may need repairing by adding large amounts of NUL.
Terry R last edited by
I’m trying to repair image files that have been partially overwritten & 1 thing I’ve been doing is trying to save headers & such to add to data I’ve recovered. I also want to try entering random data to see what kind of results I get. I’m mainly dealing with png, jpg, & bmp files, but occasionally find other types of non-images that may need repairing by adding large amounts of NUL.
I am amazed you would consider trying this with Notepad++. You do realise that Notepad++ is a TEXT editor. Sure it can open a binary file, but you have no guarantee that what Notepad++ is showing you is the correct representation of the content.
In order to edit any file you must understand the file structure. With TEXT files it’s a no-brainer, the characters appear in a linear fashion and can be directly edited. With JPG and PNG files, these are compressed files. So the original image undergoes a process to deduct (in the case of JPG as it’s a lossy process) or transform (in PNG as it can produce a lossless file) pixels and then store the new data in the file structure in a pre-determined way, thus finishing with a file smaller than the original image.
So unless you are aware of how this data has been compressed and stored you will have no chance of re-assembling missing data in such a way as to gain back missing portions of an image.
I would suggest doing research on the web, in particular on applications that have some hope of repairing damaged image files, but be aware none of these can recover the missing pixels. If the pixels are gone, then they are GONE! Your only hope to get back the missing data is to find an original copy of the file/image before damage occured.
@terry-r Sometimes the image is saved within another file. I’m then able to trim the beginning & end & “not have to touch the middle”, but it would be easier to just cut the middle & paste in a new file. Unfortunately, I’m unable to transfer the nul content in the transfer. Yes, I’m “losing” metadata, but most of the time it’s lost anyway.
guy038 last edited by
I’ve got a solution which involves an old version of N++ (
v6.9) with a modified version of the
Refer to the last part of this FAQ to know the improvements of the regex engine beta version of François-R Boyer, which, unfortunately, has never been part of regular N++ releases !
Here is the road map :
- Double-click on the link :
Download, either, the
npp.6.9.bin.ziparchive ( Portable version of N++
Create a directory on your desktop, named
Extract all contents of the archive in this
Delete the present
Download the Francois-R Boyer version of the
SciLexer.dllfile, from this link :
Place this new
SciLexer.dllfile in the
Notepad++.exe( 6.9 )
Now, open the Replace dialog (
Ctrl + H)
Regular expressionsearch mode
Click on the
Be back if any problem occurs. See you later !
Lycan Thrope last edited by
Then what you want to do, and I’m assuming you already know the structures you’re working with, it would appear that what you reallly want is a binary editor, which would be something like HxD Hex Editor where you can get right down into the binary level for editing. As stated, NPP is a text editor specializing in text, but with the unguarantee of other capabilities someone else can add, but is in no means intended to be a do all, end all programmer’s editor.
Alan Kilborn last edited by
I am amazed you would consider trying this with Notepad++
it would appear that what you reallly want is a binary editor,
I really have to second (third?) the comments of the earlier posters. Attempting to do this in Notepad++ in the modern age is just, well, downright dangerous to your data. Maybe it was OK back in the ASCII era, but those days are behind us.
@alan-kilborn I’m doing this recreationally. I’m splicing & editing remnant files, nothing I’m scared to lose. & of course, worst comes to worst, I have a backup. :^)
@guy038 I’ll give it a try!
@lycan-thrope Thank you for the suggestion. I’ll most likely try it out even if Guy’s suggestion works for me.
I found both programs very helpful. NPP 6.9 & the Scintilla edit make for a quick way to fix any number of NULs that got messed up while HxD lets me copy NULs directly & also see my entire disk for nearby clusters. Thank you 2 for your help!
PeterJones last edited by PeterJones
If you’re going to link to a previous discussion (which happens to be the issue that originally brought me to this forum!), you could at least read through the end. That post explained that there is an Edit > Paste Special > menu, with entries Copy/Cut/Paste Binary Content. That was there in 2015 when I originally asked (though I didn’t know it, and none of the regulars pointed it out), and would have worked with an unedited, plain-vanilla installation of Notepad++ v6.8.7 (which was state-of-the-art in Dec 2015); it still worked in 2019 (after the First Plugin Conversion in v7.6.3); and it still works in the latest-and-greatest v8.3.3 in March 2022:
Oops, the animation clipped the menu; here’s a static version:
The steps are:
- Highlight the text that has the NUL character(s) in it
- Edit > Paste Special > Copy Binary Content
- Move to where you want to paste
- Edit > Paste Special > Paste Binary Content
Those four simple steps will accomplish your goal, without having to go back to 2016’s NPP v6.9 and edit Scintilla.