Include pictures while converting ps1 to exe with PowerGUI - image

I use the PowerGUI editor to convert a ps1 file to an exe file. Reason is that I dont want people to see my source code. The script includes a own little GUI with a picture on it. My problem is that after converting the script to an exe file the picture will only be shown when it exists on a specific path. If I delete or move the picture from that path it wont be shown when starting the exe.
How can I include the picture to the exe? I want to have only one file in the end ...

One way you could do this is by converting your image into a Base 64 String, using the following:
[convert]::ToBase64String((get-content C:\YourPicture.jpg -encoding byte)) > C:\YourString.txt
With the string that is produced in the text file "C:\YourString.txt" you can copy and paste it into your code and load it into a picture object on the form like so:
$logo.Image = [System.Convert]::FromBase64String('
iVBORw0KGgoAAAANSUhEUgAAAfQAAACMCAYAAACK0FuSAAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAAXEQAAFxEByibzPwAAAAd0SU1FB98DFA8VLc5RQx4AANRpSURBVHhe7J0FmBTX0oZ7F1jc3d3d
nU+dOtXw4MGDZfft25fmyJEjPu+//76Xqzke8pCHPOQhD3lIQGxxcGSapvHdd9+FF3hHEdjGFHgn
....... Many more lines of string .......
OqelFQzDMAzD/CZoztADbUwhUm0JERoXCNfEQYhyPAQryiBIUQSBiiTwl1sb3skwDMMwzG+KWLVe
jTEBH6U7JvJ0CJQXoaGPQMWBm5W+Va27k14MwzDMfwCA/wfUstOLO+nBIAAAAABJRU5Jggg==')
Do this will mean that your image is stored within the code already and doesn't need to be loaded from somewhere.
Note: Make sure that the pictures size on disk is the smallest you can get it as producing the string can take sometime and could turn out thousands of lines long. So I would recommend that you only use a pic that is less that 75 Kilobytes in size. You could do it with larger one but this will take a long time to process.

Related

How to replace all files with a specific pixel size, and keep their names?

I have a .png file and a folder with multiple folders in it, that all contain multiple .png files, e.g. '1.png', '2.png' and so on. What I'd like to do is to replace the contents of all those files to the first named file, but keep their names.
I'm pretty sure this is doable and I think I found an answer to do this in one folder using command prompt on Windows, but I'd also like to only replace files that have a specific file size (in pixels, and not the same size as the file I'm replacing them to, just a specific file size).
I prefer to do this simply using a batch file, so if anyone can help that'd be appreciated a lot. If it's not possible to meet the file size criteria with a batch file, but it is possible to do this for a whole directory tree with .png files, that gets me a long way as well.
Thank you in advance!
Edit: In the comments Stephan mentioned you can't get the pixel size of a file, so it turns out this isn't possible. I'm not going to bother with an external application.

Maximum number of input file for Ghostscript (gs)

I simply want to combine multiple eps files into one big file using gs command
the command work flawlessly except that when I specify more than 20 input files.
Somehow the command ignore input files starting from 21st input.
Anyone experience the same behavior? Is there a cap of number of input files specify anywhere?
I look through the site and couldn't find one.
sample command
gs -o output.eps -sDEVICE=eps2write file1.eps file2.eps .... file21.eps
Thank you.
Edit: add sample command
Almost certainly you have simply reached the maximum length of the command line for your Operating System. You can use the # syntax for Ghostscript to supply a file containing the command line instead.
https://www.ghostscript.com/doc/current/Use.htm#Input_control
Note that the EPS files will not be placed appropriately using that command, and this does not actually combine EPS files, it creates a new EPS file whose marking content should be the same as the input(s).
If you actually want to combine the EPS files its easy enough, but will require a small amount of programming to parse the EPS file headers and produce appropriate scale/translate operations, as well as stripping off any bitmap previews (which will also happen when you run them through Ghostscript).

How to generate exe file with some settings from my application

Basically, I just wan't to know how can this be achieved.
For example, suppose that I have to exe files, app1.exe and app2.exe. Now, app2.exe does a specific job basing on some settings defined on it's variables. I wan't to know how can I code the app1.exe to generate app2.exe files while defining different settings (variables) for it, without using any config file, registry or similar.
I don't have a specific project with this problem, but I was just wondering how this can be done.
--Inspired by the famous Trojan Horse ProRat. It does the same thing, it generates server.exe file with predefined settings from its server creator (another exe file). Furthermore it can bound with other files such as images, audio, video etc.
After this period of time, I found a solution to this problem by using code injection on file.
Below is my solution on steps:
Since both exe files (app1.exe and app2.exe) are created by same person, you can create the app2.exe with some predefined variable values (like string setting1 = "${MYVAR}"), then compile and save the exe (app2.exe).
Include app2.exe as an embeded resource on app1.exe (the app2.exe generator), and get input (usually from user) that will be used to replace setting1 variables value of app2.exe
Read byte array of app2.exe on app1.exe (since it is embedded on it's resources) and convert it to HEX string
From the string (that is converted from byte array) find value of setting1 variable (by firstly converting it also in byte array then in HEX string), and then replace it with the input you got in step 2 (by also converting in byte array then in HEX string).
Convert the whole string (after replacing the values) back to byte array and save it as a file (app2.exe).
If someone want to see an example, I can put some code as proof of concept.

How to convert PDF to Image without generating a file

Based on the Code How-To-Convert-PDF-to-Image-Using-Ghostscript-API
I trying to figure out how to get a image foreach page without creating the files
To get an image foreach Page i setted OutputToMultipleFile = true.
Then i went step for step through his code but i wasn't able to find the part where the files get created.
So i want to know what i need to change in this code?
or anything else which helps to achieve this
EDIT
here my current parameters:
args[0] =
args[1] =-dNOPAUSE
args[2] =-dBATCH
args[3] =-dSAFER
args[4] =-sDEVICE=pnggray
args[5] =-r130
args[6] =-sOutputFile="C:\Scannen1.PDF%d.png"
args[7] ="C:\Scannen1.PDF"
You need to use a device which doesn't write to file, all the image format devices write their output to file. You could use the display device which will return you a bitmap in memory as a template and write your own device, or you can modify one of the existing devices.
Modifying an existing device is a task for a developer and while not excessively difficult is not trivial either.
In any event, you aren't going to get what you want by fiddling with command line switches. Like Sinatr I'm puzzled by what you can usefully do with Ghostscript which doesn't involve writing to file.
Oh, one other possibility is to load the nulldevice, which is done in PostScript and is simply a bit bucket.

convert multiple .txt to multiple ascii files fast - possible in Matlab?

I have over 120 .txt files (all named like s1.txt, s2.txt, ..., s120.txt) that I need to convert to ASCII extension to use in MATLAB.
my .txt (comma , delimited .txt) files look like the following:
20080102,43.0300,3,9.493,569.567,34174.027,34174027
20080102,43.0600,3,9.498,569.897,34193.801,34193801
In MATLAB I wish to use code similar to the following:
for i = svec;
%# where svec = [1 2 13 15] some random number between 1 and 120.
eval(['load %mydirectory', eval(['s',int2str(i)]),'.ascii']);
end;
If I am not mistaken I can't use the above command with .txt files and therefore I must use ASCII files.
Since I have a lot of files to convert and they are large in size, is there a quick way to convert all my files via MATLAB, or perhaps there is a great converting software available for Mac on the web? Would anyone have a better suggestion than using the code above?
Adding to nrz's answer:
I'm not sure what you want to do exactly, but know that you can open any file in MATLAB, both as text (ASCII) or in binary mode. The latter can be achieved using fread.
As a side note, you also asked for a better suggestion for your code.
Well, what did you try to achieve with the two eval invocations? Why not call the commands directly? Do this instead:
for i = svec
load (['%mydirectory\s', int2str(i), '.txt'], '-ascii');
end
I also took the liberty to add a backslash that I think you had omitted.
In most cases, you'd be better off without using eval. Check the alternatives...
Can you show an example file? Not every text file is valid for load command. If your file is not in a valid format, changing the extension part of filename from .txt to .ascii doesn't help at all. Instead, in that case the data must be either converted to a valid format for load command or, alternatively, loaded into MATLAB by some other means eg. by using fscanf or xlsread. File structure is needed for both ways to solve this.
See also load command in matlab loading blank file.
A slightly cleaner way:
for i=1:120
fname = fullfile('mydirectory', sprintf('s%d.txt',i));
X = load(fname, '-ascii');
end

Resources