Fixed export of <patch>ed 'data' symbols
authorshort <>
Tue, 4 Feb 2003 10:27:48 +0000 (10:27 +0000)
committershort <>
Tue, 4 Feb 2003 10:27:48 +0000 (10:27 +0000)
 - captive_ModuleList_patch() is called with NULL 'patchpoint' for them

src/libcaptive/ke/captivesym.pl
src/libcaptive/ldr/loader.c

index 14171f5..4fea915 100755 (executable)
@@ -224,10 +224,10 @@ HERE
                                .($functype eq "patches" ? "captive_ModuleList_patch" : "captive_ModuleList_add_builtin")
                                ."(\"$module\",\n";
                for my $symbol (sort keys(%$moduleref)) {
-                       next if $functype eq "patches" && (!$def{$symbol} || "data" eq $def{$symbol}{"type"});
+                       next if $functype eq "patches" && !$def{$symbol};
                        print "\t\t\t\"$symbol\",&${symbol}_",
                                        ($def{$symbol}{"type"} || "undef"),
-                                       (($functype ne "patches") ? () : (",&${symbol}_patchpoint")),
+                                       (($functype ne "patches") ? () : (",".("data" eq $def{$symbol}{"type"} ? "NULL" : "&${symbol}_patchpoint"))),
                                        ",\n";
                        }
                print <<"HERE";
index 928b3d1..6eb88b6 100644 (file)
@@ -513,6 +513,7 @@ CHAR *funcname=MODULEOBJECT_BASE_OFFSET_PLUS(NameList[Idx]);
                ExportAddressp=(PVOID *)(FunctionList+OrdinalList[Idx]);
                ExportAddress=(PVOID)MODULEOBJECT_BASE_OFFSET_PLUS(*ExportAddressp);
                if (0xF4 /* hlt */ ==*(guint8 *)ExportAddress) {
+                       /* FIXME: 'data' type symbols should be permitted to have 0xF4 byte */
                        g_error("%s: Function already patched although we did not touch it yet: %s",G_STRLOC,funcname);
                        g_assert_not_reached();
                        }
@@ -527,8 +528,7 @@ CHAR *funcname=MODULEOBJECT_BASE_OFFSET_PLUS(NameList[Idx]);
        while (captive_va_arg(sym_name,ap)) {
                captive_va_arg(sym_val ,ap);
                g_assert(sym_val!=NULL);
-               captive_va_arg(patchpoint,ap);
-               g_assert(patchpoint!=NULL);
+               captive_va_arg(patchpoint,ap);  /* 'data' type if ==NULL */
                ExportAddressp=g_hash_table_lookup(exportdir_hash,sym_name);
                if (ExportAddressp==NULL) {
                        g_error("%s: Function not found for patchpoint: %s",G_STRLOC,sym_name);
@@ -537,9 +537,12 @@ CHAR *funcname=MODULEOBJECT_BASE_OFFSET_PLUS(NameList[Idx]);
                errbool=g_hash_table_remove(exportdir_hash,sym_name);
                g_assert(errbool==TRUE);
                ExportAddress=(PVOID)MODULEOBJECT_BASE_OFFSET_PLUS(*ExportAddressp);
+               *ExportAddressp=(PVOID)MODULEOBJECT_BASE_OFFSET_MINUS(sym_val);
                if (((ULONG)ExportAddress >= (ULONG)ExportDir) &&
                                ((ULONG)ExportAddress <  (ULONG)ExportDir + ExportDirSize))
                        g_assert_not_reached(); /* LdrPEFixupForward() needed */
+               if (!patchpoint) /* 'data' type */
+                       continue;
                patchpoint->orig_w32_func=ExportAddress;
                g_assert(0xF4 /* hlt */ !=*patchpoint->orig_w32_func);
                patchpoint->orig_w32_2ndinstr=patchpoint->orig_w32_func
@@ -558,7 +561,6 @@ CHAR *funcname=MODULEOBJECT_BASE_OFFSET_PLUS(NameList[Idx]);
                                patchpoint->orig_w32_2ndinstr,  /* key */
                                patchpoint);    /* value */
                *(guint8 *)ExportAddress=0xF4;  /* hlt */
-               *ExportAddressp=(PVOID)MODULEOBJECT_BASE_OFFSET_MINUS(sym_val);
                }
        va_end(ap);