0

We have an Application that we use NSCoding to archive our object data into NSData. We then take the NSData and send it to an XML parser and send it up to a Cloud server for storage.

We have a Customer that wants to be able to alter, or Create their own Objects on the Cloud Server and have our App then read the NSData back again and see the contents of an Object.

The customer is Windows Based, so we'd need a way for them to programmatically be able to Generate the same data structure that is store as the NSData. I can Supply them with the Data Keys I'm decoding and the Type of Data.

Is there a way to reverse engineer the NSData object and inject, modify, etc it from something that is not Objective-C?

UPDATE: 2012.0413 Added code:

Here is the Code the I'm using to get the Data:

NSMutableData *data = [NSMutableData data];
NSKeyedArchiver  *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

    //go and encode ourselves so we can save our state in CD.
[self encodeWithCoder:archiver];

Here is the encodwWithCoder routine:

-(void) encodeWithCoder:(NSCoder *)encoder {

        //See if mama has anything for us...
    [super encodeWithCoder:encoder];
        //encode our state

    [encoder encodeObject:[self elementName] forKey:@"name" ];
    [encoder encodeObject:[self elementViewContents] forKey:@"elementViewContents" ];
    [encoder encodeObject:[self elementGestureRecognizerView] forKey:@"elementGestureRecognizerView" ];
    [encoder encodeCGRect:self.frame forKey:@"frame"];
    [encoder encodeCGRect:self.bounds forKey:@"bounds"];
    [encoder encodeCGPoint:self.center forKey:@"center"];
    [encoder encodeBool:elementLocked forKey:@"elementLocked"];

}

Thanks!

scooter133
  • 1,297
  • 1
  • 15
  • 29
  • Which concrete subclasses of NSCoding are you using? – paulmelnikow Apr 13 '12 at 00:10
  • My Subclass is based on UIControl. `@interface IoUIScreenElement : UIControl ` In my Class I have a `-(void) encodeWithCoder:(NSCoder *)encoder` with a call to `[super encodeWithCoder:encoder];` and then encode some of my stuff. Is that what you are asking? – scooter133 Apr 13 '12 at 00:19
  • No, I'm wondering what class gets passed in as the actual encoder. Maybe `NSKeyedArchiver`? – paulmelnikow Apr 13 '12 at 00:28
  • I've edited the OP to include the code that I'm using to get the data. Thanks! – scooter133 Apr 13 '12 at 15:16

1 Answers1

1

If you set your keyed archiver's output format like so:

NSMutableData *data = [NSMutableData data];
NSKeyedArchiver  *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
[self encodeWithCoder:archiver];

Then the NSData will just be XML text (UTF8-encoded, I think?), which anything should be able to parse and modify.

rickster
  • 124,678
  • 26
  • 272
  • 326