/// 将 Stream 转成 byte[]
public byte[] StreamToBytes(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
/// 将 byte[] 转成 Stream
public Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
//把object序列化成xml字符串
public string Serialize(Type type,Object o)
{
MemoryStream ms = new MemoryStream();
XmlSerializer xmlserializer = new XmlSerializer(type);
xmlserializer.Serialize(ms, o);
StreamReader reader = new StreamReader(ms);
return reader.ReadToEnd();
}
//把xml字符串反序列化成object
public Object Deserialize(Type type, string xmlstr)
{
byte[] xmlArray = System.Text.Encoding.UTF8.GetBytes(xmlstr);
MemoryStream ms = new MemoryStream(xmlArray);
XmlSerializer xmlserializer = new XmlSerializer(type);
return xmlserializer.Deserialize(ms);
}
using System;
using System.Xml;
using Newtonsoft.Json;
public string xml2json(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
}
public string json2xml(string json)
{
XmlDocument doc = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json);
return doc.OuterXml;
}
;示例
str =
(
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
)
xml_root_node := XA_LoadStr(str) ;从字符串加载xml 从文件用XA_Load(Path)
xml_obj := %xml_root_node% ;数组对象变量名是返回的根节点
MsgBox % xml_obj.to "`n" "<?xml version=""1.0"" encoding=""UTF-8""?>`n<" xml_root_node ">`n" . XA_ArrayToXML(xml_obj) . "`n</" xml_root_node ">"
XA_Save(Array, Path) {
FileDelete, % Path
FileAppend, % "<?xml version=""1.0"" encoding=""UTF-8""?>`n<" . Array . ">`n" . XA_ArrayToXML(Array) . "`n</" . Array . ">", % Path, UTF-8
If (ErrorLevel)
Return 1
Return 0
}
XA_LoadStr(XMLText) {
Local XMLObj, XMLRoot, Root1, Root2
XMLObj := XA_LoadXML(XMLText)
XMLObj := XMLObj.selectSingleNode("/*")
XMLRoot := XMLObj.nodeName
%XMLRoot% := XA_XMLToArray(XMLObj.childNodes)
Return XMLRoot
}
XA_Load(Path) {
Local XMLText, XMLObj, XMLRoot, Root1, Root2
If (!FileExist(Path))
Return 1
FileRead, XMLText, % Path
XMLObj := XA_LoadXML(XMLText)
XMLObj := XMLObj.selectSingleNode("/*")
XMLRoot := XMLObj.nodeName
%XMLRoot% := XA_XMLToArray(XMLObj.childNodes)
Return XMLRoot
}
XA_XMLToArray(nodes, NodeName="") {
Obj := Object()
for node in nodes
{
if (node.nodeName != "#text") ;NAME
{
If (node.nodeName == "Invalid_Name" && node.getAttribute("ahk") == "True")
NodeName := node.getAttribute("id")
Else
NodeName := node.nodeName
}
else ;VALUE
Obj := node.nodeValue
if node.hasChildNodes
{
;Same node name was used for multiple nodes
If ((node.nextSibling.nodeName = node.nodeName || node.nodeName = node.previousSibling.nodeName) && node.nodeName != "Invalid_Name" && node.getAttribute("ahk") != "True")
{
;Create object
If (!node.previousSibling.nodeName)
{
Obj[NodeName] := Object()
ItemCount := 0
}
ItemCount++
;Use the supplied ID if available
If (node.getAttribute("id") != "")
Obj[NodeName][node.getAttribute("id")] := XA_XMLToArray(node.childNodes, node.getAttribute("id"))
;Use ItemCount if no ID was provided
Else
Obj[NodeName][ItemCount] := XA_XMLToArray(node.childNodes, ItemCount)
}
Else
Obj.Insert(NodeName, XA_XMLToArray(node.childNodes, NodeName))
}
}
return Obj
}
XA_LoadXML(ByRef data){
o := ComObjCreate("MSXML2.DOMDocument.6.0")
o.async := false
o.LoadXML(data)
return o
}
XA_ArrayToXML(theArray, tabCount=1, NodeName="") {
Local tabSpace, extraTabSpace, tag, val, theXML, root
tabCount++
tabSpace := ""
extraTabSpace := ""
if (!IsObject(theArray)) {
root := theArray
theArray := %theArray%
}
While (A_Index < tabCount) {
tabSpace .= "`t"
extraTabSpace := tabSpace . "`t"
}
for tag, val in theArray {
If (!IsObject(val))
{
If (XA_InvalidTag(tag))
theXML .= "`n" . tabSpace . "<Invalid_Name id=""" . XA_XMLEncode(tag) . """ ahk=""True"">" . XA_XMLEncode(val) . "</Invalid_Name>"
Else
theXML .= "`n" . tabSpace . "<" . tag . ">" . XA_XMLEncode(val) . "</" . tag . ">"
}
Else
{
If (XA_InvalidTag(tag))
theXML .= "`n" . tabSpace . "<Invalid_Name id=""" . XA_XMLEncode(tag) . """ ahk=""True"">" . "`n" . XA_ArrayToXML(val, tabCount, "") . "`n" . tabSpace . "</Invalid_Name>"
Else
theXML .= "`n" . tabSpace . "<" . tag . ">" . "`n" . XA_ArrayToXML(val, tabCount, "") . "`n" . tabSpace . "</" . tag . ">"
}
}
theXML := SubStr(theXML, 2)
Return theXML
}
XA_InvalidTag(Tag) {
Char1 := SubStr(Tag, 1, 1)
Chars3 := SubStr(Tag, 1, 3)
StartChars := "~``!@#$%^&*()_-+={[}]|\:;""'<,>.?/1234567890 `n`r"
Chars := """'<>=/ `n`r"
Loop, Parse, StartChars
{
If (Char1 = A_LoopField)
Return 1
}
Loop, Parse, Chars
{
If (InStr(Tag, A_LoopField))
Return 1
}
If (Chars3 = "xml")
Return 1
Return 0
}
XA_XMLEncode(Text) {
StringReplace, Text, Text, &, &, All
StringReplace, Text, Text, <, <, All
StringReplace, Text, Text, >, >, All
StringReplace, Text, Text, ", ", All
StringReplace, Text, Text, ', ', All
Return Text
}
首先项目按照用C#创建COM组件全过程等方法创建c#的类库项目,本项目需要引用System.Runtime.Serialization。
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.IO;
namespace NBFS
{
[Guid("154BD6A6-5AB8-4d7d-A343-0A68AB79470B")]
public interface NBFS_Interface
{
[DispId(1)]
string DecodeBinaryXML(byte[] encodedXML);
[DispId(2)]
byte[] EncodeBinaryXML(string xml);
}
[Guid("D11FEA37-AC57-4d39-9522-E49C4F9826BB"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface NBFS_Events
{
}
[Guid("2E3C7BAD-1051-4622-9C4C-215182C6BF58"),
ClassInterface(ClassInterfaceType.None),
ProgId("NBFS.BINXML"),
ComSourceInterfaces(typeof(NBFS_Events))]
public class BINXML : NBFS_Interface
{
private WcfBinaryCodec m_wcfBinaryCodec = new WcfBinaryCodec(Encoding.UTF8);
public BINXML() { }
public string DecodeBinaryXML(byte[] encodedXML)
{
if (encodedXML == null)
{
return "";
}
return m_wcfBinaryCodec.DecodeBinaryXML(encodedXML, false);
}
public byte[] EncodeBinaryXML(string xml)
{
if (String.IsNullOrEmpty(xml.Trim()))
{
return null;
}
return m_wcfBinaryCodec.EncodeBinaryXML(xml);
}
}
public class WcfBinaryCodec
{
public WcfBinaryCodec()
{ }
public WcfBinaryCodec(Encoding encoding)
{
m_encoding = encoding;
}
Encoding m_encoding = Encoding.UTF8;
/// <summary>
/// Decode a bytestream that was encoded by WCF's BinaryEncodingBindingElement. Will throw if the bytestream does
/// not decode properly or the result is not valid XML. I/O streams are flushed but not closed.
/// </summary>
/// <param name="explodeNewlines">if true, the returned string will be nicely indented according to
/// element depth, and each attribute will be placed on its own line</param>
/// <returns></returns>
public void DecodeBinaryXML(Stream binaryInput, Stream xmlOutput, bool? explodeNewlines)
{
// defaults
var explode = explodeNewlines ?? false;
// parse bytestream into the XML DOM
var doc = new XmlDocument();
using (var binaryReader = XmlDictionaryReader.CreateBinaryReader(binaryInput, WcfDictionaryBuilder.Dict, XmlDictionaryReaderQuotas.Max))
{
doc.Load(binaryReader);
}
// write document to the output stream with customized settings
var settings = new XmlWriterSettings()
{
CheckCharacters = false,
CloseOutput = false,
ConformanceLevel = ConformanceLevel.Auto,
Encoding = m_encoding,
Indent = explode,
IndentChars = "\t",
NewLineChars = Environment.NewLine,
NewLineHandling = explode ? NewLineHandling.Replace : NewLineHandling.None,
NewLineOnAttributes = explode
};
using (var writer = XmlWriter.Create(xmlOutput, settings))
{
doc.Save(writer);
writer.Flush();
xmlOutput.Flush();
}
}
public string DecodeBinaryXML(byte[] binaryInput, bool? explodeNewLines)
{
var input = new MemoryStream(binaryInput);
var output = new MemoryStream();
DecodeBinaryXML(input, output, explodeNewLines);
output.Seek(0, SeekOrigin.Begin);
return new StreamReader(output, m_encoding).ReadToEnd();
}
/// <summary>
/// Encode a text stream into a binary XML stream compatible with WCF's BinaryEncodingBindingElement. Will throw if
/// the input stream cannot be parsed into an XML document. I/O streams are flushed but not closed.
/// </summary>
/// <param name="xmlInput"></param>
/// <param name="binaryOutput"></param>
public void EncodeBinaryXML(Stream xmlInput, Stream binaryOutput)
{
// parse string into the XML DOM
var doc = new XmlDocument();
doc.Load(xmlInput);
// write bytestream
using (var binaryWriter = XmlDictionaryWriter.CreateBinaryWriter(binaryOutput, WcfDictionaryBuilder.Dict, null, false))
{
doc.Save(binaryWriter);
binaryWriter.Flush();
binaryOutput.Flush();
}
}
public byte[] EncodeBinaryXML(string xmlInput)
{
var input = new MemoryStream(m_encoding.GetBytes(xmlInput));
var output = new MemoryStream();
EncodeBinaryXML(input, output);
return output.ToArray();
}
}
public static class WcfDictionaryBuilder
{
private static XmlDictionary dict;
public static XmlDictionary Dict
{
get { return dict; }
}
static WcfDictionaryBuilder()
{
dict = new XmlDictionary();
dict.Add("mustUnderstand");
dict.Add("Envelope");
dict.Add("http://www.w3.org/2003/05/soap-envelope");
dict.Add("http://www.w3.org/2005/08/addressing");
dict.Add("Header");
dict.Add("Action");
dict.Add("To");
dict.Add("Body");
dict.Add("Algorithm");
dict.Add("RelatesTo");
dict.Add("http://www.w3.org/2005/08/addressing/anonymous");
dict.Add("URI");
dict.Add("Reference");
dict.Add("MessageID");
dict.Add("Id");
dict.Add("Identifier");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm");
dict.Add("Transforms");
dict.Add("Transform");
dict.Add("DigestMethod");
dict.Add("Address");
dict.Add("ReplyTo");
dict.Add("SequenceAcknowledgement");
dict.Add("AcknowledgementRange");
dict.Add("Upper");
dict.Add("Lower");
dict.Add("BufferRemaining");
dict.Add("http://schemas.microsoft.com/ws/2006/05/rm");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm/SequenceAcknowledgement");
dict.Add("SecurityTokenReference");
dict.Add("Sequence");
dict.Add("MessageNumber");
dict.Add("http://www.w3.org/2000/09/xmldsig#");
dict.Add("http://www.w3.org/2000/09/xmldsig#enveloped-signature");
dict.Add("KeyInfo");
dict.Add("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
dict.Add("http://www.w3.org/2001/04/xmlenc#");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/sc");
dict.Add("DerivedKeyToken");
dict.Add("Nonce");
dict.Add("Signature");
dict.Add("SignedInfo");
dict.Add("CanonicalizationMethod");
dict.Add("SignatureMethod");
dict.Add("SignatureValue");
dict.Add("DataReference");
dict.Add("EncryptedData");
dict.Add("EncryptionMethod");
dict.Add("CipherData");
dict.Add("CipherValue");
dict.Add("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
dict.Add("Security");
dict.Add("Timestamp");
dict.Add("Created");
dict.Add("Expires");
dict.Add("Length");
dict.Add("ReferenceList");
dict.Add("ValueType");
dict.Add("Type");
dict.Add("EncryptedHeader");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd");
dict.Add("RequestSecurityTokenResponseCollection");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust#BinarySecret");
dict.Add("http://schemas.microsoft.com/ws/2006/02/transactions");
dict.Add("s");
dict.Add("Fault");
dict.Add("MustUnderstand");
dict.Add("role");
dict.Add("relay");
dict.Add("Code");
dict.Add("Reason");
dict.Add("Text");
dict.Add("Node");
dict.Add("Role");
dict.Add("Detail");
dict.Add("Value");
dict.Add("Subcode");
dict.Add("NotUnderstood");
dict.Add("qname");
dict.Add("");
dict.Add("From");
dict.Add("FaultTo");
dict.Add("EndpointReference");
dict.Add("PortType");
dict.Add("ServiceName");
dict.Add("PortName");
dict.Add("ReferenceProperties");
dict.Add("RelationshipType");
dict.Add("Reply");
dict.Add("a");
dict.Add("http://schemas.xmlsoap.org/ws/2006/02/addressingidentity");
dict.Add("Identity");
dict.Add("Spn");
dict.Add("Upn");
dict.Add("Rsa");
dict.Add("Dns");
dict.Add("X509v3Certificate");
dict.Add("http://www.w3.org/2005/08/addressing/fault");
dict.Add("ReferenceParameters");
dict.Add("IsReferenceParameter");
dict.Add("http://www.w3.org/2005/08/addressing/reply");
dict.Add("http://www.w3.org/2005/08/addressing/none");
dict.Add("Metadata");
dict.Add("http://schemas.xmlsoap.org/ws/2004/08/addressing");
dict.Add("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");
dict.Add("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault");
dict.Add("http://schemas.xmlsoap.org/ws/2004/06/addressingex");
dict.Add("RedirectTo");
dict.Add("Via");
dict.Add("http://www.w3.org/2001/10/xml-exc-c14n#");
dict.Add("PrefixList");
dict.Add("InclusiveNamespaces");
dict.Add("ec");
dict.Add("SecurityContextToken");
dict.Add("Generation");
dict.Add("Label");
dict.Add("Offset");
dict.Add("Properties");
dict.Add("Cookie");
dict.Add("wsc");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/sc");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/sc/dk");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/sc/sct");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/RST/SCT");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/RSTR/SCT");
dict.Add("RenewNeeded");
dict.Add("BadContextToken");
dict.Add("c");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/sc/dk");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/sc/sct");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT/Renew");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT/Renew");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT/Cancel");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT/Cancel");
dict.Add("http://www.w3.org/2001/04/xmlenc#aes128-cbc");
dict.Add("http://www.w3.org/2001/04/xmlenc#kw-aes128");
dict.Add("http://www.w3.org/2001/04/xmlenc#aes192-cbc");
dict.Add("http://www.w3.org/2001/04/xmlenc#kw-aes192");
dict.Add("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
dict.Add("http://www.w3.org/2001/04/xmlenc#kw-aes256");
dict.Add("http://www.w3.org/2001/04/xmlenc#des-cbc");
dict.Add("http://www.w3.org/2000/09/xmldsig#dsa-sha1");
dict.Add("http://www.w3.org/2001/10/xml-exc-c14n#WithComments");
dict.Add("http://www.w3.org/2000/09/xmldsig#hmac-sha1");
dict.Add("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/sc/dk/p_sha1");
dict.Add("http://www.w3.org/2001/04/xmlenc#ripemd160");
dict.Add("http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
dict.Add("http://www.w3.org/2000/09/xmldsig#rsa-sha1");
dict.Add("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
dict.Add("http://www.w3.org/2001/04/xmlenc#rsa-1_5");
dict.Add("http://www.w3.org/2000/09/xmldsig#sha1");
dict.Add("http://www.w3.org/2001/04/xmlenc#sha256");
dict.Add("http://www.w3.org/2001/04/xmlenc#sha512");
dict.Add("http://www.w3.org/2001/04/xmlenc#tripledes-cbc");
dict.Add("http://www.w3.org/2001/04/xmlenc#kw-tripledes");
dict.Add("http://schemas.xmlsoap.org/2005/02/trust/tlsnego#TLS_Wrap");
dict.Add("http://schemas.xmlsoap.org/2005/02/trust/spnego#GSS_Wrap");
dict.Add("http://schemas.microsoft.com/ws/2006/05/security");
dict.Add("dnse");
dict.Add("o");
dict.Add("Password");
dict.Add("PasswordText");
dict.Add("Username");
dict.Add("UsernameToken");
dict.Add("BinarySecurityToken");
dict.Add("EncodingType");
dict.Add("KeyIdentifier");
dict.Add("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
dict.Add("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#HexBinary");
dict.Add("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Text");
dict.Add("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ1510");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID");
dict.Add("Assertion");
dict.Add("urn:oasis:names:tc:SAML:1.0:assertion");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-rel-token-profile-1.0.pdf#license");
dict.Add("FailedAuthentication");
dict.Add("InvalidSecurityToken");
dict.Add("InvalidSecurity");
dict.Add("k");
dict.Add("SignatureConfirmation");
dict.Add("TokenType");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKeySHA1");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID");
dict.Add("AUTH-HASH");
dict.Add("RequestSecurityTokenResponse");
dict.Add("KeySize");
dict.Add("RequestedTokenReference");
dict.Add("AppliesTo");
dict.Add("Authenticator");
dict.Add("CombinedHash");
dict.Add("BinaryExchange");
dict.Add("Lifetime");
dict.Add("RequestedSecurityToken");
dict.Add("Entropy");
dict.Add("RequestedProofToken");
dict.Add("ComputedKey");
dict.Add("RequestSecurityToken");
dict.Add("RequestType");
dict.Add("Context");
dict.Add("BinarySecret");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/spnego");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/tlsnego");
dict.Add("wst");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/trust");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/RST/Issue");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/RSTR/Issue");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/CK/PSHA1");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/SymmetricKey");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/security/trust/Nonce");
dict.Add("KeyType");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/trust/SymmetricKey");
dict.Add("http://schemas.xmlsoap.org/ws/2004/04/trust/PublicKey");
dict.Add("Claims");
dict.Add("InvalidRequest");
dict.Add("RequestFailed");
dict.Add("SignWith");
dict.Add("EncryptWith");
dict.Add("EncryptionAlgorithm");
dict.Add("CanonicalizationAlgorithm");
dict.Add("ComputedKeyAlgorithm");
dict.Add("UseKey");
dict.Add("http://schemas.microsoft.com/net/2004/07/secext/WS-SPNego");
dict.Add("http://schemas.microsoft.com/net/2004/07/secext/TLSNego");
dict.Add("t");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/Issue");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/SymmetricKey");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/CK/PSHA1");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/Nonce");
dict.Add("RenewTarget");
dict.Add("CancelTarget");
dict.Add("RequestedTokenCancelled");
dict.Add("RequestedAttachedReference");
dict.Add("RequestedUnattachedReference");
dict.Add("IssuedTokens");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/Renew");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/Cancel");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/trust/PublicKey");
dict.Add("Access");
dict.Add("AccessDecision");
dict.Add("Advice");
dict.Add("AssertionID");
dict.Add("AssertionIDReference");
dict.Add("Attribute");
dict.Add("AttributeName");
dict.Add("AttributeNamespace");
dict.Add("AttributeStatement");
dict.Add("AttributeValue");
dict.Add("Audience");
dict.Add("AudienceRestrictionCondition");
dict.Add("AuthenticationInstant");
dict.Add("AuthenticationMethod");
dict.Add("AuthenticationStatement");
dict.Add("AuthorityBinding");
dict.Add("AuthorityKind");
dict.Add("AuthorizationDecisionStatement");
dict.Add("Binding");
dict.Add("Condition");
dict.Add("Conditions");
dict.Add("Decision");
dict.Add("DoNotCacheCondition");
dict.Add("Evidence");
dict.Add("IssueInstant");
dict.Add("Issuer");
dict.Add("Location");
dict.Add("MajorVersion");
dict.Add("MinorVersion");
dict.Add("NameIdentifier");
dict.Add("Format");
dict.Add("NameQualifier");
dict.Add("Namespace");
dict.Add("NotBefore");
dict.Add("NotOnOrAfter");
dict.Add("saml");
dict.Add("Statement");
dict.Add("Subject");
dict.Add("SubjectConfirmation");
dict.Add("SubjectConfirmationData");
dict.Add("ConfirmationMethod");
dict.Add("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key");
dict.Add("urn:oasis:names:tc:SAML:1.0:cm:sender-vouches");
dict.Add("SubjectLocality");
dict.Add("DNSAddress");
dict.Add("IPAddress");
dict.Add("SubjectStatement");
dict.Add("urn:oasis:names:tc:SAML:1.0:am:unspecified");
dict.Add("xmlns");
dict.Add("Resource");
dict.Add("UserName");
dict.Add("urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName");
dict.Add("EmailName");
dict.Add("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress");
dict.Add("u");
dict.Add("ChannelInstance");
dict.Add("http://schemas.microsoft.com/ws/2005/02/duplex");
dict.Add("Encoding");
dict.Add("MimeType");
dict.Add("CarriedKeyName");
dict.Add("Recipient");
dict.Add("EncryptedKey");
dict.Add("KeyReference");
dict.Add("e");
dict.Add("http://www.w3.org/2001/04/xmlenc#Element");
dict.Add("http://www.w3.org/2001/04/xmlenc#Content");
dict.Add("KeyName");
dict.Add("MgmtData");
dict.Add("KeyValue");
dict.Add("RSAKeyValue");
dict.Add("Modulus");
dict.Add("Exponent");
dict.Add("X509Data");
dict.Add("X509IssuerSerial");
dict.Add("X509IssuerName");
dict.Add("X509SerialNumber");
dict.Add("X509Certificate");
dict.Add("AckRequested");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm/AckRequested");
dict.Add("AcksTo");
dict.Add("Accept");
dict.Add("CreateSequence");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence");
dict.Add("CreateSequenceRefused");
dict.Add("CreateSequenceResponse");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequenceResponse");
dict.Add("FaultCode");
dict.Add("InvalidAcknowledgement");
dict.Add("LastMessage");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage");
dict.Add("LastMessageNumberExceeded");
dict.Add("MessageNumberRollover");
dict.Add("Nack");
dict.Add("netrm");
dict.Add("Offer");
dict.Add("r");
dict.Add("SequenceFault");
dict.Add("SequenceTerminated");
dict.Add("TerminateSequence");
dict.Add("http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence");
dict.Add("UnknownSequence");
dict.Add("http://schemas.microsoft.com/ws/2006/02/tx/oletx");
dict.Add("oletx");
dict.Add("OleTxTransaction");
dict.Add("PropagationToken");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wscoor");
dict.Add("wscoor");
dict.Add("CreateCoordinationContext");
dict.Add("CreateCoordinationContextResponse");
dict.Add("CoordinationContext");
dict.Add("CurrentContext");
dict.Add("CoordinationType");
dict.Add("RegistrationService");
dict.Add("Register");
dict.Add("RegisterResponse");
dict.Add("ProtocolIdentifier");
dict.Add("CoordinatorProtocolService");
dict.Add("ParticipantProtocolService");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wscoor/CreateCoordinationContext");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wscoor/CreateCoordinationContextResponse");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wscoor/Register");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wscoor/RegisterResponse");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wscoor/fault");
dict.Add("ActivationCoordinatorPortType");
dict.Add("RegistrationCoordinatorPortType");
dict.Add("InvalidState");
dict.Add("InvalidProtocol");
dict.Add("InvalidParameters");
dict.Add("NoActivity");
dict.Add("ContextRefused");
dict.Add("AlreadyRegistered");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat");
dict.Add("wsat");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Completion");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Durable2PC");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Volatile2PC");
dict.Add("Prepare");
dict.Add("Prepared");
dict.Add("ReadOnly");
dict.Add("Commit");
dict.Add("Rollback");
dict.Add("Committed");
dict.Add("Aborted");
dict.Add("Replay");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Commit");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Rollback");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Committed");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Aborted");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Prepare");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Prepared");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/ReadOnly");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/Replay");
dict.Add("http://schemas.xmlsoap.org/ws/2004/10/wsat/fault");
dict.Add("CompletionCoordinatorPortType");
dict.Add("CompletionParticipantPortType");
dict.Add("CoordinatorPortType");
dict.Add("ParticipantPortType");
dict.Add("InconsistentInternalState");
dict.Add("mstx");
dict.Add("Enlistment");
dict.Add("protocol");
dict.Add("LocalTransactionId");
dict.Add("IsolationLevel");
dict.Add("IsolationFlags");
dict.Add("Description");
dict.Add("Loopback");
dict.Add("RegisterInfo");
dict.Add("ContextId");
dict.Add("TokenId");
dict.Add("AccessDenied");
dict.Add("InvalidPolicy");
dict.Add("CoordinatorRegistrationFailed");
dict.Add("TooManyEnlistments");
dict.Add("Disabled");
dict.Add("ActivityId");
dict.Add("http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics");
dict.Add("http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#Kerberosv5APREQSHA1");
dict.Add("http://schemas.xmlsoap.org/ws/2002/12/policy");
dict.Add("FloodMessage");
dict.Add("LinkUtility");
dict.Add("Hops");
dict.Add("http://schemas.microsoft.com/net/2006/05/peer/HopCount");
dict.Add("PeerVia");
dict.Add("http://schemas.microsoft.com/net/2006/05/peer");
dict.Add("PeerFlooder");
dict.Add("PeerTo");
dict.Add("http://schemas.microsoft.com/ws/2005/05/routing");
dict.Add("PacketRoutable");
dict.Add("http://schemas.microsoft.com/ws/2005/05/addressing/none");
dict.Add("http://schemas.microsoft.com/ws/2005/05/envelope/none");
dict.Add("http://www.w3.org/2001/XMLSchema-instance");
dict.Add("http://www.w3.org/2001/XMLSchema");
dict.Add("nil");
dict.Add("type");
dict.Add("char");
dict.Add("boolean");
dict.Add("byte");
dict.Add("unsignedByte");
dict.Add("short");
dict.Add("unsignedShort");
dict.Add("int");
dict.Add("unsignedInt");
dict.Add("long");
dict.Add("unsignedLong");
dict.Add("float");
dict.Add("double");
dict.Add("decimal");
dict.Add("dateTime");
dict.Add("string");
dict.Add("base64Binary");
dict.Add("anyType");
dict.Add("duration");
dict.Add("guid");
dict.Add("anyURI");
dict.Add("QName");
dict.Add("time");
dict.Add("date");
dict.Add("hexBinary");
dict.Add("gYearMonth");
dict.Add("gYear");
dict.Add("gMonthDay");
dict.Add("gDay");
dict.Add("gMonth");
dict.Add("integer");
dict.Add("positiveInteger");
dict.Add("negativeInteger");
dict.Add("nonPositiveInteger");
dict.Add("nonNegativeInteger");
dict.Add("normalizedString");
dict.Add("ConnectionLimitReached");
dict.Add("http://schemas.xmlsoap.org/soap/envelope/");
dict.Add("Actor");
dict.Add("Faultcode");
dict.Add("Faultstring");
dict.Add("Faultactor");
dict.Add("Detail");
}
}
}
然后生成解决方案,找到.net的命令行,用regasm.exe /codebase xxxxx.dll的方式注册com控件,就可以用其他语言调用了。
下面是ahk的使用示例:
;string DecodeBinaryXML(array encodedXML)
;array EncodeBinaryXML(string xml)
binarray := BinArr_FromFile("二进制.txt") ;从文件读取字节流
str := mycom.DecodeBinaryXML(binarray) ;转换成明文
binarray2 := mycom.EncodeBinaryXML(str) ;再编码回二进制
BinArr_ToFile(binarray2, "二进制2.txt")
MsgBox % str
BinArr_FromString(str) {
oADO := ComObjCreate("ADODB.Stream")
oADO.Type := 2 ; adTypeText
oADO.Mode := 3 ; adModeReadWrite
oADO.Open
oADO.Charset := "UTF-8"
oADO.WriteText(str)
oADO.Position := 0
oADO.Type := 1 ; adTypeBinary
oADO.Position := 3 ; Skip UTF-8 BOM
return oADO.Read, oADO.Close
}
BinArr_FromFile(FileName) {
oADO := ComObjCreate("ADODB.Stream")
oADO.Type := 1 ; adTypeBinary
oADO.Open
oADO.LoadFromFile(FileName)
return oADO.Read, oADO.Close
}
BinArr_Join(Arrays*) {
oADO := ComObjCreate("ADODB.Stream")
oADO.Type := 1 ; adTypeBinary
oADO.Mode := 3 ; adModeReadWrite
oADO.Open
For i, arr in Arrays
oADO.Write(arr)
oADO.Position := 0
return oADO.Read, oADO.Close
}
BinArr_ToString(BinArr, Encoding := "UTF-8") {
oADO := ComObjCreate("ADODB.Stream")
oADO.Type := 1 ; adTypeBinary
oADO.Mode := 3 ; adModeReadWrite
oADO.Open
oADO.Write(BinArr)
oADO.Position := 0
oADO.Type := 2 ; adTypeText
oADO.Charset := Encoding
return oADO.ReadText, oADO.Close
}
BinArr_ToFile(BinArr, FileName) {
oADO := ComObjCreate("ADODB.Stream")
oADO.Type := 1 ; adTypeBinary
oADO.Open
oADO.Write(BinArr)
oADO.SaveToFile(FileName, 2)
oADO.Close
}
去年录的GUI部分的直播教程,抛砖引玉。当时念的单词parse,人懒就不后期修改了,见谅。
i := 0
Loop, Reg, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges, K
{
ti := RegExReplace(A_LoopRegName,"Range","")
if (ti>i)
i := ti
}
list =
(
192.168.9.1
192.168.9.2
192.168.9.3
192.168.9.4
192.168.9.5
)
Loop, Parse, list, `n, `r
{
if A_LoopField
{
i++
RegWrite, REG_SZ, HKCU, % "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range" i, :Range, % A_LoopField
RegWrite, REG_DWORD, HKCU, % "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range" i, http, 0x2
}
}
FileGetSize, size, 1.jpg
file := FileOpen("1.jpg","r")
readbytes := file.RawRead(buff,size)
file.close()
file2 := FileOpen("2.jpg","w")
writebytes := file2.RawWrite(&buff,readbytes)
file2.close()
兼容性仅测试通过在32位Autohotkey版本
GZIP_DecompressFile("test.txt", ret)
MsgBox % ret
GZIP_DecompressFile(file, ByRef ret, encoding:="utf-8"){
body := BinArr_FromFile(file)
VarSetCapacity(data, size := body.MaxIndex() + 1)
DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata)
DllCall("RtlMoveMemory", "ptr", &data, "ptr", pdata, "ptr", size)
DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(body))
size := GZIP_DecompressBuffer(data, size)
ret := StrGet(&data, size, encoding)
}
BinArr_FromFile(FileName) {
oADO := ComObjCreate("ADODB.Stream")
oADO.Type := 1 ; adTypeBinary
oADO.Open
oADO.LoadFromFile(FileName)
return oADO.Read, oADO.Close
}
GZIP_DecompressBuffer( ByRef var, nSz ) { ; 'Microsoft GZIP Compression DLL' SKAN 20-Sep-2010
; Decompress routine for 'no-name single file GZIP', available in process memory.
; Forum post : www.autohotkey.com/forum/viewtopic.php?p=384875#384875
; Modified by Lexikos 25-Apr-2015 to accept the data size as a parameter.
; ---------- Added by tmplinshi ----------
static hModule, _
If !hModule {
hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr")
_ := { base: {__Delete: "GZIP_DecompressBuffer"} }
}
If !_
Return DllCall("FreeLibrary", "Ptr", hModule)
; ---------- / Added by tmplinshi ----------
vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 )
DllCall( "GZIP\InitDecompression" )
DllCall( "GZIP\CreateDecompression", UIntP,CTX, UInt,1 )
If ( DllCall( "GZIP\Decompress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz
, UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) )
VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 )
, DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz )
DllCall( "GZIP\DestroyDecompression", UInt,CTX ), DllCall( "GZIP\DeInitDecompression" )
Return Ok ? vsz : 0
}
GZIP_CompressBuffer(ByRef var, nSz ){
static hModule, _
If !hModule {
hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr")
_ := { base: {__Delete: "GZIP_CompressBuffer"} }
}
If !_
Return DllCall("FreeLibrary", "Ptr", hModule)
vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 )
DllCall( "GZIP\InitCompression" )
DllCall( "GZIP\CreateCompression", UIntP,CTX, UInt,1 )
If ( DllCall( "GZIP\Compress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz
, UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) )
VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 )
, DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz )
DllCall( "GZIP\DestroyCompression", UInt,CTX ), DllCall( "GZIP\DeInitCompression" )
Return Ok ? vsz : 0
}
MButton::
xl := ComObjActive("Excel.Application")
col := xl.Selection.Address ;选择的单元格
RegExMatch(col,"\$(\w+)\$(\d*)", m)
xl.Selection.Value := "=SUM($" m1 "$1:$" m1 "$" m2-1 ")"
return
43 queries in 3.049 seconds |