Solved

Change code seg priority

Posted on 1997-12-04
6
179 Views
Last Modified: 2013-12-03
How do I change a system DLL's code segment to writeable from a ring 3 application in Win 95? (example code is prefered)
0
Comment
Question by:jcbhmc
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1409113
Strictly speaking you can never write to a code segment in protected mode.  

I use an indocumented call PrestoChangoSelector() to get a data
segment that corresponds to the same memory space as a code segment.  This works for a 16 bit exe.  Never tried it for a DLL or 32 bit.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1409114
I guess you probably need to know how to use it.

The procedure is declared as

WORD FAR PASCAL PrestoChangoSelector(WORD Source, WORD Destination)

Source is a selector for a code segment.  Destination is a selector for the same segment that has been allocated with AllocSelector().  Destination will be made into a data segment by the presto call.

for example:

WORD CodSeg,DatSeg;

   _asm
   {
   MOV AX,CS
   MOV CodSeg,AX
   }
   DatSeg = AllocSelector(CodSeg);
   PrestoChangoSelector(CodSeg,DatSeg);

There are also some other calls that are related, AllocCStoDSAlias(), AllocDStoCSAlias(), and ChangeSelector().  However, I don't think I've ever used them.
0
 

Author Comment

by:jcbhmc
ID: 1409115
16 bit is not the problem - 32 bit solutions are needed.


0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Expert Comment

by:2good
ID: 1409116
In Win95 it is possible to execute code in ring 0 mode using something called Call Gates. It's really low-level poking and I think it's described in Andrew Schulman's book Unauthorized Windows 95, but I'm not sure.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1409117
I believe in 32 bits this is a page issue, not a segment issue.  in a 32 bit process the code and data segments are 4 gig and overlap.  Some pages (4K chunks) are considered code and other pages are considered data.  The code pages are not writable.
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1409118
Call VirtualProtect() (if the page is in your own process) or VirtualProtectEx() (if the page is in some other process).

If you're writing a debugger or a post mortem tool, that's what you need to do. If you're doing something else, you're guilty of making a greasy, silly hack and should find some other way to solve your problem.

.B ekiM


0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question