Re: escaping a string
Re: escaping a string
- Subject: Re: escaping a string
- From: Sandro Noel <email@hidden>
- Date: Sun, 21 Sep 2008 14:14:54 -0400
Stephen.
I'm really new at a lot of things at this point in time...(torrents,
cocoa, binary format, )
in this litle adventure of mine, so please excuse if the questions
seem a little beginner's type.
Would this function make more sense?
is this the "right way to do it" ?
so basically what i'm dooing here, is that if i find the caracter "d"
and i'm at least 4 bytes into the file,
i check to see if the 4 caracters before my location contain the word
"info", so then i know that my
current location is the start of the info values.
the info values typically go to the end of the file so I grab
everything (length - location)
then call the hashing function, use the code to convert it to string
and return that data.
typedef struct {
NSUInteger length;
NSUInteger offset;
const char *bytes;
} BEDataStruct;
+(id)sha1HashFromEncodedData:(NSData *)sourceData
{
BEDataStruct data;
data.bytes = [sourceData bytes];
data.length = [sourceData length];
data.offset = 0;
NSData *infoDirectory;
while (data.offset < data.length) {
// we want to check if the 4 caracters before are the string "info"
if ((data.bytes[data.offset] > 4) && (data.bytes[data.offset] ==
'd') &&
(data.bytes[data.offset-4] == 'i') && (data.bytes[data.offset-3] ==
'n') &&
(data.bytes[data.offset-2] == 'f') && (data.bytes[data.offset-1] ==
'o') ){
// we now have the location of the info directory.
NSRange range;
range.location = data.offset;
range.length = (data.length - data.offset);
infoDirectory = [sourceData subdataWithRange:range];
NSData *sha1 = [infoDirectory sha1Hash];
// code taken from sugested function
NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:
([sha1 length] * 2)];
const unsigned char *dataBuffer = [sha1 bytes];
int i;
for (i = 0; i < [sha1 length]; ++i)
[stringBuffer appendFormat:@"X", (unsigned long)dataBuffer[ i ]];
return [[stringBuffer copy] autorelease];
}
data.bytes++;
}
return nil;
}
By the way, I took some code from another bencoding class I found.
and the hash generated by this looks like this.
915C2524D383CB49C67F8EC2A684B3333B207707
used in the url it looks like this, but it does not work.
http://eztv.tracker.thepiratebay.org/scrape?info_hash=915C2524D383CB49C67F8EC2A684B3333B207707
i even tried it like this just in case... :)
http://eztv.tracker.thepiratebay.org/scrape?info_hash=915c2524d383cb49c67f8ec2a684b3333b207707
the tracker replies : <title>Invalid Request</title>
Thank you so much for your help... it's really appreciated.
Sandro.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden