Jump to content

Exe Binder


nocow
 Share

Recommended Posts

The idea is good (I'm not even sure there's such a thing as a "bad idea").

It's the implementation that matters.

Yes, I can think of some ways this could be abused.

OK, I get how it inject the files, but how the heck do you get the files back out of the

exe file? I haven't seen anyone talk about that?

I have been working on a script to do just that. It will allow you to read/write data to/from executables. It may not be the best way, but it works well. One thing I noticed though, if you run the exe binder as a script and try to bind data to the autoit executable it is running from it will not work, not even giving an error. I have not tested this much yet. I can say for sure that it will work with executables that are not running. Here is the code:

#include <GUIConstants.au3>

$gui = GUICreate("Exe Binder", 500, 400)
$exe_input = GUICtrlCreateInput("", 10, 10, 400, 20)
$browse_btn = GUICtrlCreateButton("Browse", 420, 10, 70, 20, $BS_DEFPUSHBUTTON)
$edit = GUICtrlCreateEdit("", 10, 40, 480, 320)
$save_btn = GUICtrlCreateButton("Save", 10, 370, 70, 20)

$selected = False
$exe = ""
$data = ""

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $browse_btn
            $exe = FileOpenDialog("Select File", "", "Executable Files (*.exe)", 1)
            If @error Then ContinueLoop
            $data = _BindLoad($exe)
            If @error Then
                mError("Read error! The program is not accessable.")
                ContinueLoop
            EndIf
            $selected = True
            GUICtrlSetData($exe_input, $exe)
            GUICtrlSetData($edit, _BindRead($data))
        Case $save_btn
            If $selected and MsgBox(4, "Exe Binder", "Are you sure you want to save?") = 6 Then
                _BindSave($exe, _BindSet($data, GUICtrlRead($edit)))
                If @error Then mError("Write error! The program may be in use.")
            EndIf
    EndSwitch
    Sleep(10)
Wend


Func mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 )
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc

Func _BindLoad( $sEXE )
    Local $sData = FileRead($sEXE)
    If @error Then Return SetError(1)
    If not _BindExists($sData) Then $sData = _BindCreate($sData)
    Return $sData
EndFunc

Func _BindSave( $sEXE, $sData )
    Local $hFile = FileOpen($sEXE, 2)
    If $hFile = -1 Then Return SetError(1)
    FileWrite($hFile, $sData)
    FileClose($hFile)
    Return 1
EndFunc

Func _BindExists( $sData )
    Return StringLen($sData) - StringInStr($sData, Chr(190), 0, -1) <= 16
EndFunc

Func _BindCreate( $sData )
    Return $sData & Chr(190) & StringLen($sData)
EndFunc

Func _BindSet( $sData, $sValue )
    Local $iSize = StringRight($sData, StringLen($sData) - StringInStr($sData, Chr(190), 0, -1))
    Return StringLeft($sData, $iSize) & $sValue & Chr(190) & $iSize
EndFunc

Func _BindRead( $sData )
    Local $iSize = StringRight($sData, StringLen($sData) - StringInStr($sData, Chr(190), 0, -1))
    Return StringTrimLeft(StringTrimRight($sData, StringLen($iSize) + 1), $iSize)
EndFunc

Func _BindClear( $sData )
    Return _BindSet($sData, "")
EndFunc

Func _BindRemove( $sData )
    Local $iSize = StringRight($sData, StringLen($sData) - StringInStr($sData, Chr(190), 0, -1))
    Return StringLeft($sData, $iSize)
EndFunc

I have made some functions the program doesn't use. The may be helpful to someone. Tell me what you think! :)

P.S. - I like the new AutoIt code boxes!

EDIT - Found a bug, now it will give an error when you try to open an executable that is already running, which means self-modifying executables are not probable this way (please, someone prove me wrong!)

Edited by erifash
Link to comment
Share on other sites

  • 3 years later...

Yes, I can think of some ways this could be abused.

I have been working on a script to do just that. It will allow you to read/write data to/from executables. It may not be the best way, but it works well. One thing I noticed though, if you run the exe binder as a script and try to bind data to the autoit executable it is running from it will not work, not even giving an error. I have not tested this much yet. I can say for sure that it will work with executables that are not running. Here is the code:

#include <GUIConstants.au3>

$gui = GUICreate("Exe Binder", 500, 400)
$exe_input = GUICtrlCreateInput("", 10, 10, 400, 20)
$browse_btn = GUICtrlCreateButton("Browse", 420, 10, 70, 20, $BS_DEFPUSHBUTTON)
$edit = GUICtrlCreateEdit("", 10, 40, 480, 320)
$save_btn = GUICtrlCreateButton("Save", 10, 370, 70, 20)

$selected = False
$exe = ""
$data = ""

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $browse_btn
            $exe = FileOpenDialog("Select File", "", "Executable Files (*.exe)", 1)
            If @error Then ContinueLoop
            $data = _BindLoad($exe)
            If @error Then
                mError("Read error! The program is not accessable.")
                ContinueLoop
            EndIf
            $selected = True
            GUICtrlSetData($exe_input, $exe)
            GUICtrlSetData($edit, _BindRead($data))
        Case $save_btn
            If $selected and MsgBox(4, "Exe Binder", "Are you sure you want to save?") = 6 Then
                _BindSave($exe, _BindSet($data, GUICtrlRead($edit)))
                If @error Then mError("Write error! The program may be in use.")
            EndIf
    EndSwitch
    Sleep(10)
Wend


Func mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 )
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc

Func _BindLoad( $sEXE )
    Local $sData = FileRead($sEXE)
    If @error Then Return SetError(1)
    If not _BindExists($sData) Then $sData = _BindCreate($sData)
    Return $sData
EndFunc

Func _BindSave( $sEXE, $sData )
    Local $hFile = FileOpen($sEXE, 2)
    If $hFile = -1 Then Return SetError(1)
    FileWrite($hFile, $sData)
    FileClose($hFile)
    Return 1
EndFunc

Func _BindExists( $sData )
    Return StringLen($sData) - StringInStr($sData, Chr(190), 0, -1) <= 16
EndFunc

Func _BindCreate( $sData )
    Return $sData & Chr(190) & StringLen($sData)
EndFunc

Func _BindSet( $sData, $sValue )
    Local $iSize = StringRight($sData, StringLen($sData) - StringInStr($sData, Chr(190), 0, -1))
    Return StringLeft($sData, $iSize) & $sValue & Chr(190) & $iSize
EndFunc

Func _BindRead( $sData )
    Local $iSize = StringRight($sData, StringLen($sData) - StringInStr($sData, Chr(190), 0, -1))
    Return StringTrimLeft(StringTrimRight($sData, StringLen($iSize) + 1), $iSize)
EndFunc

Func _BindClear( $sData )
    Return _BindSet($sData, "")
EndFunc

Func _BindRemove( $sData )
    Local $iSize = StringRight($sData, StringLen($sData) - StringInStr($sData, Chr(190), 0, -1))
    Return StringLeft($sData, $iSize)
EndFunc

I have made some functions the program doesn't use. The may be helpful to someone. Tell me what you think! :D

P.S. - I like the new AutoIt code boxes!

EDIT - Found a bug, now it will give an error when you try to open an executable that is already running, which means self-modifying executables are not probable this way (please, someone prove me wrong!)

Hi all...

I know that this topic is old but is interesting.

I'm not sure how must work.

So i guess by pressing button 'Browse' user open FileDialog and find specific .exe file.

Before that user must add data in Editor box is'nt.

What is the data - ordinary text or something else?

Is this example work anyway?

I ave something similiar but written in Freebasic but works only for console .exe?

Why i'm interested for this program?

In first place - i have small interpreter GUI type which is of course interpreter.exe.

Also i have runtime.exe, so i wanna on this way ,bind source code in runtime.exe.

Is that posibile with this program?

Thanks advance

Aurel

Link to comment
Share on other sites

This is so old I'd forgotten about it.

So i guess by pressing button 'Browse' user open FileDialog and find specific .exe file.

Before that user must add data in Editor box is'nt.

What is the data - ordinary text or something else?

How to use the example provided:

1. Press Browse to go to the exe

2. Type in data you want to save to the exe

3. Press Save

To retrieve the data, do the following:

1. Press Browse to go to the exe

2. The data magically appears.

In first place - i have small interpreter GUI type which is of course interpreter.exe.

Also i have runtime.exe, so i wanna on this way ,bind source code in runtime.exe.

Is that posibile with this program?

How does it work:

To read the data out of the executable:

$the_data_I_want = _BindRead(_BindLoad($path_to_exe))

To save data to the executable:

_BindSave($path_to_exe, _BindSet(_BindLoad($path_to_exe), $the_data_to_save))

Work something out with that.

Link to comment
Share on other sites

What AutoIt version this script was made for?

I can't find GuiList.au3... This is for 3.3.0.0 or Beta?

Thanks in advance.

nfwu

Thanks,but you dont tell me which exe is in this case.

I guess this same program when is compiled as .exe standalone is'nt?

Hmm this is not really what i need but is interesting.

I want that i can for example add data(text or source code ) to my runtime.exe and

when i doubleclick this exe i espect that data will loaded automaticly by this runtime.exe.I hope that you understand me.

However thanks on answer...

Aurel

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...