import java.io.BufferedInputStream ;
import java.io.BufferedReader ;
import java.io.ByteArrayOutputStream ;
import java.io.IOException ;
import java.io.InputStreamReader ;
import java.io.PrintStream ;
import java.net.HttpURLConnection ;
import java.net.URL ;
import java.security.InvalidKeyException ;
import java.security.Key ;
import java.security.NoSuchAlgorithmException ;
import java.util.zip.GZIPInputStream ;
import javax.crypto.Mac ;
import javax.crypto.spec.SecretKeySpec ;
class API2ch {
private static final String HMKey
= "DgQ3aNpoluV1cl3GFJAqitBg5xKiXZ" ; private static final String AppKey
= "xxfvFQcOzpTBvwuwPMwwzLZxiCSaGb" ;
String HB
= dumpToHex
( getHash
( message
) ) ; URL url
= new URL ( "https://a...content-available-to-author-only...h.net/v1/auth/" ) ; String param
= "ID=&PW=&KY=" + AppKey
+ "&CT=" + CT
+ "&HB=" + HB
;
try {
con.setDoOutput ( true ) ;
con.setRequestMethod ( "POST" ) ;
con.setRequestProperty ( "User-Agent" , "" ) ;
con.setRequestProperty ( "X-2ch-UA" , "JaneStyle/3.80" ) ;
out.print ( param) ;
out.flush ( ) ;
con.getInputStream ( ) ) ) ;
while ( ( line = buff.readLine ( ) ) != null ) {
if ( line.startsWith ( "SESSION-ID" ) ) {
return line.split ( ":" ) [ 1 ] ;
}
}
return null ;
} finally {
try {
out.close ( ) ;
}
try {
buff.close ( ) ;
}
}
}
Key key
= new SecretKeySpec
( HMKey.
getBytes ( ) ,
"HmacSHA256" ) ; Mac mac = Mac.getInstance ( key.getAlgorithm ( ) ) ;
mac.init ( key) ;
return mac.doFinal ( message.getBytes ( ) ) ;
}
private static String dumpToHex
( byte [ ] data
) { for ( byte b : data) {
if ( s.length ( ) == 1 ) {
sb.append ( "0" ) ;
}
sb.append ( s) ;
}
return sb.toString ( ) ;
}
if ( null == sid) {
try {
sid = authenticate( ) ;
}
}
return sid;
}
public byte [ ] getDATData
( String serverName,
String boardName,
String URI
= "/v1/" + serverName
+ "/" + boardName
+ "/" + threadID
; String message
= URI
+ getSid
( ) + AppKey
; String hobo
= dumpToHex
( getHash
( message
) ) ; String param
= "sid=" + getSid
( ) + "&hobo=" + hobo
+ "&appkey=" + AppKey;
URL url
= new URL ( "https://a...content-available-to-author-only...h.net" + URI
) ; try {
con.setDoOutput ( true ) ;
con.setRequestMethod ( "POST" ) ;
con.setRequestProperty ( "User-Agent" ,
"Mozilla/3.0 (compatible; JaneStyle/3.80..)" ) ;
con.setRequestProperty ( "Accept-Encoding" , "gzip" ) ;
con.setRequestProperty ( "Connection" , "close" ) ;
con.setRequestProperty ( "Content-Type" ,
"application/x-www-form-urlencoded" ) ;
con.setRequestProperty ( "Host" , "api.2ch.net" ) ;
if ( startPos > 0 ) {
con.setRequestProperty ( "Range" , "bytes=" + startPos + "-" ) ;
}
out.print ( param) ;
out.flush ( ) ;
if ( startPos > 0 ) {
byte [ ] buff = new byte [ 1024 ] ;
int i;
while ( ( i = bis.read ( buff) ) > 0 ) {
baos.write ( buff, 0 , i) ;
}
return baos.toByteArray ( ) ;
} else {
byte [ ] buff = new byte [ 1024 ] ;
int i;
while ( ( i = gzIn.read ( buff) ) > 0 ) {
baos.write ( buff, 0 , i) ;
}
return baos.toByteArray ( ) ;
}
} finally {
try {
out.close ( ) ;
}
try {
gzIn.close ( ) ;
}
try {
bis.close ( ) ;
}
}
}
API2ch a2ch = new API2ch( ) ;
a2ch.getSid ( ) ;
System .
out .
println ( a2ch.
getSid ( ) ) ;
byte [ ] result = a2ch.getDATData ( "anago" , "software" , "1424315959" , 0 ) ;
}
}
aW1wb3J0IGphdmEuaW8uQnVmZmVyZWRJbnB1dFN0cmVhbTsKaW1wb3J0IGphdmEuaW8uQnVmZmVyZWRSZWFkZXI7CmltcG9ydCBqYXZhLmlvLkJ5dGVBcnJheU91dHB1dFN0cmVhbTsKaW1wb3J0IGphdmEuaW8uSU9FeGNlcHRpb247CmltcG9ydCBqYXZhLmlvLklucHV0U3RyZWFtUmVhZGVyOwppbXBvcnQgamF2YS5pby5QcmludFN0cmVhbTsKaW1wb3J0IGph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