使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)
我创建了一个可以读取命令参数的控制台应用程序(使用Visual Studio 2010)。
当我调试时,我解析了一些在Project-> [project name] Properties ... - > Debug - > Command line arguments中设置的测试参数:
它读取:“parametername1 | parametervalue1”“parametername2 | parametervalue2”“parametername3 | parametervalue3”
我使用下面的代码来读取参数:
for (Int16 argumentsCount = 0; argumentsCount < args.Length; argumentsCount++) { String[] parameterItem = args[argumentsCount].Split('|'); String parameterName = parameterItem[0].ToString(); String parameterValue = parameterItem[1].ToString(); /*code continues*/ }
当我在调试模式下运行该应用程序它工作得很好,并读取所有参数。
然后我发布了应用程序到服务器,并确保它安装了正确的权限(为了演示的目的,可以说它在C:\ MyApp上,并且Complied代码驻留在MyApp.application中
然后我创建了一个执行应用程序的批处理脚本。 * .BAT包含以下命令:
"C:\MyApp\MyApp.application" "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"
当我运行批处理时,这种作为应用程序的方式执行...但是...我的应用程序没有收到任何参数。 我知道这一点,因为我重新编译并发布了一些代码,以读取正在接收的参数数量:
Console.Write("Arguments " + args.Length.ToString());
并显示参数:0
有人可以告诉我如何编写我的批处理脚本来运行应用程序并解析我的参数/命令行参数。
I've created a console app (using Visual Studio 2010) which can read command arguments.
When I debug, I parse some test parameters which are set in Project-> [project name] Properties... -> Debug -> Command line arguments:
It reads: "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"
I used the following code to read the parameters:
for (Int16 argumentsCount = 0; argumentsCount < args.Length; argumentsCount++) { String[] parameterItem = args[argumentsCount].Split('|'); String parameterName = parameterItem[0].ToString(); String parameterValue = parameterItem[1].ToString(); /*code continues*/ }
When I run in debug mode the app it works just fine and all parameters are read.
I then published the app to a server and ensured it was installed with the correct permissions (for the purposes of demonstration lets say it's on C:\MyApp and the Complied code resides in MyApp.application
I then created a batch script that executes the app. The *.BAT contains the following command:
"C:\MyApp\MyApp.application" "parametername1|parametervalue1" "parametername2|parametervalue2" "parametername3|parametervalue3"
This kind of works as the application executes when I run the batch... However... none of my parameters are being received by my app. I know this because I recompiled and published with some code to read how many parameters are being received with:
Console.Write("Arguments " + args.Length.ToString());
and that shows Arguments: 0
Can someone please tell me how to write my batch script to run the app and parse my parameters/command line arguments.
原文:https://stackoverflow.com/questions/6274835
最满意答案
您需要将十六进制字符串正确转换为字节数组:
private static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; } public void decryptDatabase(String k, String iv) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException, IOException { File extStore = Environment.getExternalStorageDirectory(); FileInputStream fis = new FileInputStream(extStore + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr"); FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db"); SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(k), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, sks, new IvParameterSpec(hexStringToByteArray(iv))); CipherInputStream cis = new CipherInputStream(fis, cipher); int b; byte[] d = new byte[8]; while ((b = cis.read(d)) != -1) { fos.write(d, 0, b); } fos.flush(); fos.close(); cis.close(); }
You need to convert the hex strings to byte arrays properly:
private static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; } public void decryptDatabase(String k, String iv) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException, IOException { File extStore = Environment.getExternalStorageDirectory(); FileInputStream fis = new FileInputStream(extStore + "/WhatsApp/Databases/msgstore.db.crypt7.nohdr"); FileOutputStream fos = new FileOutputStream(extStore + "/Decrypted.db"); SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(k), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, sks, new IvParameterSpec(hexStringToByteArray(iv))); CipherInputStream cis = new CipherInputStream(fis, cipher); int b; byte[] d = new byte[8]; while ((b = cis.read(d)) != -1) { fos.write(d, 0, b); } fos.flush(); fos.close(); cis.close(); }
相关问答
更多-
Android阅读WhatsApp数据(Android Read WhatsApp Data)[2022-03-17]
我通过使用以下内容来完成此操作: 根您的设备,并尝试此代码:: public void copyDbToSdcard() { try { String comando = "cp -r /data/data/com.whatsapp/databases/msgstore.db /sdcard/My_Custom_Folder/"; Process suProcess = Runtime.getRuntime().exec("su"); Data ... -
SJCL库解密问题(SJCL library decryption issue)[2022-01-27]
我设法解决了我的问题。 基本上这是两个/三个问题。 在我将它发送到执行数据库插入的php脚本之前,我需要对参数执行jquery“encodeURIComponent”,因为PHP提取函数剥离了加密字符串中的“+”。 第二个问题是必须使用PHP rawurldecode(而不是urldecode)将我的字符串恢复为带有“+”字符的前ajax格式,而不是“”。 第三个问题是使用jquerys“JSON.stringify”将它从javascript'对象'转换为sjcl.decrypt可以使用的字符串。 原来的 ... -
警告:此答案包含您不应使用的代码,因为它不安全(在ECB模式下使用SHA1PRNG进行密钥推导和使用AES) 相反,使用PBKDF2WithHmacSHA1进行密钥推导和AES在CBC或GCM模式(GCM提供隐私和完整性) 你可以使用这些功能: private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES") ...
-
问题几乎肯定在于如何构建查询参数。 您需要使用encodeURIComponent对每个参数值进行编码,因为数据可能包含+等字符,除非正确编码,否则将转换为空格。 使用encodeURIComponent存储URL: var url = "action.php?action=r&n="+encodeURIComponent(name)+"&pw="+encodeURIComponent(pw_hashed)+"&encrypted="+encodeURIComponent(encrypted); 和您的检 ...
-
以下代码可能会对您有所帮助。 使用这个你可以在PHP和Android之间加密/解密字符串。 Java部分: import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; ...
-
这并不完全回答我的问题,但到目前为止,这是我能够获得的最多。 WhatsApp存储SD卡中所有会话的备份。 可以通过执行以下操作来访问它: 在BlueStacks上安装文件管理器,如Astro文件管理器 导航到sdcard/WhatsApp/Databases/ 消息历史记录备份存储在此处。 单击文件msgstore.db.crypt ,从出现的选项中选择Copy。 导航到/sdcard/bstfolder/bstSharedFolder/并粘贴该文件。 现在可以通过导航到C:/ProgramData/Bl ...
-
正如Ashesh所说,你可以在XDA开发者网站上使用该工具: [TOOL] Whatsapp Xtract:备份消息提取器/数据库分析器/ Chat-Backup 或者,您可以手动执行以下操作: WhatsApp数据库在Android设备上以未加密的方式存储在此路径中: /data/data/com.whatsapp/databases/msgstore.db 数据库的备份也通常在以下位置加密存储在SD卡上: /sdcard/WhatsApp/Databases/msgstore.db.crypt7 加 ...
-
您需要将十六进制字符串正确转换为字节数组: private static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) ...
-
最好的方法是使用非对称密钥对(RSA是最常见的),您在FTP站点上签署数据,在Android设备上保留私钥,呃,私钥和公钥。 您可以使用另一个密钥对进行加密/解密。 您可以使用您的签名字符串作为Android设备上的私有解密密钥的密码。 确保您的应用程序不容易受到填充oracle攻击(加密,然后签名或在解密失败时不通知对方)。 请注意,实现您自己的XML签名/验证或XML加密/解密版本可能非常困难(并且充满了至少与使用XML安全相关的库匹配的陷阱)。 我建议尝试将XML包装在CMS容器中。 对于其他用户,链 ...
-
Cipher.doFinal(byte[])返回byte[]而不是String 。 代码当前的方式是存储Object.toString()的返回值,对于byte[]来说,返回值不是很有意义,并且不显示它的内容。 如果要将字节数组存储为String,则需要先对其进行编码。 这样做的推荐方法是Base64,但是十六进制字符串也可以工作,但不会像Base64那样紧凑。 如果您只是想查看byte[]的内容以进行调试,可以使用Arrays.toString(byte[])来查看内容如何更改。 虽然即使是调试,但我认为 ...