100 * "java.base", "9.0", "java/lang/String.class", &size); |
100 * "java.base", "9.0", "java/lang/String.class", &size); |
101 */ |
101 */ |
102 extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* image, |
102 extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* image, |
103 const char* module_name, const char* version, const char* name, |
103 const char* module_name, const char* version, const char* name, |
104 jlong* size) { |
104 jlong* size) { |
105 ImageLocation location; |
105 // Concatenate to get full path |
106 char fullpath[IMAGE_MAX_PATH]; |
106 char fullpath[IMAGE_MAX_PATH]; |
107 |
107 size_t moduleNameLen = strlen(module_name); |
108 // Concatenate to get full path |
108 size_t nameLen = strlen(name); |
109 strncpy(fullpath, "/", IMAGE_MAX_PATH - 1); |
109 size_t index; |
110 strncat(fullpath, module_name, IMAGE_MAX_PATH - 1); |
110 |
111 strncat(fullpath, "/", IMAGE_MAX_PATH - 1); |
111 // TBD: assert(moduleNameLen > 0 && "module name must be non-empty"); |
112 strncat(fullpath, name, IMAGE_MAX_PATH - 1); |
112 assert(nameLen > 0 && "name must non-empty"); |
|
113 |
|
114 // If the concatenated string is too long for the buffer, return not found |
|
115 if (1 + moduleNameLen + 1 + nameLen + 1 > IMAGE_MAX_PATH) { |
|
116 return 0L; |
|
117 } |
|
118 |
|
119 index = 0; |
|
120 fullpath[index++] = '/'; |
|
121 memcpy(&fullpath[index], module_name, moduleNameLen); |
|
122 index += moduleNameLen; |
|
123 fullpath[index++] = '/'; |
|
124 memcpy(&fullpath[index], name, nameLen); |
|
125 index += nameLen; |
|
126 fullpath[index++] = '\0'; |
|
127 |
113 JImageLocationRef loc = |
128 JImageLocationRef loc = |
114 (JImageLocationRef) ((ImageFileReader*) image)->find_location_index(fullpath, (u8*) size); |
129 (JImageLocationRef) ((ImageFileReader*) image)->find_location_index(fullpath, (u8*) size); |
115 return loc; |
130 return loc; |
116 } |
131 } |
117 |
132 |