0

EDIT: My essential question (without the specific setting for which I need a solution, as described in my original posting):

BinFile.bin is a file concatenated from binary files and a text file. The included text file consists only of lines beginning with a specific string, e.g. ;;;===,,,

With a batch file:

findstr /v "^;;;===,,," "BinFile.bin" > output.bin

an output bin file is generated in which the text file is completely removed.

How to use findstr (or another dos command) to not only remove all lines beginning with the specified string, but also the part of the bin before first such line (i.e. the complete binary part preceeding the text file)?



>>> My original posting:

jeb invented a method to concatenate files using Windows native tools which can be unconcatenated (in a specific way) using native tools. His solution is just ingenious!

copy /a batchBin.bat + /b myBinaryFile.bin /b combined.bat

with batchBin.bat:

;;;===,,,@echo off
;;;===,,,echo line2
;;;===,,,findstr /v "^;;;===,,," "%~f0" > output.bin
;;;===,,,exit /b

"The key is the findstr command, it outputs all lines not beginning with ;;;===,,,. And as each of them are standard batch delimiters, they can be prefix any command in a batch file in any combination."

So myBinaryFile.bin can be extracted from the combined.bat––only by means of native tools!

My question:

In jeb's example the combined file is a batch file, because the first file in the copy command is a batch file. Could jeb's tricky method be used for the following task too, where the combined file would be combined.exe, an exe file?

copy /b aBat2ExeFile.exe + /a delimiter.bat + /b myBinaryFile.bin /b combined.exe

where delimiter.bat would be something like this:

;;;===,,,REM

and aBat2ExeFile.exe would be a batch file (aBat2ExeFile.bat) converted to exe, with a tricky use of findstr like in batchBin.bat, but with the result

[...] > output.exe

In aBat2ExeFile.bat findstr should be used with the result that all lines of combined.exe before and including the line ';;;===,,,REM' would be ignored and output.exe would be equal to myBinaryFile.bin again?

In think the concept is correct. But how this could be implemented in the aBat2ExeFile.bat?

EDIT: My question can be simplified (the frame described above is not essential): How the findstr method used by jeb could be adapted to process a binary file in such a way that not only lines starting with ';;;===,,,' but also all lines preceding the first such line are "ignored"?

newbieforever
  • 217
  • 1
  • 4
  • 15
  • I'd wager that you haven't converted a batch file to an .exe! It is more likely that you have a container .exe file which at runtime extracts and runs the batch file. – Compo Jun 01 '18 at 19:23
  • Compo: Hm? "You haven't converted a batch file..."–what do you mean by this? I think you misunderstud the concept. If you refer to my anBatExeFile.exe: This should be a bat converted to exe e.g. using the bat2exe tool. – newbieforever Jun 01 '18 at 20:30
  • 1
    Exactly what I said, **you've been fooled**, `bat2exe` creates a container `.exe` file which extracts and runs your batch file. So, as such, I see no reason why you cannot use another utility to create a self extracting executable file containing all of your files. – Compo Jun 01 '18 at 20:37
  • Compo: OK, you see no reason. But I am working on another tricky solution for an specific problem, and the concept described in my posting would be perfect, believe me. Nevertheless, this all is not the point in my question. – newbieforever Jun 01 '18 at 20:41
  • Well it is absolutely relevant because the exe you're talking about is not your batch file, it is a file much like the one you're trying to create, a file which upon running 'unconcatenates' that which is within it. – Compo Jun 01 '18 at 20:46
  • Compo: And? That "which is within" still would be an bat which would do what is intended, i.e. to extract myBinaryFile.bin. – newbieforever Jun 01 '18 at 20:56

0 Answers0