Jump to content

Embed text in a file other than ".txt"


Recommended Posts

Hello, I am looking for a way to "hide" text (a word) in a file of any type (the file will be corrupted and unusable ... it's ok), but after I would like to open the file extract my "word ", delete it from the file to" rebuild "it so that it becomes usable again.
I was thinking of using FileOpen's "$ FO_BINARY" mode but I can only open it !! I would need functions like: FileDataRead, FileDataApend, FileDataWrite ...
I'm blocking ... I'm looking for help or information ...
thank you in advance

Link to comment
Share on other sites

  • Moderators

wattexi,

Yes, please do explain just why you want to "hide" something inside another file, thus corrupting it, and then extract it later while restoring the original file. A number of possible explanations come to mind - some of which I really do not like very much.

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

my script does that:

select a file (.txt .rar .docx or other ...), isolate the extansion, encrypt the file (_Crypt_EncryptFile)

I want to integrate the extension of the original file into the encrypt file, for another script then decrypt (_Crypt_DecryptFile) the file and  renamed with good extansion.

Thanks for your help.

Link to comment
Share on other sites

  • Moderators

wattexi,

That explains clearly what you want to do - now how about explaining why you want to do this.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Imagine a person encrypts a file type .xxx (for more security  the original extension does not appear in the file name encrypt) and send it to another person who owns the encryption key.
This second person can decrypt it and rebuild it if the script extracts the extension.
My "exercise" is already operational, it is the "hide" of the extension that annoys me, but if that is not possible, I think to do that by adding (to encrypt) the type of extension original in the file name encrypt ...

Link to comment
Share on other sites

  • Moderators

wattexi,

Thank you for that - happy for the thread to stay open.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You could encrypt the file as you do, but then grab the extension and hide it somewhere you choose inside the file.

The extension would be whatever you want, but the real extension would be hidden inside the file and recoverable because you know the offset where it would be.

Would something like this work for you? I did this for a similar purpose, the difference is that it doesn't really encrypt the file, only the filename and extension, the file data is scrambled, you just need to remember the pin, that pin will be the offset in bytes, oh well it's complicated to explain.

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

yes that's what I want to do, but I'm in trouble about rebuilding the file:

If I transform the file, add text and re transform:
_FileReadToArray ($file_path, $array) > _ArrayAdd ($array, $text) > _FileWriteFromArray ($new_file_path, $array, 1)

during extraction and reconstruction:
_FileReadToArray ($new_file_path, $array) > _ArrayPop ($array) > _FileWriteFromArray ($new_new_file_path, $array, 1,3)

I find my text thanks to _ArrayPop ($array), my table looks correct (such as before adding text), but it is corrupt (the decryption is in error), a verif with notepad ++ gives the same characters encrypt but a "lenght" different (a @crlf in +)?

Edited by wattexi
Link to comment
Share on other sites

I dont know what to say... there's no code.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

#include <File.au3>
#include <Array.au3>
#include <Crypt.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Crypted", 230, 88, 192, 124)
$Button1 = GUICtrlCreateButton("Select file", 56, 18, 115, 49)
$Button2 = GUICtrlCreateButton("Encrypt", 120, 50, 89, 25)
$Input1 = GUICtrlCreateInput("", 88, 16, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_PASSWORD))
$Label1 = GUICtrlCreateLabel("Pws =", 24, 20, 36, 17)
$Checkbox1 = GUICtrlCreateCheckbox("Show pws", 24, 54, 73, 17)
GUISetState(@SW_SHOW)


HotKeySet("{F5}","stop")
hide_elmts()

Global $file_crypted = False
Global $file_selected = ""
Global $extension, $file_path_without_extension

$algorithm = $CALG_AES_256


;Retrieve the ASCII value of the default password char
$sDefaultPassChar = GUICtrlSendMsg($Input1, $EM_GETPASSWORDCHAR, 0, 0)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            select_file()
        Case $Button2
            encrypt_decrypt_file()

        Case $Checkbox1

            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                GUICtrlSendMsg($Input1, $EM_SETPASSWORDCHAR, 0, 0)
                GUICtrlSetData($Checkbox1, "Hide Psw")
            Else
                GUICtrlSendMsg($Input1, $EM_SETPASSWORDCHAR, $sDefaultPassChar, 0)
                GUICtrlSetData($Checkbox1, "Show Pws")
            EndIf

            GUICtrlSetState($Input1, $GUI_FOCUS)
            GUICtrlSetState($Button1, $GUI_FOCUS)

    EndSwitch
