File: XADXORHandle.m

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (56 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#import "XADXORHandle.h"

@implementation XADXORHandle

-(id)initWithHandle:(CSHandle *)handle password:(NSData *)passdata
{
	if((self=[super initWithName:[handle name]]))
	{
		parent=[handle retain];
		password=[passdata retain];
		passwordbytes=[password bytes];
		passwordlength=[password length];
	}
	return self;
}

-(id)initAsCopyOf:(XADXORHandle *)other
{
	[self _raiseNotSupported:_cmd];
	return nil;
}

-(void)dealloc
{
	[parent release];
	[password release];
	[super dealloc];
}



-(off_t)fileSize { return [parent fileSize]; }

-(off_t)offsetInFile { return [parent offsetInFile]; }

-(BOOL)atEndOfFile { return [parent atEndOfFile]; }

-(void)seekToFileOffset:(off_t)offs { [parent seekToFileOffset:offs]; }

-(void)seekToEndOfFile { [parent seekToEndOfFile]; }

-(int)readAtMost:(int)num toBuffer:(void *)buffer
{
	off_t pos=[parent offsetInFile];
	int actual=[parent readAtMost:num toBuffer:buffer];

	if(passwordlength)
	{
		uint8_t *buf=(uint8_t *)buffer;
		for(int i=0;i<actual;i++) buf[i]^=passwordbytes[(pos+i)%passwordlength];
	}

	return actual;
}

@end