├── bin └── replace.exe ├── samples ├── PCPlayer │ ├── PcPlayer.idl │ ├── PCPlayer.vcxproj.filters │ ├── PcSpeaker.idl │ ├── common │ │ ├── const.cpp │ │ └── const.h │ ├── PCSpeakerDriver.vcxproj.filters │ └── driver │ │ ├── PcSpeakerDriver.cpp │ │ ├── PcSpeakerDriver.h │ │ ├── driverConsts.h │ │ ├── PcSpeakerCode.cpp │ │ └── PcSpeakerDevice.h └── Manager │ ├── InfiniteProgressBar.cpp │ ├── InfiniteProgressBar.h │ ├── KbHit.h │ └── KbHit.cpp ├── LICENSE ├── tests ├── const.cpp ├── const.h ├── testsContainer.h ├── testDriver.h ├── testMemoryManager │ ├── kernel │ │ ├── KTMem.h │ │ ├── DefaultMem.h │ │ └── KTMem.cpp │ └── testMemoryManager │ │ ├── main.cpp │ │ └── TestSmallMemoryHeapManager.cpp ├── testObject.cpp └── XDKtestExecutor │ └── test.cpp ├── Source ├── XDK │ ├── driverEntry.cpp │ ├── hooker │ │ ├── Processors │ │ │ └── ia32 │ │ │ │ ├── idt │ │ │ │ ├── InterrutpListener.cpp │ │ │ │ ├── InterruptException.cpp │ │ │ │ └── IdtHookerManager.cpp │ │ │ │ ├── PageTable │ │ │ │ └── PageTable386.cpp │ │ │ │ ├── Intel386Utils.cpp │ │ │ │ ├── descriptorTable.cpp │ │ │ │ └── tss.cpp │ │ ├── Locks │ │ │ ├── GlobalSystemLock.cpp │ │ │ └── RecursiveProtector.cpp │ │ └── ProcessorsThread.cpp │ ├── utils │ │ ├── exitCounter.cpp │ │ ├── ResourceLock.cpp │ │ └── consoleDeviceControls.cpp │ ├── driverFactory.cpp │ ├── device.cpp │ ├── kernel.cpp │ ├── unicodeString.cpp │ ├── ehlib │ │ ├── NTDDKthrowException.cpp │ │ ├── ehVectorConstructor.cpp │ │ ├── ehVectorDestructor.cpp │ │ └── ehlibcpp.cpp │ ├── memory │ │ └── MemorySuperblockHeapManager.cpp │ ├── assert.cpp │ ├── xdkTrace.cpp │ └── atexit.cpp └── Loader │ ├── Win32Command.cpp │ └── device.cpp ├── xdk_loader.vcxproj.filters ├── Include ├── XDK │ ├── memory │ │ └── MemoryLockableObject.h │ ├── utils │ │ ├── exitCounter.h │ │ ├── consoleDeviceControls.h │ │ ├── ResourceLock.h │ │ └── bugcheck.h │ ├── driverException.h │ ├── hooker │ │ ├── Processors │ │ │ └── ia32 │ │ │ │ ├── Win386Lock.h │ │ │ │ ├── Intel386Utils.h │ │ │ │ ├── descriptorTable.h │ │ │ │ ├── idt │ │ │ │ └── IdtHookerManager.h │ │ │ │ ├── registers.h │ │ │ │ ├── eflags.h │ │ │ │ ├── tss32.h │ │ │ │ └── PageTable │ │ │ │ └── Win32PageTable386.h │ │ ├── StackObject.h │ │ └── Locks │ │ │ └── GlobalSystemLock.h │ ├── unicodeString.h │ ├── xdkTraceSingleton.h │ ├── xdkTrace.h │ └── driverFactory.h └── Loader │ ├── deviceException.h │ └── command.h └── README.md /bin/replace.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eladraz/XDK/HEAD/bin/replace.exe -------------------------------------------------------------------------------- /samples/PCPlayer/PcPlayer.idl: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface PcPlayer 3 | * 4 | * Control functions which handles wave-out (PCM) stream. 5 | * The streams is uses mainly for transfer to the Sound-Blaster 6 | * 7 | * Author: Elad Raz 8 | */ 9 | [ 10 | // The IOCTL_PLAYER_xxx prefix 11 | prefix("PLAYER"), 12 | helpstring("Control functions which handles wave-out (PCM) stream") 13 | ] 14 | interface PcPlayer 15 | { 16 | // Get version 17 | comment("Return the version of the interface"); 18 | uint32 getVersion(); 19 | 20 | // Starts playing the queued buffer 21 | comment("Starts playing the queued buffer"); 22 | void play(); 23 | 24 | // Stop playing the buffer. The stream is paused. 25 | comment("Stop playing the buffer. The stream is paused."); 26 | void stop(); 27 | 28 | // Empty the queued buffer and reset all pointers. Stop playing if active 29 | comment("Empty the queued buffer and reset all pointers. Stop playing if active."); 30 | void reset(); 31 | }; 32 | -------------------------------------------------------------------------------- /samples/PCPlayer/PCPlayer.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {29d82e5e-0054-42b1-8ab7-c6d9e5c9f5b5} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm 7 | 8 | 9 | {8ef4f487-3a59-41d7-b1c5-03c46d140154} 10 | h;hpp;hxx;hm;inl;inc 11 | 12 | 13 | {ab0f793a-2362-4a0c-9735-ade5eed71ee1} 14 | 15 | 16 | 17 | 18 | Source Files 19 | 20 | 21 | Source Files 22 | 23 | 24 | Common 25 | 26 | 27 | 28 | 29 | Header Files 30 | 31 | 32 | Common 33 | 34 | 35 | Common 36 | 37 | 38 | -------------------------------------------------------------------------------- /samples/PCPlayer/PcSpeaker.idl: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface PcSpeaker 3 | * 4 | * Declare the PcSpeaker class. This class provieds the abstraction of the 5 | * PcSpeaker sreatrm device functions. The class contains the basic 6 | * functionality of the pc-speaker device. 7 | * 8 | * Author: Elad Raz 9 | */ 10 | [ 11 | // The IOCTL_PLAYER_xxx prefix 12 | prefix("PLAYER"), 13 | base(0x900), 14 | helpstring("Basic speaker device class. Handles the features of the PC-Speaker") 15 | ] 16 | interface PcSpeaker 17 | { 18 | comment("Activate the sound signal."); 19 | void soundOn(); 20 | 21 | comment("Stop the sound signal."); 22 | void soundOff(); 23 | 24 | comment("Change the frequency of the timer chip 8254 The timer connected"); 25 | comment("to the speaker and transfer a sinus wave to the speaker."); 26 | comment("The frequency is from 10Hz to 119250Hz."); 27 | comment(""); 28 | comment("frequency - The number of times when 1 puls will be heard."); 29 | void setFrequency([in] uint32 frequency); 30 | 31 | comment("This method change the 8254 channel 2 counter to generate a"); 32 | comment("single impulse for a short prioed of time."); 33 | comment(""); 34 | comment("counter - Number of counts to pass over them. The frequency"); 35 | comment(" of the chip is 119250Hz. This number is the length"); 36 | comment(" of the out signal. The counter is limited to the"); 37 | comment(" low 16bit."); 38 | void makeImpulse([in] uint32 counter); 39 | }; 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | Neither the name of the Integrity Project nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE 29 | -------------------------------------------------------------------------------- /tests/const.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * const.cpp 34 | * 35 | * Author: Elad Raz 36 | */ 37 | #include "const.h" 38 | 39 | const character XDKConsts::CON_DEVICENAME[] = XSTL_STRING("XDKTEST"); 40 | -------------------------------------------------------------------------------- /Source/XDK/driverEntry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #include "xStl/types.h" 33 | #include "xdk/kernel.h" 34 | #include "xdk/libCPP.h" 35 | 36 | NTSTATUS DriverEntry(PDRIVER_OBJECT driverObject, 37 | PUNICODE_STRING registryPath) 38 | { 39 | return cXDKLibCPP::driverEntry(driverObject, registryPath); 40 | } 41 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/idt/InterrutpListener.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * InterrutpListener.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/except/trace.h" 41 | #include "xStl/except/exception.h" 42 | #include "xdk/hooker/Processors/ia32/idt/InterruptListener.h" 43 | 44 | InterruptListener::~InterruptListener() 45 | { 46 | } 47 | -------------------------------------------------------------------------------- /Source/XDK/utils/exitCounter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * exitCounter.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xdk/utils/exitCounter.h" 41 | 42 | cExitCounterAppender::cExitCounterAppender(cCounter& counter) : 43 | m_counter(counter) 44 | { 45 | ++m_counter; 46 | } 47 | 48 | cExitCounterAppender::~cExitCounterAppender() 49 | { 50 | --m_counter; 51 | } 52 | -------------------------------------------------------------------------------- /samples/PCPlayer/common/const.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * const.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/char.h" 41 | #include "common/const.h" 42 | 43 | const character Const::PCSPEAKER_DEVICE_NAME[] = 44 | XSTL_STRING("TBA_PCSPEKAER_V1"); 45 | 46 | const character Const::PCSPEAKER_DEVICE_FILENAME[] = 47 | XSTL_STRING("C:\\Temp\\PcSpeakerDriver.sys"); 48 | -------------------------------------------------------------------------------- /tests/const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_TESTS_CONST_H 33 | #define __TBA_XDK_TESTS_CONST_H 34 | 35 | /* 36 | * const.h 37 | * 38 | * Definitions for the both driver and ring3 console application 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/char.h" 44 | 45 | class XDKConsts 46 | { 47 | public: 48 | /* 49 | * The console device-driver name 50 | */ 51 | static const character CON_DEVICENAME[]; 52 | }; 53 | 54 | #endif // __TBA_XDK_TESTS_CONST_H -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/PageTable/PageTable386.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * PageTable386.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xdk/hooker/Processors/ia32/PageTable/PageTable386.h" 41 | 42 | GlobalPageValue getPageValue(GlobalPage page) 43 | { 44 | return *((GlobalPageValue*)(&page)); 45 | } 46 | 47 | GlobalPage getPageFromValue(GlobalPageValue pageContent) 48 | { 49 | return *((GlobalPage*)(&pageContent)); 50 | } 51 | -------------------------------------------------------------------------------- /xdk_loader.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Sources 6 | 7 | 8 | Sources 9 | 10 | 11 | Sources 12 | 13 | 14 | Sources 15 | 16 | 17 | Sources\console 18 | 19 | 20 | 21 | 22 | Includes 23 | 24 | 25 | Includes 26 | 27 | 28 | Includes 29 | 30 | 31 | Includes 32 | 33 | 34 | Includes 35 | 36 | 37 | Includes\console 38 | 39 | 40 | 41 | 42 | {47df7909-fdbb-425f-8306-2a61b7559f18} 43 | 44 | 45 | {89723c32-85f7-4885-80f8-8b385d1881c3} 46 | 47 | 48 | {f9d5784e-068e-40b6-a09f-b88cf762980e} 49 | 50 | 51 | {e7d8a3bf-5742-4e30-9c3c-de7264d42347} 52 | 53 | 54 | -------------------------------------------------------------------------------- /Source/XDK/driverFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * driverFactory.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "XDK/driverFactory.h" 41 | 42 | cPrivateDriverFactory* cPrivateDriverFactory::m_driverFactory = NULL; 43 | 44 | cPrivateDriverFactory& cPrivateDriverFactory::getInstance() 45 | { 46 | ASSERT(m_driverFactory != NULL); 47 | // Test whether the cDriver object was instanced 48 | if (m_driverFactory == NULL) 49 | { 50 | XSTL_THROW(cException, EXCEPTION_FAILED); 51 | } 52 | return *m_driverFactory; 53 | } 54 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Locks/GlobalSystemLock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * GlobalSystemLock.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xdk/hooker/Locks/GlobalSystemLock.h" 41 | 42 | void GlobalSystemLock::lock() 43 | { 44 | // Only Ring0 can invoke a CPU Clear-Interrupt command 45 | #ifdef _KERNEL 46 | m_lock.lock(); 47 | #endif 48 | } 49 | 50 | void GlobalSystemLock::unlock() 51 | { 52 | // Only Ring0 can invoke a CPU Clear-Interrupt command 53 | #ifdef _KERNEL 54 | m_lock.unlock(); 55 | #endif 56 | } 57 | -------------------------------------------------------------------------------- /Source/XDK/utils/ResourceLock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * ResourceLock.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/except/trace.h" 41 | #include "xStl/os/lockable.h" 42 | #include "xdk/kernel.h" 43 | #include "xdk/utils/ResourceLock.h" 44 | 45 | cResourceLock::cResourceLock(PERESOURCE resource) : 46 | m_resource(resource) 47 | { 48 | } 49 | 50 | void cResourceLock::lock() 51 | { 52 | CHECK(ExAcquireResourceExclusiveLite(m_resource, TRUE)); 53 | } 54 | 55 | void cResourceLock::unlock() 56 | { 57 | ExReleaseResourceLite(m_resource); 58 | } -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/Intel386Utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * Intel386Utils.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/endian.h" 41 | #include "xdk/hooker/Processors/ia32/Intel386Utils.h" 42 | 43 | void Intel386Utils::generateAbsoluteJmpOpcode(uint8* memory, 44 | uint32 location) 45 | { 46 | uint32 relative = location - (getNumeric(memory) + ABSOLUTE_JMP_LENGTH); 47 | memory[0] = 0xE9; // relative jmp 48 | cLittleEndian::writeUint32(memory + 1, 49 | relative); 50 | } 51 | -------------------------------------------------------------------------------- /tests/testsContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_TESTS_TESTSCONTAINER_H 33 | #define __TBA_XDK_TESTS_TESTSCONTAINER_H 34 | 35 | /* 36 | * testsContainer.h 37 | * 38 | * Author: Elad Raz 39 | */ 40 | #include "xStl/types.h" 41 | #include "xStl/data/list.h" 42 | #include "../tests/tests.h" 43 | 44 | /* 45 | * All the constructed class are register inside a link-list 46 | * which execute them. 47 | */ 48 | class TestsContainer{ 49 | public: 50 | static cList& getTests() 51 | { 52 | static cList globalTests; 53 | return globalTests; 54 | } 55 | }; 56 | 57 | 58 | #endif // __TBA_XDK_TESTS_TESTSCONTAINER_H 59 | -------------------------------------------------------------------------------- /samples/PCPlayer/common/const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_PCPLAYER_COMMON_CONST_H 33 | #define __TBA_PCPLAYER_COMMON_CONST_H 34 | 35 | /* 36 | * const.h 37 | * 38 | * The common consts values. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/char.h" 44 | 45 | /* 46 | * Contains the name of the driver 47 | */ 48 | class Const { 49 | public: 50 | // The name for the PcSpeaker device. See PcSpekaer.idl for info. 51 | static const character PCSPEAKER_DEVICE_NAME[]; 52 | // The name for the PcSpeaker device filename. 53 | static const character PCSPEAKER_DEVICE_FILENAME[]; 54 | }; 55 | 56 | #endif // __TBA_PCPLAYER_COMMON_CONST_H 57 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/idt/InterruptException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * InterruptException.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/string.h" 41 | #include "xStl/data/datastream.h" 42 | #include "xStl/stream/traceStream.h" 43 | #include "xdk/hooker/Processors/ia32/idt/InterruptException.h" 44 | 45 | InterruptException::InterruptException(uint8 vector, uint data) : 46 | m_vector(vector), 47 | m_data(data) 48 | { 49 | } 50 | 51 | uint8 InterruptException::getVector() const 52 | { 53 | return m_vector; 54 | } 55 | 56 | uint InterruptException::getData() const 57 | { 58 | return m_data; 59 | } 60 | -------------------------------------------------------------------------------- /Source/XDK/device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * device.cpp 34 | * 35 | * Author: Elad Raz 36 | */ 37 | #include "xStl/types.h" 38 | #include "xStl/data/hash.h" 39 | #include "XDK/kernel.h" 40 | #include "XDK/device.h" 41 | 42 | const character cDevice::m_ntDeviceName[] = XSTL_STRING("\\Device\\"); 43 | 44 | const character cDevice::m_symbolicDeviceName[] = XSTL_STRING("\\??\\"); 45 | 46 | cDevice::cDevice() : 47 | m_isValid(false) 48 | { 49 | } 50 | 51 | cDevice::~cDevice() 52 | { 53 | } 54 | 55 | bool cDevice::isValid() const 56 | { 57 | return m_isValid; 58 | } 59 | 60 | uint cHashFunction(const PDEVICE_OBJECT& index, uint range) 61 | { 62 | uint memLocation = (uint)index; 63 | return cHashFunction(memLocation, range); 64 | } 65 | -------------------------------------------------------------------------------- /samples/PCPlayer/PCSpeakerDriver.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {e1c2b9ee-d4bb-40c5-af7d-2d4b456d2b9c} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm 7 | 8 | 9 | {4ae505d7-54de-49e7-b498-f4bfc7890f56} 10 | h;hpp;hxx;hm;inl;inc 11 | 12 | 13 | {35afd8d2-e786-433d-99b9-c79dab035fb5} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe 15 | 16 | 17 | {bb3f9ecf-d7d7-4a09-bbd5-3986d76bd4ad} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Common 38 | 39 | 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Common 55 | 56 | 57 | Common 58 | 59 | 60 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/descriptorTable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * descriptorTable.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xdk/hooker/Processors/ia32/descriptorTable.h" 41 | 42 | DescriptorTableRegister::DescriptorTableRegister() : 43 | m_limit(0), 44 | m_base(0) 45 | { 46 | } 47 | 48 | DescriptorTableRegister::~DescriptorTableRegister() 49 | { 50 | } 51 | 52 | uint16 DescriptorTableRegister::getLimit() const 53 | { 54 | return m_limit; 55 | } 56 | 57 | uint16 DescriptorTableRegister::getEntries() const 58 | { 59 | return m_limit / sizeof(DescriptorValue); 60 | } 61 | 62 | DescriptorValue* DescriptorTableRegister::getBase() const 63 | { 64 | return m_base; 65 | } 66 | -------------------------------------------------------------------------------- /samples/Manager/InfiniteProgressBar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #include "xStl/types.h" 33 | #include "xStl/data/char.h" 34 | #include "xStl/stream/iostream.h" 35 | #include "InfiniteProgressBar.h" 36 | 37 | InfiniteProgressBar::InfiniteProgressBar() : 38 | m_progress(XSTL_CHAR('|')) 39 | { 40 | } 41 | 42 | void InfiniteProgressBar::out() 43 | { 44 | cout << XSTL_CHAR('\r') << m_progress; 45 | cout.flush(); 46 | 47 | switch (m_progress) 48 | { 49 | case '|': m_progress = '/'; break; 50 | case '/': m_progress = '-'; break; 51 | case '-': m_progress = '\\'; break; 52 | case '\\': m_progress = '|'; break; 53 | } 54 | } 55 | 56 | void InfiniteProgressBar::clear() 57 | { 58 | cout << XSTL_CHAR('\r') << XSTL_CHAR(' ') << XSTL_CHAR('\r'); 59 | cout.flush(); 60 | } 61 | -------------------------------------------------------------------------------- /Include/XDK/memory/MemoryLockableObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_MEMORY_MEMORYLOCKABLEOBJECT_H 33 | #define __TBA_XDK_MEMORY_MEMORYLOCKABLEOBJECT_H 34 | 35 | /* 36 | * MemoryLockableObject.h 37 | * 38 | * Author: Elad Raz 39 | */ 40 | #include "xStl/types.h" 41 | 42 | /* 43 | * Define the MemoryLockableObject to be one of the operating system best 44 | * lockable objects 45 | */ 46 | #ifndef XDK_TEST 47 | // Kernel mode 48 | // The MemoryLockableObject is defines as cInterruptSpinLock 49 | #include "xdk/utils/interruptSpinLock.h" 50 | #define MemoryLockableObject cInterruptSpinLock 51 | #else 52 | // User mode 53 | // The MemoryLockableObject is defines as a simple mutex 54 | #include "xStl/os/mutex.h" 55 | #define MemoryLockableObject cMutex 56 | #endif 57 | 58 | #endif // __TBA_XDK_MEMORY_MEMORYLOCKABLEOBJECT_H 59 | -------------------------------------------------------------------------------- /Include/XDK/utils/exitCounter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_UTILS_EXITCOUNTER_H 33 | #define __TBA_XDK_UTILS_EXITCOUNTER_H 34 | 35 | /* 36 | * exitCounter.h 37 | * 38 | * Protect block section from sudden death 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/counter.h" 44 | 45 | class cExitCounterAppender { 46 | public: 47 | // Constructor. Append 1 to the counter 48 | cExitCounterAppender(cCounter& counter); 49 | // Destructor. Substract 1 from the counter 50 | ~cExitCounterAppender(); 51 | 52 | private: 53 | // Deny copy-constructor and operator = 54 | cExitCounterAppender(const cExitCounterAppender& other); 55 | cExitCounterAppender& operator = (const cExitCounterAppender& other); 56 | // The counter object 57 | cCounter& m_counter; 58 | }; 59 | 60 | #endif // __TBA_TODO_exitCounter_H 61 | -------------------------------------------------------------------------------- /samples/Manager/InfiniteProgressBar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_MANAGER_INFINITEPROGRESSBAR_H 33 | #define __TBA_MANAGER_INFINITEPROGRESSBAR_H 34 | 35 | /* 36 | * InfiniteProgressBar.h 37 | * 38 | * For console application this class prints a rotated progress bar. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/char.h" 44 | 45 | /* 46 | * Prints '|', '/', '-'... characters at the begining of a line to indicate 47 | * a progress was being made 48 | */ 49 | class InfiniteProgressBar 50 | { 51 | public: 52 | // Default constructor. 53 | InfiniteProgressBar(); 54 | 55 | // Print the progress and increase it by 1 steps. 56 | void out(); 57 | 58 | // Clear the progress bar. 59 | void clear(); 60 | 61 | private: 62 | // The progress character 63 | character m_progress; 64 | }; 65 | 66 | #endif // __TBA_MANAGER_INFINITEPROGRESSBAR_H -------------------------------------------------------------------------------- /tests/testDriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_TESTS_TESTDRIVER_H 33 | #define __TBA_XDK_TESTS_TESTDRIVER_H 34 | 35 | /* 36 | * testDriver.h 37 | * 38 | * Instance the test driver. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xdk/kernel.h" 44 | #include "xdk/driver.h" 45 | #include "xdk/device.h" 46 | 47 | class cTestDriver : public cDriver 48 | { 49 | public: 50 | /* 51 | * Inits the device-driver. 52 | */ 53 | cTestDriver(); 54 | 55 | /* 56 | * Dtor 57 | */ 58 | virtual ~cTestDriver(); 59 | 60 | /* 61 | * Start the tests. 62 | * 63 | * See cDriver::driverEntry for more information 64 | */ 65 | virtual NTSTATUS driverEntry(); 66 | 67 | private: 68 | /* 69 | * The console device-driver 70 | */ 71 | cDevicePtr m_consoleDevice; 72 | }; 73 | 74 | #endif // __TBA_XDK_TESTS_TESTDRIVER_H 75 | -------------------------------------------------------------------------------- /Source/XDK/kernel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * kernel.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/datastream.h" 41 | #include "xStl/except/exception.h" 42 | #include "xStl/stream/traceStream.h" 43 | #include "xdk/kernel.h" 44 | #include "xdk/utils/processorUtil.h" 45 | #include "xdk/utils/bugcheck.h" 46 | 47 | void testPageableCode() 48 | { 49 | if (cProcessorUtil::getCurrentIrql() != PASSIVE_LEVEL) 50 | { 51 | // Debug mode raise BugCheck 52 | #ifdef _DEBUG 53 | cBugCheck::bugCheck(0xDEAD1A6E, 54 | cProcessorUtil::getCurrentIrql(), 55 | KeGetCurrentIrql(), 56 | 0, 0xDEAD1A6E); 57 | #endif 58 | 59 | // Relase MODE just throw exception. 60 | XSTL_THROW(cException, EXCEPTION_FAILED); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/testMemoryManager/kernel/KTMem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_KTMem_DRIVER_H 33 | #define __TBA_KTMem_DRIVER_H 34 | 35 | /* 36 | * KTMem.h 37 | * 38 | * A driver which perform 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "XDK/driver.h" 44 | #include "XDK/device.h" 45 | 46 | /* 47 | * The drive handles the driver entry by 48 | */ 49 | class KTMem : public cDriver 50 | { 51 | public: 52 | // Default constructor 53 | KTMem(); 54 | 55 | /* 56 | * Loads the driver device objects. 57 | * Perform the following operations: 58 | * 1. 59 | * 60 | * See cDriver::driverEntry for more information 61 | */ 62 | virtual NTSTATUS driverEntry(); 63 | 64 | private: 65 | // Leave these line if you wishes to use the 'cout' 66 | static const character m_consoleDeviceName[]; 67 | cDevicePtr m_consoleDevice; 68 | }; 69 | 70 | #endif // __TBA_KTMem_DRIVER_H 71 | -------------------------------------------------------------------------------- /samples/PCPlayer/driver/PcSpeakerDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * PcSpeakerDriver.cpp 34 | * 35 | * Implementation file for the PC-Speaker driver object 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/except/trace.h" 41 | #include "xStl/stream/traceStream.h" 42 | #include "common/const.h" 43 | #include "driver/PcSpeakerDriver.h" 44 | #include "driver/PcSpeakerDevice.h" 45 | 46 | NTSTATUS PcSpeakerDriver::driverEntry() 47 | { 48 | traceHigh("PcSpeaker: Driver entry called..." << endl); 49 | 50 | // Create the device 51 | m_speakerDevice = cDevicePtr(new 52 | PcSpeakerDevice(Const::PCSPEAKER_DEVICE_NAME)); 53 | // Add the device 54 | addDevice(m_speakerDevice); 55 | 56 | return STATUS_SUCCESS; 57 | } 58 | 59 | PcSpeakerDriver::PcSpeakerDriver() : 60 | m_speakerDevice(NULL) 61 | { 62 | } 63 | 64 | // Create a singleton driver object 65 | PcSpeakerDriver myDriver; 66 | -------------------------------------------------------------------------------- /Include/XDK/driverException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_EXCEPTION_H 33 | #define __TBA_XDK_EXCEPTION_H 34 | 35 | /* 36 | * driverException.h 37 | * 38 | * Defines the exception types inside the XDK library 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/except/exception.h" 43 | 44 | /* 45 | * class cDriverException 46 | * 47 | * Device driver exception class. All exceptions in the XDK are driven from this 48 | * class. 49 | */ 50 | class cDriverException : public cException 51 | { 52 | public: 53 | /* 54 | * Construct an exception using a string from description 55 | * 56 | * msg - The error message 57 | */ 58 | cDriverException(const character* msg) : cException(msg) {}; 59 | 60 | /* 61 | * Construct an exception using a number 62 | * 63 | * id - The error message identfication number 64 | */ 65 | cDriverException(const uint32 id) : cException(id) {}; 66 | }; 67 | 68 | #endif // __TBA_XDK_EXCEPTION_H 69 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/Win386Lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_WIN386LOCK_H 33 | #define __TBA_XDK_HOOKER_IA32_WIN386LOCK_H 34 | 35 | /* 36 | * Win386Lock.h 37 | * 38 | * A lockable object which lock the entire Windows operating system and locked 39 | * the i386 processor against interferences. 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/os/lockable.h" 45 | 46 | /* 47 | * The Win386Lock implementation is very simple. 48 | * Under user-application the function uses critical sections. In kernel-mode 49 | * drivers the function invoke a call to 'CLI' and 'STI' to halt any interrupts 50 | * 51 | * NOTE: This code is still unsafe since there may-be several of running 52 | * processors. 53 | * 54 | * The first executed Win386Lock for a processor will disable interrupts. The 55 | * second execution, will not affect the IF. 56 | */ 57 | typedef cProcessorLock Win386Lock; 58 | 59 | #endif // __TBA_XDK_HOOKER_IA32_WIN386LOCK_H 60 | -------------------------------------------------------------------------------- /Include/XDK/utils/consoleDeviceControls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_UTILS_CONSOLE_DEVICECONTROL_H 33 | #define __TBA_XDK_UTILS_CONSOLE_DEVICECONTROL_H 34 | /* 35 | * consoleDeviceControls.h 36 | * 37 | * The device-driver side of the cConsoleDeviceIoctl interface 38 | * 39 | * Author: Elad Raz 40 | */ 41 | #include "xStl/types.h" 42 | #include "XDK/utils/consoleDeviceIoctl.h" 43 | 44 | /* 45 | * Implements the controls using a thunk to xStl/stream/iostream memory objects 46 | */ 47 | class cConsoleDeviceControls : public cConsoleDeviceIoctl { 48 | public: 49 | /* 50 | * Default constructor. 51 | */ 52 | cConsoleDeviceControls(); 53 | 54 | 55 | /* 56 | * Taken from cConsoleDeviceControls. 57 | * See cConsoleDeviceControls for documentation 58 | */ 59 | virtual uint getVersion(); 60 | virtual uint getNextLineSize(); 61 | virtual bool poolLine(uint8* outputLine, uint outputLineLength); 62 | }; 63 | 64 | #endif // __TBA_XDK_UTILS_CONSOLE_DEVICECONTROL_H 65 | -------------------------------------------------------------------------------- /samples/Manager/KbHit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_MANAGER_KBHIT_H 33 | #define __TBA_MANAGER_KBHIT_H 34 | 35 | /* 36 | * kbhit.h 37 | * 38 | * Singnal when the user press a key inside Windows console application 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | 44 | /* 45 | * Usefull inside main applications loops. Change for flag to notify when a 46 | * user press any key. 47 | * 48 | * Usage: 49 | * if (KbHit::isHit()) { break; } 50 | * 51 | * TODO: Make this class Waitable. 52 | */ 53 | class KbHit 54 | { 55 | public: 56 | // Constructor 57 | KbHit(); 58 | 59 | /* 60 | * Returns true when any key pressed inside the console. 61 | */ 62 | bool isHit(); 63 | 64 | /* 65 | * Read the last pressed keyboard character 66 | */ 67 | character readKey(); 68 | 69 | private: 70 | // The last pressed character 71 | character m_char; 72 | // The console handle 73 | HANDLE m_consoleInput; 74 | }; 75 | 76 | #endif // __TBA_MANAGER_KBHIT_H 77 | -------------------------------------------------------------------------------- /tests/testObject.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * testObject.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/char.h" 41 | #include "xStl/data/list.h" 42 | #include "xStl/except/trace.h" 43 | #include "xStl/except/exception.h" 44 | #include "xStl/stream/ioStream.h" 45 | #include "../tests/tests.h" 46 | #include "../tests/testsContainer.h" 47 | 48 | bool cTestObject::isException = false; 49 | 50 | /* 51 | * cTestObject constructor 52 | * 53 | * Register the class to the global test list 54 | */ 55 | cTestObject::cTestObject() 56 | { 57 | TestsContainer::getTests().append(this); 58 | } 59 | 60 | #define MAX_STRING (400) 61 | character* makeString(char* string) 62 | { 63 | static character temp[MAX_STRING]; 64 | uint len = t_min((int)strlen(string), (int)MAX_STRING); 65 | for (uint i = 0; i < len; i++) 66 | { 67 | temp[i] = (character)string[i]; 68 | } 69 | temp[len] = cChar::getNullCharacter(); 70 | return temp; 71 | } 72 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/idt/IdtHookerManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * IdtHookerManager.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/smartptr.h" 41 | #include "xdk/hooker/Processors/IA32/idt/IDTRouterHooker.h" 42 | #include "xdk/hooker/Processors/IA32/idt/IdtTableHooker.h" 43 | #include "xdk/hooker/Processors/IA32/idt/IdtHookerManager.h" 44 | 45 | IdtHookerManager::IdtHookerManager() : 46 | m_routerObjectPtr(new IdtRouterHooker(0,3)) // TODO: Restore after fixing Hooking 47 | //IdtTableHooker::MAX_VECTOR_COUNT - 1)) 48 | { 49 | } 50 | 51 | IdtHookerManager& IdtHookerManager::getInstance() 52 | { 53 | static IdtHookerManager gSingleton; 54 | return gSingleton; 55 | } 56 | 57 | void IdtHookerManager::killManager() 58 | { 59 | m_routerObjectPtr = cSmartPtr(); 60 | } 61 | 62 | IdtRouterHooker& IdtHookerManager::getRouterObject() 63 | { 64 | return *m_routerObjectPtr; 65 | } 66 | -------------------------------------------------------------------------------- /Include/XDK/unicodeString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_UNICODESTRING_H 33 | #define __TBA_XDK_UNICODESTRING_H 34 | 35 | /* 36 | * unicodeString.h 37 | * 38 | * The unicode string is used to translate normal string into the OS rediculese 39 | * UNICODE_STRING struct. 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/data/string.h" 45 | #include "XDK/kernel.h" 46 | 47 | class cUnicodeString 48 | { 49 | public: 50 | /* 51 | * Constructor. Translate between cString and UNICODE_STRING struct 52 | */ 53 | cUnicodeString(const cString& data); 54 | 55 | /* 56 | * Destructor. Free all resources allocated 57 | */ 58 | ~cUnicodeString(); 59 | 60 | /* 61 | * Covert the string into an operating system represintation. 62 | */ 63 | operator PUNICODE_STRING(); 64 | 65 | private: 66 | // The struct for the operation system 67 | UNICODE_STRING m_unicodeString; 68 | // The local string data 69 | WCHAR* m_unicodeData; 70 | }; 71 | 72 | #endif // __TBA_XDK_UNICODESTRING_H 73 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Processors/ia32/tss.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * tss.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/except/trace.h" 41 | #include "xdk/hooker/Processors/ia32/registers.h" 42 | #include "xdk/hooker/Processors/ia32/segments.h" 43 | #include "xdk/hooker/Processors/ia32/tss32.h" 44 | 45 | TaskStateSegment32* TaskStateSegment::getTSS32(uint16 selector) 46 | { 47 | Selector sel(selector); 48 | CHECK(sel.isGDTselector()); 49 | GDTR gdt; 50 | SegmentDescriptor tss(gdt, sel); 51 | CHECK(tss.isSystem()); 52 | CHECK((tss.getSystemSegmentType() == SegmentDescriptor::SEGMENT_TSS32_FREE) || 53 | (tss.getSystemSegmentType() == SegmentDescriptor::SEGMENT_TSS32_BUSY)); 54 | CHECK(tss.getSegmentLimit() >= sizeof(TaskStateSegment32)); 55 | return (TaskStateSegment32*)getPtr(tss.getOffset()); 56 | } 57 | 58 | uint16 TaskStateSegment::getTaskRegister() 59 | { 60 | uint16 returnCode; 61 | // Get the opcode 62 | _asm { str returnCode }; 63 | return returnCode; 64 | } 65 | -------------------------------------------------------------------------------- /Source/XDK/unicodeString.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #include "xStl/types.h" 33 | #include "xStl/os/os.h" 34 | #include "xStl/except/trace.h" 35 | #include "XDK/unicodeString.h" 36 | 37 | /* 38 | * unicodeString.cpp 39 | * 40 | * Author: Elad Raz 41 | */ 42 | 43 | cUnicodeString::cUnicodeString(const cString& data) : 44 | m_unicodeData(NULL) 45 | { 46 | uint length = data.length(); 47 | // Allocate the nessasry memory 48 | m_unicodeData = new WCHAR[length + 1]; 49 | 50 | // Copy memory 51 | #ifdef XSTL_UNICODE 52 | cOS::memcpy(m_unicodeData, data.getBuffer(), length * sizeof(WCHAR)); 53 | #else 54 | for (uint i = 0; i < length; i++) 55 | { 56 | m_unicodeData[i] = (WCHAR)data[i]; 57 | } 58 | #endif 59 | 60 | m_unicodeData[length] = 0; 61 | 62 | // Inits the struct 63 | RtlInitUnicodeString(&m_unicodeString, m_unicodeData); 64 | } 65 | 66 | cUnicodeString::~cUnicodeString() 67 | { 68 | delete[] m_unicodeData; 69 | } 70 | 71 | cUnicodeString::operator PUNICODE_STRING() 72 | { 73 | return &m_unicodeString; 74 | } 75 | -------------------------------------------------------------------------------- /Source/Loader/Win32Command.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * Win32DeviceLoader.cpp 34 | * 35 | * Implementation file for NT and 9x operation system over Win32 API. 36 | * 37 | * Author: Elad Raz 38 | */ 39 | 40 | #include "xStl/types.h" 41 | #include "xStl/except/trace.h" 42 | #include "xStl/except/exception.h" 43 | #include "loader/command.h" 44 | 45 | cCommand::cCommand(cOSDef::deviceHandle handle) : 46 | m_handle(handle) 47 | { 48 | CHECK(m_handle != NULL); 49 | } 50 | 51 | uint cCommand::invoke(uint code, 52 | const uint8* inputBuffer, 53 | uint inputBufferLength, 54 | uint8* outputBuffer, 55 | uint outputBufferLength) 56 | { 57 | DWORD ret; 58 | if (!DeviceIoControl(m_handle, 59 | code, 60 | (void*)inputBuffer, inputBufferLength, 61 | outputBuffer, outputBufferLength, 62 | &ret, 63 | NULL)) 64 | { 65 | XSTL_THROW(cException, EXCEPTION_FAILED); 66 | } 67 | 68 | return ret; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /samples/PCPlayer/driver/PcSpeakerDriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_PCPLAYER_PCSPEAKERDRIVER_H 33 | #define __TBA_PCPLAYER_PCSPEAKERDRIVER_H 34 | 35 | /* 36 | * PcSpeakerDriver.h 37 | * 38 | * The main driver object for 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "XDK/kernel.h" 44 | #include "XDK/driver.h" 45 | #include "driver/PcSpeakerDriver.h" 46 | 47 | /* 48 | * The driver contains implementation for the several interfaces: 49 | * PcSpeaker - Control the timer chip and the PC-Speaker port. 50 | * PcPlayer - The sound-blaster PCM player interface. 51 | */ 52 | class PcSpeakerDriver : public cDriver { 53 | public: 54 | // Default constructor 55 | PcSpeakerDriver(); 56 | 57 | /* 58 | * The driver's "main" function. Creates the different devices and 59 | * connects the interfaces to them. 60 | * 61 | * See cDriver::driverEntry() for more information 62 | */ 63 | virtual NTSTATUS driverEntry(); 64 | 65 | private: 66 | // The main device-driver 67 | cDevicePtr m_speakerDevice; 68 | }; 69 | 70 | #endif // __TBA_PCPLAYER_PCSPEAKERDRIVER_H 71 | 72 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/Intel386Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_INTEL386UTILS_H 33 | #define __TBA_XDK_HOOKER_IA32_INTEL386UTILS_H 34 | 35 | /* 36 | * Intel386Utils.h 37 | * 38 | * Contain functions which are generic for the Intel IA32 bit processors family. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | 44 | /* 45 | * Contain functions which are generic for the Intel IA32 bit processors family. 46 | */ 47 | class Intel386Utils { 48 | public: 49 | // The number of bytes absolute JMP opcode required 50 | enum { ABSOLUTE_JMP_LENGTH = 5 }; 51 | 52 | /* 53 | * Write the following opcode: 54 | * jmp relative [memory-location] 55 | * 56 | * memory - The address to write the data to. 57 | * location - The address to invoke the JMP to. 58 | * 59 | * Notice: 'memory' must be a pointer to array with at least 60 | * ABSOLUTE_JMP_LENGTH bytes 61 | */ 62 | static void generateAbsoluteJmpOpcode(uint8* memory, 63 | uint32 location); 64 | }; 65 | 66 | #endif // __TBA_XDK_HOOKER_IA32_INTEL386UTILS_H 67 | -------------------------------------------------------------------------------- /Include/XDK/utils/ResourceLock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_UTILS_RESOURCELOCK_H 33 | #define __TBA_XDK_UTILS_RESOURCELOCK_H 34 | 35 | /* 36 | * ResourceLock.h 37 | * 38 | * C++ lock over kernel ERESOURCES mutex. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/os/lockable.h" 44 | #include "xdk/kernel.h" 45 | 46 | /* 47 | * Usage: 48 | * cResourceLock rootDirectoryMutex(ObpRootDirectoryMutex); 49 | * cLock lock(rootDirectoryMutex); 50 | * // And your code! 51 | */ 52 | class cResourceLock : public cLockableObject { 53 | public: 54 | /* 55 | * Constructor. 56 | */ 57 | cResourceLock(PERESOURCE resource); 58 | 59 | /* 60 | * Acquire the resource using a call to ExAcquireResourceExclusiveLite 61 | * 62 | * See cLockable::lock 63 | */ 64 | virtual void lock(); 65 | 66 | /* 67 | * Free the resource using a call to ExReleaseResourceLite 68 | * 69 | * See cLockable::unlock 70 | */ 71 | virtual void unlock(); 72 | 73 | private: 74 | // The resource handle 75 | PERESOURCE m_resource; 76 | }; 77 | 78 | #endif // __TBA_XDK_UTILS_RESOURCELOCK_H 79 | -------------------------------------------------------------------------------- /Source/XDK/ehlib/NTDDKthrowException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * NTthorwException.cpp 34 | * 35 | * A thunk to EHLib::internalThrowException. 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "XDK/EHLib/ehlib.h" 41 | 42 | void internalThrowException(void* object, 43 | EHLib::ExceptionTypeInformation* objectType, 44 | void* exceptionLocation) 45 | { 46 | EHLib::internalThrowException(object,objectType, exceptionLocation); 47 | } 48 | 49 | 50 | /* 51 | * The compiler have a problem declaring the _CxxThrowException so we generate 52 | * a function which called __DxxThrowException@8 and replace it with 53 | * __CxxThrowException@8 function 54 | */ 55 | EXTERNC void _declspec(naked) __stdcall _DxxThrowException(uint32 object, 56 | uint32 objectType) 57 | { 58 | _asm { 59 | push ebp 60 | mov ebp, esp 61 | push [ebp + 4] ; // Return address 62 | push objectType 63 | push object 64 | call internalThrowException 65 | ; // Will never reached here! 66 | pop ebp 67 | ret 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/testMemoryManager/testMemoryManager/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * main.cpp 34 | * 35 | * The main entry point of the application 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/char.h" 41 | #include "xStl/except/trace.h" 42 | #include "xStl/stream/iostream.h" 43 | 44 | /* 45 | * Extern modules 46 | */ 47 | void testSmallMemoryHeapManager(); 48 | void testSuperiorManager(); 49 | 50 | /* 51 | * The main entry point. Captures all unexpected exceptions and make sure 52 | * that the application will notify the programmer. 53 | * 54 | * Invoke a call to the following modules: 55 | * 1. 56 | */ 57 | int main(const uint argc, const char** argv) 58 | { 59 | XSTL_TRY 60 | { 61 | //testSmallMemoryHeapManager(); 62 | //testSuperiorManager(); 63 | return RC_OK; 64 | } 65 | XSTL_CATCH(cException& e) 66 | { 67 | // Print the exception 68 | cout << "Exceptions " << e.getMessage() << " caught at main()." << endl; 69 | return RC_ERROR; 70 | } 71 | XSTL_CATCH_ALL 72 | { 73 | cout << "Unknwon exceptions caught at main()..." << endl; 74 | return RC_ERROR; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /samples/Manager/KbHit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * KbHit.cpp 34 | * 35 | * The implementation of keyboard hitting class. 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/except/trace.h" 41 | #include 42 | #include "KbHit.h" 43 | 44 | KbHit::KbHit() : 45 | m_char(0) 46 | { 47 | m_consoleInput = GetStdHandle(STD_INPUT_HANDLE); 48 | CHECK(m_consoleInput != INVALID_HANDLE_VALUE); 49 | } 50 | 51 | bool KbHit::isHit() 52 | { 53 | DWORD count; 54 | INPUT_RECORD input; 55 | GetNumberOfConsoleInputEvents(m_consoleInput, &count); 56 | 57 | for (uint i = 0; i < count; i++) 58 | { 59 | DWORD read = 0; 60 | if (ReadConsoleInput(m_consoleInput, &input, 1, &read)) 61 | { 62 | if (input.EventType == KEY_EVENT) 63 | { 64 | if (input.Event.KeyEvent.bKeyDown) 65 | { 66 | m_char = input.Event.KeyEvent.uChar.UnicodeChar; 67 | return true; 68 | } 69 | } 70 | } 71 | } 72 | 73 | return false; 74 | } 75 | 76 | character KbHit::readKey() 77 | { 78 | return m_char; 79 | m_char = 0; 80 | } 81 | -------------------------------------------------------------------------------- /Source/XDK/utils/consoleDeviceControls.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * consoleDeviceControls.cpp 34 | * 35 | * Author: Elad Raz 36 | */ 37 | #include "xStl/types.h" 38 | #include "xStl/os/os.h" 39 | #include "xStl/data/string.h" 40 | #include "xStl/stream/iostream.h" 41 | #include "XDK/kernel.h" 42 | #include "XDK/driver.h" 43 | #include "XDK/utils/consoleDeviceIoctl.h" 44 | #include "XDK/utils/consoleDeviceControls.h" 45 | 46 | cConsoleDeviceControls::cConsoleDeviceControls() 47 | { 48 | } 49 | 50 | uint cConsoleDeviceControls::getVersion() 51 | { 52 | return CONSOLE_VERSION_1; 53 | } 54 | 55 | uint cConsoleDeviceControls::getNextLineSize() 56 | { 57 | return conOutStream::getCout().m_conOut.getQueueMessageLength(); 58 | } 59 | 60 | bool cConsoleDeviceControls::poolLine(uint8* outputLine, uint outputLineLength) 61 | { 62 | // Check space 63 | if (getNextLineSize() > outputLineLength) 64 | { 65 | return false; 66 | } 67 | // Pool 68 | cString ret; 69 | if (!conOutStream::getCout().m_conOut.getMessage(&ret)) 70 | { 71 | return false; 72 | } 73 | // And copy 74 | cOS::memcpy(outputLine, ret.getBuffer(), (ret.length() + 1) * sizeof(character)); 75 | return true; 76 | } 77 | -------------------------------------------------------------------------------- /Include/XDK/hooker/StackObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_STACKOBJECT_H 33 | #define __TBA_XDK_HOOKER_STACKOBJECT_H 34 | 35 | /* 36 | * StackObject.h 37 | * 38 | * A new generated stack API 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/array.h" 44 | #include "xStl/utils/callbacker.h" 45 | 46 | /* 47 | * TODO! This code should only be executed from HIGH_LEVEL irql, otherwise 48 | * the NT_TIB can context-switch into illegal value. 49 | */ 50 | class StackObject { 51 | public: 52 | // The default generated stack is 32kb stack 53 | enum { DefaultStackSize = 32*1024 }; 54 | 55 | /* 56 | * Default constructor 57 | */ 58 | StackObject(uint stackSize = DefaultStackSize ); 59 | 60 | /* 61 | * Changes the stack pointer to the new allocated stack. 62 | * 63 | * function - The function to be executed 64 | * parameter - The parameter to send 65 | * 66 | * Return the function return code. 67 | * NOTE: In case the function throw uncaught exception, An exception-failed 68 | * exception will be sent to the main thread. 69 | */ 70 | void* spawnNewStackJob(cCallbackPtr function, void* parameter); 71 | 72 | private: 73 | // The stack object 74 | cBuffer m_stack; 75 | }; 76 | 77 | #endif // __TBA_XDK_HOOKER_STACKOBJECT_H 78 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/descriptorTable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_DESCRIPTORTABLE_H 33 | #define __TBA_XDK_HOOKER_IA32_DESCRIPTORTABLE_H 34 | 35 | /* 36 | * descriptorTable.h 37 | * 38 | * Intel IA32 processor descriptors. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | 44 | /// Each interrupt descriptor is 64bits long 45 | typedef uint64 DescriptorValue; 46 | 47 | /** 48 | * A virtual descriptor register representation. 49 | * This class is match the LDT table, GDT table and IDT tables 50 | * Even the TSS can be formated in this way. 51 | * 52 | * See Intel System programming vol I for more information. 53 | */ 54 | class DescriptorTableRegister 55 | { 56 | public: 57 | /// Virtual class 58 | virtual ~DescriptorTableRegister(); 59 | 60 | /// Return the limit part 61 | uint16 getLimit() const; 62 | 63 | /// Calculate the number of entries in the table 64 | uint16 getEntries() const; 65 | 66 | /// Return the base part 67 | DescriptorValue* getBase() const; 68 | 69 | protected: 70 | /// This class cannot be constructed 71 | DescriptorTableRegister(); 72 | /// The limit is the number of bytes for the table 73 | uint16 m_limit; 74 | /// The base entry. 75 | DescriptorValue* m_base; 76 | }; 77 | 78 | #endif // __TBA_XDK_HOOKER_IA32_DESCRIPTORTABLE_H 79 | -------------------------------------------------------------------------------- /Source/XDK/memory/MemorySuperblockHeapManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * MemorySuperblockHeapManager.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xdk/memory/MemorySuperblockHeapManager.h" 41 | 42 | MemorySuperblockHeapManager::MemorySuperblockHeapManager(void* superBlock, 43 | uint superBlockLength) : 44 | m_superBlock(superBlock), 45 | m_superBlockLength(superBlockLength), 46 | m_allocatedBytes(0) 47 | { 48 | } 49 | 50 | MemorySuperblockHeapManager::~MemorySuperblockHeapManager() 51 | { 52 | } 53 | 54 | uint MemorySuperblockHeapManager::getNumberOfAllocatedBytes() const 55 | { 56 | return m_allocatedBytes; 57 | } 58 | 59 | uint MemorySuperblockHeapManager::getNumberOfFreeBytes() const 60 | { 61 | return m_superBlockLength - m_allocatedBytes; 62 | } 63 | 64 | bool MemorySuperblockHeapManager::isInBoundries(void* addr, 65 | uint prefixLength, 66 | uint postfixLength) 67 | { 68 | addressNumericValue naddr = getNumeric(addr); 69 | addressNumericValue saddr = getNumeric(m_superBlock); 70 | 71 | return (((naddr - prefixLength) >= saddr)) && 72 | (((naddr + postfixLength) <= (saddr + m_superBlockLength))); 73 | } 74 | -------------------------------------------------------------------------------- /tests/testMemoryManager/kernel/DefaultMem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_TODO_DefaultMem_H 33 | #define __TBA_TODO_DefaultMem_H 34 | 35 | /* 36 | * DefaultMem.h 37 | * 38 | * Author: Elad Raz 39 | */ 40 | #include "xStl/types.h" 41 | #include "xdk/memory/MemorySuperblockHeapManager.h" 42 | 43 | class DefaultMem : public MemorySuperblockHeapManager { 44 | public: 45 | // Default constructor 46 | DefaultMem() : MemorySuperblockHeapManager(NULL, 0) {}; 47 | 48 | /* 49 | * See MemorySuperblockHeapManager::allocate 50 | * use operator new[] 51 | */ 52 | virtual void* allocate(uint length) { 53 | return new uint8[length]; 54 | } 55 | 56 | /* 57 | * See MemorySuperblockHeapManager::free 58 | * use operator delete[] 59 | */ 60 | virtual bool free(void* buffer) { 61 | delete[] ((uint8*)buffer); 62 | return true; 63 | } 64 | 65 | 66 | /* 67 | * See MemorySuperblockHeapManager::getMaximumAllocationUnit 68 | * return -1 69 | */ 70 | virtual uint getMaximumAllocationUnit() const { 71 | return 0xFFFFFFFF; 72 | } 73 | 74 | /* 75 | * See MemorySuperblockHeapManager::getMinimumAllocationUnit 76 | * return 0 77 | */ 78 | virtual uint getMinimumAllocationUnit() const { 79 | return 0; 80 | } 81 | }; 82 | 83 | #endif // __TBA_TODO_DefaultMem_H 84 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Locks/GlobalSystemLock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_LOCKS_GLOBALSYSTEMLOCK_H 33 | #define __TBA_XDK_HOOKER_LOCKS_GLOBALSYSTEMLOCK_H 34 | 35 | /* 36 | * GlobalSystemLock.h 37 | * 38 | * Locks the entire operating system. Hooking over multi-processors, threads 39 | * or any other high-priority, non-preemtive task should be locked by this 40 | * class. 41 | * 42 | * Author: Elad Raz 43 | */ 44 | #include "xStl/types.h" 45 | #include "xStl/os/lockable.h" 46 | 47 | // The kernel-mode uses the Win386Lock 48 | #ifdef XSTL_NTDDK 49 | #include "xdk/utils/processorLock.h" 50 | #endif 51 | 52 | /* 53 | * Locks the entire operating system. Hooking over multi-processors, threads 54 | * or any other high-priority, non-preemtive task should be locked by this 55 | * class. 56 | * 57 | * TODO: For now this class applies only for a single processor. 58 | * Add complete processors locks 59 | */ 60 | class GlobalSystemLock : public cLockableObject 61 | { 62 | public: 63 | /* 64 | * See cLockable::lock() 65 | */ 66 | virtual void lock(); 67 | 68 | /* 69 | * See cLockable::unlock() 70 | */ 71 | virtual void unlock(); 72 | 73 | private: 74 | #ifdef _KERNEL 75 | // The lockable object 76 | cProcessorLock m_lock; 77 | #endif 78 | }; 79 | 80 | #endif // __TBA_XDK_HOOKER_LOCKS_GLOBALSYSTEMLOCK_H 81 | -------------------------------------------------------------------------------- /Include/Loader/deviceException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_LOADER_EXCEPTION_H 33 | #define __TBA_XDK_LOADER_EXCEPTION_H 34 | 35 | /* 36 | * deviceException.h 37 | * 38 | * Defines the exception types regarding to handling a device 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/except/exception.h" 43 | 44 | /* 45 | * class cDeviceException 46 | * 47 | * Device loader exception class. All the device exception are driven from this 48 | * class. 49 | */ 50 | class cDeviceException : public cException 51 | { 52 | public: 53 | /* 54 | * Construct an exception using a string from description 55 | * 56 | * msg - The error message 57 | * id - The error message identfication number 58 | */ 59 | cDeviceException(char * file, uint32 line, const character* msg, uint32 id) : cException(file, line, msg, id) {}; 60 | 61 | /* 62 | * Construct an exception using a string from description 63 | * 64 | * msg - The error message 65 | */ 66 | cDeviceException(char * file, uint32 line, const character* msg) : cException(file, line, msg) {}; 67 | 68 | /* 69 | * Construct an exception using a number 70 | * 71 | * id - The error message identfication number 72 | */ 73 | cDeviceException(char * file, uint32 line, uint32 id) : cException(file, line, id) {}; 74 | }; 75 | 76 | #endif // __TBA_XDK_LOADER_EXCEPTION_H 77 | -------------------------------------------------------------------------------- /Source/XDK/ehlib/ehVectorConstructor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * ehVectorDestructor.cpp 34 | * 35 | * Author: Elad Raz 36 | */ 37 | #include "xStl/types.h" 38 | #include "xStl/data/datastream.h" 39 | #include "xStl/except/exception.h" 40 | #include "xStl/except/trace.h" 41 | #include "XDK/EHLib/ehlib.h" 42 | #include "XDK/EHLib/ehlibcpp.h" 43 | 44 | 45 | void __stdcall ec(void* objectArray, 46 | uint objectSize, 47 | int elementsCount, 48 | void (__stdcall *constructor)(void*), 49 | void (__stdcall *destructor)(void*)) 50 | { 51 | // Start constructing from the first element 52 | uint8* objectData = (uint8*)objectArray; 53 | 54 | for (int i = 0; i < elementsCount; i++) 55 | { 56 | // Call to object constructor 57 | if (!EHLib::callCppMethod(objectData, (void*)constructor)) 58 | { 59 | // Exception during the current array initialization... 60 | // Destruct the element generated so far. 61 | arrayUnwind((uint8*)objectArray, 62 | objectSize, 63 | i - 1, 64 | (void*)destructor); 65 | // Thorw the exception 66 | XSTL_THROW(cException, EXCEPTION_VIOLATION); 67 | } 68 | // Change pointer to the next array element 69 | objectData+= objectSize; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Source/Loader/device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * device.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/refCountObject.h" 41 | #include "loader/device.h" 42 | #include "loader/loader.h" 43 | 44 | REFCOUNTABLE_CPP(cDevice); 45 | 46 | cDevice::cDevice(const cString& deviceName, 47 | const cString& deviceFilename) : 48 | REFCOUNTABLE_INIT, 49 | m_deviceName(deviceName), 50 | m_deviceFilename(deviceFilename), 51 | m_command(NULL) 52 | { 53 | cOSDef::deviceHandle handle = cDeviceLoader::loadDevice(deviceName, 54 | deviceFilename); 55 | m_command = new cCommand(handle); 56 | init(handle); 57 | } 58 | 59 | cCommand& cDevice::getCommand() 60 | { 61 | ASSERT(m_command != NULL); 62 | return *m_command; 63 | } 64 | 65 | cDevice::~cDevice() 66 | { 67 | if (free()) { 68 | // Delete the command-center 69 | delete m_command; 70 | // Unload the device. 71 | cDeviceLoader::unloadDevice(m_deviceName, 72 | m_deviceFilename, 73 | getHandle()); 74 | } 75 | } 76 | 77 | void cDevice::copy(const cDevice& other) 78 | { 79 | m_deviceFilename = other.m_deviceFilename; 80 | m_deviceName = other.m_deviceName; 81 | m_command = other.m_command; 82 | } 83 | 84 | cOSDef::deviceHandle cDevice::getHandle() const 85 | { 86 | return getObject(); 87 | } 88 | -------------------------------------------------------------------------------- /Source/XDK/ehlib/ehVectorDestructor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * ehVectorDestructor.cpp 34 | * 35 | * Author: Elad Raz 36 | */ 37 | #include "xStl/types.h" 38 | #include "xStl/except/exception.h" 39 | #include "XDK/EHLib/ehlib.h" 40 | #include "XDK/EHLib/ehlibcpp.h" 41 | 42 | void __stdcall arrayUnwind(uint8* objectArray, 43 | uint objectSize, 44 | int elementsCount, 45 | void* destructor) 46 | { 47 | // Start destructing from the last element 48 | uint8* objectData = objectArray + ((elementsCount - 1)*objectSize); 49 | // Check for exceptions. 50 | bool exceptionNotThrow = true; 51 | 52 | for (int i = 0; i < elementsCount; i++) 53 | { 54 | // Call to object destructor 55 | exceptionNotThrow = exceptionNotThrow && 56 | EHLib::callCppMethod(objectData, destructor); 57 | // Change pointer to the previous array element 58 | objectData-= objectSize; 59 | } 60 | 61 | // Test for exceptions... 62 | if (!exceptionNotThrow) 63 | { 64 | // Rethrow exception 65 | XSTL_THROW(cException, EXCEPTION_VIOLATION); 66 | } 67 | } 68 | 69 | 70 | void __stdcall ed(void* objectArray, 71 | uint objectSize, 72 | int elementsCount, 73 | void (__stdcall *destructor)(void*)) 74 | { 75 | arrayUnwind((uint8*)objectArray, objectSize, elementsCount, destructor); 76 | } 77 | -------------------------------------------------------------------------------- /Include/XDK/xdkTraceSingleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | // For debug mode only 33 | #ifdef _DEBUG 34 | 35 | #ifndef __XDK_TRACESIGNLETON_H 36 | #define __XDK_TRACESIGNLETON_H 37 | 38 | /* 39 | * xdkTraceSingleton.h 40 | * 41 | * Declare the singleton object which acts as a respository for global trace messages 42 | * 43 | * Author: Elad Raz 44 | */ 45 | #include "xStl/types.h" 46 | #include "XDK/xdkTrace.h" 47 | 48 | /* 49 | * This class holds the trace-messages for the XDK driver 50 | */ 51 | class cXdkTraceSingleton { 52 | public: 53 | /* 54 | * The singleton which holds the messages for the XDK. 55 | * 56 | * The function construct the singleton in first use by using operator new. 57 | * In order to safe free system resource make sure that the C++ library 58 | * calls to the 'destroyTraceObject' function. 59 | */ 60 | static cXdkTraceSingleton& getInstance(); 61 | 62 | /* 63 | * Free all resources allocated by this singleton. 64 | * Called by the unload process. 65 | */ 66 | static void destroyTraceObject(); 67 | 68 | // The maximum number of messages 69 | enum { MAX_MESSAGES = 1024 * 20 }; 70 | 71 | // The list of elements 72 | cXdkTrace m_traceObject; 73 | 74 | // The singleton object 75 | static cXdkTraceSingleton* m_singleton; 76 | 77 | private: 78 | /* 79 | * Singleton constructor. 80 | * Builds the main trace repository module. 81 | */ 82 | cXdkTraceSingleton(); 83 | }; 84 | 85 | 86 | #endif // __XDK_TRACESIGNLETON_H 87 | #endif // _DEBUG -------------------------------------------------------------------------------- /samples/PCPlayer/driver/driverConsts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_PCPLAYER_DRIVERCONSTS_H 33 | #define __TBA_PCPLAYER_DRIVERCONSTS_H 34 | 35 | /* 36 | * driverConsts.h 37 | * 38 | * All the consts needed for the driver. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/char.h" 44 | 45 | /* 46 | * Contains all data needed for proper operation of the pc-speaker 47 | */ 48 | class DriverConsts { 49 | public: 50 | }; 51 | 52 | 53 | /* 54 | * Timer8254Defines.h 55 | * 56 | * Definition of the system ports. 57 | */ 58 | 59 | #define TIMER_PORT (PUCHAR)(0x43) // Timer - 8254 I/O Address 60 | #define TIMER_DATA_0 (PUCHAR)(0x40) // Timer channel 0 (IRQ0) counter data register. 61 | #define TIMER_DATA_2 (PUCHAR)(0x42) // Timer channel 2 counter data register. 62 | #define SPEAKER_PORT (PUCHAR)(0x61) // Speaker IO control register 63 | #define SPEAKER_SIGNAL_BIT (0x03) // Speaker signal bit. 64 | #define TIMER_SPEAKER_COUNTER_S3 (0xB6) // Binary counter, singal mode 3 (quarte signal), LSB first, channel 2. 65 | #define TIMER_SPEAKER_COUNTER_S0 (0xB0) // Binary counter, singal mode 0 (impolse), LSB first, channel 2. 66 | #define TIMER_FREQUENCY (1193181) // The frequency of the 8254 chip: 1.193181mHz 67 | 68 | /* 69 | * Analog to impulse setting 70 | */ 71 | #define SIGNAL_AMPLITUDE (1) // Increase the signal 72 | #define TIMER_CTCCLK (14318180.0) // clock frequency for 8254 in internal mesuare 73 | #define TIMER_HZCCLK (12.0) // The clock in Hz. 74 | 75 | 76 | #endif // __TBA_PCPLAYER_DRIVERCONSTS_H 77 | -------------------------------------------------------------------------------- /tests/testMemoryManager/kernel/KTMem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * KTMem.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/stream/ioStream.h" 41 | #include "xStl/stream/traceStream.h" 42 | #include "XDK/kernel.h" 43 | #include "XDK/driver.h" 44 | #include "XDK/device.h" 45 | #include "XDK/driverFactory.h" 46 | #include "XDK/ehlib/ehlib.h" 47 | #include "XDK/utils/consoleDevice.h" 48 | #include "../testMemoryManager/TestSuperBlock.h" 49 | #include "KTMem.h" 50 | #include "DefaultMem.h" 51 | 52 | const character KTMem::m_consoleDeviceName[] = 53 | XSTL_STRING("KTMem"); 54 | 55 | KTMem::KTMem() : 56 | m_consoleDevice(NULL) 57 | { 58 | } 59 | 60 | NTSTATUS KTMem::driverEntry() 61 | { 62 | // Leave this lines if you wishes to 63 | // use the console device... 64 | // Construct the console device 65 | m_consoleDevice = cDevicePtr(new cConsoleDevice(m_consoleDeviceName)); 66 | // Add the device to the queue 67 | addDevice(m_consoleDevice); 68 | 69 | DefaultMem mem; 70 | TestSuperBlock test(mem, cout, 1, 1024); 71 | uint8* temp[100]; 72 | // Allocate and free from interrupt time 73 | uint i; 74 | for (i = 0; i < 100; i++) 75 | temp[i] = new uint8[i + 50]; 76 | 77 | KIRQL oldIrql; 78 | KeRaiseIrql(HIGH_LEVEL, &oldIrql); 79 | // Before test 80 | for (i = 0; i < 50; i++) 81 | delete[] temp[i]; 82 | test.test(); 83 | // After test 84 | for (i = 50; i < 100; i++) 85 | delete[] temp[i]; 86 | KeLowerIrql(oldIrql); 87 | 88 | // TODO! Add your handler here 89 | return STATUS_SUCCESS; 90 | } 91 | 92 | // The single global object... 93 | cDriverFactory theDriver; 94 | -------------------------------------------------------------------------------- /Source/XDK/hooker/ProcessorsThread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * ProcessorsThread.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xdk/undocumented.h" 41 | #include "xdk/utils/processorUtil.h" 42 | #include "xdk/hooker/ProcessorsThread.h" 43 | 44 | ProcessorsThread::ProcessorsThread(ProcessorJob& job) 45 | { 46 | for (uint i = 0; i < cProcessorUtil::getNumberOfProcessors(); i++) 47 | { 48 | // Create a thread 49 | ProcessorSingleThreadPtr newThread(new ProcessorSingleThread( 50 | job, 51 | i, 52 | cProcessorUtil::getNumberOfProcessors())); 53 | m_processorSingleThread.append(newThread); 54 | } 55 | } 56 | 57 | const uint ProcessorsThread::getNumberOfProcessors() 58 | { 59 | return cProcessorUtil::getNumberOfProcessors(); 60 | } 61 | 62 | ProcessorsThread::~ProcessorsThread() 63 | { 64 | // Destructor will call. TODO! Check for premature death 65 | } 66 | 67 | ProcessorsThread::ProcessorSingleThread::ProcessorSingleThread( 68 | ProcessorJob& job, 69 | uint id, 70 | uint processors) : 71 | m_job(job), 72 | m_id(id), 73 | m_processors(processors) 74 | { 75 | start(); 76 | } 77 | 78 | void ProcessorsThread::ProcessorSingleThread::run() 79 | { 80 | /* 81 | * TODO! 82 | * Check and apply only for active processors! 83 | */ 84 | 85 | // Change the thread affinity map 86 | //PKTHREAD threadHandle = getThreadHandle().getHandle(); 87 | //KeSetAffinityThread(threadHandle, (1 << m_id)); 88 | 89 | KeSetSystemAffinityThread((1 << m_id)); 90 | 91 | // Execute the handler 92 | m_job.run(m_id, m_processors); 93 | } 94 | -------------------------------------------------------------------------------- /Source/XDK/assert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * trace.cpp 34 | * 35 | * Implementation file for nt-ddk (XDK package). 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xdk/kernel.h" 40 | #include "xStl/types.h" 41 | #include "xStl/data/string.h" 42 | #include "xStl/except/trace.h" 43 | #include "xStl/except/assert.h" 44 | #include "xStl/except/traceStack.h" 45 | #include "xdk/utils/bugcheck.h" 46 | 47 | #ifdef _DEBUG 48 | 49 | void assertFunction(bool condition, 50 | unsigned int line, 51 | const char* file, 52 | const character* msg) 53 | { 54 | // Test whether we should activate ASSERT 55 | if (!condition) 56 | { 57 | #ifdef _DEBUG 58 | // Catch the bug using blue-screen 59 | // Prevent recursive behaviour. 60 | cBugCheck::bugCheck(0xDEAD, 0xAAA, 61 | getNumeric(file), 62 | line, 63 | getNumeric(msg)); 64 | #endif 65 | 66 | // Trace the message 67 | cString message("Assertion at file "); 68 | message+= file; 69 | message+= " line "; 70 | message+= cString((uint32)line); 71 | message+= " "; 72 | message+= msg; 73 | 74 | TRACE(TRACE_VERY_HIGH, message); 75 | 76 | // Trace the stack 77 | traceStack(); 78 | 79 | // Terminate the program 80 | #ifdef XDK_DBG_RELEASE 81 | cBugCheck::bugCheck(0xDEAD, 0xAAA, 82 | getNumeric(file), 83 | line, 84 | getNumeric(msg)); 85 | #else 86 | XSTL_THROW(cException, EXCEPTION_ASSERTION); 87 | #endif 88 | } 89 | } 90 | 91 | #endif // _DEBUG 92 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/idt/IdtHookerManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_IDT_IDTHOOKER_MANAGER_H 33 | #define __TBA_XDK_HOOKER_IA32_IDT_IDTHOOKER_MANAGER_H 34 | 35 | /* 36 | * IdtHookerManager.h 37 | * 38 | * Handles multi-driver interrupt-table hooking. 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | #include "xStl/data/smartptr.h" 44 | #include "xdk/hooker/Processors/ia32/idt/IdtRouterHooker.h" 45 | 46 | /* 47 | * A system-wide singleton which controls interrupt hooking API. 48 | * Using this object will provide solution for wild-west hooking. 49 | * 50 | * TODO! This class is implement as an interface only (for now only)! 51 | */ 52 | class IdtHookerManager { 53 | public: 54 | /* 55 | * Return handler to the IDT manager 56 | */ 57 | static IdtHookerManager& getInstance(); 58 | 59 | /* 60 | * Return a pointer to the router object 61 | */ 62 | IdtRouterHooker& getRouterObject(); 63 | 64 | /* 65 | * Destroy the manager. Used in order to safely destroy the IDT hooking 66 | * table before the ProcessorThreadsManager will dead-lock. 67 | */ 68 | void killManager(); 69 | 70 | private: 71 | /* 72 | * Default constructor. This class is a singleton. 73 | * 74 | * Try to scan for exist IDTRouterHooker object in other drivers, if found 75 | * link this manager to a main manager object. Control flow for driver 76 | * loading/unload etc.. If not found, hook the interrupt table and start 77 | * dispatch messages. 78 | */ 79 | IdtHookerManager(); 80 | 81 | /// The Hooker referenced objects 82 | cSmartPtr m_routerObjectPtr; 83 | }; 84 | 85 | #endif // __TBA_XDK_HOOKER_IA32_IDT_IDTHOOKER_MANAGER_H 86 | -------------------------------------------------------------------------------- /Include/XDK/utils/bugcheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_UTILS_BUGCHECK_H 33 | #define __TBA_XDK_UTILS_BUGCHECK_H 34 | 35 | /* 36 | * bugcheck.h 37 | * 38 | * Define a private bug-check routine which might not be implemented by the 39 | * KeBugCheck routine of microsoft. This routine might be trapped 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xdk/kernel.h" 45 | // For now on 46 | class cBugCheck { 47 | public: 48 | /* 49 | * For now the implementation is simple 50 | */ 51 | static void bugCheck(uint32 code, 52 | uint32 paramA = 0, 53 | uint32 paramB = 0, 54 | uint32 paramC = 0, 55 | uint32 paramD = 0) 56 | { 57 | #ifndef _KERNEL 58 | DebugBreak(); 59 | #else 60 | stackDump(300); 61 | /*__debugbreak();*/ 62 | KeBugCheckEx(code, paramA,paramB,paramC,paramD); 63 | #endif // _WIN32 64 | } 65 | 66 | static void stackDump(uint32 depth) 67 | { 68 | uint32 index = 0; 69 | uint32 * stack = &index; 70 | 71 | DbgPrint("!!Dump Start!!\n"); 72 | 73 | while (depth > index) 74 | { 75 | DbgPrint("%08x\n", stack[index]); 76 | index++; 77 | } 78 | 79 | DbgPrint("!!Dump End!!\n"); 80 | 81 | //DbgPrint("!! Ebp walk !!\n"); 82 | //uint32 * frame = NULL; 83 | //uint32 * next_frame = NULL; 84 | 85 | //_asm{ 86 | // mov frame, ebp 87 | //} 88 | 89 | //DbgPrint("EIP = %08x\n", frame[1]); 90 | //frame = (uint32 *)frame[0]; 91 | //DbgPrint("EIP = %08x\n", frame[1]); 92 | //frame = (uint32 *)frame[0]; 93 | //DbgPrint("EIP = %08x\n", frame[1]); 94 | //frame = (uint32 *)frame[0]; 95 | //DbgPrint("EIP = %08x\n", frame[1]); 96 | } 97 | }; 98 | 99 | #endif // __TBA_XDK_UTILS_BUGCHECK_H 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![unmaintained](http://img.shields.io/badge/status-unmaintained-red.png) 2 | 3 | XDK 4 | ==== 5 | XDK is a fully featured C++ wrapper library that uses [xStl](https://github.com/eladraz/xStl) as a base library. 6 | XDK includes the following features: 7 | * Easy driver development. 8 | * Full C++ features, including **exception handling**. 9 | * Synchronization objects, threads and file access APIs. 10 | 11 | For more information about using C++ in kernel, please see [this](ReadmeKernelCPP.html) article. 12 | 13 | Requirements 14 | ============ 15 | The compiled binaries can be operated on `Windows NT` operating system or higher. 16 | Need [Visual Studio](http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx) Express 2010 or higher, or Visual Studio 2010 or higher. 17 | Need [Windows Driver Kit (DDK) Version 7.1.0](http://www.microsoft.com/en-us/download/details.aspx?id=11800). 18 | 19 | Setting Up Environment 20 | ====================== 21 | Git 22 | --- 23 | ``` 24 | git clone https://github.com/eladraz/xStl 25 | git clone https://github.com/eladraz/XDK 26 | ``` 27 | 28 | Compilation tools 29 | ----------------- 30 | * Install [Visual Studio](http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx) Express 2010 or higher, or Visual Studio 2010 or higher. 31 | * Install [Windows Driver Kit (DDK) Version 7.1.0](http://www.microsoft.com/en-us/download/details.aspx?id=11800) 32 | 33 | Windows 34 | ------- 35 | In order to pass variable arguments to [Visual Studio](http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx), you need to declare the following system arguments: 36 | * XSTL_PATH (for example: `C:\WORK\github\xStl`) 37 | * XDK_PATH (for example: `C:\WORK\github\XDK`) 38 | * DDK_PATH (for example: `C:\WinDDK\7600.16385.1`) 39 | 40 | > To add system variables you should: 41 | >> * Right-click **My Computer**, and then click **Properties**. 42 | >> * Click the **Advanced** tab. 43 | >> * Click **Environment variables**. 44 | >> * Click *New* to add a new variable name (e.g. `XDK_PATH`) and its location (e.g. `C:\WORK\github\XDK`). 45 | 46 | How to Build 47 | ============ 48 | In order to build the XDK library, open `XDK.sln` solution project with [Visual Studio](http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx). 49 | In Visual Studio's configuration manager, choose the desired build configuration. Choosing `Release|Win32` or `Debug|Win32` builds the user-mode components. Choosing 'Kernel Release|Win32` or `Debug Release|Win32` builds the kernel-mode components. 50 | 51 | > NOTE: I have decided not to upload the x64 version of XDK 52 | 53 | How to Run 54 | ========== 55 | The XDK solution comes with the following projects: 56 | 57 | * `xStl` - [xStl](https://github.com/eladraz/xStl) is a cross-compile, cross-platform C++ library that works in both user mode and kernel mode. 58 | 59 | * `xdk_loader` - A user-mode library that implements driver-loading APIs. 60 | * `Manager` - A generic driver-loading application that uses xdk_loader (e.g. CLI front-end for driver loading). 61 | * `PCPlayer` - A dedicated user-mode application that loads PCSpeakerDriver from hardcoded location (`C:\Temp\PCSpeakerDriver.sys`), which demonstrates user mode => kernel mode commands and events. The application sends a few commands to the driver to turn on the PC speaker. 62 | 63 | * `XDK` - A fully featured C++ kernel mode library (including synchronization objects, threads and file access file-access APIs). 64 | * `PCSpeakerDriver` - A sample driver for PC Speaker. 65 | 66 | License 67 | ======= 68 | Please see LICENSE file 69 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/registers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_REGISTERS_H 33 | #define __TBA_XDK_HOOKER_IA32_REGISTERS_H 34 | 35 | /** 36 | * register.h 37 | * 38 | * The content of the IA32 registers 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | 44 | #pragma pack(push) 45 | #pragma pack(1) 46 | 47 | /** 48 | * When the processor execute 32bits PUSHAD instruction (opcode: 60h) 49 | * the following register is pushed (in reveresed order, but esp is expand 50 | * downward). 51 | * 52 | * The reason why the 'Registers' struct is separated than the InterruptFrame 53 | * is that the processor may insert an ErrorCode or push the stack registers 54 | * on the stack 55 | */ 56 | struct Registers { 57 | // The segment selectors. 58 | uint16 es; 59 | uint16 empty1; // not in used 60 | uint16 ds; 61 | uint16 empty2; // not in used 62 | uint16 ss; 63 | uint16 empty3; // not in used 64 | uint16 fs; 65 | uint16 empty4; // not in used 66 | uint16 gs; 67 | uint16 empty5; // not in used 68 | // The pusha registers 69 | uint32 edi; 70 | uint32 esi; 71 | uint32 ebp; 72 | uint32 esp; 73 | uint32 ebx; 74 | uint32 edx; 75 | uint32 ecx; 76 | uint32 eax; 77 | uint32 esp_orig; // !YOAV! 78 | uint32 frame_holder1; // !YOAV! 79 | uint32 frame_holder2; // !YOAV! 80 | uint32 frame_holder3; // !YOAV! 81 | }; 82 | 83 | /** 84 | * When a 32bit task execute an interrupt the EFLAGS, CS and EIP are pushed 85 | * and the function should return in IRET. 86 | */ 87 | struct InterruptFrame { 88 | // The trap frame 89 | uint32 eip; 90 | uint16 cs; // The cs is 16 bits but at 32bit task it's taken 32 bit 91 | uint16 empty; // not in used 92 | uint32 eflags; 93 | // For some traps there is an uint32 error-code here. 94 | }; 95 | #pragma pack(pop) 96 | 97 | #endif // __TBA_XDK_HOOKER_IA32_REGISTERS_H -------------------------------------------------------------------------------- /Include/Loader/command.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_LOADER_COMMAND_H 33 | #define __TBA_XDK_LOADER_COMMAND_H 34 | 35 | /* 36 | * command.h 37 | * 38 | * Invoke commands into the device-driver from ring3 applications. 39 | * The commands are IOCTLs (I/O controls) which has the following parts: 40 | * - Destination device, the device for sending the commands to 41 | * - Command number, index number of the command 42 | * - Sending memory, block of memory which contains the information that the 43 | * device-driver will be recieved. 44 | * - Recieving memory, block of memory which the driver can write it's 45 | * information to. The driver also return the number of bytes written 46 | * to that memory area. 47 | * 48 | * Author: Elad Raz 49 | */ 50 | #include "xStl/types.h" 51 | #include "xStl/os/osdef.h" 52 | 53 | class cCommand { 54 | public: 55 | /* 56 | * Constructor. Inits the command module for a device object. 57 | * 58 | * handle - Handle to the device-driver. See cDeviceLoader. 59 | */ 60 | cCommand(cOSDef::deviceHandle handle); 61 | 62 | /* 63 | * Sends a command to the device. 64 | * 65 | * code - The code of the command. 66 | * inputBuffer,inputBufferLength - The buffer which transfer to the driver 67 | * outputBuffer,outputBufferLength - The buffer which will be filled with 68 | * more information from the driver side. 69 | * 70 | * Return the number of bytes written to the output buffer 71 | * 72 | * Throws exception if the device failed to process the message. 73 | */ 74 | uint invoke(uint code, 75 | const uint8* inputBuffer, 76 | uint inputBufferLength, 77 | uint8* outputBuffer, 78 | uint outputBufferLength); 79 | 80 | private: 81 | // Handle for the device-object 82 | cOSDef::deviceHandle m_handle; 83 | }; 84 | 85 | #endif // __TBA_XDK_LOADER_COMMAND_H 86 | 87 | -------------------------------------------------------------------------------- /Source/XDK/hooker/Locks/RecursiveProtector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * RecursiveProtector.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/os/mutex.h" 41 | #include "xStl/os/lock.h" 42 | #include "xStl/data/smartptr.h" 43 | #include "xStl/utils/algorithm.h" 44 | #include "xStl/utils/callbacker.h" 45 | #include "xdk/hooker/Locks/RecursiveProtector.h" 46 | 47 | // The global list 48 | cList RecursiveProtector::m_lockedRegions; 49 | // The global list locked 50 | #ifdef XSTL_NTDDK 51 | cInterruptSpinLock 52 | #else 53 | cMutex 54 | #endif 55 | RecursiveProtector::m_lockedRegionsLocked; 56 | 57 | RecursiveProtector::RecursiveProtector(uint id1, uint id2, 58 | cCallback& callbackClass) : 59 | m_isRegionLocked(false), 60 | m_region(id1, id2) 61 | { 62 | cLock lock(m_lockedRegionsLocked); 63 | if (isRegionLocked(m_region)) 64 | { 65 | // RAISE EXCEPTION! 66 | callbackClass.call(NULL); 67 | } else 68 | { 69 | m_lockedRegions.append(m_region); 70 | m_isRegionLocked = true; 71 | } 72 | } 73 | 74 | RecursiveProtector::~RecursiveProtector() 75 | { 76 | if (m_isRegionLocked) 77 | { 78 | // Remove the locked region. 79 | cLock lock(m_lockedRegionsLocked); 80 | m_lockedRegions.remove(m_region); 81 | } 82 | } 83 | 84 | bool RecursiveProtector::isRegionLocked(const LockRegion& other) 85 | { 86 | return (find(m_lockedRegions.begin(), 87 | m_lockedRegions.end(), 88 | other) 89 | != m_lockedRegions.end()); 90 | } 91 | 92 | RecursiveProtector::LockRegion::LockRegion(uint id1, uint id2) : 93 | m_id1(id1), 94 | m_id2(id2) 95 | { 96 | } 97 | 98 | bool RecursiveProtector::LockRegion::operator == (const LockRegion& other) 99 | { 100 | return (m_id1 == other.m_id1) && (m_id2 == other.m_id2); 101 | } 102 | -------------------------------------------------------------------------------- /Source/XDK/xdkTrace.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * xdkTrace.cpp 34 | * 35 | * Implementation file for nt-ddk (XDK package). 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/except/exception.h" 41 | #include "xStl/os/lock.h" 42 | #include "XDK/kernel.h" 43 | #include "XDK/xdkTrace.h" 44 | 45 | cXdkTrace::cXdkTrace(uint queueQuata) : 46 | m_queueMaxSize(queueQuata), 47 | m_queueSize(0) 48 | { 49 | } 50 | 51 | void cXdkTrace::addMessage(const cString& message) 52 | { 53 | // Lock queue 54 | cLock lock(m_listMutex); 55 | 56 | // Test quata limits 57 | if (m_queueSize >= m_queueMaxSize) 58 | { 59 | XSTL_THROW(cException, EXCEPTION_OUT_OF_MEM); 60 | } 61 | 62 | // Ok to append. Adds. 63 | m_traceStrings.append(message); 64 | 65 | // Increase cache counter 66 | m_queueSize++; 67 | } 68 | 69 | bool cXdkTrace::getMessage(cString* outputString) 70 | { 71 | ASSERT(outputString != NULL); 72 | 73 | // Lock queue 74 | cLock lock(m_listMutex); 75 | 76 | // Polls the first element 77 | cList::iterator i = m_traceStrings.begin(); 78 | 79 | // Test whether the list is empty 80 | if (i == m_traceStrings.end()) 81 | { 82 | return false; 83 | } 84 | 85 | // Polls the element 86 | *outputString = *i; 87 | // And delete the position 88 | m_traceStrings.remove(i); 89 | m_queueSize--; 90 | 91 | // Successfully retrieve element 92 | return true; 93 | } 94 | 95 | uint cXdkTrace::getQueueMessageLength() 96 | { 97 | // Lock queue 98 | cLock lock(m_listMutex); 99 | // Polls the first element 100 | cList::iterator i = m_traceStrings.begin(); 101 | // Test whether the list is empty 102 | if (i == m_traceStrings.end()) 103 | { 104 | return 0; 105 | } 106 | return ((*i).length() + 1) * sizeof(character); 107 | } 108 | 109 | uint cXdkTrace::getMessageCount() 110 | { 111 | // This function cannot be thread-safe anyway. 112 | return m_queueSize; 113 | } 114 | -------------------------------------------------------------------------------- /samples/PCPlayer/driver/PcSpeakerCode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * PcSpeakerCode.cpp 34 | * 35 | * Custom server side implementation for the interface. 36 | * Don't forget to link this class to the device IOCTL handler code. 37 | * 38 | * Author: Elad Raz 39 | */ 40 | #include "xStl/types.h" 41 | #include "xStl/stream/traceStream.h" 42 | #include "driver/driverConsts.h" 43 | #include "driver/PcSpeakerServer.h" 44 | 45 | 46 | void cPcSpeakerServer::soundOn() 47 | { 48 | traceMedium("PcSpeakerServer: soundOn" << endl); 49 | 50 | // Activate PcSpekaer gate 51 | UCHAR speaker = READ_PORT_UCHAR(SPEAKER_PORT); 52 | WRITE_PORT_UCHAR(SPEAKER_PORT, speaker | SPEAKER_SIGNAL_BIT); 53 | } 54 | 55 | void cPcSpeakerServer::soundOff() 56 | { 57 | traceMedium("PcSpeakerServer: soundOff" << endl); 58 | 59 | // Turn off the PcSpekaer gate 60 | UCHAR speaker = READ_PORT_UCHAR(SPEAKER_PORT); 61 | WRITE_PORT_UCHAR(SPEAKER_PORT, speaker & (~SPEAKER_SIGNAL_BIT)); 62 | } 63 | 64 | void cPcSpeakerServer::setFrequency(uint32 frequency) 65 | { 66 | traceMedium("PcSpeakerServer: setFrequency " << frequency << "Hz" << endl); 67 | 68 | // Calculate the timer step over... 69 | if (frequency == 0) 70 | { 71 | traceHigh("PcSpeakerServer: setFrequency invalid frequency" << endl); 72 | return; 73 | } 74 | 75 | // Calculate new frequency 76 | uint32 stepOverCount = TIMER_FREQUENCY / frequency; 77 | 78 | // Change the frequency. 79 | WRITE_PORT_UCHAR(TIMER_PORT, TIMER_SPEAKER_COUNTER_S3); 80 | WRITE_PORT_UCHAR(TIMER_DATA_2, (UCHAR)((stepOverCount >> 0) & 0xFF)); // LSB first 81 | WRITE_PORT_UCHAR(TIMER_DATA_2, (UCHAR)((stepOverCount >> 8) & 0xFF)); 82 | } 83 | 84 | void cPcSpeakerServer::makeImpulse(uint32 counter) 85 | { 86 | // TODO: To decrease debug-print this line is in comment. 87 | // traceMedium("PcSpeakerServer: makeImpulse " << counter << endl); 88 | 89 | // Generate the impulse 90 | WRITE_PORT_UCHAR(TIMER_PORT, TIMER_SPEAKER_COUNTER_S0); 91 | WRITE_PORT_UCHAR(TIMER_DATA_2, (UCHAR)(counter & 0xFF)); // LSB first 92 | WRITE_PORT_UCHAR(TIMER_DATA_2, (UCHAR)((counter >> 8) & 0xFF)); 93 | } 94 | 95 | -------------------------------------------------------------------------------- /Source/XDK/ehlib/ehlibcpp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * ehlibpp.cpp 34 | * 35 | * Author: Elad Raz 36 | */ 37 | 38 | #include "xStl/types.h" 39 | #include "xStl/except/trace.h" 40 | #include "xStl/except/assert.h" 41 | #include "XDK/EHLib/ehlib.h" 42 | #include "XDK/EHLib/ehlibcpp.h" 43 | 44 | 45 | void __cdecl stackFaild() 46 | { 47 | #ifndef EHLIB_STATIC 48 | TRACE(TRACE_VERY_HIGH, XSTL_STRING("Stack failed!")); 49 | #endif // EHLIB_STATIC 50 | // Force a breakpoint 51 | #ifdef _KERNEL 52 | KdBreakPoint(); 53 | #else 54 | FatalExit(EHLib::EHLIB_EXCEPTION_CODE); 55 | #endif 56 | // Throw exception. Revert the stack to it's original state. 57 | XSTL_THROW(0); 58 | } 59 | 60 | EXTERNC __declspec(naked) void __cdecl _chkesp() 61 | { 62 | _asm { 63 | jnz error 64 | retn 65 | error: 66 | call stackFaild 67 | retn 68 | } 69 | } 70 | 71 | EXTERNC __declspec(naked) void __cdecl _EH_prolog() 72 | { 73 | _asm { 74 | push 0FFFFFFFFh ; // Try level. 75 | push eax ; // Exception handling vector 76 | mov eax, dword ptr fs:[0] 77 | push eax ; // Old stack handler 78 | mov eax, [esp+0Ch] 79 | mov dword ptr fs:[0], esp ; // Frame handler 80 | mov [esp+0Ch], ebp 81 | lea ebp, [esp+0Ch] 82 | push eax 83 | retn 84 | } 85 | } 86 | 87 | /* 88 | * This function is in remark since the kernel stack is limited in bytes. 89 | * See ehlibcpp.h for more information 90 | * 91 | EXTERNC __declspec(naked) void __cdecl _chkstk() 92 | { 93 | _asm { 94 | push ecx 95 | cmp eax, 1000h 96 | lea ecx, [esp+8] 97 | jb end 98 | 99 | next: 100 | sub ecx, 1000h 101 | sub eax, 1000h 102 | test [ecx], eax 103 | cmp eax, 1000h 104 | jnb next 105 | 106 | end: 107 | sub ecx, eax 108 | mov eax, esp 109 | test [ecx], eax 110 | mov esp, ecx 111 | mov ecx, [eax] 112 | mov eax, [eax+4] 113 | push eax 114 | retn 115 | } 116 | */ 117 | -------------------------------------------------------------------------------- /Include/XDK/xdkTrace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __XDK_TRACE_H 33 | #define __XDK_TRACE_H 34 | 35 | /* 36 | * xdkTrace.h 37 | * 38 | * Declare the cXdkTrace module which responisable to store trace messages 39 | * for the driver. Using this message-queue. The driver can 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/data/string.h" 45 | #include "xStl/data/list.h" 46 | #include "xdk/utils/interruptSpinLock.h" 47 | 48 | /* 49 | * The trace class is a storage for messages. 50 | * This class is a thread-safe. 51 | */ 52 | class cXdkTrace 53 | { 54 | public: 55 | // The maximum number of messages for default behaviour 56 | enum { MAX_QUEUE = 0xFFFFFFFF }; 57 | 58 | /* 59 | * Construct a new message queue 60 | * 61 | * queueQuata - The limit (total number of message) for the queue 62 | */ 63 | cXdkTrace(uint queueQuata = MAX_QUEUE); 64 | 65 | /* 66 | * Appends message to the queue. 67 | * 68 | * Throw exception if the queue is full. 69 | */ 70 | void addMessage(const cString& message); 71 | 72 | /* 73 | * Pools a message from the queue. 74 | * 75 | * outputString - Will be filled with the first waiting message. 76 | * 77 | * Return true if the message was pooled. False if no messages are waiting. 78 | */ 79 | bool getMessage(cString* outputString); 80 | 81 | /* 82 | * Returns the number of active messages in the queue. 83 | */ 84 | uint getMessageCount(); 85 | 86 | /* 87 | * Returns the number of bytes which are in used (including the NULL- 88 | * terminate character) for the queued pending line. 89 | * 0 when there aren't any messages waiting. 90 | */ 91 | uint getQueueMessageLength(); 92 | 93 | private: 94 | // The queue limits. 95 | uint m_queueMaxSize; 96 | // The queue synchrounzier 97 | cInterruptSpinLock m_listMutex; 98 | // The string storage queue 99 | cList m_traceStrings; 100 | // Cache value for queue size 101 | uint m_queueSize; 102 | }; 103 | 104 | #endif // __XDK_TRACE_H 105 | -------------------------------------------------------------------------------- /samples/PCPlayer/driver/PcSpeakerDevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_PCPLAYER_PCSPEAKERDEVICE_H 33 | #define __TBA_PCPLAYER_PCSPEAKERDEVICE_H 34 | 35 | /* 36 | * PcSpeakerDevice.h 37 | * 38 | * The major device-driver. Execute commands sends from ring3 in IOCTL 39 | * format. 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/data/smartPtr.h" 45 | #include "XDK/kernel.h" 46 | #include "XDK/device.h" 47 | #include "XDK/driver.h" 48 | #include "XDK/unicodeString.h" 49 | #include "XDK/utils/IoctlDispatcher.h" 50 | #include "common/PcSpeakerIoctl.h" 51 | 52 | /* 53 | * Creates a name device driver and attach the RPC IOCTL dispatcher to it. 54 | * All IOCTLs are handled and transfered to the stub codes. 55 | */ 56 | class PcSpeakerDevice : public cDevice { 57 | public: 58 | /* 59 | * Constructor. Creates the device-driver. Register the RPC server code 60 | * to the new ioctl-dispatcher. 61 | * 62 | * name - The name for the newly created device. 63 | * 64 | * Throw exception if there was an error generating the device. 65 | */ 66 | PcSpeakerDevice(const cString& name); 67 | 68 | /* 69 | * Destruct the device-driver. 70 | */ 71 | virtual ~PcSpeakerDevice(); 72 | 73 | /* 74 | * See cDevice::handleIrp. 75 | * 76 | * Handles the communication with the ring3 application 77 | */ 78 | virtual NTSTATUS handleIrp(PIRP irp); 79 | 80 | /* 81 | * See cDevice::getDeviceObject. 82 | */ 83 | virtual PDEVICE_OBJECT getDeviceObject() const; 84 | 85 | private: 86 | // The handle for this device driver 87 | PDEVICE_OBJECT m_device; 88 | 89 | // The IOCTL dispatcher. Execute the different RPC commands sends from 90 | // ring3 and dispatch them to ring0 code. 91 | cIoctlDispatcher m_ioctlDispatcher; 92 | 93 | // The RPC-server code 94 | cSmartPtr m_rpcServer; 95 | 96 | // The device names 97 | cUnicodeString m_deviceNtName; 98 | cUnicodeString m_deviceSymbolicName; 99 | }; 100 | 101 | #endif // __TBA_PCPLAYER_PCSPEAKERDEVICE_H 102 | 103 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/eflags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_EFLAGS_H 33 | #define __TBA_XDK_HOOKER_IA32_EFLAGS_H 34 | 35 | /* 36 | * eflags.h 37 | * 38 | * The content of the IA32 EFLAGS register 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | 44 | /* 45 | * See Intel System Programming manual, chapter 2 46 | * "SYSTEM FLAGS AND FIELDS IN THE EFLAGS REGISTER" 47 | */ 48 | typedef union { 49 | // The selector raw data 50 | uint32 m_value; 51 | // The flags bits 52 | struct { 53 | // First Byte 54 | // The CF 55 | unsigned m_carryFlag : 1; 56 | // Always 1 57 | unsigned m_reserved1 : 1; 58 | // TODO! 59 | unsigned pf : 1; 60 | // Always 0 61 | unsigned m_reserved2 : 1; 62 | // TODO! 63 | unsigned af : 1; 64 | // Always 0 65 | unsigned m_reserved3 : 1; 66 | // The ZF 67 | unsigned m_zeroFlag : 1; 68 | // TODO! 69 | unsigned sf : 1; 70 | 71 | // Second Byte 72 | // Set (1) to enable single-step operation 73 | unsigned m_trapFlag : 1; 74 | // 0 to mask-out all interrupts. 75 | unsigned m_interruptEnable : 1; 76 | // TODO! 77 | unsigned df : 1; 78 | // The OF 79 | unsigned m_overflowFlag : 1; 80 | // The IOPL 81 | unsigned m_iopl : 2; 82 | // The NT. 83 | unsigned m_nestedTask : 1; 84 | // Always 0 85 | unsigned m_reserved4 : 1; 86 | 87 | // Third Byte 88 | // The RF 89 | unsigned m_resumeFlag : 1; 90 | // The VM 91 | unsigned m_virtualMode : 1; 92 | // The AC 93 | unsigned m_alignmentCheck : 1; 94 | // The VIF 95 | unsigned m_virtualInterruptFlag : 1; 96 | // The VIP 97 | unsigned m_virtualInterruptPending : 1; 98 | // The ID 99 | unsigned m_identificationFlag : 1; 100 | // Reserved 101 | unsigned m_reserved : 10; 102 | } m_flags; 103 | } EFlags; 104 | 105 | #endif // __TBA_XDK_HOOKER_IA32_EFLAGS_H -------------------------------------------------------------------------------- /Include/XDK/driverFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_DRIVERFACTORY_H 33 | #define __TBA_XDK_DRIVERFACTORY_H 34 | 35 | /* 36 | * driverFactory.h 37 | * 38 | * The driver-factory is a class which instance driver-objects. The purpose of 39 | * this class is to generate driver object after all global objects constructed. 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/data/smartptr.h" 45 | #include "XDK/driver.h" 46 | 47 | /* 48 | * Used to remember the template object. Don't use this class. See 49 | * cDriverFactory for more information. 50 | */ 51 | class cPrivateDriverFactory { 52 | private: 53 | // Deny operator = and copy constructor. 54 | cPrivateDriverFactory(const cPrivateDriverFactory& other); 55 | cPrivateDriverFactory& operator = (const cPrivateDriverFactory& other); 56 | 57 | protected: 58 | friend class cXDKLibCPP; 59 | 60 | /* 61 | * Default private constructor. (EMPTY) 62 | */ 63 | cPrivateDriverFactory() {}; 64 | 65 | /* 66 | * Returns the instance to the global factory. 67 | */ 68 | static cPrivateDriverFactory& getInstance(); 69 | 70 | /* 71 | * Creates the main driver object. 72 | */ 73 | virtual cDriver& generateDriverObject() = 0; 74 | 75 | /// The main factory instance 76 | static cPrivateDriverFactory* m_driverFactory; 77 | }; 78 | 79 | /* 80 | * Register the factory inside a global list. 81 | */ 82 | template 83 | class cDriverFactory : public cPrivateDriverFactory { 84 | public: 85 | /* 86 | * Constructor. Register the driver. 87 | */ 88 | cDriverFactory() 89 | { 90 | ASSERT(m_driverFactory == NULL); 91 | if (m_driverFactory != NULL) 92 | { 93 | // There is an instance of the class! 94 | XSTL_THROW(cException, EXCEPTION_FAILED); 95 | } 96 | m_driverFactory = this; 97 | } 98 | 99 | protected: 100 | // Implements the driver creation using the template information 101 | virtual cDriver& generateDriverObject() 102 | { 103 | static T gDriverObject; 104 | return gDriverObject; 105 | } 106 | }; 107 | 108 | #endif // __TBA_XDK_DRIVERFACTORY_H 109 | -------------------------------------------------------------------------------- /tests/testMemoryManager/testMemoryManager/TestSmallMemoryHeapManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * TestSmallMemoryHeapManager.cpp 34 | * 35 | * Implementation file 36 | * 37 | * Author: Elad Raz 38 | */ 39 | #include "xStl/types.h" 40 | #include "xStl/data/char.h" 41 | #include "xStl/except/trace.h" 42 | #include "xStl/stream/iostream.h" 43 | #include "xStl/except/exception.h" 44 | #include "xdk/memory/SmallMemoryHeapManager.h" 45 | #include "TestSuperBlock.h" 46 | 47 | void simpleOverrunTest() 48 | { 49 | uint superblockLength = 16; // Allocate 2 units 50 | uint8* superblockBuffer = new uint8[superblockLength]; 51 | 52 | // Contains only 2 units 53 | SmallMemoryHeapManager newManager(superblockBuffer, 54 | superblockLength, 55 | 8); 56 | 57 | CHECK(newManager.allocate(0) == NULL); 58 | 59 | void* x = newManager.allocate(12); CHECK(x != NULL); 60 | CHECK(newManager.allocate(1) == NULL); 61 | CHECK(newManager.free(x)); 62 | 63 | x = newManager.allocate(4); CHECK(x != NULL); 64 | void* y = newManager.allocate(4); CHECK(y != NULL); 65 | CHECK(newManager.allocate(1) == NULL); 66 | CHECK(newManager.allocate(0) == NULL); 67 | CHECK(newManager.free(x)); 68 | x = newManager.allocate(1); CHECK(x != NULL); 69 | CHECK(newManager.allocate(4) == NULL); 70 | CHECK(newManager.free(x)); 71 | CHECK(newManager.free(y)); 72 | 73 | CHECK(newManager.allocate(17) == NULL); 74 | CHECK(newManager.allocate(16) == NULL); 75 | 76 | // Allocating two blocks here will decline since the memory is defragment. 77 | // TODO for future works 78 | } 79 | 80 | void simpleRandomTest() 81 | { 82 | uint superblockLength = 5*1024*1024; // Allocate 5mb 83 | uint8* superblockBuffer = new uint8[superblockLength]; 84 | 85 | SmallMemoryHeapManager newManager(superblockBuffer, 86 | superblockLength, 87 | 16); 88 | TestSuperBlock test(newManager, cout, 8, 12); 89 | test.test(); 90 | 91 | // And delete the block 92 | delete[] superblockBuffer; 93 | } 94 | 95 | void testSmallMemoryHeapManager() 96 | { 97 | simpleOverrunTest(); 98 | simpleRandomTest(); 99 | } 100 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/tss32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_TSS32_H 33 | #define __TBA_XDK_HOOKER_IA32_TSS32_H 34 | 35 | /* 36 | * tss32.h 37 | * 38 | * The content of the IA32 32 bit task state segment 39 | * 40 | * Author: Elad Raz 41 | */ 42 | #include "xStl/types.h" 43 | 44 | #pragma pack(push) 45 | #pragma pack(1) 46 | 47 | /* 48 | * The content of the IA32 32 bit task state segment 49 | */ 50 | struct TaskStateSegment32 { 51 | uint16 previousTaskLink; 52 | uint16 empty1; 53 | // SS0:ESP0 54 | uint32 ring0StackPointer; 55 | uint16 ring0StackSegment; 56 | uint16 empty2; 57 | // SS1:ESP1 58 | uint32 ring1StackPointer; 59 | uint16 ring1StackSegment; 60 | uint16 empty3; 61 | // SS2:ESP2 62 | uint32 ring2StackPointer; 63 | uint16 ring2StackSegment; 64 | uint16 empty4; 65 | uint32 cr3; 66 | uint32 eip; 67 | uint32 eflags; 68 | uint32 eax; 69 | uint32 ecx; 70 | uint32 edx; 71 | uint32 ebx; 72 | uint32 esp; 73 | uint32 ebp; 74 | uint32 esi; 75 | uint32 edi; 76 | uint16 es; 77 | uint16 empty5; // not in used 78 | uint16 cs; 79 | uint16 empty6; // not in used 80 | uint16 ss; 81 | uint16 empty7; // not in used 82 | uint16 ds; 83 | uint16 empty8; // not in used 84 | uint16 fs; 85 | uint16 empty9; // not in used 86 | uint16 gs; 87 | uint16 emptyA; // not in used 88 | uint16 ldt; 89 | uint16 emptyB; // not in used 90 | uint16 emptyC; // not in used 91 | uint16 ioMapBaseAddress; 92 | }; 93 | #pragma pack(pop) 94 | 95 | /* 96 | * Some useful function regarding to IA32 task register and task API. 97 | */ 98 | class TaskStateSegment { 99 | public: 100 | /* 101 | * Returns the based virtual memory location of the TSS32 segment inside 102 | * the GDT tables. 103 | * 104 | * selector - The GDT selector 105 | * 106 | * Throw exception if the selector is invalid. 107 | */ 108 | static TaskStateSegment32* getTSS32(uint16 selector); 109 | 110 | /* 111 | * Returns the current selector of the task-register 112 | */ 113 | static uint16 getTaskRegister(); 114 | }; 115 | 116 | #endif // __TBA_XDK_HOOKER_IA32_TSS32_H -------------------------------------------------------------------------------- /tests/XDKtestExecutor/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * test.cpp 34 | * 35 | * The main enrty point for the testing utility. 36 | * The application bring up the test-driver and perform the uni-testing 37 | * for the driver. 38 | * 39 | * Author: Elad Raz 40 | */ 41 | #include "xStl/types.h" 42 | #include "xStl/stream/iostream.h" 43 | #include "xStl/os/osdef.h" 44 | #include "loader/loader.h" 45 | #include "loader/deviceException.h" 46 | #include "loader/console/consolePooler.h" 47 | #include "../const.h" 48 | 49 | /* 50 | * The path for the device-driver 51 | */ 52 | static const character PATHNAME[] = XSTL_STRING("c:\\temp\\xdk_test.sys"); 53 | 54 | /* 55 | * Perform the testing and printing the result. The function performs the 56 | * following: 57 | * 1. Load the device-driver. 58 | * 2. During the loading of the device the testing will be run at ring0. 59 | * 3. Query the status of the driver and print the result to the console. 60 | * 4. Unload the device-driver. 61 | */ 62 | int main(const unsigned int argc, const char** argv) 63 | { 64 | XSTL_TRY 65 | { 66 | cout << "Welcome for T.B.A. XDK testing utility" << endl; 67 | cout << "(C) Elad Raz T.B.A." << endl << endl; 68 | cout << "Load testing driver..." << endl; 69 | 70 | XSTL_TRY 71 | { 72 | // Open the cout device 73 | cConsolePooler deviceCout(XDKConsts::CON_DEVICENAME, PATHNAME); 74 | 75 | // Pools all messages 76 | while (deviceCout.isStringPending()) 77 | { 78 | cout << deviceCout.poolString(); 79 | } 80 | 81 | // Terminate device 82 | cout << endl << endl << endl << "Testing completed." << endl; 83 | return RC_OK; 84 | } 85 | XSTL_CATCH (cDeviceException& e) 86 | { 87 | cout << "Exception: An exception occured during device loading: " 88 | << e.getMessage() << endl; 89 | return RC_ERROR; 90 | } 91 | } 92 | XSTL_CATCH(cException& e) 93 | { 94 | cout << "Exception: Exception throw from main: " << e.getMessage() << endl; 95 | return RC_ERROR; 96 | } 97 | XSTL_CATCH(...) 98 | { 99 | cout << "Exception: Unknown exception" << endl; 100 | return RC_ERROR; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Include/XDK/hooker/Processors/ia32/PageTable/Win32PageTable386.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | #ifndef __TBA_XDK_HOOKER_IA32_PAGETABLE_WIN32PAGETABLE386_H 33 | #define __TBA_XDK_HOOKER_IA32_PAGETABLE_WIN32PAGETABLE386_H 34 | 35 | /* 36 | * Win32PageTable386.h 37 | * 38 | * Functions which are used inside Windows 32bit operating system and supports 39 | * page-table operation. 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/stream/stringerStream.h" 45 | #include "xdk/hooker/Processors/ia32/PageTable/PageTable386.h" 46 | 47 | /* 48 | * Windows saves the current memory map (e.g. CR3 pyshical memory mapping) into 49 | * address 0xC0000000. This core module extents the normal operating behaviour 50 | * by allowing ring0 utilities to manage this core area. 51 | * 52 | * NOTE: Use extreme cautions when manipulates this data. 53 | */ 54 | class Win32PageTable386 { 55 | public: 56 | /* 57 | * Return the page-directory entry reference 58 | */ 59 | static GlobalPage* getPageDirectory(void* linearAddress); 60 | 61 | /* 62 | * Reads the PDE and try to access to the PTE for the linear-address. 63 | * 64 | * Throw exception if the page is 4MB page. 65 | * Note: To access the attributes of a linear-address use the getPageEntry() 66 | * function. 67 | */ 68 | static GlobalPage* getPageTableEntry(void* linearAddress); 69 | 70 | /* 71 | * Return the page descriptor which represent the 'linearAddress'. This page 72 | * can be either PTE or PDE. 73 | */ 74 | static GlobalPage* getPageEntry(void* linearAddress); 75 | 76 | #ifdef COMMON_DUMP 77 | /* 78 | * Dump a page to a human readable stream. 79 | * 80 | * pageContent - The content of the page 81 | * out - The stream to write the data to. 82 | */ 83 | static void dumpPage(GlobalPage pageContent, 84 | cStringerStream& out); 85 | #endif 86 | 87 | private: 88 | // The virtual address for the page- 89 | static const uint32 PagesVirtualAddress; 90 | static const uint32 PagesDirectoryVirtualAddress; 91 | 92 | // The array of all PDE's 93 | static GlobalPage* m_pdeArray; 94 | 95 | // The array of all PTE's 96 | static GlobalPage* m_pteArray; 97 | }; 98 | 99 | #endif // __TBA_XDK_HOOKER_IA32_PAGETABLE_WIN32PAGETABLE386_H 100 | -------------------------------------------------------------------------------- /Source/XDK/atexit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2016, Integrity Project Ltd. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the Integrity Project nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE 30 | */ 31 | 32 | /* 33 | * atexit.cpp 34 | * 35 | * Since I can't find a single discent "LIBC" for the kernel. 36 | * I will have to implement the "atexit" function. The atexit 37 | * function should able to register functions and call them 38 | * when the Driver will terminate - When the Unload function 39 | * calls. 40 | * 41 | * Author: Elad Raz 42 | */ 43 | #include "xStl/types.h" 44 | #include "xStl/data/list.h" 45 | #include "xStl/data/datastream.h" 46 | #include "xStl/except/trace.h" 47 | #include "xStl/except/assert.h" 48 | #include "xStl/except/exception.h" 49 | #include "xStl/os/mutex.h" 50 | #include "xStl/os/lock.h" 51 | #include "XDK/kernel.h" 52 | #include "XDK/atexit.h" 53 | 54 | /// Inits the singleton 55 | cAtExit* cAtExit::m_instance = NULL; 56 | 57 | void cAtExit::init() 58 | { 59 | CHECK(m_instance == NULL); 60 | m_instance = new cAtExit(); 61 | } 62 | 63 | void cAtExit::exit() 64 | { 65 | // Destruct objects 66 | getInstance().destroyObjects(); 67 | // Free memory 68 | delete m_instance; 69 | m_instance = NULL; 70 | } 71 | 72 | cAtExit& cAtExit::getInstance() 73 | { 74 | if (m_instance == NULL) 75 | { 76 | // Throw exception 77 | XSTL_THROW(cException, EXCEPTION_FAILED); 78 | } 79 | return *m_instance; 80 | } 81 | 82 | 83 | void cAtExit::addFunction(ATEXITFUNC newFunction) 84 | { 85 | cLock lock(m_atExitProtector); 86 | m_atExitList.insert(newFunction); 87 | } 88 | 89 | void cAtExit::destroyObjects() 90 | { 91 | // Keep the IRQL level for the constructed object at PASSIVE_LEVEL 92 | cList list; 93 | copyAtexitObjects(list); 94 | 95 | for (cList::iterator i = list.begin(); 96 | i != list.end(); 97 | i++) 98 | { 99 | // Safe call to the destructor. 100 | XSTL_TRY 101 | { 102 | (*i)(); 103 | } 104 | XSTL_CATCH_ALL 105 | { 106 | TRACE(TRACE_VERY_HIGH, "ATEXIT: Destructor throw exception!"); 107 | } 108 | } 109 | } 110 | 111 | void cAtExit::copyAtexitObjects(cList& list) 112 | { 113 | cLock lock(m_atExitProtector); 114 | list = m_atExitList; 115 | } 116 | 117 | int __cdecl atexit(void (__cdecl *function)(void)) 118 | { 119 | cAtExit::getInstance().addFunction(function); 120 | return true; 121 | } 122 | --------------------------------------------------------------------------------