Skip to content
This repository was archived by the owner on Jun 9, 2019. It is now read-only.

Commit ad5b04f

Browse files
committed
Fix bugs in the resource file format.
This fixes bugs in the resource file format which would lead to incorrect parsing. This occured due to a missing 4 bytes on the end of resource headers. Additionally this fixes an issue in the gitignore which was causing the POD files to be ignored.
1 parent 1512f54 commit ad5b04f

14 files changed

+227
-16
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ xcuserdata/
2828
*.dSYM.zip
2929
*.dSYM
3030

31-
Pods/
31+
./Pods/

ResourceKit/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.5.0</string>
18+
<string>0.5.1</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2017 Tom Hancocks
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
25+
#import <Foundation/Foundation.h>
26+
27+
@class RKTypePOD, RKResourcePOD;
28+
29+
@interface RKResourceFileParserPOD : NSObject
30+
31+
@property (nonatomic, assign) uint32_t dataOffset;
32+
@property (nonatomic, assign) uint32_t mapOffset;
33+
@property (nonatomic, assign) uint32_t dataSize;
34+
@property (nonatomic, assign) uint32_t mapSize;
35+
36+
@property (nonatomic, assign) uint32_t handleToNextResouceMapReserved;
37+
@property (nonatomic, assign) uint16_t fileReferenceNumberReserved;
38+
39+
@property (nonatomic, assign) uint16_t mainFlags;
40+
41+
@property (nonatomic, assign) uint16_t typeListOffset;
42+
@property (nonatomic, assign) uint16_t nameListOffset;
43+
44+
@property (nonatomic, assign) uint16_t numberOfTypes;
45+
46+
@property (nonatomic, strong) NSMutableArray <RKTypePOD *> *typePods;
47+
@property (nonatomic, strong) NSMutableArray <RKResourcePOD *> *resourcePods;
48+
49+
@end
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2017 Tom Hancocks
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
25+
#import "RKResourceFileParserPOD.h"
26+
27+
@implementation RKResourceFileParserPOD
28+
29+
@end

ResourceKit/PODs/RKResourcePOD.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2017 Tom Hancocks
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
25+
#import <Foundation/Foundation.h>
26+
27+
@interface RKResourcePOD : NSObject
28+
29+
@property (nonatomic, assign) int16_t id;
30+
@property (nonatomic, assign) uint8_t flags;
31+
@property (nonatomic, assign) int32_t offset;
32+
@property (nonatomic, assign) int16_t nameOffset;
33+
@property (nonatomic, assign) uint32_t size;
34+
@property (nonatomic, assign) uint32_t handleReserved;
35+
36+
@property (nonatomic, strong) NSString *name;
37+
@property (nonatomic, strong) NSString *typeCode;
38+
@property (nonatomic, strong) NSData *data;
39+
40+
@end

ResourceKit/PODs/RKResourcePOD.m

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2017 Tom Hancocks
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
25+
#import "RKResourcePOD.h"
26+
27+
@implementation RKResourcePOD
28+
29+
@end

ResourceKit/PODs/RKTypePOD.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2017 Tom Hancocks
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
25+
#import <Foundation/Foundation.h>
26+
27+
@interface RKTypePOD : NSObject
28+
29+
@property (nonatomic, strong) NSString *code;
30+
@property (nonatomic, assign) NSInteger numberOfResources;
31+
@property (nonatomic, assign) NSInteger resourceOffset;
32+
33+
@end

ResourceKit/PODs/RKTypePOD.m

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2017 Tom Hancocks
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
25+
#import "RKTypePOD.h"
26+
27+
@implementation RKTypePOD
28+
29+
@end

ResourceKit/Parsers/RKResourceFileMapParser.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ + (BOOL)parseData:(id<RKDataParserProtocol>)data againstObject:(RKResourceFilePa
4545
return NO;
4646
}
4747

48-
// Skip the next 6 bytes as they appear to be unused.
49-
data.position += 6;
48+
// The next 2 values are reserved by the system.
49+
pod.handleToNextResouceMapReserved = data.readLong;
50+
pod.fileReferenceNumberReserved = data.readWord;
5051

5152
// We now have a flags field.
5253
pod.mainFlags = data.readWord;

ResourceKit/Parsers/RKResourceFileResourceListParser.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#import <ResourceKit/RKTypePOD.h>
3131
#import <ResourceKit/RKResourcePOD.h>
3232

33-
#define RKResourceHeaderStructureDataLength 8
33+
#define RKResourceHeaderStructureDataLength 12
3434

3535
@implementation RKResourceFileResourceListParser
3636

@@ -48,7 +48,7 @@ + (BOOL)parseData:(id<RKDataParserProtocol>)data againstObject:(RKResourceFilePa
4848

4949
// Step through each of the resources for the type. Each resource header is
5050
// 8 bytes long.
51-
for (NSUInteger idx = 0; idx <= typePod.lastResourceIndex; ++idx) {
51+
for (NSUInteger idx = 0; idx < typePod.numberOfResources; ++idx) {
5252

5353
// Seek to the start of the resource header for the type.
5454
data.position = pod.mapOffset + pod.typeListOffset + typePod.resourceOffset + (idx * RKResourceHeaderStructureDataLength);
@@ -60,6 +60,7 @@ + (BOOL)parseData:(id<RKDataParserProtocol>)data againstObject:(RKResourceFilePa
6060
resourcePod.nameOffset = resourceData.readWord;
6161
resourcePod.flags = resourceData.readByte;
6262
resourcePod.offset = (resourceData.readWord << 8) | resourceData.readByte;
63+
resourcePod.handleReserved = resourceData.readLong;
6364
return resourcePod;
6465
}];
6566

ResourceKit/Parsers/RKResourceFileTypeListParser.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ + (BOOL)parseData:(id<RKDataParserProtocol>)data againstObject:(RKResourceFilePa
4343
// This is done by confirming the values currently in the POD.
4444
data.position = pod.mapOffset + pod.typeListOffset;
4545

46-
// Read in the resource count. This is a final index value.
47-
pod.lastTypeIndex = data.readWord;
46+
// Read in the number of resource types. This value is minus 1 to the real value.
47+
pod.numberOfTypes = data.readWord + 1;
4848

4949
// Step through each resource type structure in the map. Each entry is 8 bytes
5050
// long.
5151
pod.typePods = NSMutableArray.new;
52-
for (NSInteger i = 0; i <= pod.lastTypeIndex; ++i) {
52+
for (NSInteger i = 0; i < pod.numberOfTypes; ++i) {
5353

5454
RKTypePOD *newTypePod = [data readDataOfLength:RKTypeStructureDataLength transform:^id(NSData *typeData) {
5555
RKTypePOD *typePod = RKTypePOD.new;
5656
typePod.code = [typeData readStringOfLength:4];
57-
typePod.lastResourceIndex = typeData.readWord;
57+
typePod.numberOfResources = typeData.readWord + 1;
5858
typePod.resourceOffset = typeData.readWord;
5959
return typePod;
6060
}];

ResourceKitTests/RKResourceFileResourceListParserTests.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ - (void)setUp
5050
pod.mapSize = 0x25;
5151

5252
pod.typeListOffset = 0x00;
53-
pod.nameListOffset = 0x10;
53+
pod.nameListOffset = 0x18;
5454

5555
RKTypePOD *testType = RKTypePOD.new;
5656
testType.code = @"TEST";
5757
testType.resourceOffset = 0;
58-
testType.lastResourceIndex = 1;
58+
testType.numberOfResources = 2;
5959
pod.typePods = @[testType].mutableCopy;
6060
}
6161

ResourceKitTests/RKResourceFileTypeListParser.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ - (void)testParser_correctlyReadsResourceMapMetaData_setsPODValuesAsExpected
6565
XCTAssertTrue([RKResourceFileTypeListParser parseData:fileHandle againstObject:pod]);
6666

6767
XCTAssertEqual(pod.typePods.count, 3);
68-
XCTAssertEqual(pod.lastTypeIndex, 2);
68+
XCTAssertEqual(pod.numberOfTypes, 3);
6969

7070
XCTAssertEqualObjects(pod.typePods[0].code, @"TYPE");
71-
XCTAssertEqual(pod.typePods[0].lastResourceIndex, 1);
71+
XCTAssertEqual(pod.typePods[0].numberOfResources, 2);
7272
XCTAssertEqual(pod.typePods[0].resourceOffset, 0x1000);
7373

7474
XCTAssertEqualObjects(pod.typePods[1].code, @"TEST");
75-
XCTAssertEqual(pod.typePods[1].lastResourceIndex, 2);
75+
XCTAssertEqual(pod.typePods[1].numberOfResources, 3);
7676
XCTAssertEqual(pod.typePods[1].resourceOffset, 0x2000);
7777

7878
XCTAssertEqualObjects(pod.typePods[2].code, @"PICT");
79-
XCTAssertEqual(pod.typePods[2].lastResourceIndex, 3);
79+
XCTAssertEqual(pod.typePods[2].numberOfResources, 4);
8080
XCTAssertEqual(pod.typePods[2].resourceOffset, 0x3000);
8181
}
8282

Binary file not shown.

0 commit comments

Comments
 (0)