注册 登录
编程论坛 ASP技术论坛

向高手求助力:有没有什么办法用asp将torrent文件信息提取出来

职业借钱 发布于 2009-08-20 10:34, 370 次点击
最近做的一个项目需要用asp将torrent文件信息提取出来,不知道各位高手有没有什么办法,有知道的麻烦帮帮忙,谢谢!
下面是我找到的一段相关的代码,可是不能用

程序代码:
<%
class CBencodingInteger

 public lngPosition '在文件中的位置

 public lngLength '其全部结构包括子数据的长度

 public dblValue  '值
end class
class CBencodingString

 public lngPosition '在文件中的位置

 public lngLength '其全部结构包括子数据的长度

 public binValue  '值
end class
Class CBencodingList

 Public lngPosition,lngLength

 Private m_aobj,m_intCount

 

 Private Sub class_initialize()
  ReDim m_aobj(0)
  m_intCount=0

 End Sub


 Public Property Get Count()
  Count=m_intCount

 End Property


 Public Default Function Item(intIndex)
  If intIndex<0 Or intIndex>=m_intCount Then Err.raise vbObjectError,"Item()","index overflow"
  Set Item=m_aobj(intIndex)

 End Function


 Public Function Add(objItem)
  ReDim preserve m_aobj(m_intCount)
  Set m_aobj(m_intCount)=objItem
  m_intCount=m_intCount+1

 End Function
End Class

Class CBencodingDictionary

 Public lngPosition,lngLength

 private m_objDict

 

 Public Sub class_initialize()
  Set m_objDict=CreateObject("scripting.dictionary")

 End Sub


 Public Default Function Item(strIndex)
  If m_objDict.Exists(strIndex) then
   Set Item=m_objDict.item(strIndex)
  else
   Err.raise vbObjectError,"Item()","not such key in dictionary."
  End If

 End Function


 Public Function Add(strKey,objItem)

  m_objDict.add strkey,objItem

 End Function


 Public Property Get Count()
  Count=mobjDict.count

 End Property
End Class

'将byte()字符转化为vbString
Function PickBinChar(binSrc,lngPos)

 PickBinChar=midb(binSrc,lngPos,1)&Chrb(0)
End Function

'读取整数
'[in]binSrc
'[in,out]lngCurpos
'[in]lngMaxPos
'[out]objRet
Function readInteger(binSrc,lngCurPos,objRet)

 Dim i,j

 Dim chrBuf

 Dim strNum,dblNum

 Dim lngBakPos


 lngBakPos=lngCurPos '直接更改解析位置lngCurPos好处是发生err,可以知道错误的字符位置

 Set objRet=Nothing


 If PickBinChar(binSrc,lngCurPos)<>"i" Then Err.raise vbObjectError,"readInteger()","'i' head missing."


 lngCurPos=lngCurPos+1


 i=0

 strNum=""

 chrBuf=PickBinChar(binSrc,lngCurPos)

 Do While chrBuf<="9" And chrBuf>="0"
  strNum=strNum & chrBuf
  lngCurPos=lngCurPos+1
  chrBuf=PickBinChar(binSrc,lngCurPos)
  i=i+1
  If i>MAX_INT_LEN Then Err.raise vbobjectError,"readInteger()","Integer overflow."

 Loop


 If chrBuf<>"e" Then Err.raise vbobjectError,"readInteger()","'e' rare missing."

 If strNum="" Then Err.raise vbObjectError,"readInteger()","empty between 'i' and 'e'."


 Set objRet=new CBencodingInteger

 objRet.lngPosition=lngBakPos

 objRet.lngLength=lngCurPos-lngBakPos

 objRet.dblValue=CDbl(strNum)


 lngCurPos=lngCurPos+1
End Function

'readString,readList,readDictionary我就不贴了,基本类似,就是dictionary和list的位置指针要小心一些


'测试


Function LoadFromFile(strPath,bin)  '也可以改成request.binaryread,不过要先处理一下multiform数据格式

 Dim objAdoStm


 Set objAdoStm=CreateObject("adodb.stream")

 objAdoStm.Type=1

 objAdoStm.Mode=3

 objAdoStm.Open


 objAdoStm.LoadFromFile strPath

 objAdoStm.Position=0

 bin=objAdoStm.Read(-1)


 objAdoStm.close

 Set objAdoStm=Nothing
End Function

Debug:Sub Debug()

 Dim bin

 LoadFromFile "test.torrent",bin


 Dim objTmp

 '解析根节点,以此递归解析全部文件

 readDictionary bin,1,0,objTmp

 '显示第0个节点的IP位置

 

 MsgBox byte2Str(objTmp.item("nodes").item(0).item(0).binValue)
End Sub
%>
0 回复
1