WEnd


Func select_file()

    $file_selected = FileOpenDialog("Select file",@DesktopDir,"All (*.*)");"Text files (*.txt)"

    If @error Then

        MsgBox(16, "", "No file selected.")
        stop()
    EndIf

    ;MsgBox(0,"",$file_selected)

    $arrayay_file_path = StringSplit($file_selected,".")
    ;MsgBox(0,"",$arrayay_file_path[2] &@CRLF& $arrayay_file_path[1])

    $file_path_without_extension = $arrayay_file_path[1]
    $extension = $arrayay_file_path[2]

    If $extension = "crypted" Then
        GUICtrlSetData($Button2, "Decrypt")
        $file_crypted = True
        show_elmts()
    Else
        GUICtrlSetData($Button2, "Encrypt")
        $file_crypted = False
        show_elmts()
    EndIf

EndFunc


Func encrypt_decrypt_file()

    $file = $file_selected ; Read the source filepath input.
    $psw = GUICtrlRead($Input1) ; Read the password input.

    If StringStripWS($file, 8) <> "" And StringStripWS($psw, 8) <> "" And FileExists($file) Then ; Check there is a file available to encrypt and a password has been set.

        If $file_crypted = False  Then

            $new_file_path = $file_path_without_extension & ".crypted"

            If _Crypt_EncryptFile($file, $new_file_path, $psw, $algorithm) Then ; Encrypt the file.

                local $array
                _FileReadToArray($new_file_path,$array)
                ;_ArrayDisplay($array)
                _ArrayAdd($array, $extension)
                ;_ArrayDisplay($array)
                _FileWriteFromArray($new_file_path,$array,1)

                MsgBox(0, "Success", "Operation succeeded.")
            Else
                Switch @error
                    Case 1
                        MsgBox(16, "Error", "Failed to create the key.")
                    Case 2
                        MsgBox(16, "Error", "Couldn't open the source file.")
                    Case 3
                        MsgBox(16, "Error", "Couldn't open the destination file.")
                    Case 4 Or 5
                        MsgBox(16, "Error", "Encryption error.")
                EndSwitch
            EndIf

        Else

            $new_file_path = $file_path_without_extension & ".txt"
            If FileExists($new_file_path) Then
                $new_file_path = $file_path_without_extension & "_decrypted.txt"
            EndIf

            local $array
            _FileReadToArray($file,$array)
            _ArrayPop ($array)
            ;_ArrayDisplay($array)
            _FileWriteFromArray($file,$array,1,3)

            If _Crypt_DecryptFile($file, $new_file_path, $psw, $algorithm) Then ; Encrypt the file.
                MsgBox(0, "Success", "Operation succeeded.")
            Else
                Switch @error
                    Case 1
                        MsgBox(16, "Error", "Failed to create the key.")
                    Case 2
                        MsgBox(16, "Error", "Couldn't open the source file.")
                    Case 3
                        MsgBox(16, "Error", "Couldn't open the destination file.")
                    Case 4 Or 5
                        MsgBox(16, "Error", "Decryption error.")
                EndSwitch
            EndIf

        EndIf

    Else
        MsgBox(16, "Error", "Please ensure the relevant information has been entered correctly.")

    EndIf

EndFunc




Func hide_elmts()
    GUICtrlSetState($Label1,32)
    GUICtrlSetState($Input1,32)
    GUICtrlSetState($Checkbox1,32)
    GUICtrlSetState($Button2,32)
EndFunc

Func show_elmts()
    GUICtrlSetState($Button1,32)
    GUICtrlSetState($Label1,16)
    GUICtrlSetState($Input1,16)
    GUICtrlSetState($Checkbox1,16)
    GUICtrlSetState($Button2,16)
EndFunc



Func stop()
    Exit
EndFunc

_FileWriteFromArray($file,$array,1,3) => is for test, i know the array size with _ArrayDisplay($array). I make test with a little txt file with somme text...

Edited by wattexi
Link to comment
Share on other sites

If you want to embed this file inside another file, use the NTFS ADS (alternate data streams). There are examples of how to do this in the forum, and I linked to a google search that should give you choices.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...