AutoIT How to encrypt a single file - arrays

So here's my current code:
Local $source = "C:\Users\EXAMPLE\Documents\EXAMPLE"
Local $password = "Example"
Local $array = _FileListToArrayRec($source, "*", 1, , 1, 2); LOADS ALL FILES FROM $source AS AN ARRAY
I don't know how to continue from there because what I want to do is take all of the files in that array and encrypt them all. But that's where another problem arises, how do I encrypt all of the files and save them in the SAME LOCATION?
Example: _Crypt_EncryptFile($sSourceFile, $sDestinationFile, $vCryptKey, $iALG_ID) takes a file and saves the unencrypted version to another location, how do I make it so that it overrides the original file with the encrypted version? I'm VERY stumped here and have Googled multiple subjects and can't find anything that would help me, so I came here hoping I could find my answer. Anyways thanks in advance.

#include <Crypt.au3>
#include <File.au3>
Local $sSource = "C:\Users\EXAMPLE\Documents\EXAMPLE"
Local $sPassword = "Example"
Local $aArray = _FileListToArrayRec($sSource, "*", 1, 1, 1, 2); LOADS ALL FILES FROM $sSource AS AN ARRAY AND AS A FULLPATH
If Not #error Then
For $i = 1 To $aArray[0]
If Not _Crypt_EncryptFile($aArray[$i], $aArray[$i], $sPassword, $CALG_AES_256) Then
ConsoleWrite("Error: " & #error & ", " & $aArray[$i] & #CRLF)
EndIf
Next
EndIf

If you need file encryption for AutoIt consider the solution listed here
https://www.autoitscript.com/forum/topic/178131-autoit-string-files-encryption/
It uses polymorphic (random) encryption on the file and generates the output code in AutoIt with the file contents encrypted:
; encrypted with https://www.stringencrypt.com (v1.0.0) [AutoIt]
#include <Array.au3>
; $Label = "Fast & easy AutoIt string and file encryption."
Global $Label[47] = [ 0xC254, 0xC273, 0xC261, 0xC260, 0xC212, 0xC236, 0xC202, 0xC24B, _
0xC253, 0xC281, 0xC277, 0xC20C, 0xC22B, 0xC277, 0xC27E, 0xC27D, _
0xC21B, 0xC280, 0xC22A, 0xC281, 0xC27E, 0xC25A, 0xC237, 0xC232, _
0xC255, 0xC21C, 0xC24F, 0xC22A, 0xC24E, 0xC214, 0xC248, 0xC247, _
0xC23E, 0xC237, 0x3E0A, 0xC233, 0xC234, 0xC251, 0xC27C, 0xC227, _
0xC282, 0xC280, 0xC247, 0xC27D, 0xC224, 0xC23E, 0x3D92 ];
For $SYdIB = 0 to 46
$fWyHA = $Label[$SYdIB];
$fWyHA += $SYdIB;
$fWyHA = BitNOT($fWyHA);
$fWyHA = BitXOR($fWyHA, $SYdIB);
$fWyHA += $SYdIB;
$fWyHA -= $SYdIB;
$fWyHA = BitXOR($fWyHA, $SYdIB);
$fWyHA = $fWyHA - 1;
$fWyHA = BitXOR($fWyHA, $SYdIB);
$fWyHA = $fWyHA + 1;
$fWyHA += $SYdIB;
$fWyHA = BitXOR($fWyHA, 0xC212);
$fWyHA = BitNOT($fWyHA);
$fWyHA += $SYdIB;
$Label[$SYdIB] = ChrW(BitAND($fWyHA, 0xFFFF));
Next
$Label = _ArrayToString($Label, "")
ConsoleWrite($Label);
It's also pretty hard to overcome by deobfuscators because of the complex and random decryption code.

Related

Download a file reading first a file which contains the url

I have an mp3.txt file which contains URLs to download. How do I read the contents to then download the URLs? I tried this but it's not working:
Func _downloader($link)
Local $dwnarrayread[3] = [IniRead(#ScriptDir & "\mp3.txt", "file_links", "link_1", Default), IniRead(#ScriptDir & "\mp3-2.txt", "file_links", "link_2", Default), IniRead(#ScriptDir & "\mp3-3.txt", "file_links", "link_3", Default)]
$dwnlink = InetGet($dwnarrayread[$link], #ScriptDir & "PSU-04.mp3", 1, 1)
Do
Sleep(50)
$prc = Round(InetGetInfo($dwnlink, 0) / (InetGetInfo($dwnlink, 1)) * 100)
GUICtrlSetData($progressbar1, $prc)
Until InetGetInfo($dwnlink, $INET_DOWNLOADCOMPLETE)
EndFunc
mp3.txt file :
[files_links]
link_1=https://ftp.psu.ac.th/pub/demo/mp3/PSU-04.mp3
link_2=http://somesite.com/files/file2.zip
link_3=http://somesite.com/files/file3.zip
How do I read the contents to then download the URLs?
Example (as per additional requirement):
_Download('mp3.txt', 'files_links', #DesktopDir & '\')
Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
Local Const $aFile = IniReadSection($sFileIni, $sSection)
For $i1 = 1 To $aFile[0][0]
InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)))
Next
EndFunc
Example as per GUICtrlSetData() -attempt:
#include <AutoItConstants.au3>
#include <InetConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
_Download('mp3.txt', 'files_links', #DesktopDir & '\')
Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
Local Const $aFile = IniReadSection($sFileIni, $sSection)
Local $aDownload[$aFile[0][0] + 1]
$aDownload[0] = $aFile[0][0]
For $i1 = 1 To $aFile[0][0]
$aDownload[$i1] = InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)), $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Next
Local Const $iWidth = 400, _
$iHeight = 20
Local $hWnd = GUICreate(#ScriptName, $iWidth, $iHeight * $aDownload[0])
Local $aHnd[$aDownload[0] + 1]
For $i1 = 1 To $aDownload[0]
$aHnd[$i1] = GUICtrlCreateProgress(0, ($i1 - 1) * $iHeight, $iWidth, $iHeight)
GUICtrlSetTip($aHnd[$i1], $aFile[$i1][1])
Next
GUISetState(#SW_SHOW, $hWnd)
Local $aInfo
While Not (GUIGetMsg() = $GUI_EVENT_CLOSE)
For $i1 = 1 To $aDownload[0]
$aInfo = InetGetInfo($aDownload[$i1])
GUICtrlSetData($aHnd[$i1], ($aInfo[$INET_DOWNLOADCOMPLETE] Or $aInfo[$INET_DOWNLOADSUCCESS]) ? 100 : $aInfo[$INET_DOWNLOADSIZE] / $aInfo[$INET_DOWNLOADREAD])
Next
If InetGetInfo() Then ContinueLoop
MsgBox($MB_OK, #ScriptName, 'No more running downloads.', 0, $hWnd)
ExitLoop
WEnd
For $i1 = 1 To $aDownload[0]
InetClose($aDownload[$i1])
Next
EndFunc

How to put some variables in the script into the configuration file, read and parse it from the configuration file?

For example , the connection string required by the ODBC connection is placed in the configuration file for easy maintenance.
connDict = dict(`ip`port`db`uid`pwd`driver, [`192.168.xxx.xxx, `xxxxx, `xxxx, `user, "passwd", `MySQL])
odbcconn = odbc::connect("Driver={" + connDict.driver + "};Server=" + connDict.ip + ";Port=" + connDict.port + ";Database=" + connDict.db + "; Uid=" + connDict.uid + ";Pwd=" + connDict.pwd + ";")
Execute the following script to convert the dictionary into JSON format data conforming to the DolphinDB specification and put it in a JSON file.
connDict = dict(`ip`port`db`uid`pwd`driver, [`192.168.xxx.xxx, `xxxxx, `xxxx, `user, "passwd", `MySQL])
toJson(connDict)
Custom functions, read JSON files and convert them into dictionaries.
def getMysqlConnDictFrom Json(filePath) {
              f = file(filePath)
              arr = f.readLines()
              json = reduce(concat, trim(arr[arr != string(NULL)]))
              return fromJson(json)
}
 
connDict = getMysqlConnDictFromJson("/data/software/dolphin/server/mysqlconn.json")

Google Script import txt files from Google Drive

so I'm trying to write a script to import text files, based on the file names, and the tab names.
The txt files are game server log extracts, 3 different types of logs.
I have managed to get the script to import the text based on the file names (types), but having issues running some simple formatting at the end of a loop before moving to the next type or log.
Basically, the script imports all the text from the log files parses it as a CSV and dumps it to the sheet. The sheet removes duplicates, splits the text into columns etc, they should move on to the next type of log (and switch tab) - repeat.
I'm still picking scripting up so please be gentle....! Any help is greatly appreciated.
function ImportAll() {
var folderID = "my google drive foler"
var folder = DriveApp.getFolderById(folderID);
var ss, sRow, lRow, fRow, csvData, logFile, file, sheet =
SpreadsheetApp.getActive();
var data = [];
var logType = ["admin_", "kill_", "login_"]
var allSheets = ['Admin', 'Kill', 'Login']
for (var k = 0; k < logType.length; k++) {
var files = folder.searchFiles('title contains "' + logType[k] + '"');
while (files.hasNext()) {
file = files.next();
data.push(file.getName())
};
ss = sheet.getSheetByName(allsheets[k])
sRow = ss.getDataRange().getLastRow() + 1;
//Browser.msgBox(data[0])
for (var i = 0; i < data.length; i++) {
logFile = DriveApp.getFilesByName(data[i]).next();
csvData = Utilities.parseCsv(logFile.getBlob().getDataAsString());
fRow = ss.getDataRange().getLastRow() + 1;
ss.getRange(fRow, 1, csvData.length, csvData[0].length).setValues(csvData);
};
lRow = ss.getDataRange().getLastRow();
ss.getRange('A' + sRow + ':A' + lRow).removeDuplicates().activate();
ss.getRange('A' + sRow + ':A' + lRow).splitTextToColumns('-');
ss.getRange('B' + sRow + ':B' + lRow).splitTextToColumns(':');
ss.getRange('B:B').setNumberFormat('HH:mm:ss');
ss.getFilter().remove();
ss.getRange('A1:E' + lRow).createFilter();
var rng = sheet.getRange('D2:D' + lRow)
var rngV = rng.getValues();
var String = "";
for(var i=0;i<rngV.length;i++)
{
String = rngV[i].toString().replace(s, '')
rngV[i] = String // is working
}
rng.setValues(rngV) // NOT WORKING!!!!!!
//sheet.appendRow(data); //throws [L]JavaLang#****
}
};
}
I keep getting thrown "TypeError: Cannot call method "getDataRange" of null." errors, and I've tried a heap of different things to no avail.

How to read msExchMailboxSecurityDescriptor attribute in C#

I am trying to read all the user attributes in AD.
How to read msExchMailboxSecurityDescriptor attribute in C# ?
I used the following code but I got a cast error. Any suggestions would be welcome.
DirectoryObjectSecurity oSec = new ActiveDirectorySecurity();
oSec.SetSecurityDescriptorBinaryForm((byte[])val);
String m_Value = oSec.GetSecurityDescriptorSddlForm(AccessControlSections.All);
return m_Value;
Ok. I was able to figure it out. The code is given below for anyone interested. I wish Microsoft had put out some code samples so that people do not have to break their heads.
SecurityDescriptor sd = (SecurityDescriptor) p_InputValue;
AccessControlList acl = (AccessControlList)sd.DiscretionaryAcl;
String m_Trustee = "";
String m_AccessMask = "";
String m_AceType = "";
String m_ReturnValue="";
foreach (AccessControlEntry ace in (IEnumerable)acl)
{
m_Trustee = m_Trustee + "," + ace.Trustee;
m_AccessMask = m_AccessMask + "," + ace.AccessMask.ToString();
m_AceType = m_AceType + "," +ace.AceType.ToString();
}
m_ReturnValue="Trustee: " + m_Trustee + " " + "AccessMask: " + m_AccessMask + "AceType: " + m_AceType;
return m_ReturnValue

Reading TDM (Diadem) files from script

My customer is sending TDM/TDX files captured in National Instruments Diadem, which I haven't got. I'm looking for a way to convert the files into .CSV, XLS or .MAT files for analysis in Matlab (without using Diadem or Diadem DLLs!)
The format consists of a well structured XML file (.TDM) and a binary (.TDX), with the .TDM defining how fields are packed as bits in the binary TDX. I'd like to read the files (for use in Matlab and other environments). Does anyone have a general purpose tool or conversion script in for instance Python or Perl (not using the NI DLL's) or directly in Matlab?
I've looked into buying the tool, but didn't like it for anything other than one-time conversion to a compatible file format.
Thanks!
I know this is a little late, but I have a simple library to read TDM/TDX files in Python. It works by parsing the TDM file to figure out the data type, then using NumPy.memmap to open the TDX file. It can then be used like a standard NumPy array. The code is pretty simple, so you could probably implement something similar in Matlab.
Here's the link: https://bitbucket.org/joshayers/tdm_loader
Hope that helps.
Maybe a little too late, but I think there is a simple way to get the data from TDM files: NI provides plug-ins for reading TDM files into Excel and OpenOffice Calc. Having the data in one of these programs you could use the CSV export. Search google for "tdm excel" or "tdm openoffice".
Hope this helps...
Gemue
The following script can convert all variables into 'variable' struct.
CurrDirectory = '...//'; % Path to current directory
fileNametdx = '.../utility/'; % Path to TDX file
%%
% Data type conversion
Dtype.eInt8Usi='int8';
Dtype.eInt16Usi='int16';
Dtype.eInt32Usi='int32';
Dtype.eInt64Usi='int64';
Dtype.eUInt8Usi='uint8';
Dtype.eUInt16Usi='uint16';
Dtype.eUInt32Usi='uint32';
Dtype.eUInt64Usi='uint64';
Dtype.eFloat32Usi='single';
Dtype.eFloat64Usi='double';
%% Read .tdx file Name
wb=waitbar(0,'Reading *.tdx Files');
fileNameTDM = strrep(fileNametdx,'.tdx','.TDM');
%% Read .TDM
tdm=xml2struct(fileNameTDM);
for i=1:numel(tdm.usi_colon_tdm.usi_colon_data.tdm_channel)
waitbar((1/numel(tdm.usi_colon_tdm.usi_colon_data.tdm_channel))*i,wb,['File ' fileNametdx ' conversion started']);
s1=strsplit(string(tdm.usi_colon_tdm.usi_colon_data.tdm_channel{1, i}.local_columns.Text),'"');
usi1=s1(2);
% if condition match untill we get usi2
for j=1:numel(tdm.usi_colon_tdm.usi_colon_data.localcolumn)
usi2=string(tdm.usi_colon_tdm.usi_colon_data.localcolumn{1, j}.Attributes.id);
if usi1==usi2
%take new usi
s2=strsplit(string(tdm.usi_colon_tdm.usi_colon_data.localcolumn{1, j}.values.Text),'"');
new_usi1=s2(2);
w1=strsplit(string(tdm.usi_colon_tdm.usi_colon_data.tdm_channel{1, i}.datatype.Text),'_');
str_1=char(strcat('tdm.usi_colon_tdm.usi_colon_data.',lower(w1(2)),'_sequence'));
str_2=char(strcat('tdm.usi_colon_tdm.usi_colon_data.',lower(w1(2)),'_sequence{1, k}.Attributes.id'));
str_3=char(strcat('tdm.usi_colon_tdm.usi_colon_data.',lower(w1(2)),'_sequence{1, k}.values.Attributes.external'));
str_4=char(strcat('tdm.usi_colon_tdm.usi_colon_data.',lower(w1(2)),'_sequence{1, k}.values'));
for k=1:numel(eval(str_1))
new_usi2=string(eval(str_2));
if new_usi1==new_usi2
if isfield(eval(str_4), 'Attributes')
inc_value1=string(eval(str_3));
for m=1:numel(tdm.usi_colon_tdm.usi_colon_include.file.block)
inc_value2=string(tdm.usi_colon_tdm.usi_colon_include.file.block{1, m}.Attributes.id);
if inc_value1==inc_value2
% offset=round(str2num(tdm.usi_colon_tdm.usi_colon_include.file.block{1, m}.Attributes.byteOffset)/8);
length = round(str2num(tdm.usi_colon_tdm.usi_colon_include.file.block{1, m}.Attributes.length));
offset1=round(str2num(tdm.usi_colon_tdm.usi_colon_include.file.block{1, m}.Attributes.byteOffset));
value_type = tdm.usi_colon_tdm.usi_colon_include.file.block{1, m}.Attributes.valueType;
m = memmapfile(fullfile(CurrDirectory,fileNametdx),'Offset',offset1,'Format',{Dtype.(value_type) [length 1] 'dat'},'Writable',true,'Repeat',1);
dat=m.Data.dat ;
end
end
else
str_5=char(strcat('tdm.usi_colon_tdm.usi_colon_data.',lower(w1(2)),'_sequence{1, k}.values.',char(fieldnames(tdm.usi_colon_tdm.usi_colon_data.string_sequence{1, k}.values))));
dat=eval(str_5)';
end
name_variable = string(tdm.usi_colon_tdm.usi_colon_data.tdm_channel{1, i}.name.Text);
varname = genvarname(char(name_variable));
variable.(varname) = dat;
end
end
end
end
end
waitbar(1,wb,[fileNametdx ' conversion completed']);
pause(1)
close(wb)
delete(fullfile(CurrDirectory,fileNametdx),fullfile(CurrDirectory,fileNameTDM));
%Output Variable is Struct
clearvars -except variable
This script requires following XML parser
function [ s ] = xml2struct( file )
%Convert xml file into a MATLAB structure
% [ s ] = xml2struct( file )
%
% A file containing:
% <XMLname attrib1="Some value">
% <Element>Some text</Element>
% <DifferentElement attrib2="2">Some more text</Element>
% <DifferentElement attrib3="2" attrib4="1">Even more text</DifferentElement>
% </XMLname>
%
% Will produce:
% s.XMLname.Attributes.attrib1 = "Some value";
% s.XMLname.Element.Text = "Some text";
% s.XMLname.DifferentElement{1}.Attributes.attrib2 = "2";
% s.XMLname.DifferentElement{1}.Text = "Some more text";
% s.XMLname.DifferentElement{2}.Attributes.attrib3 = "2";
% s.XMLname.DifferentElement{2}.Attributes.attrib4 = "1";
% s.XMLname.DifferentElement{2}.Text = "Even more text";
%
% Please note that the following characters are substituted
% '-' by '_dash_', ':' by '_colon_' and '.' by '_dot_'
%
% Written by W. Falkena, ASTI, TUDelft, 21-08-2010
% Attribute parsing speed increased by 40% by A. Wanner, 14-6-2011
% Added CDATA support by I. Smirnov, 20-3-2012
%
% Modified by X. Mo, University of Wisconsin, 12-5-2012
if (nargin < 1)
clc;
help xml2struct
return
end
if isa(file, 'org.apache.xerces.dom.DeferredDocumentImpl') || isa(file, 'org.apache.xerces.dom.DeferredElementImpl')
% input is a java xml object
xDoc = file;
else
%check for existance
if (exist(file,'file') == 0)
%Perhaps the xml extension was omitted from the file name. Add the
%extension and try again.
if (isempty(strfind(file,'.xml')))
file = [file '.xml'];
end
if (exist(file,'file') == 0)
error(['The file ' file ' could not be found']);
end
end
%read the xml file
xDoc = xmlread(file);
end
%parse xDoc into a MATLAB structure
s = parseChildNodes(xDoc);
end
% ----- Subfunction parseChildNodes -----
function [children,ptext,textflag] = parseChildNodes(theNode)
% Recurse over node children.
children = struct;
ptext = struct; textflag = 'Text';
if hasChildNodes(theNode)
childNodes = getChildNodes(theNode);
numChildNodes = getLength(childNodes);
for count = 1:numChildNodes
theChild = item(childNodes,count-1);
[text,name,attr,childs,textflag] = getNodeData(theChild);
if (~strcmp(name,'#text') && ~strcmp(name,'#comment') && ~strcmp(name,'#cdata_dash_section'))
%XML allows the same elements to be defined multiple times,
%put each in a different cell
if (isfield(children,name))
if (~iscell(children.(name)))
%put existsing element into cell format
children.(name) = {children.(name)};
end
index = length(children.(name))+1;
%add new element
children.(name){index} = childs;
if(~isempty(fieldnames(text)))
children.(name){index} = text;
end
if(~isempty(attr))
children.(name){index}.('Attributes') = attr;
end
else
%add previously unknown (new) element to the structure
children.(name) = childs;
if(~isempty(text) && ~isempty(fieldnames(text)))
children.(name) = text;
end
if(~isempty(attr))
children.(name).('Attributes') = attr;
end
end
else
ptextflag = 'Text';
if (strcmp(name, '#cdata_dash_section'))
ptextflag = 'CDATA';
elseif (strcmp(name, '#comment'))
ptextflag = 'Comment';
end
%this is the text in an element (i.e., the parentNode)
if (~isempty(regexprep(text.(textflag),'[\s]*','')))
if (~isfield(ptext,ptextflag) || isempty(ptext.(ptextflag)))
ptext.(ptextflag) = text.(textflag);
else
%what to do when element data is as follows:
%<element>Text <!--Comment--> More text</element>
%put the text in different cells:
% if (~iscell(ptext)) ptext = {ptext}; end
% ptext{length(ptext)+1} = text;
%just append the text
ptext.(ptextflag) = [ptext.(ptextflag) text.(textflag)];
end
end
end
end
end
end
% ----- Subfunction getNodeData -----
function [text,name,attr,childs,textflag] = getNodeData(theNode)
% Create structure of node info.
%make sure name is allowed as structure name
name = toCharArray(getNodeName(theNode))';
name = strrep(name, '-', '_dash_');
name = strrep(name, ':', '_colon_');
name = strrep(name, '.', '_dot_');
attr = parseAttributes(theNode);
if (isempty(fieldnames(attr)))
attr = [];
end
%parse child nodes
[childs,text,textflag] = parseChildNodes(theNode);
if (isempty(fieldnames(childs)) && isempty(fieldnames(text)))
%get the data of any childless nodes
% faster than if any(strcmp(methods(theNode), 'getData'))
% no need to try-catch (?)
% faster than text = char(getData(theNode));
text.(textflag) = toCharArray(getTextContent(theNode))';
end
end
% ----- Subfunction parseAttributes -----
function attributes = parseAttributes(theNode)
% Create attributes structure.
attributes = struct;
if hasAttributes(theNode)
theAttributes = getAttributes(theNode);
numAttributes = getLength(theAttributes);
for count = 1:numAttributes
%attrib = item(theAttributes,count-1);
%attr_name = regexprep(char(getName(attrib)),'[-:.]','_');
%attributes.(attr_name) = char(getValue(attrib));
%Suggestion of Adrian Wanner
str = toCharArray(toString(item(theAttributes,count-1)))';
k = strfind(str,'=');
attr_name = str(1:(k(1)-1));
attr_name = strrep(attr_name, '-', '_dash_');
attr_name = strrep(attr_name, ':', '_colon_');
attr_name = strrep(attr_name, '.', '_dot_');
attributes.(attr_name) = str((k(1)+2):(end-1));
end
end
end

Resources