According to a recent survey, in 2005, 500+ million people used handheld devices (PDA, cell phone, etc.) worldwide, while this number was 200+ million in 1999. Hence, this increase can play a vital role for pervasive computing. The goal of pervasive computing is to provide services to anyone anytime, overcoming the constraints of place, time and character. With this tremendous increase of use of handheld and wearable devices, the pervasive computing arena is becoming more strong and powerful day by day. Despite of having various physical constraints, most of the facilities enjoyed by resource-rich devices are tried to be incorporated in these tiny devices. That is why different research fields have been developed to cover this area. There are still some unexplored but crucial attributes like Knowledge Usability, Resource Discovery, and Self-healing that deserve high attention. Besides exploration, implementation as well as evaluation of these features from security and privacy perspectives is also needed. In this paper, we illustrate the design and implementation of a middleware, which incorporates these less explored areas of pervasive computing not only to guarantee the optimum utilization of the physical capabilities but also to ensure the highest degree of security and supreme privacy. The name of the middleware is MARKS since it stands for Middleware Adaptability for Resource Discovery, Knowledge Usability and Self-healing for Pervasive Computing Environments, which are illustrated in this paper.