Powershell로 암호화 복호화runprogram/powershell을 사용하여 유효한 JSL 목록을 암호화하려고 합니다.성능 때문에 이것이 powershell에 대한 단일 호출이라는 것이 중요합니다.나는 그것이 작동한다고 생각했지만 작은 따옴표 또는 큰 따옴표가 중첩 목록 일 때 나를 엉망으로 만든다는 것을 깨달았습니다.
또한 파일에 쓸 수 없고 powershell에서 읽을 수 없습니다.잘 작동하지만 허용되지 않습니다.JSL과 C 및 Powershell을 탈출하는 데 문제가 있다고 생각합니다.
Names default to here(1);
encryption_key = J(16, 1, randominteger(0, 255));
unencrypted_input = {"Fa'ke\!"", {Empty(), "Str'\!"ing"}}; // this one breaks me
unencrypted_input = {"Fake", {Empty(), "String"}}; // this one is fine
print("encryptng");
init_str = "@("; // creating a powershell array
for(i=1, i<=nitems(unencrypted_input), i++,
if(i!=1, init_str ||= ", ");
item = unencrypted_input[i];
// for encrypt we want to put it in quotes so we can pull it out later so we can parse;
if( isstring(item), item = "\!""||char(item)||"\!"");
// because of the way runprogram works we have to C escape the quotes as well
init_str ||= "\\!""||substitute(char(item), "\!"", "'")||"\\!"";
);
init_str ||= ")";
exec_str = init_str || " | ConvertTo-SecureString -AsPlainText -Force"
|| " | ConvertFrom-SecureString -Key " || Substitute(char(encryption_key), "[", "(", "]", ")");
write("\!n"||exec_str);
rp = Run Program(
Executable("powershell"),
Options(exec_str),
ReadFunction("text")
);
print("");
show(rp);
encrypted_list = words(rp, "\!n\!r");
print("decrypting");
// now to decrypt
init_str = "@("; // creating a powershell array
for(i=1, i<=nitems(encrypted_list), i++,
if(i!=1, init_str ||= ", ");
item = encrypted_list[i];
// because of the way runprogram works we have to C escape the quotes as well
init_str ||= "\\!""||substitute(char(item), "\!"", "'")||"\\!"";
);
init_str ||= ")";
exec_str = init_str || " | ConvertTo-SecureString -Key " || Substitute(char(encryption_key), "[", "(", "]", ")")
|| " | ForEach-Object {"// doing this in a loop in case of multiple lines
|| "$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($_);"
|| "[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)}";
write("\!n"||exec_str);
rp = Run Program(
Executable("powershell"),
Options(exec_str),
ReadFunction("text")
);
print("");
show(rp);
dec_list = Words(rp, "\!n\!r");
for(i=1, i<=nitems(dec_list), i++,
r = substitute(dec_list[i], "'", "\!"");
r = parse(r); // parse it because we wrapped everything
dec_list[i] = r;
);
show(dec_list, unencrypted_input);
show(dec_list == unencrypted_input);
스크립팅Re: Powershell로 암호화 복호화나는 핵심이 powershell 어레이로/에서 가는 것이라고 생각합니다.
어쩌면 이것은 일을 더 쉽게 이해할 수 있도록
Names default to here(1);
//unencrypted_input = {"Fa'ke\!"", {Empty(), "Str'\!"ing"}}; // this one breaks me
unencrypted_input = {"Fake", {Empty(), "String"}}; // this one is fine
to_pwsh_array = function({input, wrap_string = 1},
// wrap string because the inputs for decrypt aren't valid JSL so we don't want to wrap those
{DEFAULT LOCAL},
init_str = "@("; // creating a powershell array
for(i=1, i<=nitems(input), i++,
if(i!=1, init_str ||= ", ");
item = input[i];
// for encrypt we want to put it in quotes so we can pull it out later so we can parse;
if( wrap_string & isstring(item), item = "\!""||char(item)||"\!"");
// because of the way runprogram works we have to C escape the quotes as well
init_str ||= "\\!""||substitute(char(item), "\!"", "'")||"\\!"";
);
init_str ||= ")";
);
from_pwsh_array = function({input},
final_list = Words(input, "\!n\!r");
for(i=1, i<=nitems(final_list), i++,
r = substitute(final_list[i], "'", "\!"");
r = parse(r); // parse it because we wrapped everything
final_list[i] = r;
);
return(final_list);
);
rp = Run Program(
Executable("powershell"),
Options(to_pwsh_array(unencrypted_input)),
ReadFunction("text")
);
out = from_pwsh_array(rp);
show(out == unencrypted_input);Re: Powershell로 암호화 복호화JSL의 따옴표를 따옴표가 포함되지 않은 것으로 대체한 다음 대체를 사용하여 powershell 내에서 다시 대체할 수 있습니까?
Re: Powershell로 암호화 복호화[quote]로 그렇게 하려고 했지만 char(문자열을 포함하는 목록)이 작동하는 방식 때문에 작동하지 못했습니다.나는 따옴표를 다시 줄 powershell을 얻을 수 없으며 따옴표를 제거하므로 다시 가져올 때 (내부에 따옴표가있는 경우) 구문 분석을 망칩니다.깊이가 있는 재귀 함수를 만들 수 있으므로 모든 것을 필요한 것으로 바꾸고 최상위 수준만 감쌀 수 있습니다.의미가 있다면.
Names default to here(1);
ll = {"Fak'e\!"", {Empty(), "Str'\!"ing"}};
char(ll); // "{\!"Fak'e\!\!\!"\!", {Empty(), \!"Str'\!\!\!"ing\!"}}"