├── .gitignore ├── COPYING ├── Makefile ├── README ├── procfs.cc ├── procfs.plist ├── procfs_displays.cc ├── procfs_displays.h ├── procfs_proc_info.cc ├── procfs_proc_info.h ├── procfs_tpm.cc ├── procfs_tpm.h ├── procfs_windows.cc ├── procfs_windows.h └── sequencegrab ├── CSGCamera.h ├── CSGCamera.m ├── CSGImage.h ├── CSGImage.m ├── CocoaSequenceGrabber.h ├── Makefile ├── procfs_sequencegrab.h └── procfs_sequencegrab.mm /.gitignore: -------------------------------------------------------------------------------- 1 | *.dSYM/ 2 | *.a 3 | *.dylib 4 | *.o 5 | 6 | .DS_Store 7 | procfs 8 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # procfs as a OSXFUSE file system for Mac OS X 2 | # 3 | # Copyright 2007 Amit Singh (osxbook.com). All Rights Reserved. 4 | 5 | CC ?= gcc 6 | CXX ?= g++ 7 | 8 | CFLAGS_OSXFUSE=-D_FILE_OFFSET_BITS=64 -Wall -O -I/usr/local/include/osxfuse -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk 9 | CFLAGS :=$(CFLAGS_OSXFUSE) $(CFLAGS) 10 | CXXFLAGS:=$(CFLAGS_OSXFUSE) $(CXXFLAGS) 11 | LDFLAGS=-L/usr/local/lib -losxfuse -framework Carbon -framework IOKit -framework ApplicationServices -framework Accelerate -framework OpenGL -weak-lproc 12 | SEQUENCEGRAB_LDFLAGS=-framework AudioUnit -framework Cocoa -framework CoreAudioKit -framework Foundation -framework QuartzCore -framework QuickTime -framework QuartzCore 13 | 14 | # Configure this depending on where you installed pcrecpp 15 | # http://www.pcre.org 16 | # 17 | PCRECPP_PREFIX=$(shell pcre-config --prefix) 18 | 19 | PCRECPP_CXXFLAGS=-I$(PCRECPP_PREFIX)/include 20 | PCRECPP_LDFLAGS=-arch x86_64 $(PCRECPP_PREFIX)/lib/libpcrecpp.a $(PCRECPP_PREFIX)/lib/libpcre.a 21 | 22 | all: procfs 23 | 24 | procfs.o: procfs.cc 25 | $(CXX) -c $(CXXFLAGS) $(PCRECPP_CXXFLAGS) -o $@ $< 26 | 27 | procfs_displays.o: procfs_displays.cc procfs_displays.h 28 | $(CXX) -c $(CXXFLAGS) -o $@ $< 29 | 30 | procfs_proc_info.o: procfs_proc_info.cc procfs_proc_info.h 31 | $(CXX) -c $(CXXFLAGS) -o $@ $< 32 | 33 | procfs_tpm.o: procfs_tpm.cc procfs_tpm.h 34 | $(CXX) -c $(CXXFLAGS) -o $@ $< 35 | 36 | procfs_windows.o: procfs_windows.cc procfs_windows.h 37 | $(CXX) -c $(CXXFLAGS) -o $@ $< 38 | 39 | procfs: procfs.o procfs_displays.o procfs_proc_info.o procfs_tpm.o procfs_windows.o 40 | $(CXX) $(CXXFLAGS) $(PCRECPP_CXXFLAGS) -o $@ $^ $(LDFLAGS) $(PCRECPP_LDFLAGS) 41 | 42 | sequencegrab/libprocfs_sequencegrab.a: 43 | $(MAKE) -C sequencegrab 44 | 45 | install: procfs 46 | sudo chown root:wheel procfs 47 | sudo chmod u+s procfs 48 | sudo mv procfs /usr/local/bin/procfs 49 | 50 | clean: 51 | rm -f procfs procfs.o procfs_displays.o procfs_proc_info.o procfs_tpm.o procfs_windows.o 52 | $(MAKE) -C sequencegrab clean 53 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | System Requirements 2 | =================== 3 | 4 | * Mac OS X 10.5+ (10.4 is no longer supported) 5 | 6 | * pcre (specifically, the C++ wrapper for pcre) 7 | 8 | ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 9 | 10 | Usage 11 | ===== 12 | 13 | You can mount procfs as: 14 | 15 | $ sudo mkdir /proc 16 | $ sudo chown root:admin /proc 17 | $ sudo ./procfs /proc -f 18 | 19 | For certain things to work (and not crash procfs), you must either run 20 | procfs foregrounded (through the -f option), or use the procfs.plist 21 | file to run procfs through launchd. 22 | -------------------------------------------------------------------------------- /procfs.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.osxbook.procfs 7 | ProgramArguments 8 | 9 | /usr/local/bin/procfs 10 | /proc 11 | -f 12 | 13 | KeepAlive 14 | 15 | UserName 16 | root 17 | WorkingDirectory 18 | / 19 | 20 | 21 | -------------------------------------------------------------------------------- /procfs_displays.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * MacFUSE-Based procfs 3 | * Display Files 4 | * 5 | * Thanks to Daniel Waylonis for image processing code. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | extern "C" { 15 | 16 | #include "procfs_displays.h" 17 | 18 | #define MAX_DISPLAYS 8 19 | 20 | static CGLContextObj CreateScreenGLContext(CGDirectDisplayID targetDisplay); 21 | static void ReleaseScreenGLContext(CGLContextObj context); 22 | static void CaptureScreenRectToBuffer(CGRect srcRect, vImage_Buffer *buffer); 23 | static void *CreateFullScreenXRGB32(CGDirectDisplayID targetDisplay, 24 | int *width, int *height, int *rowBytes); 25 | static CFMutableDataRef CreatePNGDataFromXRGB32Raster(void *raster, 26 | int width, int height, 27 | int bytesPerRow); 28 | 29 | static CGLContextObj 30 | CreateScreenGLContext(CGDirectDisplayID targetDisplay) 31 | { 32 | CGOpenGLDisplayMask displayMask; 33 | CGLPixelFormatObj pixelFormatObj; 34 | GLint numPixelFormats; 35 | 36 | displayMask = CGDisplayIDToOpenGLDisplayMask(targetDisplay); 37 | 38 | CGLPixelFormatAttribute attribs[] = { 39 | kCGLPFAFullScreen, 40 | kCGLPFADisplayMask, 41 | (CGLPixelFormatAttribute)displayMask, 42 | (CGLPixelFormatAttribute)NULL 43 | }; 44 | 45 | CGLContextObj context = NULL; 46 | 47 | /* Build a full-screen GL context */ 48 | 49 | CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats); 50 | CGLCreateContext(pixelFormatObj, NULL, &context); 51 | CGLDestroyPixelFormat(pixelFormatObj); 52 | CGLSetCurrentContext(context); 53 | CGLSetFullScreen(context); 54 | 55 | return context; 56 | } 57 | 58 | static void 59 | ReleaseScreenGLContext(CGLContextObj context) 60 | { 61 | CGLSetCurrentContext(NULL); 62 | CGLClearDrawable(context); 63 | CGLDestroyContext(context); 64 | } 65 | 66 | static void 67 | CaptureScreenRectToBuffer(CGRect srcRect, vImage_Buffer *buffer) 68 | { 69 | /* Configure data packing and alignment for store operation. */ 70 | /* 4-byte-aligned pixels packed. */ 71 | 72 | glPixelStorei(GL_PACK_ALIGNMENT, 4); 73 | glPixelStorei(GL_PACK_ROW_LENGTH, buffer->rowBytes / 4); 74 | glPixelStorei(GL_PACK_SKIP_ROWS, 0); 75 | glPixelStorei(GL_PACK_SKIP_PIXELS, 0); 76 | 77 | #if __BIG_ENDIAN__ 78 | GLenum pixelDataType = GL_UNSIGNED_INT_8_8_8_8_REV; 79 | #else 80 | GLenum pixelDataType = GL_UNSIGNED_INT_8_8_8_8; 81 | #endif /* __BIG_ENDIAN__ */ 82 | 83 | /* 84 | * Fetch data in XRGB format to our buffer (no alpha needed because we are 85 | * reading from the framebuffer, which has no alpha). 86 | */ 87 | 88 | glReadPixels((GLint)srcRect.origin.x, (GLint)srcRect.origin.y, 89 | (GLint)srcRect.size.width, (GLint)srcRect.size.height, 90 | GL_BGRA, pixelDataType, buffer->data); 91 | 92 | /* 93 | * Vertically reflect in place (OpenGL uses inverted coordinate space, 94 | * so the image is upside down in memory with respect to what we want. 95 | */ 96 | vImageVerticalReflect_ARGB8888(buffer, buffer, kvImageNoFlags); 97 | } 98 | 99 | static void * 100 | CreateFullScreenXRGB32(CGDirectDisplayID targetDisplay, 101 | int *width, int *height, int *rowBytes) 102 | { 103 | GLint viewport[4]; 104 | long bytes; 105 | void *raster = NULL; 106 | 107 | CGLContextObj context = CreateScreenGLContext(targetDisplay); 108 | CGLSetCurrentContext(context); 109 | glReadBuffer(GL_FRONT); 110 | glGetIntegerv(GL_VIEWPORT, viewport); 111 | glFinish(); 112 | 113 | *width = viewport[2]; 114 | *height = viewport[3]; 115 | *rowBytes = (((*width) * 4) + 3) & ~3; 116 | bytes = (*rowBytes) * (*height); 117 | 118 | raster = malloc(bytes); 119 | if (!raster) { 120 | goto out; 121 | } 122 | 123 | vImage_Buffer buffer; 124 | buffer.data = raster; 125 | buffer.height = *height; 126 | buffer.width = *width; 127 | buffer.rowBytes = *rowBytes; 128 | 129 | CaptureScreenRectToBuffer(CGRectMake(0, 0, *width, *height), &buffer); 130 | 131 | out: 132 | ReleaseScreenGLContext(context); 133 | 134 | return raster; 135 | } 136 | 137 | static CFMutableDataRef 138 | CreatePNGDataFromXRGB32Raster(void *raster, int width, int height, 139 | int bytesPerRow) 140 | { 141 | CGColorSpaceRef colorSpace; 142 | CGContextRef context; 143 | CGImageRef image = NULL; 144 | 145 | colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 146 | context = CGBitmapContextCreate(raster, width, height, 8, bytesPerRow, 147 | colorSpace, kCGImageAlphaNoneSkipFirst); 148 | CGColorSpaceRelease(colorSpace); 149 | 150 | if (context) { 151 | image = CGBitmapContextCreateImage(context); 152 | CGContextRelease(context); 153 | } 154 | 155 | if (!image) { 156 | return NULL; 157 | } 158 | 159 | CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0); 160 | CGImageDestinationRef dest = 161 | CGImageDestinationCreateWithData((CFMutableDataRef)data, kUTTypePNG, 162 | 1, nil); 163 | 164 | if (dest) { 165 | CGImageDestinationAddImage(dest, image, nil); 166 | CGImageDestinationFinalize(dest); 167 | CFRelease(dest); 168 | } 169 | 170 | CGImageRelease(image); 171 | 172 | return data; 173 | } 174 | 175 | static CGDirectDisplayID 176 | PROCFS_GetDisplayIDForDisplayAtIndex(unsigned int index) 177 | { 178 | CGDisplayErr dErr; 179 | CGDisplayCount displayCount; 180 | CGDisplayCount maxDisplays = MAX_DISPLAYS; 181 | CGDirectDisplayID onlineDisplays[MAX_DISPLAYS]; 182 | 183 | dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount); 184 | 185 | if (dErr != kCGErrorSuccess) { 186 | displayCount = 0; 187 | } 188 | 189 | if (index > (displayCount - 1)) { 190 | return 0; 191 | } 192 | 193 | return onlineDisplays[index]; 194 | } 195 | 196 | CGDisplayCount 197 | PROCFS_GetDisplayCount(void) 198 | { 199 | CGDisplayErr dErr; 200 | CGDisplayCount displayCount; 201 | CGDisplayCount maxDisplays = MAX_DISPLAYS; 202 | CGDirectDisplayID onlineDisplays[MAX_DISPLAYS]; 203 | 204 | dErr = CGGetOnlineDisplayList(maxDisplays, onlineDisplays, &displayCount); 205 | 206 | if (dErr != kCGErrorSuccess) { 207 | displayCount = 0; 208 | } 209 | 210 | return displayCount; 211 | } 212 | 213 | int 214 | PROCFS_GetInfoForDisplayAtIndex(unsigned int index, char *buf, size_t *size) 215 | { 216 | CGDirectDisplayID d = PROCFS_GetDisplayIDForDisplayAtIndex(index); 217 | size_t insize = *size; 218 | 219 | if (d == 0) { 220 | return -1; 221 | } 222 | 223 | size_t acc = 0; 224 | 225 | acc += snprintf(buf + acc, insize - acc, "%-20s%ldx%ld\n", "resolution", 226 | CGDisplayPixelsWide(d), CGDisplayPixelsHigh(d)); 227 | acc += snprintf(buf + acc, insize - acc, "%-20s%p\n", "base address", 228 | CGDisplayBaseAddress(d)); 229 | acc += snprintf(buf + acc, insize - acc, "%-20s%ld\n", "bits per pixel", 230 | CGDisplayBitsPerPixel(d)); 231 | acc += snprintf(buf + acc, insize - acc, "%-20s%ld\n", "bits per sample", 232 | CGDisplayBitsPerSample(d)); 233 | acc += snprintf(buf + acc, insize - acc, "%-20s%ld\n", "samples per pixel", 234 | CGDisplaySamplesPerPixel(d)); 235 | acc += snprintf(buf + acc, insize - acc, "%-20s%ld\n", "bytes per row", 236 | CGDisplayBytesPerRow(d)); 237 | acc += snprintf(buf + acc, insize - acc, "%-20s%s\n", "main display", 238 | CGDisplayIsMain(d) ? "yes" : "no"); 239 | acc += snprintf(buf + acc, insize - acc, "%-20s%s\n", "builtin display", 240 | CGDisplayIsBuiltin(d) ? "yes" : "no"); 241 | acc += snprintf(buf + acc, insize - acc, "%-20s%s\n", "OpenGL acceleration", 242 | CGDisplayUsesOpenGLAcceleration(d) ? "yes" : "no"); 243 | acc += snprintf(buf + acc, insize - acc, "%-20s%08x\n", "model number", 244 | CGDisplayModelNumber(d)); 245 | acc += snprintf(buf + acc, insize - acc, "%-20s%08x\n", "serial number", 246 | CGDisplaySerialNumber(d)); 247 | acc += snprintf(buf + acc, insize - acc, "%-20s%08x\n", "unit number", 248 | CGDisplayUnitNumber(d)); 249 | acc += snprintf(buf + acc, insize - acc, "%-20s%08x\n", "vendor number", 250 | CGDisplayVendorNumber(d)); 251 | 252 | *size = acc; 253 | 254 | return 0; 255 | } 256 | 257 | off_t 258 | PROCFS_GetPNGSizeForDisplayAtIndex(unsigned int index) 259 | { 260 | CGDirectDisplayID targetDisplay = 261 | PROCFS_GetDisplayIDForDisplayAtIndex(index); 262 | 263 | if (targetDisplay == 0) { 264 | return (off_t)0; 265 | } 266 | 267 | off_t size = ((off_t)CGDisplayPixelsWide(targetDisplay) * 268 | (off_t)CGDisplayPixelsHigh(targetDisplay) * 269 | (off_t)3) + (off_t)8192; 270 | 271 | return size; 272 | } 273 | 274 | int 275 | PROCFS_GetPNGForDisplayAtIndex(unsigned int index, CFMutableDataRef *data) 276 | { 277 | CGDirectDisplayID targetDisplay = 278 | PROCFS_GetDisplayIDForDisplayAtIndex(index); 279 | 280 | *data = (CFMutableDataRef)0; 281 | 282 | if (targetDisplay == 0) { 283 | return -1; 284 | } 285 | 286 | void *raster = NULL; 287 | int width, height, rowBytes; 288 | 289 | raster = CreateFullScreenXRGB32(targetDisplay, &width, &height, &rowBytes); 290 | if (!raster) { 291 | return -1; 292 | } 293 | 294 | *data = CreatePNGDataFromXRGB32Raster(raster, width, height, rowBytes); 295 | 296 | free(raster); 297 | 298 | if (!*data) { 299 | return -1; 300 | } 301 | 302 | return 0; 303 | } 304 | 305 | } /* extern "C" */ 306 | -------------------------------------------------------------------------------- /procfs_displays.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MacFUSE-Based procfs 3 | */ 4 | 5 | #ifndef _PROCFS_DISPLAYS_H_ 6 | #define _PROCFS_DISPLAYS_H_ 7 | 8 | #include 9 | #include 10 | 11 | extern "C" { 12 | 13 | CGDisplayCount PROCFS_GetDisplayCount(void); 14 | int PROCFS_GetInfoForDisplayAtIndex(unsigned int index, char *buf, 15 | size_t *size); 16 | int PROCFS_GetPNGForDisplayAtIndex(unsigned int index, CFMutableDataRef *data); 17 | off_t PROCFS_GetPNGSizeForDisplayAtIndex(unsigned int index); 18 | 19 | /* Declare deprecated functions */ 20 | void * CGDisplayBaseAddress ( CGDirectDisplayID display ); 21 | size_t CGDisplayBitsPerPixel ( CGDirectDisplayID display ); 22 | size_t CGDisplayBitsPerSample ( CGDirectDisplayID display ); 23 | size_t CGDisplaySamplesPerPixel ( CGDirectDisplayID display ); 24 | size_t CGDisplayBytesPerRow ( CGDirectDisplayID display ); 25 | 26 | } /* extern "C" */ 27 | 28 | #endif /* _PROCFS_DISPLAYS_H_ */ 29 | -------------------------------------------------------------------------------- /procfs_proc_info.cc: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | 3 | #if __i386__ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "procfs_proc_info.h" 16 | 17 | enum { 18 | PROC_INFO_LISTPIDS = 1, 19 | PROC_INFO_PIDINFO = 2, 20 | PROC_INFO_PIDFDINFO = 3, 21 | PROC_INFO_KERNMSGBUF = 4, 22 | }; 23 | 24 | extern int proc_pidinfo(int32_t pid, uint32_t flavor, uint64_t arg, 25 | caddr_t buffer, int32_t buffersize); 26 | extern int proc_pidfdinfo(int32_t pid, uint32_t flavor, uint32_t arg, 27 | caddr_t buffer, int32_t buffersize); 28 | 29 | static const char * 30 | fd_type_string(uint32_t proc_fdtype) 31 | { 32 | switch (proc_fdtype) { 33 | 34 | case PROX_FDTYPE_ATALK: 35 | return "AppleTalk"; 36 | break; 37 | 38 | case PROX_FDTYPE_VNODE: 39 | return "vnode"; 40 | break; 41 | 42 | case PROX_FDTYPE_SOCKET: 43 | return "socket"; 44 | break; 45 | 46 | case PROX_FDTYPE_PSHM: 47 | return "POSIX shm"; 48 | break; 49 | 50 | case PROX_FDTYPE_PSEM: 51 | return "POSIX sem"; 52 | break; 53 | 54 | case PROX_FDTYPE_KQUEUE: 55 | return "kqueue"; 56 | break; 57 | 58 | case PROX_FDTYPE_PIPE: 59 | return "pipe"; 60 | break; 61 | 62 | case PROX_FDTYPE_FSEVENTS: 63 | return "fsevents"; 64 | break; 65 | 66 | default: 67 | return "unknown descriptor type"; 68 | break; 69 | } 70 | 71 | /* NOTREACHED */ 72 | 73 | return "UNKNOWN"; 74 | } 75 | 76 | static const char *socket_families[] = { 77 | "AF_UNSPEC", 78 | "AF_UNIX", 79 | "AF_INET", 80 | "AF_IMPLINK", 81 | "AF_PUP", 82 | "AF_CHAOS", 83 | "AF_NS", 84 | "AF_ISO", 85 | "AF_ECMA", 86 | "AF_DATAKIT", 87 | "AF_CCITT", 88 | "AF_SNA", 89 | "AF_DECnet", 90 | "AF_DLI", 91 | "AF_LAT", 92 | "AF_HYLINK", 93 | "AF_APPLETALK", 94 | "AF_ROUTE", 95 | "AF_LINK", 96 | "#define", 97 | "AF_COIP", 98 | "AF_CNT", 99 | "pseudo_AF_RTIP", 100 | "AF_IPX", 101 | "AF_SIP", 102 | "pseudo_AF_PIP", 103 | "pseudo_AF_BLUE", 104 | "AF_NDRV", 105 | "AF_ISDN", 106 | "pseudo_AF_KEY", 107 | "AF_INET6", 108 | "AF_NATM", 109 | "AF_SYSTEM", 110 | "AF_NETBIOS", 111 | "AF_PPP", 112 | "pseudo_AF_HDRCMPLT", 113 | "AF_RESERVED_36", 114 | }; 115 | #define SOCKET_FAMILY_MAX (int)(sizeof(socket_families)/sizeof(char *)) 116 | 117 | static const char * 118 | socket_family_string(int soi_family) 119 | { 120 | if ((soi_family < 0) || (soi_family >= SOCKET_FAMILY_MAX)) { 121 | return "unknown socket family"; 122 | } 123 | 124 | return socket_families[soi_family]; 125 | } 126 | 127 | static const char * 128 | socket_type_string(int soi_type) 129 | { 130 | switch (soi_type) { 131 | 132 | case SOCK_STREAM: 133 | return "SOCK_STREAM"; 134 | break; 135 | 136 | case SOCK_DGRAM: 137 | return "SOCK_DGRAM"; 138 | break; 139 | 140 | case SOCK_RAW: 141 | return "SOCK_RAW"; 142 | break; 143 | 144 | case SOCK_RDM: 145 | return "SOCK_RDM"; 146 | break; 147 | 148 | case SOCK_SEQPACKET: 149 | return "SOCK_SEQPACKET"; 150 | break; 151 | } 152 | 153 | /* NOTREACHED */ 154 | 155 | return "unknown socket type"; 156 | } 157 | 158 | int 159 | procfs_proc_pidinfo(pid_t pid, char *buf, int *len) 160 | { 161 | int ret; 162 | int orig_len = *len; 163 | int used_len = 0; 164 | 165 | ret = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0); 166 | if (ret == -1) { 167 | return -1; 168 | } 169 | 170 | size_t buffersize = (size_t)ret; 171 | 172 | char *buffer = (char *)malloc((size_t)buffersize); 173 | if (!buffer) { 174 | return -1; 175 | } 176 | 177 | ret = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, buffer, 178 | (size_t)buffersize); 179 | 180 | struct proc_fdinfo *infop; 181 | int nfd = ret / sizeof(struct proc_fdinfo); 182 | infop = (struct proc_fdinfo *)buffer; 183 | 184 | int i; 185 | 186 | for (i = 0; i < nfd; i++) { 187 | 188 | if (used_len >= orig_len) { 189 | goto out; 190 | } 191 | 192 | used_len += snprintf(buf + used_len, orig_len - used_len, 193 | "%-4d %-10s ", infop[i].proc_fd, 194 | fd_type_string(infop[i].proc_fdtype)); 195 | 196 | switch (infop[i].proc_fdtype) { 197 | 198 | case PROX_FDTYPE_ATALK: 199 | case PROX_FDTYPE_FSEVENTS: 200 | case PROX_FDTYPE_KQUEUE: 201 | case PROX_FDTYPE_PIPE: 202 | if (used_len >= orig_len) { 203 | goto out; 204 | } 205 | used_len += snprintf(buf + used_len, orig_len - used_len, "\n"); 206 | break; 207 | 208 | case PROX_FDTYPE_PSEM: 209 | { 210 | int nb; 211 | struct psem_fdinfo ps; 212 | if (used_len >= orig_len) { 213 | goto out; 214 | } 215 | nb = proc_pidinfo(pid, infop[i].proc_fd, PROC_PIDFDPSEMINFO, 216 | (char *)&ps, sizeof(ps)); 217 | if (nb <= 0) { 218 | used_len += snprintf(buf + used_len, orig_len - used_len, "\n"); 219 | } else if ((unsigned int)nb < sizeof(ps)) { 220 | used_len += snprintf(buf + used_len, orig_len - used_len, 221 | "(%s)\n", "incomplete info"); 222 | } else { 223 | if (ps.pseminfo.psem_name[0]) { 224 | used_len += snprintf(buf + used_len, orig_len - used_len, 225 | "%s\n", ps.pseminfo.psem_name); 226 | } else { 227 | used_len += snprintf(buf + used_len, orig_len - used_len, 228 | "\n"); 229 | } 230 | } 231 | break; 232 | } 233 | 234 | case PROX_FDTYPE_PSHM: 235 | { 236 | int nb; 237 | struct pshm_fdinfo ps; 238 | if (used_len >= orig_len) { 239 | goto out; 240 | } 241 | nb = proc_pidinfo(pid, infop[i].proc_fd, PROC_PIDFDPSHMINFO, 242 | (char *)&ps, sizeof(ps)); 243 | if (nb <= 0) { 244 | used_len += snprintf(buf + used_len, orig_len - used_len, "\n"); 245 | } else if ((unsigned int)nb < sizeof(ps)) { 246 | used_len += snprintf(buf + used_len, orig_len - used_len, 247 | "(%s)\n", "incomplete info"); 248 | } else { 249 | if (ps.pshminfo.pshm_name[0]) { 250 | ps.pshminfo.pshm_name[sizeof(ps.pshminfo.pshm_name) - 1] = '\0'; 251 | used_len += snprintf(buf + used_len, orig_len - used_len, 252 | "%s\n", ps.pshminfo.pshm_name); 253 | } else if (ps.pshminfo.pshm_mappaddr) { 254 | /* ick */ 255 | #define CAST_DOWN(type, addr) (((type)((uintptr_t)(addr)))) 256 | used_len += snprintf(buf + used_len, orig_len - used_len, 257 | "obj=%p\n", 258 | CAST_DOWN(void *, ps.pshminfo.pshm_mappaddr)); 259 | } else { 260 | used_len += snprintf(buf + used_len, orig_len - used_len, 261 | "\n"); 262 | } 263 | } 264 | break; 265 | } 266 | 267 | case PROX_FDTYPE_SOCKET: 268 | { 269 | int nb; 270 | struct socket_fdinfo si; 271 | if (used_len >= orig_len) { 272 | goto out; 273 | } 274 | nb = proc_pidfdinfo(pid, infop[i].proc_fd, PROC_PIDFDSOCKETINFO, 275 | (char *)&si, sizeof(si)); 276 | if (nb <= 0) { 277 | used_len += snprintf(buf + used_len, orig_len - used_len, "\n"); 278 | } else if ((unsigned int)nb < sizeof(si)) { 279 | used_len += snprintf(buf + used_len, orig_len - used_len, 280 | "(%s)\n", "incomplete info"); 281 | } else { 282 | struct protoent *proto = getprotobynumber(si.psi.soi_protocol); 283 | unsigned char *la = NULL, *fa = NULL; 284 | int lp = 0, fp = 0; 285 | if ((si.psi.soi_family == AF_INET) && 286 | (si.psi.soi_kind == SOCKINFO_TCP)) { 287 | la = (unsigned char *)&si.psi.soi_proto.pri_tcp.tcpsi_ini.insi_laddr.ina_46.i46a_addr4; 288 | lp = (int)ntohs(si.psi.soi_proto.pri_tcp.tcpsi_ini.insi_lport); 289 | fa = (unsigned char *)&si.psi.soi_proto.pri_tcp.tcpsi_ini.insi_faddr.ina_46.i46a_addr4; 290 | fp = (int)ntohs(si.psi.soi_proto.pri_tcp.tcpsi_ini.insi_fport); 291 | char lh[MAXHOSTNAMELEN + 1] = { 0 }; 292 | char fh[MAXHOSTNAMELEN + 1] = { 0 }; 293 | char *h; 294 | h = inet_ntoa(*(struct in_addr *)la); 295 | if (h) { 296 | snprintf(lh, MAXHOSTNAMELEN, "%s", h); 297 | } 298 | h = inet_ntoa(*(struct in_addr *)fa); 299 | if (h) { 300 | snprintf(fh, MAXHOSTNAMELEN, "%s", h); 301 | } 302 | used_len += snprintf(buf + used_len, orig_len - used_len, 303 | "%s, %s, %s, %s:%d --> %s:%d\n", 304 | socket_type_string(si.psi.soi_type), 305 | (proto) ? proto->p_name : "unknown protocol", 306 | socket_family_string(si.psi.soi_family), 307 | (lh[0]) ? lh : "unknown host", ntohs(lp), 308 | (fh[0]) ? fh : "unknown host", ntohs(fp)); 309 | } else { 310 | used_len += snprintf(buf + used_len, orig_len - used_len, 311 | "%s, %s, %s\n", 312 | socket_type_string(si.psi.soi_type), 313 | (proto) ? proto->p_name : "unknown protocol", 314 | socket_family_string(si.psi.soi_family)); 315 | } 316 | } 317 | break; 318 | } 319 | 320 | case PROX_FDTYPE_VNODE: 321 | { 322 | int nb; 323 | struct vnode_fdinfowithpath vi; 324 | nb = proc_pidfdinfo(pid, infop[i].proc_fd, PROC_PIDFDVNODEPATHINFO, 325 | (char *)&vi, sizeof(vi)); 326 | if (used_len >= orig_len) { 327 | goto out; 328 | } 329 | if (nb <= 0) { 330 | if (errno == ENOENT) { 331 | used_len += snprintf(buf + used_len, orig_len - used_len, 332 | "(%s)\n", "revoked"); 333 | } else { 334 | used_len += snprintf(buf + used_len, orig_len - used_len, 335 | "\n"); 336 | } 337 | } else if ((unsigned int)nb < sizeof(vi)) { 338 | used_len += snprintf(buf + used_len, orig_len - used_len, 339 | "(%s)\n", "incomplete info"); 340 | } else { 341 | used_len += snprintf(buf + used_len, orig_len - used_len, 342 | "%s\n", vi.pvip.vip_path); 343 | } 344 | break; 345 | } 346 | 347 | default: 348 | used_len += snprintf(buf + used_len, orig_len - used_len, 349 | "(%s)\n", "unknown descriptor type"); 350 | break; 351 | } 352 | } 353 | 354 | out: 355 | if (buffer) { 356 | free(buffer); 357 | } 358 | 359 | *len = used_len; 360 | 361 | return 0; 362 | } 363 | 364 | #endif /* __i386__ */ 365 | 366 | } 367 | -------------------------------------------------------------------------------- /procfs_proc_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * procfs as a MacFUSE file system for Mac OS X 3 | * 4 | * Copyright Amit Singh. All Rights Reserved. 5 | * http://osxbook.com 6 | * 7 | * http://code.google.com/p/macfuse/ 8 | * 9 | * Source License: GNU GENERAL PUBLIC LICENSE (GPL) 10 | */ 11 | 12 | #ifndef _LOCAL_SYS_PROC_INFO_H 13 | #define _LOCAL_SYS_PROC_INFO_H 14 | 15 | extern "C" { 16 | 17 | __BEGIN_DECLS 18 | 19 | #include 20 | 21 | extern int procfs_proc_pidinfo(pid_t pid, char *buf, int *len); 22 | 23 | __END_DECLS 24 | 25 | } 26 | 27 | #endif /*_LOCAL_SYS_PROC_INFO_H */ 28 | -------------------------------------------------------------------------------- /procfs_tpm.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003 IBM 3 | * Source License: GNU GENERAL PUBLIC LICENSE (GPL) 4 | */ 5 | 6 | /* 7 | * OSXFUSE-Based procfs 8 | * TPM Files 9 | */ 10 | 11 | extern "C" { 12 | 13 | #if OSXFUSE_PROCFS_ENABLE_TPM 14 | 15 | #include "procfs_tpm.h" 16 | 17 | uint32_t 18 | TPM_GetCapability_Version(int *major, int *minor, int *version, int *rev) 19 | { 20 | unsigned char blob[4096] = { 21 | 0, 193, /* TPM_TAG_RQU_COMMAND */ 22 | 0, 0, 0, 18, /* blob length, bytes */ 23 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ 24 | 0, 0, 0, 6, /* TCPA_CAP_VERSION */ 25 | 0, 0, 0, 0 /* no sub capability */ 26 | }; 27 | uint32_t ret; 28 | ret = TPM_Transmit(blob, "TPM_GetCapability_Version"); 29 | if (ret) 30 | return (ret); 31 | *major = (int) (blob[14]); 32 | *minor = (int) (blob[15]); 33 | *version = (int) (blob[16]); 34 | *rev = (int) (blob[17]); 35 | return (ret); 36 | } 37 | 38 | uint32_t 39 | TPM_GetCapability_Slots(uint32_t * slots) 40 | { 41 | unsigned char blob[4096] = { 42 | 0, 193, /* TPM_TAG_RQU_COMMAND */ 43 | 0, 0, 0, 22, /* blob length, bytes */ 44 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ 45 | 0, 0, 0, 5, /* TCPA_CAP_PROPERTY */ 46 | 0, 0, 0, 4, /* SUB_CAP size, bytes */ 47 | 0, 0, 1, 4 /* TCPA_CAP_PROP_SLOTS */ 48 | }; 49 | uint32_t ret; 50 | ret = TPM_Transmit(blob, "TPM_GetCapability_Slots"); 51 | if (ret) 52 | return (ret); 53 | *slots = ntohl(*(uint32_t *) (blob + 14)); 54 | return (ret); 55 | } 56 | 57 | uint32_t 58 | TPM_GetCapability_Pcrs(uint32_t * pcrs) 59 | { 60 | unsigned char blob[4096] = { 61 | 0, 193, /* TPM_TAG_RQU_COMMAND */ 62 | 0, 0, 0, 22, /* blob length, bytes */ 63 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ 64 | 0, 0, 0, 5, /* TCPA_CAP_PROPERTY */ 65 | 0, 0, 0, 4, /* SUB_CAP size, bytes */ 66 | 0, 0, 1, 1 /* TCPA_CAP_PROP_PCR */ 67 | }; 68 | uint32_t ret; 69 | ret = TPM_Transmit(blob, "TPM_GetCapability_Pcrs"); 70 | if (ret) 71 | return (ret); 72 | *pcrs = ntohl(*(uint32_t *) (blob + 14)); 73 | return (ret); 74 | } 75 | 76 | uint32_t 77 | TPM_GetCapability_Key_Handle(uint16_t * num, uint32_t keys[]) 78 | { 79 | unsigned char blob[4096] = { 80 | 0, 193, /* TPM_TAG_RQU_COMMAND */ 81 | 0, 0, 0, 18, /* blob length, bytes */ 82 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ 83 | 0, 0, 0, 7, /* TCPA_CAP_KEY_HANDLE */ 84 | 0, 0, 0, 0 /* no sub capability */ 85 | }; 86 | uint32_t ret; 87 | int i; 88 | ret = TPM_Transmit(blob, "TPM_GetCapability_Handle_List"); 89 | if (ret) 90 | return (ret); 91 | *num = ntohs(*(uint16_t *) (blob + 14)); 92 | for (i = 0; i < *num; i++) 93 | keys[i] = ntohl(*(uint32_t *) (blob + 16 + 4 * i)); 94 | return (ret); 95 | } 96 | 97 | #endif /* OSXFUSE_PROCFS_ENABLE_TPM */ 98 | 99 | } 100 | -------------------------------------------------------------------------------- /procfs_tpm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003 IBM 3 | * Source License: GNU GENERAL PUBLIC LICENSE (GPL) 4 | */ 5 | 6 | /* 7 | * OSXFUSE-Based procfs 8 | */ 9 | 10 | #ifndef _PROCFS_TPM_H_ 11 | #define _PROCFS_TPM_H_ 12 | 13 | #include 14 | #include 15 | 16 | uint32_t 17 | TPM_GetCapability_Version(int *major, int *minor, int *version, int *rev); 18 | 19 | uint32_t 20 | TPM_GetCapability_Slots(uint32_t *slots); 21 | 22 | uint32_t 23 | TPM_GetCapability_Pcrs(uint32_t *pcrs); 24 | 25 | uint32_t 26 | TPM_GetCapability_Key_Handle(uint16_t *num, uint32_t keys[]); 27 | 28 | #endif /* _PROCFS_TPM_H_ */ 29 | -------------------------------------------------------------------------------- /procfs_windows.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * MacFUSE-Based procfs 3 | * Windows 4 | * 5 | */ 6 | 7 | #include 8 | 9 | extern "C" { 10 | 11 | #include "procfs_windows.h" 12 | 13 | off_t 14 | PROCFS_GetPNGSizeForWindowAtIndex(CGWindowID index) 15 | { 16 | CGRect rect; 17 | 18 | CGError err = CGSGetScreenRectForWindow(_CGSDefaultConnection(), index, 19 | &rect); 20 | if (err) { 21 | return (off_t)0; 22 | } 23 | 24 | off_t size = ((off_t)rect.size.width * (off_t)rect.size.height * (off_t)3) 25 | + (off_t)8192; 26 | 27 | return size; 28 | } 29 | 30 | int 31 | PROCFS_GetPNGForWindowAtIndex(CGWindowID index, CFMutableDataRef *data) 32 | { 33 | *data = (CFMutableDataRef)0; 34 | 35 | CGImageRef image = CGWindowListCreateImage( 36 | CGRectNull, kCGWindowListOptionIncludingWindow, 37 | index, kCGWindowImageBoundsIgnoreFraming); 38 | 39 | if (!image) { 40 | return -1; 41 | } 42 | 43 | *data = CFDataCreateMutable(kCFAllocatorDefault, 0); 44 | if (!*data) { 45 | CFRelease(image); 46 | return -1; 47 | } 48 | 49 | CGImageDestinationRef dest = 50 | CGImageDestinationCreateWithData((CFMutableDataRef)*data, kUTTypePNG, 51 | 1, nil); 52 | if (!dest) { 53 | CFRelease(*data); 54 | CFRelease(image); 55 | return -1; 56 | } 57 | 58 | CGImageDestinationAddImage(dest, image, nil); 59 | CGImageDestinationFinalize(dest); 60 | 61 | CFRelease(dest); 62 | CGImageRelease(image); 63 | 64 | return 0; 65 | } 66 | 67 | } /* extern "C" */ 68 | -------------------------------------------------------------------------------- /procfs_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MacFUSE-Based procfs 3 | */ 4 | 5 | #ifndef _PROCFS_WINDOWS_H_ 6 | #define _PROCFS_WINDOWS_H_ 7 | 8 | #include 9 | #include 10 | 11 | extern "C" { 12 | 13 | typedef mach_port_t CGSConnectionID; 14 | typedef mach_port_t CGSWindowID; 15 | 16 | extern CGSConnectionID _CGSDefaultConnection(void); 17 | extern CGError CGSGetWindowLevel(CGSConnectionID connectionID, 18 | CGSWindowID windowID, CGWindowLevel *level); 19 | extern CGError CGSGetConnectionIDForPSN(CGSConnectionID connectionID, 20 | ProcessSerialNumber *psn, 21 | CGSConnectionID *out); 22 | extern CGError CGSGetOnScreenWindowList(CGSConnectionID connectionID, 23 | CGSConnectionID targetConnectionID, 24 | int maxCount, 25 | CGSWindowID *windowList, 26 | int *outCount); 27 | extern CGError CGSGetWindowList(CGSConnectionID connectionID, 28 | CGSConnectionID targetConnectionID, 29 | int maxCount, 30 | CGSWindowID *windowList, 31 | int *outCount); 32 | extern CGError CGSGetScreenRectForWindow(CGSConnectionID connectionID, 33 | CGSWindowID windowID, CGRect *outRect); 34 | 35 | extern CGError CGSGetParentWindowList(CGSConnectionID connectionID, 36 | CGSConnectionID targetConnectionID, 37 | int maxCount, 38 | CGSWindowID *windowList, 39 | int *outCount); 40 | 41 | int PROCFS_GetPNGForWindowAtIndex(CGWindowID index, CFMutableDataRef *data); 42 | off_t PROCFS_GetPNGSizeForWindowAtIndex(CGWindowID index); 43 | 44 | struct ProcfsWindowData { 45 | CFMutableDataRef window_png; 46 | size_t len; 47 | size_t max_len; 48 | }; 49 | 50 | } /* extern "C" */ 51 | 52 | #endif /* _PROCFS_WINDOWS_H_ */ 53 | -------------------------------------------------------------------------------- /sequencegrab/CSGCamera.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSGCamera.h 3 | // MotionTracker 4 | // 5 | // Created by Tim Omernick on 3/7/05. 6 | // Copyright 2005 Tim Omernick. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class CSGImage; 13 | 14 | /* 15 | CSGCamera provides a simple way to access the default sequence grabber component (say, an iSight or other DV camera). To use: 16 | 17 | - Instantiate an CSGCamera instance (using the plain old -init method) 18 | - Set the CSGCamera's delegate using -setDelegate:. The delegate is the object which will receive -camera:didReceiveFrame: messages. 19 | - Call -startWithSize: on the CSGCamera instance with a decent size (like 512x384). 20 | - Call -stop to stop recording. 21 | */ 22 | 23 | @interface CSGCamera : NSObject 24 | { 25 | id delegate; 26 | SeqGrabComponent component; 27 | SGChannel channel; 28 | GWorldPtr gWorld; 29 | Rect boundsRect; 30 | ImageSequence decompressionSequence; 31 | TimeScale timeScale; 32 | TimeValue lastTime; 33 | NSTimeInterval startTime; 34 | NSTimer *frameTimer; 35 | } 36 | 37 | - (void)setDelegate:(id)newDelegate; 38 | - (BOOL)startWithSize:(NSSize)frameSize; 39 | - (BOOL)stop; 40 | 41 | @end 42 | 43 | @interface NSObject (Private) 44 | - (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame; 45 | @end 46 | -------------------------------------------------------------------------------- /sequencegrab/CSGCamera.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSGCamera.m 3 | // MotionTracker 4 | // 5 | // Created by Tim Omernick on 3/7/05. 6 | // Copyright 2005 Tim Omernick. All rights reserved. 7 | // 8 | 9 | // Portions of this file were inspired by Apple Computer, Inc.'s Cocoa SGDataProc example, which can be found here: 10 | // 11 | // Also, I'd like to thank Chris Meyer for his excellent -imageFromGWorld: method, which he gave me permission to use for this framework. 12 | 13 | #import "CSGCamera.h" 14 | 15 | #import "CSGImage.h" 16 | 17 | @interface CSGCamera (Private) 18 | - (void)_sequenceGrabberIdle; 19 | - (BOOL)_setupDecompression; 20 | - (void)_didUpdate; 21 | - (CSGImage *)_imageFromGWorld:(GWorldPtr)gworld; 22 | @end 23 | 24 | @interface CSGCamera (SequenceGrabber) 25 | pascal OSErr CSGCameraSGDataProc(SGChannel channel, Ptr data, long dataLength, long *offset, long channelRefCon, TimeValue time, short writeType, long refCon); 26 | @end 27 | 28 | @implementation CSGCamera 29 | 30 | // Init and dealloc 31 | 32 | - (void)dealloc; 33 | { 34 | [self stop]; 35 | 36 | [delegate release]; 37 | 38 | [super dealloc]; 39 | } 40 | 41 | // API 42 | 43 | - (void)setDelegate:(id)newDelegate; 44 | { 45 | if (delegate == newDelegate) 46 | return; 47 | 48 | [delegate release]; 49 | delegate = [newDelegate retain]; 50 | } 51 | 52 | - (BOOL)startWithSize:(NSSize)frameSize; 53 | { 54 | OSErr theErr; 55 | 56 | timeScale = 0; 57 | lastTime = 0; 58 | 59 | // Initialize movie toolbox 60 | theErr = EnterMovies(); 61 | if (theErr != noErr) { 62 | NSLog(@"EnterMovies() returned %hd", theErr); 63 | return NO; 64 | } 65 | 66 | // Open default sequence grabber component 67 | component = OpenDefaultComponent(SeqGrabComponentType, 0); 68 | if (!component) { 69 | NSLog(@"Could not open sequence grabber component."); 70 | return NO; 71 | } 72 | 73 | // Initialize sequence grabber component 74 | theErr = SGInitialize(component); 75 | if (theErr != noErr) { 76 | NSLog(@"SGInitialize() returned %hd", theErr); 77 | return NO; 78 | } 79 | 80 | // Don't make movie 81 | theErr = SGSetDataRef(component, 0, 0, seqGrabDontMakeMovie); 82 | if (theErr != noErr) { 83 | NSLog(@"SGSetDataRef() returned %hd", theErr); 84 | return NO; 85 | } 86 | 87 | // Create sequence grabber video channel 88 | theErr = SGNewChannel(component, VideoMediaType, &channel); 89 | if (theErr != noErr) { 90 | NSLog(@"SGNewChannel() returned %hd", theErr); 91 | return NO; 92 | } 93 | 94 | // Set the grabber's bounds 95 | boundsRect.top = 0; 96 | boundsRect.left = 0; 97 | boundsRect.bottom = frameSize.height; 98 | boundsRect.right = frameSize.width; 99 | 100 | // NSLog(@"boundsRect=(%d, %d, %d, %d)", boundsRect.top, boundsRect.left, boundsRect.bottom, boundsRect.right); 101 | 102 | theErr = SGSetChannelBounds(component, &boundsRect); 103 | 104 | // Create the GWorld 105 | theErr = QTNewGWorld(&gWorld, k32ARGBPixelFormat, &boundsRect, 0, NULL, 0); 106 | if (theErr != noErr) { 107 | NSLog(@"QTNewGWorld() returned %hd", theErr); 108 | return NO; 109 | } 110 | 111 | // Lock the pixmap 112 | if (!LockPixels(GetPortPixMap(gWorld))) { 113 | NSLog(@"Could not lock pixels."); 114 | return NO; 115 | } 116 | 117 | // Set GWorld 118 | theErr = SGSetGWorld(component, gWorld, GetMainDevice()); 119 | if (theErr != noErr) { 120 | NSLog(@"SGSetGWorld() returned %hd", theErr); 121 | return NO; 122 | } 123 | 124 | // Set the channel's bounds 125 | theErr = SGSetChannelBounds(channel, &boundsRect); 126 | if (theErr != noErr) { 127 | NSLog(@"SGSetChannelBounds(2) returned %hd", theErr); 128 | return NO; 129 | } 130 | 131 | // Set the channel usage to record 132 | theErr = SGSetChannelUsage(channel, seqGrabRecord); 133 | if (theErr != noErr) { 134 | NSLog(@"SGSetChannelUsage() returned %hd", theErr); 135 | return NO; 136 | } 137 | 138 | // Set data proc 139 | theErr = SGSetDataProc(component, NewSGDataUPP(&CSGCameraSGDataProc), (long)self); 140 | if (theErr != noErr) { 141 | NSLog(@"SGSetDataProc() returned %hd", theErr); 142 | return NO; 143 | } 144 | 145 | // Prepare 146 | theErr = SGPrepare(component, false, true); 147 | if (theErr != noErr) { 148 | NSLog(@"SGPrepare() returned %hd", theErr); 149 | return NO; 150 | } 151 | 152 | // Start recording 153 | theErr = SGStartRecord(component); 154 | if (theErr != noErr) { 155 | NSLog(@"SGStartRecord() returned %hd", theErr); 156 | return NO; 157 | } 158 | 159 | startTime = [NSDate timeIntervalSinceReferenceDate]; 160 | 161 | // Set up decompression sequence (camera -> GWorld) 162 | [self _setupDecompression]; 163 | 164 | // Start frame timer 165 | frameTimer = [[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(_sequenceGrabberIdle) userInfo:nil repeats:YES] retain]; 166 | 167 | [self retain]; // Matches autorelease in -stop 168 | 169 | return YES; 170 | } 171 | 172 | - (BOOL)stop; 173 | { 174 | // Stop frame timer 175 | if (frameTimer) { 176 | [frameTimer invalidate]; 177 | [frameTimer release]; 178 | frameTimer = nil; 179 | } 180 | 181 | // Stop recording 182 | if (component) 183 | SGStop(component); 184 | 185 | ComponentResult theErr; 186 | 187 | // End decompression sequence 188 | if (decompressionSequence) { 189 | theErr = CDSequenceEnd(decompressionSequence); 190 | if (theErr != noErr) { 191 | NSLog(@"CDSequenceEnd() returned %ld", theErr); 192 | } 193 | decompressionSequence = 0; 194 | } 195 | 196 | // Close sequence grabber component 197 | if (component) { 198 | theErr = CloseComponent(component); 199 | if (theErr != noErr) { 200 | NSLog(@"CloseComponent() returned %ld", theErr); 201 | } 202 | component = NULL; 203 | } 204 | 205 | // Dispose of GWorld 206 | if (gWorld) { 207 | DisposeGWorld(gWorld); 208 | gWorld = NULL; 209 | } 210 | 211 | [self autorelease]; // Matches retain in -start 212 | 213 | return YES; 214 | } 215 | 216 | @end 217 | 218 | @implementation CSGCamera (Private) 219 | 220 | - (void)_sequenceGrabberIdle; 221 | { 222 | OSErr theErr; 223 | 224 | theErr = SGIdle(component); 225 | if (theErr != noErr) { 226 | NSLog(@"SGIdle returned %hd", theErr); 227 | return; 228 | } 229 | } 230 | 231 | - (BOOL)_setupDecompression; 232 | { 233 | ComponentResult theErr; 234 | 235 | ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(0); 236 | theErr = SGGetChannelSampleDescription(channel, (Handle)imageDesc); 237 | if (theErr != noErr) { 238 | NSLog(@"SGGetChannelSampleDescription() returned %ld", theErr); 239 | return NO; 240 | } 241 | 242 | Rect sourceRect; 243 | sourceRect.top = 0; 244 | sourceRect.left = 0; 245 | sourceRect.right = (**imageDesc).width; 246 | sourceRect.bottom = (**imageDesc).height; 247 | 248 | MatrixRecord scaleMatrix; 249 | RectMatrix(&scaleMatrix, &sourceRect, &boundsRect); 250 | 251 | theErr = DecompressSequenceBegin(&decompressionSequence, imageDesc, gWorld, NULL, NULL, &scaleMatrix, srcCopy, NULL, 0, codecNormalQuality, bestSpeedCodec); 252 | if (theErr != noErr) { 253 | NSLog(@"DecompressionSequenceBegin() returned %ld", theErr); 254 | return NO; 255 | } 256 | 257 | DisposeHandle((Handle)imageDesc); 258 | 259 | return YES; 260 | } 261 | 262 | - (void)_didUpdate; 263 | { 264 | if ([delegate respondsToSelector:@selector(camera:didReceiveFrame:)]) { 265 | CSGImage *frameImage = [self _imageFromGWorld:gWorld]; 266 | if (frameImage) { 267 | [frameImage setSampleTime:startTime + ((double)lastTime / (double)timeScale)]; 268 | [delegate camera:self didReceiveFrame:frameImage]; 269 | } 270 | } 271 | } 272 | 273 | // Thanks to Chris Meyer from http://www.cocoadev.com/ 274 | - (CSGImage *)_imageFromGWorld:(GWorldPtr)gworld; 275 | { 276 | NSParameterAssert( gworld != NULL ); 277 | 278 | PixMapHandle pixMapHandle = GetGWorldPixMap( gworld ); 279 | if ( LockPixels( pixMapHandle ) ) 280 | { 281 | Rect portRect; 282 | GetPortBounds( gworld, &portRect ); 283 | int pixels_wide = (portRect.right - portRect.left); 284 | int pixels_high = (portRect.bottom - portRect.top); 285 | 286 | int bps = 8; 287 | int spp = 4; 288 | BOOL has_alpha = YES; 289 | 290 | NSBitmapImageRep *frameBitmap = [[[NSBitmapImageRep alloc] 291 | initWithBitmapDataPlanes:NULL 292 | pixelsWide:pixels_wide 293 | pixelsHigh:pixels_high 294 | bitsPerSample:bps 295 | samplesPerPixel:spp 296 | hasAlpha:has_alpha 297 | isPlanar:NO 298 | colorSpaceName:NSDeviceRGBColorSpace 299 | bytesPerRow:0 300 | bitsPerPixel:0] autorelease]; 301 | 302 | CGColorSpaceRef dst_colorspaceref = CGColorSpaceCreateDeviceRGB(); 303 | 304 | CGImageAlphaInfo dst_alphainfo = has_alpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNone; 305 | 306 | CGContextRef dst_contextref = CGBitmapContextCreate( [frameBitmap bitmapData], 307 | pixels_wide, 308 | pixels_high, 309 | bps, 310 | [frameBitmap bytesPerRow], 311 | dst_colorspaceref, 312 | dst_alphainfo ); 313 | 314 | void *pixBaseAddr = GetPixBaseAddr(pixMapHandle); 315 | 316 | long pixmapRowBytes = GetPixRowBytes(pixMapHandle); 317 | 318 | CGDataProviderRef dataproviderref = CGDataProviderCreateWithData( NULL, pixBaseAddr, pixmapRowBytes * pixels_high, NULL ); 319 | 320 | int src_bps = 8; 321 | int src_spp = 4; 322 | BOOL src_has_alpha = YES; 323 | 324 | CGColorSpaceRef src_colorspaceref = CGColorSpaceCreateDeviceRGB(); 325 | 326 | CGImageAlphaInfo src_alphainfo = src_has_alpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNone; 327 | 328 | CGImageRef src_imageref = CGImageCreate( pixels_wide, 329 | pixels_high, 330 | src_bps, 331 | src_bps * src_spp, 332 | pixmapRowBytes, 333 | src_colorspaceref, 334 | src_alphainfo, 335 | dataproviderref, 336 | NULL, 337 | NO, // shouldInterpolate 338 | kCGRenderingIntentDefault ); 339 | 340 | CGRect rect = CGRectMake( 0, 0, pixels_wide, pixels_high ); 341 | 342 | CGContextDrawImage( dst_contextref, rect, src_imageref ); 343 | 344 | CGImageRelease( src_imageref ); 345 | CGColorSpaceRelease( src_colorspaceref ); 346 | CGDataProviderRelease( dataproviderref ); 347 | CGContextRelease( dst_contextref ); 348 | CGColorSpaceRelease( dst_colorspaceref ); 349 | 350 | UnlockPixels( pixMapHandle ); 351 | 352 | CSGImage *image = [[CSGImage alloc] initWithSize:NSMakeSize(pixels_wide, pixels_high)]; 353 | [image addRepresentation:frameBitmap]; 354 | 355 | return [image autorelease]; 356 | } 357 | 358 | return NULL; 359 | } 360 | 361 | @end 362 | 363 | @implementation CSGCamera (SequenceGrabber) 364 | 365 | pascal OSErr CSGCameraSGDataProc(SGChannel channel, Ptr data, long dataLength, long *offset, long channelRefCon, TimeValue time, short writeType, long refCon) 366 | { 367 | CSGCamera *camera = (CSGCamera *)refCon; 368 | ComponentResult theErr; 369 | 370 | if (camera->timeScale == 0) { 371 | theErr = SGGetChannelTimeScale(camera->channel, &camera->timeScale); 372 | if (theErr != noErr) { 373 | NSLog(@"SGGetChannelTimeScale() returned %ld", theErr); 374 | return theErr; 375 | } 376 | } 377 | 378 | if (camera->gWorld) { 379 | CodecFlags ignore; 380 | theErr = DecompressSequenceFrameS(camera->decompressionSequence, data, dataLength, 0, &ignore, NULL); 381 | if (theErr != noErr) { 382 | NSLog(@"DecompressSequenceFrameS() returned %ld", theErr); 383 | return theErr; 384 | } 385 | } 386 | 387 | camera->lastTime = time; 388 | 389 | [camera _didUpdate]; 390 | 391 | return noErr; 392 | } 393 | 394 | @end 395 | -------------------------------------------------------------------------------- /sequencegrab/CSGImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSGImage.h 3 | // MotionTracker 4 | // 5 | // Created by Tim Omernick on 3/6/05. 6 | // Copyright 2005 Tim Omernick. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSGImage : NSImage 12 | { 13 | NSTimeInterval sampleTime; 14 | } 15 | 16 | - (NSTimeInterval)sampleTime; 17 | - (void)setSampleTime:(NSTimeInterval)newSampleTime; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /sequencegrab/CSGImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSGImage.m 3 | // MotionTracker 4 | // 5 | // Created by Tim Omernick on 3/6/05. 6 | // Copyright 2005 Tim Omernick. All rights reserved. 7 | // 8 | 9 | #import "CSGImage.h" 10 | 11 | @implementation CSGImage 12 | 13 | // NSObject subclass 14 | 15 | - (NSString *)description; 16 | { 17 | return [NSString stringWithFormat:@"<%@: %p> (sampleTime=%.4f)", NSStringFromClass([self class]), self, sampleTime]; 18 | } 19 | 20 | // API 21 | 22 | - (NSTimeInterval)sampleTime; 23 | { 24 | return sampleTime; 25 | } 26 | 27 | - (void)setSampleTime:(NSTimeInterval)newSampleTime; 28 | { 29 | sampleTime = newSampleTime; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /sequencegrab/CocoaSequenceGrabber.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CocoaSequenceGrabber.h 3 | * CocoaSequenceGrabber 4 | * 5 | * Created by Tim Omernick on 3/18/05. 6 | * Copyright 2005 Tim Omernick. All rights reserved. 7 | * 8 | */ 9 | 10 | #import 11 | #import "CSGCamera.h" 12 | #import "CSGImage.h" 13 | -------------------------------------------------------------------------------- /sequencegrab/Makefile: -------------------------------------------------------------------------------- 1 | # Sequence Grabbing Library 2 | # 3 | # Dave MacLachlan 4 | 5 | CC ?= gcc 6 | CXX ?= g++ 7 | CFLAGS := -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk $(CFLAGS) 8 | CXXFLAGS := -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk $(CXXFLAGS) 9 | LDFLAGS = -framework Cocoa -framework CoreAudioKit -framework Foundation -framework QuartzCore -framework QuickTime -framework QuartzCore 10 | 11 | OBJECTS = CSGCamera.o CSGImage.o procfs_sequencegrab.o 12 | 13 | all: libprocfs_sequencegrab.dylib libprocfs_sequencegrab.a 14 | 15 | %o.%m: 16 | $(CC) -c $(CFLAGS) -o $@ $< 17 | 18 | CSGCamera.o: CSGCamera.m 19 | CSGImage.o: CSGImage.m 20 | 21 | procfs_sequencegrab.o: procfs_sequencegrab.mm 22 | $(CXX) -c $(CXXFLAGS) -o $@ $< 23 | 24 | libprocfs_sequencegrab.dylib: $(OBJECTS) 25 | $(CXX) -dynamiclib -install_name /usr/local/lib/libprocfs_sequencegrab.dylib $(CXXFLAGS) -o $@ $(OBJECTS) $(LDFLAGS) 26 | 27 | libprocfs_sequencegrab.a: $(OBJECTS) 28 | libtool -static -o libprocfs_sequencegrab.a $(OBJECTS) 29 | ranlib libprocfs_sequencegrab.a 30 | 31 | clean: 32 | rm -f *.o libprocfs_sequencegrab.dylib libprocfs_sequencegrab.a 33 | -------------------------------------------------------------------------------- /sequencegrab/procfs_sequencegrab.h: -------------------------------------------------------------------------------- 1 | #ifndef _PROCFS_SEQUENCEGRAB_H_ 2 | #define _PROCFS_SEQUENCEGRAB_H_ 3 | 4 | #include 5 | 6 | #define CAMERA_TRIGGER_THRESHOLD 4 7 | #define CAMERA_ACTIVE_DURATION 1 8 | 9 | static int PROCFS_GetTIFFFromCamera(CFMutableDataRef *data); 10 | static off_t PROCFS_GetTIFFSizeFromCamera(void); 11 | 12 | static 13 | off_t 14 | PROCFS_GetTIFFSizeFromCamera(void) 15 | { 16 | return (off_t)((off_t)(640 * 480 * 4) + (off_t)8192); 17 | } 18 | 19 | static 20 | int 21 | PROCFS_GetTIFFFromCamera(CFMutableDataRef *data) 22 | { 23 | return 0; 24 | } 25 | 26 | #endif /* _PROCFS_SEQUENCEGRAB_H_ */ 27 | -------------------------------------------------------------------------------- /sequencegrab/procfs_sequencegrab.mm: -------------------------------------------------------------------------------- 1 | #import "procfs_sequencegrab.h" 2 | #import "CocoaSequenceGrabber.h" 3 | 4 | static int loopCount = 0; 5 | 6 | @interface Snapshot : CSGCamera 7 | { 8 | CFMutableDataRef tiff; 9 | } 10 | 11 | - (void)setDataRef:(CFMutableDataRef)dataRef; 12 | - (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame; 13 | 14 | @end 15 | 16 | @implementation Snapshot 17 | 18 | - (void)setDataRef:(CFMutableDataRef)dataRef 19 | { 20 | tiff = dataRef; 21 | } 22 | 23 | - (void)camera:(CSGCamera *)aCamera didReceiveFrame:(CSGImage *)aFrame; 24 | { 25 | if (++loopCount == CAMERA_TRIGGER_THRESHOLD) { 26 | CFDataRef image = (CFDataRef)[aFrame TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:0.0]; 27 | CFIndex len = CFDataGetLength(image); 28 | CFDataSetLength(tiff, len); 29 | CFDataReplaceBytes(tiff, CFRangeMake((CFIndex)0, len), CFDataGetBytePtr(image), len); 30 | //CFRelease(image); 31 | [self stop]; 32 | } 33 | } 34 | 35 | @end 36 | 37 | off_t 38 | PROCFS_GetTIFFSizeFromCamera(void) 39 | { 40 | return (off_t)((off_t)(640 * 480 * 4) + (off_t)8192); 41 | } 42 | 43 | int 44 | PROCFS_GetTIFFFromCamera(CFMutableDataRef *data) 45 | { 46 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 47 | 48 | loopCount = 0; 49 | 50 | Snapshot *camera = [[Snapshot alloc] init]; 51 | [camera setDataRef:*data]; 52 | [camera setDelegate:camera]; 53 | [camera startWithSize:NSMakeSize(640, 480)]; 54 | [[NSRunLoop currentRunLoop] 55 | runUntilDate:[NSDate dateWithTimeIntervalSinceNow:CAMERA_ACTIVE_DURATION]]; 56 | [camera release]; 57 | 58 | [pool release]; 59 | 60 | return 0; 61 | } 62 | --------------------------------------------------------------------------------