【文件读取】离线版用扩展读文件
scratch吧
全部回复
仅看楼主
level 5
ssilspro 楼主
首先把下面放到.txt文件里
这个文件用scratch载入,按住shift点文件菜单,点“导入实验性HTTP扩展”
{ "extensionName": "File",
"extensionPort": 12345,
"blockSpecs": [
["w", "read file %s data", "filedata"],
["w", "get file %s size", "filesize"],
["r", "data", "data"],
],
}
之后下面的放入.vbs文件里,直接执行就可以了,结果是十六进制串,
也有可能需要从网上找个winsck.ocx并注册到系统
Option Explicit
Dim sckServer(1)
Dim fdid, fsid, fileread, proc, fso
Run32()
Set fso = CreateObject("Scripting.FileSystemObject")
Set sckServer(0) = WScript.CreateObject("MSWinsock.Winsock", "Server_")
Set sckServer(1) = WScript.CreateObject("MSWinsock.Winsock", "Server_")
sckServer(1).Close
sckServer(0).Protocol = 0
sckServer(0).LocalPort = 12345
sckServer(0).Bind
sckServer(0).Listen
MsgBox "Scratch Agent Working..." & vbNewLine & "Exit?"
Sub Server_ConnectionRequest(ByVal requestID)
While proc
WScript.sleep 30
Wend
proc = 1
sckServer(1).Close
sckServer(1).Accept (requestID)
End Sub
Sub Server_DataArrival(ByVal bytesTotal)
Dim buf
sckServer(1).GetData buf, vbString
buf = SvrStr(buf)
If Len(buf) Then sckServer(1).SendData (buf)
End Sub
Sub Server_Close()
sckServer(1).Close
proc = 0
End Sub
Sub Server_SendComplete()
sckServer(1).Close
proc = 0
End Sub
Function URLDecode(ByRef strURL)
Dim i, l
If InStr(strURL, "%") = 0 Then URLDecode = strURL: Exit Function
For i = 1 To Len(strURL)
If Mid(strURL, i, 1) = "%" Then
If ("&H" & Mid(strURL, i + 1, 2)) >= 224 Then
l = ((("&H" & Mid(strURL, i + 1, 2)) - 224) * 64 + (("&H" & Mid(strURL, i + 4, 2)) - 128)) * 64 + (("&H" & Mid(strURL, i + 7, 2)) - 128)
URLDecode = URLDecode & ChrW(l)
i = i + 8
ElseIf 0 + ("&H" & Mid(strURL, i + 1, 2)) >= 192 Then
l = (("&H" & Mid(strURL, i + 1, 2)) - 192) * 64 + (("&H" & Mid(strURL, i + 4, 2)) - 128)
URLDecode = URLDecode & Chr(l)
i = i + 5
ElseIf ("&H" & Mid(strURL, i + 1, 2)) < 128 Then
URLDecode = URLDecode & Chr(("&H" & Mid(strURL, i + 1, 2)))
i = i + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, i, 1)
End If
Next
End Function
Public Function SvrStr(Str)
Dim tmp, cmd
Dim i, j
cmd = Split(Str)
tmp = Split(cmd(1), "/")
If tmp(1) = "poll" Then
SvrStr = "data " & fileread & Chr(10)
If fdid Then SvrStr = "_busy " & fdid & Chr(10) & SvrStr
If fsid Then SvrStr = "_busy " & fsid & Chr(10) & SvrStr
Exit Function
End If
If tmp(1) = "reset_all" Then
SvrStr = Chr(10)
fsid = 0
fdid = 0
fileread = ""
Exit Function
End If
If tmp(1) = "filesize" Then
fileread = ""
fsid = tmp(2)
Str = URLDecode((tmp(3)))
If fso.fileExists(Str) Then fileread = fso.getfile(Str).Size
SvrStr = Chr(10)
fsid = 0
Exit Function
End If
If tmp(1) = "filedata" Then
fileread = ""
fdid = tmp(2)
Str = URLDecode((tmp(3)))
sckServer(1).Close
proc = 0
If fso.fileExists(Str) Then fileread = ReadBinary(Str)
SvrStr = ""
fdid = 0
Exit Function
End If
SvrStr = Chr(10)
End Function
Sub Run32()
Dim strComputer, objWMIService, colItems, objItem, strSystemType
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem", , 48)
For Each objItem In colItems
strSystemType = objItem.SystemType
Next
If InStr(strSystemType, "x64") > 0 Then
Dim fso, WshShell, strFullName
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strFullName = WScript.FullName
If InStr(1, strFullName, "system32", 1) > 0 Then
strFullName = Replace(strFullName, "system32", "SysWOW64", 1, 1, 1)
WshShell.Run strFullName & " " & """" & WScript.ScriptFullName & """", 10, False
WScript.Quit
End If
End If
End Sub
Function ReadBinary(FileName)
Const adTypeBinary = 1
Dim stream, xmldom, node
Set xmldom = CreateObject("Microsoft.XMLDOM")
Set node = xmldom.CreateElement("binary")
node.DataType = "bin.hex"
Set stream = CreateObject("ADODB.Stream")
stream.Type = adTypeBinary
stream.Open
stream.LoadFromFile FileName
node.NodeTypedValue = stream.Read
stream.Close
Set stream = Nothing
ReadBinary = node.Text
Set node = Nothing
Set xmldom = Nothing
End Function
2018年12月08日 13点12分 1
level 11
这就很niubi了[滑稽]
2018年12月08日 14点12分 2
一开始还打算exe来着,结果发现需要網盘[滑稽]
2018年12月08日 14点12分
level 12
vb…
做扩展用的是js……
2018年12月09日 02点12分 3
你理解错了
2018年12月09日 02点12分
是通过端口通讯运行的
2018年12月09日 02点12分
这种通过端口的好像只能127.0.0.1,js好像是代理也可以放网上的,不过连硬件还得按点什么吧
2018年12月10日 01点12分
vbs用记事本粘就行,不用开ide挺好[滑稽]
2018年12月10日 01点12分
level 5
ssilspro 楼主
If tmp(1) = "poll" Then
SvrStr = "data " & fileread & Chr(10)
If fdid Then SvrStr = "_busy " & fdid & Chr(10) & SvrStr
If fsid Then SvrStr = "_busy " & fsid & Chr(10) & SvrStr
SvrStr = "HTTP/1.1 200 OK" & vbCrLf & vbCrLf & SvrStr
Exit Function
End If
If tmp(1) = "crossdomain.xml" Then
SvrStr = "<cross-domain-policy><allow-access-from domain=""*"" to-ports=""" & sckServer(0).LocalPort & """/></cross-domain-policy>"
SvrStr = "HTTP/1.1 200 OK" & vbCrLf & "Content-Type: application/xml" & vbCrLf & "Content-Length: " & Len(SvrStr) & vbCrLf & vbCrLf & SvrStr
Exit Function
End If
2018年12月10日 01点12分 6
吞了2次, 这回只发改动
2018年12月10日 01点12分
網耶板的也能用,vbs用记事本粘就可以,改动的粘在SvrStr里,之前的poll替换
2018年12月10日 02点12分
level 12
熟悉的VB,Msg Box 一看我顿时明白了[滑稽][滑稽]
2018年12月10日 10点12分 7
快餐版vb[滑稽]
2018年12月10日 10点12分
1