Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- request = require 'request'
- querystring = require 'querystring'
- {parseString} = require 'xml2js'
- socks_agent = require 'socks5-https-client/lib/Agent'
- url = require 'url'
- RosCrypt = require './roscrypt'
- # gta5
- game =
- name: 'gta5'
- rosCrypt: RosCrypt 'C4pWJwWIKGUxcHd69eGl2AOwH2zrmzZAoQeHfQFcMelybd32QFw9s10px6k0o75XZeB5YsI9Q9TdeuRgdbvKsxc='
- newSecurity: true
- crypto = require 'crypto'
- addSecurity = (game, options, sessionKey, sessionTicket) ->
- # define headers
- options.headers['ros-SecurityFlags'] = '239' # nothing else is allowed in prod
- options.headers['ros-Challenge'] = new Buffer(8).toString 'base64' # to make the HMAC more random?
- options.headers['ros-SessionTicket'] = sessionTicket
- # set HMAC
- nullBuffer = new Buffer(1)
- nullBuffer.writeUInt8 0, 0
- baseKey = game.rosCrypt.getBaseKey false
- key = new Buffer(16)
- for i in [0..15]
- key.writeUInt8 (baseKey.readUInt8(i) ^ sessionKey.readUInt8(i)), i
- hmac = crypto.createHmac 'sha1', key
- # helper to append null buffer
- updateString = (str) ->
- hmac.update str
- hmac.update nullBuffer
- # add the request method
- updateString options.method
- # add the request URI
- parts = url.parse options.url
- updateString parts.path
- # security headers
- updateString options.headers['ros-SecurityFlags']
- updateString options.headers['ros-SessionTicket']
- updateString options.headers['ros-Challenge']
- # platform hash key
- hmac.update game.rosCrypt.getBaseKey true
- # set hmac
- options.headers['ros-HeadersHmac'] = hmac.digest().toString 'base64'
- requestRos = (game, service, kv, secOptions, cb) ->
- ua = game.rosCrypt.encryptUA "e=1,t=#{ game.name },p=pcros,v=11"
- sessionKey = null
- sessionTicket = null
- sessionKey = secOptions.sessionKey if secOptions
- sessionTicket = secOptions.sessionTicket if secOptions
- sessionKey = new Buffer(sessionKey, 'base64') if sessionKey
- options =
- url: "https://prod.ros.rockstargames.com/#{ game.name }/11/gameservices/#{ service }"
- headers:
- 'User-Agent': 'ros ' + ua
- 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
- 'Accept': 'text/html'
- method: 'POST'
- body: game.rosCrypt.encrypt new Buffer(querystring.stringify kv), sessionKey
- encoding: null
- strictSSL: false
- agentClass: socks_agent
- agentOptions:
- socksPort: 9050
- if game.newSecurity and sessionKey
- addSecurity game, options, sessionKey, sessionTicket
- await request options, defer err, response, body
- if err
- cb err
- else
- try
- decrypted = game.rosCrypt.decrypt(body, false, sessionKey).toString 'utf8'
- cb null, decrypted
- catch e
- console.log response.statusCode
- console.log response.headers
- console.log e
- cb e
- # auth ticket handler
- authData = {}
- authUser = process.env.ROS_USER
- authPassword = process.env.ROS_PASSWORD
- doAuth = () ->
- requestRos game, 'auth.asmx/CreateTicketSc3', { ticket: '', email: '', platformName: 'pcros', nickname: authUser, password: authPassword }, null, (err, res) ->
- return if err
- parseString res, (err, res) ->
- res = res.Response
- console.log "Reauthenticated as #{ res.RockstarAccount[0].Nickname }"
- authData.ticket = res.Ticket[0]
- authData.sessionTicket = res.SessionTicket[0]
- authData.sessionKey = res.SessionKey[0]
- setTimeout doAuth, 7200 * 1000
- doAuth()
- savedUris = {}
- allowedPaths = ['DigitalData/DLCPacks2', 'DigitalData/DLCPacks3', 'Game_EFIGS']
- # webapp
- express = require 'express'
- app = express()
- app.get '/file', (req, res) ->
- filename = req.query.name
- # check if the path is allowed
- allowed = false
- for path of allowedPaths
- if filename.indexOf path != -1
- allowed = true
- break
- if not allowed
- res.status(404).end()
- return
- if savedUris[filename] and savedUris[filename].expires > new Date()
- res.redirect(savedUris[filename].uri)
- return
- await requestRos game, 'Entitlements.asmx/GetDownloadUrlFromPath', { ticket: authData.ticket, path: filename }, authData, defer err, resp
- await parseString resp, defer err, resp
- uri = resp.Response.Url[0]
- expireDate = new Date()
- expireDate.setSeconds expireDate.getSeconds() + 240
- savedUris[filename] =
- expires: expireDate
- uri: uri
- res.redirect(uri)
- app.listen(process.env.PORT || 8902)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement