• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: escaping a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: escaping a string
      • From: Andrew Farmer <email@hidden>
References: 
 >escaping a string (From: Sandro Noel <email@hidden>)
 >Re: escaping a string (From: "Michael Ash" <email@hidden>)
 >Re: escaping a string (From: Sandro Noel <email@hidden>)
 >Re: escaping a string (From: "Stephen J. Butler" <email@hidden>)

  • Prev by Date: Re: Finding other apps' paths - deterministically!
  • Next by Date: Re: Finding other apps' paths - deterministically!
  • Previous by thread: Re: escaping a string
  • Next by thread: Re: escaping a string
  • Index(es):
    • Date
    • Thread