|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.0 (the 'License'). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License."
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: #import "load.h"
26: #import <streams/streams.h>
27: #import <mach-o/loader.h>
28: #import <stdio.h>
29: #import <stdlib.h>
30: #import <string.h>
31: #import <objc/objc-load.h>
32:
33: static void load_module(Class cls, Category cat)
34: {
35: if (cat)
36: printf("load_module(): loading Category `%s' for Class `%s'\n",
37: cat->category_name, cat->class_name);
38: else
39: printf("load_module(): loading Class `%s'\n",[cls name]);
40: }
41:
42: static void unload_module(Class cls, Category cat)
43: {
44: if (cat)
45: printf("unload_module(): unloading Category `%s' for Class `%s'\n",
46: cat->category_name, cat->class_name);
47: else
48: printf("unload_module(): unloading Class `%s'\n",[cls name]);
49: }
50:
51: static char **get_module_list()
52: {
53: static char foo[256], tmpfoo[256];
54: char *tmp, **mlist;
55: int nmods = 0, i;
56:
57: fprintf(stdout,"Enter list of object modules to be loaded.\n");
58: fprintf(stdout,"module list = ");
59: fgets(foo, 256, stdin);
60: if (foo[strlen(foo)-1] == '\n')
61: foo[strlen(foo)-1] = '\0';
62:
63: /* make a copy, strtok() is destructive */
64: strcpy(tmpfoo, foo);
65:
66: tmp = strtok(foo, " ");
67: while (tmp) {
68: nmods++;
69: tmp = strtok(0, " ");
70: }
71: mlist = malloc((nmods + 1) * sizeof(char *));
72:
73: tmp = strtok(tmpfoo, " ");
74: i = 0;
75: while (i < nmods) {
76: mlist[i++] = tmp;
77: tmp = strtok(0, " ");
78: }
79: mlist[i] = 0;
80: return mlist;
81: }
82:
83: static void handle_error(NXStream *stream)
84: {
85: /* something went wrong */
86: char *errorstring;
87: int len, max;
88:
89: NXGetMemoryBuffer(stream, &errorstring, &len, &max);
90:
91: /* all error messages contain exactly 1 `\n' at the end */
92: printf("%s", errorstring);
93: }
94:
95: void main (void)
96: {
97: while (1) {
98: NXStream *stream;
99: char **modlist;
100: struct mach_header *mh;
101:
102: modlist = get_module_list();
103: stream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
104:
105: if (strcmp(modlist[0], "unload") == 0) {
106: if (objc_unloadModules(stream, unload_module))
107: handle_error(stream);
108: } else {
109: if (objc_loadModules(modlist, stream, load_module,
110: &mh, "weeb"))
111: handle_error(stream);
112: }
113: NXCloseMemory(stream, NX_FREEBUFFER);
114: }
115: }
116:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.