├── BlackHat-DC-09-Iozzo-Macho-on-the-fly.pdf ├── Blackhat-DC-2010-Advanced-Mac-OS-X-Physical-Memory-Analysis-wp.pdf ├── D2T1-Cedric-Halbronn-and-Jean-Sigwald-iPhone-Security-Model.pdf ├── LoadingCode.pdf ├── README ├── beginners-tut-II.txt ├── code ├── Makefile ├── main └── main.c ├── csw09-daizovi-miller.pdf ├── egele-ndss11.pdf ├── gdb-i386-apple-darwin ├── gdbinit-ios-v0.3 ├── gdbinit732 ├── gdbreferencecard.html ├── hello.s ├── hellouikit ├── .deps │ └── mainApp.Po ├── Makefile.am ├── configure.in ├── configure4ios └── src │ ├── .deps │ ├── SampleApp.Po │ ├── SampleApp.Tpo │ └── mainapp.Po │ ├── CMakeLists.txt │ ├── Hello_WorldAppDelegate.h │ ├── Hello_WorldAppDelegate.m │ ├── Makefile │ ├── Makefile.am │ ├── Makefile.in │ ├── MyView.h │ ├── MyView.m │ ├── bak │ ├── SampleApp.h │ ├── SampleApp.mm │ └── mainapp.mm │ └── main.m ├── ios_helloworld ├── Classes │ ├── Hello_WorldAppDelegate.h │ ├── Hello_WorldAppDelegate.m │ ├── MyView.h │ └── MyView.m ├── Hello World.xcodeproj │ ├── admin.mode2v3 │ ├── admin.pbxuser │ └── project.pbxproj ├── Hello World_Prefix.pch ├── Info.plist ├── build.sh └── main.m ├── offset1.3.pl ├── osx.pdf ├── ptool1.3.pl ├── resetapp ├── build.sh ├── gas-preprocessor.pl └── main.m └── tools ├── inject_bundle ├── Makefile ├── inject-bundle ├── inject-bundle.c └── run-bundle.c └── macho_module ├── Makefile ├── mach_override.c ├── mach_override.h ├── wow └── wow.c /BlackHat-DC-09-Iozzo-Macho-on-the-fly.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/BlackHat-DC-09-Iozzo-Macho-on-the-fly.pdf -------------------------------------------------------------------------------- /Blackhat-DC-2010-Advanced-Mac-OS-X-Physical-Memory-Analysis-wp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/Blackhat-DC-2010-Advanced-Mac-OS-X-Physical-Memory-Analysis-wp.pdf -------------------------------------------------------------------------------- /D2T1-Cedric-Halbronn-and-Jean-Sigwald-iPhone-Security-Model.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/D2T1-Cedric-Halbronn-and-Jean-Sigwald-iPhone-Security-Model.pdf -------------------------------------------------------------------------------- /LoadingCode.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/LoadingCode.pdf -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/README -------------------------------------------------------------------------------- /beginners-tut-II.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/beginners-tut-II.txt -------------------------------------------------------------------------------- /code/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = main 2 | CFLAGS = -arch i686 3 | LDFLAGS = -framework CoreFoundation -framework MobileDevice -F/System/Library/PrivateFrameworks 4 | 5 | all: $(TARGET) 6 | 7 | %.o:: %.c 8 | $CC $< 9 | 10 | clean: 11 | rm -f main 12 | rm -f *.o 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /code/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/code/main -------------------------------------------------------------------------------- /code/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* Path to the MobileDevice framework is used to look up symbols and offsets */ 7 | #define MOBILEDEVICE_FRAMEWORK "/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice" 8 | 9 | /* Used as a pointer to the iPhone/iTouch device, when booted into recovery */ 10 | typedef struct AMRecoveryModeDevice *AMRecoveryModeDevice_t; 11 | 12 | /* Memory pointers to private functions inside the MobileDevice framework */ 13 | typedef int(*symbol) (AMRecoveryModeDevice_t, CFStringRef) \ 14 | __attribute__ ((regparm(2))); 15 | static symbol sendCommandToDevice; 16 | static symbol sendFileToDevice; 17 | 18 | /* Very simple symbol lookup. Returns the position of the function in memory */ 19 | static unsigned int loadSymbol (const char *path, const char *name) 20 | { 21 | struct nlist nl[2]; 22 | memset(&nl, 0, sizeof(nl)); 23 | nl[0].n_un.n_name = (char *) name; 24 | // nl[0].n_un.n_strx = (char *) name; 25 | if (nlist(path, nl) < 0 || nl[0].n_type == N_UNDF) { 26 | return 0; 27 | } 28 | return nl[0].n_value; 29 | } 30 | 31 | // static unsigned int loadSymbol (const char *path, const char *name) 32 | // { 33 | // void* handle,*p; 34 | // handle = dlopen(path, RTLD_NOW); 35 | // if ( handle == NULL ) 36 | // fprintf(stderr, dlerror()); 37 | // p = dlsym(handle, name); 38 | // if ( p == NULL ) 39 | // fprintf(stderr, dlerror()); 40 | // return p; 41 | // } 42 | 43 | /* How to proceed when the device is connected in recovery mode. 44 | * This is the function responsible for sending the ramdisk image and booting 45 | * into the memory location containing it. */ 46 | 47 | void Recovery_Connect(AMRecoveryModeDevice_t device) { 48 | int r; 49 | 50 | fprintf(stderr, "Recovery_Connect: DEVICE CONNECTED in Recovery Mode\n"); 51 | 52 | /* Upload RAM disk image from file */ 53 | r = sendFileToDevice(device, CFSTR("ramdisk.bin")); 54 | fprintf(stderr, "sendFileToDevice returned %d\n", r); 55 | 56 | /* Set the boot environment arguments sent to the kernel */ 57 | r = sendCommandToDevice(device, 58 | CFSTR("setenv boot-args rd=md0 -s -x pmd0=0x9340000.0xA00000")); 59 | fprintf(stderr, "sendCommandToDevice returned %d\n", r); 60 | 61 | /* Instruct the device to save the environment variable change */ 62 | r = sendCommandToDevice(device, CFSTR("saveenv")); 63 | fprintf(stderr, "sendCommandToDevice returned %d\n", r); 64 | 65 | /* Invoke boot sequence (bootx may also be used) */ 66 | r = sendCommandToDevice(device, CFSTR("fsboot")); 67 | fprintf(stderr, "sendCommandToDevice returned %d\n", r); 68 | } 69 | 70 | /* Used for notification only */ 71 | void Recovery_Disconnect(AMRecoveryModeDevice_t device) { 72 | 73 | fprintf(stderr, "Recovery_Disconnect: Device Disconnected\n"); 74 | } 75 | 76 | /* Main program loop */ 77 | int main(int argc, char *argv[]) { 78 | AMRecoveryModeDevice_t recoveryModeDevice; 79 | unsigned int r; 80 | 81 | /* Find the __sendCommandToDevice and __sendFileToDevice symbols */ 82 | 83 | // sendCommandToDevice = (symbol) loadSymbol(MOBILEDEVICE_FRAMEWORK, "_lockconn_send_message"); 84 | sendCommandToDevice = (symbol) loadSymbol(MOBILEDEVICE_FRAMEWORK, "__sendCommandToDevice"); 85 | if (!sendCommandToDevice) { 86 | fprintf(stderr, "ERROR: Could not locate symbol: __sendCommandToDevice in %s\n", MOBILEDEVICE_FRAMEWORK); 87 | return EXIT_FAILURE; 88 | } 89 | fprintf(stderr, "sendCommandToDevice: %08x\n", sendCommandToDevice); 90 | 91 | sendFileToDevice = (symbol) loadSymbol(MOBILEDEVICE_FRAMEWORK, "__sendFileToDevice"); 92 | if (!sendFileToDevice) { 93 | fprintf(stderr, "ERROR: Could not locate symbol: __sendFileToDevice in %s\n", MOBILEDEVICE_FRAMEWORK); 94 | return EXIT_FAILURE; 95 | } 96 | 97 | /* Invoke callback functions for recovery mode connect and disconnect */ 98 | r = AMRestoreRegisterForDeviceNotifications( 99 | NULL, 100 | Recovery_Connect, 101 | NULL, 102 | Recovery_Disconnect, 103 | 0, 104 | NULL); 105 | fprintf(stderr, "AMRestoreRegisterForDeviceNotifications returned %d\n", 106 | r); 107 | fprintf(stderr, "Waiting for device in restore mode...\n"); 108 | 109 | /* Loop */ 110 | CFRunLoopRun(); 111 | } -------------------------------------------------------------------------------- /csw09-daizovi-miller.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/csw09-daizovi-miller.pdf -------------------------------------------------------------------------------- /egele-ndss11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/egele-ndss11.pdf -------------------------------------------------------------------------------- /gdb-i386-apple-darwin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/gdb-i386-apple-darwin -------------------------------------------------------------------------------- /gdbreferencecard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | GDB reference card 6 | 7 | 8 | 9 | 10 | GDB user manual 11 |

12 | GDB internals documentation 13 |

14 | A useful GDB initilization script .gdbinit 15 | (a local copy here) Detailed explanation here 16 | 17 |

Hacking GDB

18 | To see how a function in GDB is implemented, seek calls to 19 | the following functions in GDB source tree: 20 |
 21 | add_com
 22 | add_com_alias
 23 | add_info
 24 | add_info_alias
 25 | 
26 | where add_info add a hook to the implementation of commands beginning with info. 27 |

28 | For example, info functions command is added in function _initialize_symtab 29 | gdb/symtab.c 30 | as 31 |

 32 |   add_info ("functions", functions_info,
 33 |         _("All function names, or those matching REGEXP."));
 34 | 
35 | so the actual implementation is functions_info 36 |

37 |

Invoking GDB

38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
gdb program
gdb program -c core Debug a program with core file
gdb -p pid Debug a running process whose ID is pid
gdb --args program arg1 arg2 Debug program and pass arg1 arg2 to program
56 | 57 |

58 |

Running debuggee ("inferior" in GDB parlance) and set up its environments

59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
r > outputfile Run the debuggee and redirect all console output to outputfile
startRun the debuggee and stop at main
kill Kill the debuggee. Use "r" again to restart the debuggee.
set args arg1 arg2 Set the command-line arguments arg1 arg2 for debuggee
show args
set env varname=value Set the environment varname=value for debuggee
unset env varname Remove the environment variable varname
set exec-wrapper env 'LD_PRELOAD=libfoo.so'Run the debuggee with wrapper program env and use 'LD_PRELOAD=libfoo.so' as env's command-line argument
show env
attach pidAttach to the running process pid
info threadsList threads
thread threadIDSwitch to thread threadID
set non-stop onWhen one thread stops, GDB will not stop other threads.
set scheduler-locking onOnly the current thread may run when the debuggee is resumed.
set scheduler-locking stepIn the single-step mode, only the current thread may run.
info inferiorsList processes
shell command stringInvoke a standard shell to execute command string
148 | 149 |

150 |

Break points, 151 | watch points, single-step execution

152 |

153 | One should set the environmental variable LD_BIND_NOW to 1 if 154 | one wants to set a break point in a function in a dynamic link library. 155 |

156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 193 | 194 | 195 | 196 | 197 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 215 | 216 | 217 | 218 | 219 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 363 | 364 | 365 |
set breakpoint pending onWhen setting a break point on a not-yet-loaded dynamic library, this will automatically create a pending break point WITHOUT asking.
b functionSet a break point at first line of function
tbreak functionSet one-time break point at first line of function
b numSet a break point at line number num
b *0x12345Set a break point at address 0x12345
b *functionSet a break point at actual starting address of function
b *0x12345 if foo==5Stop at address 0x12345 if foo==5 190 |

See here 191 | for more details on conditional break points. 192 |

watch fooStop if the variable foo changed. 198 |

The number of watch points is limited (depending on hardware). On x86, only 4 hardware watch points can be set simultaneously.

set can-use-hw-watchpoint 0Do not use hardware watch points.
watch *0x12345Stop if the value at address 0x12345 changed
rwatch fooStop if the variable foo is read.

This feature is hardware dependent. 214 |

awatch fooStop if the variable foo is read or written.

This feature is hardware dependent. 220 |

catch syscallStop when a system call occurs.
catch syscall [name| number]Stop when a specified system call occurs.
catch throwStop when a C++ exception is thrown.
handle signal stop
handle signal nostop
handle signal print
Signal handling.
245 |
246 | b function if foo==5
247 | commands
248 |   silent
249 |   printf "x is %d\n",x
250 |   c
251 | end
252 |     
253 |
Execute the commands "silent", "print...", and "c" after reaching the break point at function
info breakList all break/watch points
clearRemove all break/watch points
clear functionRemove the break point at function
disable numDisable the break point num (use "info break" first to get a list of break/watch points)
cContinue execution after reaching a break point
rcReverse execution until reaching a break point
finishContinue execution until the current function returns
return 1Return from current function immediately with value 1
sExecute one line of source code
nSame as above, but don't jump into function calls
siExecute one machine instruction
niSame as above, but don't jump into function calls
reverse-stepReverse execute one line of source code. 320 |

See here for a tutorial. 321 |

reverse-nextSame as above, but don't jump into function calls
reverse-stepiReverse execute one machine instruction
reverse-nextiSame as above, but don't jump into function calls
checkpointSave a snapshot of debuggee's state
restart checkpoint_idRestore the debuggee's state to checkpoint_id
delete checkpoint checkpoint_idDelete checkpoint_id
info checkpointsShow all checkpoints
(Record and replay the execution)See here for details 362 | and here for a tutorial.
366 | 367 |

368 |

Examining the stack

369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 |
btPrint a backtrace (list of stack frames)
f numSelect frame number num
down numMove down num frames (most recent ones)
info fPrint info about the frame
info argsPrint arguments passed to the frame
info localPrint local variables of the frame
400 | 401 |

402 |

Examining source files and machine code

403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 461 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 |
list functionShow source code of function
list filename:functionShow source code of function in file filename
list *0x12345Show source code at address 0x12345
info line functionShow the starting and ending address of the machine code for function
disas functionDisassemble function
set disassembly-flavor intel
set disassembly-flavor att
Use specified syntax for disassmbly
disas/m functionDisassemble function and show the source code side-by-side (the debuggee must be compiled with -g option)
disas/r functionDisassemble function and show the raw instructions in hexadecimals
set disassemble-next-line onDisassemble the next instruction whenever GDB stops
set print asm-demangle on Show demangled symbol names in disassembly
456 |
457 | define hook-stop
458 | x/i $pc
459 | end
460 | 
Disassemble the next instruction whenever GDB stops.

This is a special example 462 | of user-defined hooks.

x/4i 0x12345Show the machine code for the first 4 instructions starting at address 0x12345
x/4i $pc-6Show the machine code of 4 instructions starting at current program counter minus 6
476 | 477 |

478 |

Examining data, memory, registers

479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 583 | 584 | 585 | 586 | 592 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 623 | 624 | 625 |
p varPrint the value of var.

var can be a register, e.g. $r1

whatis varPrint the data type of var.
ptype fooPrint the data type of symbol foo
p/t varPrint the value of var in binary
p/c varPrint the value of var in format c:
503 | x=hexadecimal, c=char, t=binary, d=signed, u=unsigned, o=octal, a=address, f=floating
p function::varPrint the value of var in function
p *array@lenPrint the values of array (allocated by malloc) with length len
call getpid()Print the PID of current process
info inferiorsList processes
x &varPrint the address of var.
info address fooPrint the address of symbol foo.
info symbol 0x12345Print the name of the symbol which is stored at 0x12345
info macro fooPrint the definition of macro foo.

The debuggee must be compiled with -ggdb3 flag.

macro expand fooExpand the definition of macro foo.

The debuggee must be compiled with -ggdb3 flag.

x/1s 0x12345Print 1 null-terminated string starting at 0x12345
x/5xb 0x12345Print 5 bytes of memory in hexadecimal starting at 0x12345
x/nfu 0x12345n is repeat count
564 | f is format (i=instruction, s=string, x=hexadecimal, c=char, t=binary, d=signed, u=unsigned, o=octal, a=address, f=floating)
565 | u is unit (b=byte, h=2 bytes, w=4 bytes, g=8 bytes) 566 |
info registers
info float
info vector
info all-registers
List regular/floating-point/vector/all registers
p/x $pcPrint the program counter
display varAutomatically display var each time GDB stops. 582 |
587 |
588 | define hook-stop
589 | print var
590 | end
591 | 
Display var each time GDB stops.

This is a special example 593 | of user-defined hooks.

display/nfu 0x12345Display address 0x12345 (with format nfu) each time GDB stops.
info displayList all automatic displays
undisplay numRemove display num
find start_addr, +len, val1 [, val2, ...]Search memory
heapShow heap usage and classify heap objects

This is a Fedora extension for GDB. 619 | See here 620 | and here 621 | for details. 622 |

626 | 627 |

628 |

Changing data, memory, registers, execution

629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 |
set var foo+=5Set the value of variable foo to increment by 5
set {int}0x12345=6Set the value of at address 0x12345 to be 6 (treat as an integer)
set $rax=$rbx+5Set the value of x86_64 register RAX to be the sum of 5 and register RBX
set $ps=$ps|1

set $ps=$ps&~1

Set/Clean the Carry flag (x86)
set $ps=$ps|0x4Set the Parity flag (x86)
set $ps=$ps|0x40Set the Zero flag (x86)
set $ps=$ps|0x80Set the Sign flag (x86)
set $ps=$ps|0x800Set the Overflow flag (x86)
set write onMake text region writeable
signal SIGSEGVSend the signal SIGSEGV to debuggee
generate-core-fileCreate a core dump file
686 | 687 |

688 |

Examining the symbol table

689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 |
info scope fooPrint all variables in the scope of function foo
info sharedPrint info about the shared libraries
info sourcePrint info about the source file
info functionsPrint info about all functions
info variablesPrint info about all variables
716 | 717 |

718 |

Dump memory to files

719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 |
dump memory file 0x12345 0x34567Dump the memory region 0x12345 to 0x34567 to file
restore file 0 0x12345Load file content to memory starting at 0x12345
731 | 732 |

733 |

Memory region attributes

734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 |
mem 0x12345 0x34567 roSet the memory region from 0x12345 to 0x34567 to be read-only (this restriction applies to GDB only)
info memList all memory regions
delete mem numRemove memory region num
disable mem numDisable memory region num
755 | 756 |

757 |

Tracing facility

758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 |
trace foo.c:121Set a tracepoint at line 121 of foo.c
actionSet a series of actions for tracepoint
tstartStart the trace experiment
tdumpDump the trace
tstatusPrint info about current trace data collection
781 | 782 |

Troubleshooting GDB

783 |

What is
[Thread debugging using libthread_db enabled]
Cannot find new threads: generic error

error ?

784 | According to this link, it 785 | seems GDB has issue when the debuggee "suddenly" loads libpthread.so. The fix is to start 786 | GDB with 787 |
788 |  $ LD_PRELOAD=/lib/libpthread.so.0 gdb --args ./myapps
789 | 
790 | or at GDB prompt (untested!), 791 |
792 |  (gdb) set exec-wrapper env 'LD_PRELOAD=/lib/libpthread.so.0'
793 | 
794 | 795 |

Target does not support this type of hardware watchpoint error ?

796 | When setting a read-access watch point (rwatch), one could encounter this error. The fix 797 | is to launch the debuggee first (e.g. set a break point somewhere), then use rwatch: 798 |
799 |  (gdb) start
800 |  (gdb) rwatch foo
801 | 
802 | 803 | 804 | 805 | 806 | -------------------------------------------------------------------------------- /hello.s: -------------------------------------------------------------------------------- 1 | # GAS filename : hello.s 2 | # use as to compile 3 | # /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as -arch armv6 hello.s -o hello 4 | # use otool to disassemble 5 | # otool -tv hello 6 | 7 | .globl _main 8 | .code 16 9 | .thumb_func _main 10 | _main: 11 | push {r7, lr} 12 | add r7, sp, #0 13 | add r3, pc 14 | mov ip, r3 15 | mov r3, ip 16 | mov r0, r3 17 | pop {r7, pc} 18 | 19 | -------------------------------------------------------------------------------- /hellouikit/.deps/mainApp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /hellouikit/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=src -------------------------------------------------------------------------------- /hellouikit/configure.in: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.59) 2 | AC_INIT(ihello, 1.0) 3 | 4 | 5 | AC_CANONICAL_SYSTEM 6 | AM_INIT_AUTOMAKE() 7 | 8 | AC_PROG_CC 9 | AC_PROG_OBJC 10 | 11 | AC_CONFIG_FILES(Makefile src/Makefile) 12 | AC_OUTPUT 13 | 14 | -------------------------------------------------------------------------------- /hellouikit/configure4ios: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Filename : configure4ios 4 | # Author : Satoshi Konno 5 | # Copyright 2010 Satoshi Konno. All rights reserved. 6 | # 7 | 8 | export DEVROOT="`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer" 9 | export SDKVER=`xcodebuild -showsdks | grep iphoneos | sort | tail -n 1 | awk '{ print $2}' ` 10 | export SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk" 11 | 12 | export PREFIX="/opt/ios-$SDKVER" 13 | export ARCH="armv6" 14 | 15 | export CC="$DEVROOT/usr/bin/gcc" 16 | export CFLAGS="-arch $ARCH -isysroot $SDKROOT" 17 | 18 | ./configure \ 19 | --prefix="$PREFIX" \ 20 | --host="arm-apple-darwin" \ 21 | --enable-static \ 22 | --disable-shared $@ 23 | -------------------------------------------------------------------------------- /hellouikit/src/.deps/SampleApp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /hellouikit/src/.deps/SampleApp.Tpo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/hellouikit/src/.deps/SampleApp.Tpo -------------------------------------------------------------------------------- /hellouikit/src/.deps/mainapp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /hellouikit/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(ihello) 2 | set(NAME ihello) 3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 4 | 5 | # SET(GCC_THUMB_SUPPORT NO) 6 | SET(IPHONE_SDKVER "4.3") 7 | 8 | #set either the device sdk or the simulator sdk. Can't find away to separate these in the same project 9 | # SET(IPHONE_DEVROOT "/Developer/Platforms/iPhoneOS.platform/Developer") 10 | # SET(IPHONE_SDKROOT "${IPHONE_DEVROOT}/SDKs/iPhoneOS${IPHONE_SDKVER}.sdk") 11 | SET(IPHONE_DEVROOT "/Developer/Platforms/iPhoneSimulator.platform/Developer") 12 | SET(IPHONE_SDKROOT "${IPHONE_DEVROOT}/SDKs/iPhoneSimulator${IPHONE_SDKVER}.sdk") 13 | 14 | #set iphone arch and flags taken from http://sites.google.com/site/michaelsafyan/coding/resources/how-to-guides/cross-compile-for-the-iphone/how-to-cross-compile-for-the-iphone-using-cmake 15 | # SET(CMAKE_CXX_COMPILER "${IPHONE_DEVROOT}/usr/bin/arm-apple-darwin-g++") 16 | # SET(CMAKE_C_COMPILER "${IPHONE_DEVROOT}/usr/bin/arm-apple-darwin-gcc") 17 | # SET(CMAKE_OSX_ARCHITECTURES "armv6;armv7") 18 | # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -miphoneos-version-min=3.1 -mno-thumb -arch armv6 -pipe -no-cpp-precomp") 19 | 20 | #simulator uses i386 architectures 21 | # SET(CMAKE_OSX_ARCHITECTURES "i386") 22 | 23 | ## 24 | SET(CMAKE_CXX_COMPILER "${IPHONE_DEVROOT}/usr/bin/llvm-g++") 25 | SET(CMAKE_C_COMPILER "${IPHONE_DEVROOT}/usr/bin/llvm-gcc") 26 | 27 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${IPHONE_DEVROOT}/usr/include") 28 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${IPHONE_SDKROOT}/usr/include") 29 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c99 -W -Wall -arch i386 -pipe -no-cpp-precomp") 30 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -DDEBUG_MUTEX") 31 | # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} "-O3 -DNDEBUG") 32 | 33 | #here we set the specific iphone sdk version. We can only set either device or simulator sdk. So if you want both you currently have to have two seperate projects 34 | SET(CMAKE_OSX_SYSROOT "${IPHONE_SDKROOT}") 35 | 36 | #hack, force link to opengles 37 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -F${IPHONE_SDKROOT}/System/Library/Frameworks -F${IPHONE_SDKROOT}/System/Library/PrivateFrameworks") 38 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lobjc -framework Foundation -framework UIKit -framework CoreFoundation") 39 | 40 | file(GLOB headers *.h) 41 | file(GLOB sources *.m) 42 | 43 | set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mycompany.\${PRODUCT_NAME:identifier}") 44 | set(APP_TYPE MACOSX_BUNDLE) 45 | 46 | add_executable(${NAME} 47 | ${APP_TYPE} 48 | ${headers} 49 | ${sources} 50 | ) 51 | 52 | # code signing 53 | set_target_properties(${NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer: My Name") 54 | 55 | # copy resource phase 56 | set(APP_NAME \${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME}) 57 | set(RES_DIR ${test_SOURCE_DIR}/data) 58 | add_custom_command( 59 | TARGET ${NAME} 60 | POST_BUILD 61 | COMMAND /Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks ${RES_DIR} ${APP_NAME} 62 | ) -------------------------------------------------------------------------------- /hellouikit/src/Hello_WorldAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Hello_WorldAppDelegate.h 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class MyView; 12 | 13 | @interface Hello_WorldAppDelegate : NSObject { 14 | UIWindow *window; 15 | MyView *contentView; 16 | } 17 | 18 | @property (nonatomic, retain) UIWindow *window; 19 | @property (nonatomic, retain) MyView *contentView; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /hellouikit/src/Hello_WorldAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // Hello_WorldAppDelegate.m 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import "Hello_WorldAppDelegate.h" 10 | #import "MyView.h" 11 | 12 | @implementation Hello_WorldAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize contentView; 16 | 17 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 18 | // Create window 19 | self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 20 | 21 | // Set up content view 22 | self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; 23 | [window addSubview:contentView]; 24 | 25 | UIView *mainView; 26 | UITextView *textView; 27 | 28 | mainView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 29 | textView = [[UITextView alloc] 30 | initWithFrame: CGRectMake(10.0f, 10.0f, 320.0f, 480.0f)]; 31 | [textView setEditable:YES]; 32 | 33 | //[textView setTextSize:14]; 34 | 35 | //[window orderFront: self]; 36 | //[window makeKey: self]; 37 | //[window _setHidden: NO]; 38 | [window addSubview: mainView]; 39 | [mainView addSubview:textView]; 40 | 41 | [textView setText:@"Hello World"]; 42 | 43 | 44 | // Show window 45 | [window makeKeyAndVisible]; 46 | } 47 | 48 | - (void)dealloc { 49 | [contentView release]; 50 | [window release]; 51 | [super dealloc]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /hellouikit/src/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.10 from Makefile.am. 2 | # src/Makefile. Generated from Makefile.in by configure. 3 | 4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 | # 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 6 | # This Makefile.in is free software; the Free Software Foundation 7 | # gives unlimited permission to copy and/or distribute it, 8 | # with or without modifications, as long as this notice is preserved. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 12 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 13 | # PARTICULAR PURPOSE. 14 | 15 | 16 | 17 | 18 | pkgdatadir = $(datadir)/ihello 19 | pkglibdir = $(libdir)/ihello 20 | pkgincludedir = $(includedir)/ihello 21 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 22 | install_sh_DATA = $(install_sh) -c -m 644 23 | install_sh_PROGRAM = $(install_sh) -c 24 | install_sh_SCRIPT = $(install_sh) -c 25 | INSTALL_HEADER = $(INSTALL_DATA) 26 | transform = $(program_transform_name) 27 | NORMAL_INSTALL = : 28 | PRE_INSTALL = : 29 | POST_INSTALL = : 30 | NORMAL_UNINSTALL = : 31 | PRE_UNINSTALL = : 32 | POST_UNINSTALL = : 33 | build_triplet = i386-apple-darwin10 34 | host_triplet = arm-apple-darwin10 35 | target_triplet = arm-apple-darwin10 36 | bin_PROGRAMS = ihello$(EXEEXT) 37 | subdir = src 38 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in 39 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 40 | am__aclocal_m4_deps = $(top_srcdir)/configure.in 41 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 42 | $(ACLOCAL_M4) 43 | mkinstalldirs = $(install_sh) -d 44 | CONFIG_CLEAN_FILES = 45 | am__installdirs = "$(DESTDIR)$(bindir)" 46 | binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) 47 | PROGRAMS = $(bin_PROGRAMS) 48 | am_ihello_OBJECTS = SampleApp.$(OBJEXT) mainapp.$(OBJEXT) 49 | ihello_OBJECTS = $(am_ihello_OBJECTS) 50 | ihello_LDADD = $(LDADD) 51 | ihello_LINK = $(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(ihello_LDFLAGS) \ 52 | $(LDFLAGS) -o $@ 53 | DEFAULT_INCLUDES = -I. 54 | depcomp = $(SHELL) $(top_srcdir)/depcomp 55 | am__depfiles_maybe = depfiles 56 | OBJCCOMPILE = $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 57 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) 58 | OBJCLD = $(OBJC) 59 | OBJCLINK = $(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) \ 60 | $(LDFLAGS) -o $@ 61 | SOURCES = $(ihello_SOURCES) 62 | DIST_SOURCES = $(ihello_SOURCES) 63 | ETAGS = etags 64 | CTAGS = ctags 65 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 66 | ACLOCAL = ${SHELL} /Users/dli/code/projects/github/osxrce/hellouikit/missing --run aclocal-1.10 67 | AMTAR = ${SHELL} /Users/dli/code/projects/github/osxrce/hellouikit/missing --run tar 68 | AUTOCONF = ${SHELL} /Users/dli/code/projects/github/osxrce/hellouikit/missing --run autoconf 69 | AUTOHEADER = ${SHELL} /Users/dli/code/projects/github/osxrce/hellouikit/missing --run autoheader 70 | AUTOMAKE = ${SHELL} /Users/dli/code/projects/github/osxrce/hellouikit/missing --run automake-1.10 71 | AWK = gawk 72 | 73 | ###///////////////////////////////////////////////////////////// 74 | ### Executable files 75 | ###///////////////////////////////////////////////////////////// 76 | CC = $(PREFIX)gcc 77 | CCDEPMODE = depmode=gcc3 78 | CFLAGS = -g -O2 79 | CPPFLAGS = 80 | CYGPATH_W = echo 81 | DEFS = -DPACKAGE_NAME=\"ihello\" -DPACKAGE_TARNAME=\"ihello\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"ihello\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"ihello\" -DVERSION=\"1.0\" 82 | DEPDIR = .deps 83 | ECHO_C = \c 84 | ECHO_N = 85 | ECHO_T = 86 | EXEEXT = 87 | INSTALL = /usr/bin/install -c 88 | INSTALL_DATA = ${INSTALL} -m 644 89 | INSTALL_PROGRAM = ${INSTALL} 90 | INSTALL_SCRIPT = ${INSTALL} 91 | INSTALL_STRIP_PROGRAM = $(install_sh) -c -s 92 | LDFLAGS = 93 | LIBOBJS = 94 | LIBS = 95 | LTLIBOBJS = 96 | MAKEINFO = ${SHELL} /Users/dli/code/projects/github/osxrce/hellouikit/missing --run makeinfo 97 | MKDIR_P = .././install-sh -c -d 98 | OBJC = gcc 99 | OBJCDEPMODE = depmode=gcc3 100 | OBJCFLAGS = -g -O2 101 | OBJEXT = o 102 | PACKAGE = ihello 103 | PACKAGE_BUGREPORT = 104 | PACKAGE_NAME = ihello 105 | PACKAGE_STRING = ihello 1.0 106 | PACKAGE_TARNAME = ihello 107 | PACKAGE_VERSION = 1.0 108 | PATH_SEPARATOR = : 109 | SET_MAKE = 110 | SHELL = /bin/sh 111 | STRIP = $(PREFIX)strip 112 | VERSION = 1.0 113 | abs_builddir = /Users/dli/code/projects/github/osxrce/hellouikit/src 114 | abs_srcdir = /Users/dli/code/projects/github/osxrce/hellouikit/src 115 | abs_top_builddir = /Users/dli/code/projects/github/osxrce/hellouikit 116 | abs_top_srcdir = /Users/dli/code/projects/github/osxrce/hellouikit 117 | ac_ct_CC = gcc 118 | ac_ct_OBJC = gcc 119 | am__include = include 120 | am__leading_dot = . 121 | am__quote = 122 | am__tar = ${AMTAR} chof - "$$tardir" 123 | am__untar = ${AMTAR} xf - 124 | bindir = ${exec_prefix}/bin 125 | build = i386-apple-darwin10 126 | build_alias = i386-apple-darwin10 127 | build_cpu = i386 128 | build_os = darwin10 129 | build_vendor = apple 130 | builddir = . 131 | datadir = ${datarootdir} 132 | datarootdir = ${prefix}/share 133 | docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} 134 | dvidir = ${docdir} 135 | exec_prefix = ${prefix} 136 | host = arm-apple-darwin10 137 | host_alias = arm-apple-darwin10 138 | host_cpu = arm 139 | host_os = darwin10 140 | host_vendor = apple 141 | htmldir = ${docdir} 142 | includedir = ${prefix}/include 143 | infodir = ${datarootdir}/info 144 | install_sh = $(SHELL) /Users/dli/code/projects/github/osxrce/hellouikit/install-sh 145 | libdir = ${exec_prefix}/lib 146 | libexecdir = ${exec_prefix}/libexec 147 | localedir = ${datarootdir}/locale 148 | localstatedir = ${prefix}/var 149 | mandir = ${datarootdir}/man 150 | mkdir_p = $(top_builddir)/./install-sh -c -d 151 | oldincludedir = /usr/include 152 | pdfdir = ${docdir} 153 | prefix = /usr/local 154 | program_transform_name = s,x,x, 155 | psdir = ${docdir} 156 | sbindir = ${exec_prefix}/sbin 157 | sharedstatedir = ${prefix}/com 158 | srcdir = . 159 | sysconfdir = ${prefix}/etc 160 | target = arm-apple-darwin10 161 | target_alias = 162 | target_cpu = arm 163 | target_os = darwin10 164 | target_vendor = apple 165 | top_builddir = .. 166 | top_srcdir = .. 167 | SDKVER = 4.3 168 | IPHONESDK = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(SDKVER).sdk 169 | 170 | # /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/bin/arm-apple-darwin10- 171 | PREFIX = $(IPHONESDK)/usr/bin/arm-apple-darwin10- 172 | CXX = $(PREFIX)g++ 173 | LD = $(CC) 174 | AR = $(PREFIX)ar 175 | OBJCOPY = $(PREFIX)objcopy 176 | 177 | #################################################################################### 178 | INCPATH = -I"$(IPHONESDK)/usr/include" \ 179 | -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/gcc/arm-apple-darwin10/4.2/include/" \ 180 | -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/include/" \ 181 | -I"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(SDKVER).sdk/usr/include" 182 | #AM_LDFLAGS += -framework AddressBookUI 183 | #AM_LDFLAGS += -framework AddressBook 184 | #AM_LDFLAGS += -framework QuartzCore 185 | #AM_LDFLAGS += -framework GraphicsServices 186 | #AM_LDFLAGS += -framework CoreSurface 187 | #AM_LDFLAGS += -framework CoreAudio 188 | #AM_LDFLAGS += -framework Celestial 189 | #AM_LDFLAGS += -framework AudioToolbox 190 | #AM_LDFLAGS += -framework WebCore 191 | #AM_LDFLAGS += -framework WebKit 192 | #AM_LDFLAGS += -framework SystemConfiguration 193 | #AM_LDFLAGS += -framework CFNetwork 194 | #AM_LDFLAGS += -framework MediaPlayer 195 | #AM_LDFLAGS += -framework OpenGLES 196 | #AM_LDFLAGS += -framework OpenAL 197 | AM_LDFLAGS = -lobjc -bind_at_load -multiply_defined suppress -w \ 198 | -framework CoreFoundation -framework Foundation -framework \ 199 | UIKit -framework CoreGraphics \ 200 | -F"$(IPHONESDK)/System/Library/Frameworks" \ 201 | -F"$(IPHONESDK)/System/Library/PrivateFrameworks" 202 | # AM_CFLAGS += -O3 -DNDEBUG 203 | AM_CFLAGS = $(INCPATH) -std=c99 -W -Wall -funroll-loops \ 204 | -Diphoneos_version_min=2.0 -Wno-unused-parameter \ 205 | -Wno-sign-compare -O0 -g -DDEBUG_MUTEX \ 206 | -F"$(IPHONESDK)/System/Library/Frameworks" \ 207 | -F"$(IPHONESDK)/System/Library/PrivateFrameworks" 208 | ihello_SOURCES = SampleApp.m mainapp.m 209 | ihello_CFLAGS = $(AM_CFLAGS) 210 | ihello_LDFLAGS = $(AM_LDFLAGS) 211 | all: all-am 212 | 213 | .SUFFIXES: 214 | .SUFFIXES: .m .o .obj 215 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 216 | @for dep in $?; do \ 217 | case '$(am__configure_deps)' in \ 218 | *$$dep*) \ 219 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ 220 | && exit 0; \ 221 | exit 1;; \ 222 | esac; \ 223 | done; \ 224 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ 225 | cd $(top_srcdir) && \ 226 | $(AUTOMAKE) --gnu src/Makefile 227 | .PRECIOUS: Makefile 228 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 229 | @case '$?' in \ 230 | *config.status*) \ 231 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ 232 | *) \ 233 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ 234 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ 235 | esac; 236 | 237 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 238 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 239 | 240 | $(top_srcdir)/configure: $(am__configure_deps) 241 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 242 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 243 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 244 | install-binPROGRAMS: $(bin_PROGRAMS) 245 | @$(NORMAL_INSTALL) 246 | test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" 247 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ 248 | p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ 249 | if test -f $$p \ 250 | ; then \ 251 | f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ 252 | echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ 253 | $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ 254 | else :; fi; \ 255 | done 256 | 257 | uninstall-binPROGRAMS: 258 | @$(NORMAL_UNINSTALL) 259 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ 260 | f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ 261 | echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ 262 | rm -f "$(DESTDIR)$(bindir)/$$f"; \ 263 | done 264 | 265 | clean-binPROGRAMS: 266 | -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) 267 | ihello$(EXEEXT): $(ihello_OBJECTS) $(ihello_DEPENDENCIES) 268 | @rm -f ihello$(EXEEXT) 269 | $(ihello_LINK) $(ihello_OBJECTS) $(ihello_LDADD) $(LIBS) 270 | 271 | mostlyclean-compile: 272 | -rm -f *.$(OBJEXT) 273 | 274 | distclean-compile: 275 | -rm -f *.tab.c 276 | 277 | include ./$(DEPDIR)/SampleApp.Po 278 | include ./$(DEPDIR)/mainapp.Po 279 | 280 | .m.o: 281 | $(OBJCCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< 282 | mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 283 | # source='$<' object='$@' libtool=no \ 284 | # DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) \ 285 | # $(OBJCCOMPILE) -c -o $@ $< 286 | 287 | .m.obj: 288 | $(OBJCCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` 289 | mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 290 | # source='$<' object='$@' libtool=no \ 291 | # DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) \ 292 | # $(OBJCCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` 293 | 294 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) 295 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 296 | unique=`for i in $$list; do \ 297 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 298 | done | \ 299 | $(AWK) ' { files[$$0] = 1; } \ 300 | END { for (i in files) print i; }'`; \ 301 | mkid -fID $$unique 302 | tags: TAGS 303 | 304 | TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 305 | $(TAGS_FILES) $(LISP) 306 | tags=; \ 307 | here=`pwd`; \ 308 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 309 | unique=`for i in $$list; do \ 310 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 311 | done | \ 312 | $(AWK) ' { files[$$0] = 1; } \ 313 | END { for (i in files) print i; }'`; \ 314 | if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ 315 | test -n "$$unique" || unique=$$empty_fix; \ 316 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 317 | $$tags $$unique; \ 318 | fi 319 | ctags: CTAGS 320 | CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 321 | $(TAGS_FILES) $(LISP) 322 | tags=; \ 323 | here=`pwd`; \ 324 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 325 | unique=`for i in $$list; do \ 326 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 327 | done | \ 328 | $(AWK) ' { files[$$0] = 1; } \ 329 | END { for (i in files) print i; }'`; \ 330 | test -z "$(CTAGS_ARGS)$$tags$$unique" \ 331 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 332 | $$tags $$unique 333 | 334 | GTAGS: 335 | here=`$(am__cd) $(top_builddir) && pwd` \ 336 | && cd $(top_srcdir) \ 337 | && gtags -i $(GTAGS_ARGS) $$here 338 | 339 | distclean-tags: 340 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 341 | 342 | distdir: $(DISTFILES) 343 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 344 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 345 | list='$(DISTFILES)'; \ 346 | dist_files=`for file in $$list; do echo $$file; done | \ 347 | sed -e "s|^$$srcdirstrip/||;t" \ 348 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 349 | case $$dist_files in \ 350 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 351 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 352 | sort -u` ;; \ 353 | esac; \ 354 | for file in $$dist_files; do \ 355 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 356 | if test -d $$d/$$file; then \ 357 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 358 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 359 | cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ 360 | fi; \ 361 | cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ 362 | else \ 363 | test -f $(distdir)/$$file \ 364 | || cp -p $$d/$$file $(distdir)/$$file \ 365 | || exit 1; \ 366 | fi; \ 367 | done 368 | check-am: all-am 369 | check: check-am 370 | all-am: Makefile $(PROGRAMS) 371 | installdirs: 372 | for dir in "$(DESTDIR)$(bindir)"; do \ 373 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ 374 | done 375 | install: install-am 376 | install-exec: install-exec-am 377 | install-data: install-data-am 378 | uninstall: uninstall-am 379 | 380 | install-am: all-am 381 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 382 | 383 | installcheck: installcheck-am 384 | install-strip: 385 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 386 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 387 | `test -z '$(STRIP)' || \ 388 | echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install 389 | mostlyclean-generic: 390 | 391 | clean-generic: 392 | 393 | distclean-generic: 394 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 395 | 396 | maintainer-clean-generic: 397 | @echo "This command is intended for maintainers to use" 398 | @echo "it deletes files that may require special tools to rebuild." 399 | clean: clean-am 400 | 401 | clean-am: clean-binPROGRAMS clean-generic mostlyclean-am 402 | 403 | distclean: distclean-am 404 | -rm -rf ./$(DEPDIR) 405 | -rm -f Makefile 406 | distclean-am: clean-am distclean-compile distclean-generic \ 407 | distclean-tags 408 | 409 | dvi: dvi-am 410 | 411 | dvi-am: 412 | 413 | html: html-am 414 | 415 | info: info-am 416 | 417 | info-am: 418 | 419 | install-data-am: 420 | 421 | install-dvi: install-dvi-am 422 | 423 | install-exec-am: install-binPROGRAMS 424 | 425 | install-html: install-html-am 426 | 427 | install-info: install-info-am 428 | 429 | install-man: 430 | 431 | install-pdf: install-pdf-am 432 | 433 | install-ps: install-ps-am 434 | 435 | installcheck-am: 436 | 437 | maintainer-clean: maintainer-clean-am 438 | -rm -rf ./$(DEPDIR) 439 | -rm -f Makefile 440 | maintainer-clean-am: distclean-am maintainer-clean-generic 441 | 442 | mostlyclean: mostlyclean-am 443 | 444 | mostlyclean-am: mostlyclean-compile mostlyclean-generic 445 | 446 | pdf: pdf-am 447 | 448 | pdf-am: 449 | 450 | ps: ps-am 451 | 452 | ps-am: 453 | 454 | uninstall-am: uninstall-binPROGRAMS 455 | 456 | .MAKE: install-am install-strip 457 | 458 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ 459 | clean-generic ctags distclean distclean-compile \ 460 | distclean-generic distclean-tags distdir dvi dvi-am html \ 461 | html-am info info-am install install-am install-binPROGRAMS \ 462 | install-data install-data-am install-dvi install-dvi-am \ 463 | install-exec install-exec-am install-html install-html-am \ 464 | install-info install-info-am install-man install-pdf \ 465 | install-pdf-am install-ps install-ps-am install-strip \ 466 | installcheck installcheck-am installdirs maintainer-clean \ 467 | maintainer-clean-generic mostlyclean mostlyclean-compile \ 468 | mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ 469 | uninstall-am uninstall-binPROGRAMS 470 | 471 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 472 | # Otherwise a system limit (for SysV at least) may be exceeded. 473 | .NOEXPORT: 474 | -------------------------------------------------------------------------------- /hellouikit/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## SDK 2 | SDKVER = 4.3 3 | 4 | ## iPhone SDK 5 | IPHONESDK = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(SDKVER).sdk 6 | 7 | # /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/bin/arm-apple-darwin10- 8 | 9 | PREFIX = $(IPHONESDK)/usr/bin/arm-apple-darwin10- 10 | 11 | ###///////////////////////////////////////////////////////////// 12 | ### Executable files 13 | ###///////////////////////////////////////////////////////////// 14 | 15 | CC = $(PREFIX)gcc 16 | CXX = $(PREFIX)g++ 17 | LD = $(CC) 18 | AR = $(PREFIX)ar 19 | STRIP = $(PREFIX)strip 20 | OBJCOPY = $(PREFIX)objcopy 21 | 22 | #################################################################################### 23 | 24 | ## 25 | INCPATH = 26 | INCPATH += -I"$(IPHONESDK)/usr/include" 27 | INCPATH += -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/gcc/arm-apple-darwin10/4.2/include/" 28 | INCPATH += -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/include/" 29 | INCPATH += -I"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(SDKVER).sdk/usr/include" 30 | 31 | ## 32 | AM_LDFLAGS = 33 | AM_LDFLAGS += -lobjc \ 34 | -bind_at_load \ 35 | -multiply_defined suppress \ 36 | -w 37 | 38 | AM_LDFLAGS += -framework CoreFoundation 39 | AM_LDFLAGS += -framework Foundation 40 | AM_LDFLAGS += -framework UIKit 41 | AM_LDFLAGS += -framework CoreGraphics 42 | #AM_LDFLAGS += -framework AddressBookUI 43 | #AM_LDFLAGS += -framework AddressBook 44 | #AM_LDFLAGS += -framework QuartzCore 45 | #AM_LDFLAGS += -framework GraphicsServices 46 | #AM_LDFLAGS += -framework CoreSurface 47 | #AM_LDFLAGS += -framework CoreAudio 48 | #AM_LDFLAGS += -framework Celestial 49 | #AM_LDFLAGS += -framework AudioToolbox 50 | #AM_LDFLAGS += -framework WebCore 51 | #AM_LDFLAGS += -framework WebKit 52 | #AM_LDFLAGS += -framework SystemConfiguration 53 | #AM_LDFLAGS += -framework CFNetwork 54 | #AM_LDFLAGS += -framework MediaPlayer 55 | #AM_LDFLAGS += -framework OpenGLES 56 | #AM_LDFLAGS += -framework OpenAL 57 | 58 | AM_LDFLAGS += -F"$(IPHONESDK)/System/Library/Frameworks" 59 | AM_LDFLAGS += -F"$(IPHONESDK)/System/Library/PrivateFrameworks" 60 | 61 | ## 62 | AM_CFLAGS = 63 | AM_CFLAGS += $(INCPATH) \ 64 | -std=c99 \ 65 | -W -Wall \ 66 | -funroll-loops \ 67 | -Diphoneos_version_min=2.0 \ 68 | -Wno-unused-parameter \ 69 | -Wno-sign-compare 70 | 71 | AM_CFLAGS += -O0 -g -DDEBUG_MUTEX 72 | # AM_CFLAGS += -O3 -DNDEBUG 73 | 74 | AM_CFLAGS += -F"$(IPHONESDK)/System/Library/Frameworks" 75 | AM_CFLAGS += -F"$(IPHONESDK)/System/Library/PrivateFrameworks" 76 | 77 | bin_PROGRAMS = ihello 78 | 79 | ihello_SOURCES = SampleApp.m mainapp.m 80 | ihello_CFLAGS = $(AM_CFLAGS) 81 | ihello_LDFLAGS = $(AM_LDFLAGS) 82 | 83 | -------------------------------------------------------------------------------- /hellouikit/src/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.10 from Makefile.am. 2 | # @configure_input@ 3 | 4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 | # 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 6 | # This Makefile.in is free software; the Free Software Foundation 7 | # gives unlimited permission to copy and/or distribute it, 8 | # with or without modifications, as long as this notice is preserved. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 12 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 13 | # PARTICULAR PURPOSE. 14 | 15 | @SET_MAKE@ 16 | 17 | VPATH = @srcdir@ 18 | pkgdatadir = $(datadir)/@PACKAGE@ 19 | pkglibdir = $(libdir)/@PACKAGE@ 20 | pkgincludedir = $(includedir)/@PACKAGE@ 21 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 22 | install_sh_DATA = $(install_sh) -c -m 644 23 | install_sh_PROGRAM = $(install_sh) -c 24 | install_sh_SCRIPT = $(install_sh) -c 25 | INSTALL_HEADER = $(INSTALL_DATA) 26 | transform = $(program_transform_name) 27 | NORMAL_INSTALL = : 28 | PRE_INSTALL = : 29 | POST_INSTALL = : 30 | NORMAL_UNINSTALL = : 31 | PRE_UNINSTALL = : 32 | POST_UNINSTALL = : 33 | build_triplet = @build@ 34 | host_triplet = @host@ 35 | target_triplet = @target@ 36 | bin_PROGRAMS = ihello$(EXEEXT) 37 | subdir = src 38 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in 39 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 40 | am__aclocal_m4_deps = $(top_srcdir)/configure.in 41 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 42 | $(ACLOCAL_M4) 43 | mkinstalldirs = $(install_sh) -d 44 | CONFIG_CLEAN_FILES = 45 | am__installdirs = "$(DESTDIR)$(bindir)" 46 | binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) 47 | PROGRAMS = $(bin_PROGRAMS) 48 | am_ihello_OBJECTS = SampleApp.$(OBJEXT) mainapp.$(OBJEXT) 49 | ihello_OBJECTS = $(am_ihello_OBJECTS) 50 | ihello_LDADD = $(LDADD) 51 | ihello_LINK = $(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(ihello_LDFLAGS) \ 52 | $(LDFLAGS) -o $@ 53 | DEFAULT_INCLUDES = -I.@am__isrc@ 54 | depcomp = $(SHELL) $(top_srcdir)/depcomp 55 | am__depfiles_maybe = depfiles 56 | OBJCCOMPILE = $(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 57 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS) 58 | OBJCLD = $(OBJC) 59 | OBJCLINK = $(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) \ 60 | $(LDFLAGS) -o $@ 61 | SOURCES = $(ihello_SOURCES) 62 | DIST_SOURCES = $(ihello_SOURCES) 63 | ETAGS = etags 64 | CTAGS = ctags 65 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 66 | ACLOCAL = @ACLOCAL@ 67 | AMTAR = @AMTAR@ 68 | AUTOCONF = @AUTOCONF@ 69 | AUTOHEADER = @AUTOHEADER@ 70 | AUTOMAKE = @AUTOMAKE@ 71 | AWK = @AWK@ 72 | 73 | ###///////////////////////////////////////////////////////////// 74 | ### Executable files 75 | ###///////////////////////////////////////////////////////////// 76 | CC = $(PREFIX)gcc 77 | CCDEPMODE = @CCDEPMODE@ 78 | CFLAGS = @CFLAGS@ 79 | CPPFLAGS = @CPPFLAGS@ 80 | CYGPATH_W = @CYGPATH_W@ 81 | DEFS = @DEFS@ 82 | DEPDIR = @DEPDIR@ 83 | ECHO_C = @ECHO_C@ 84 | ECHO_N = @ECHO_N@ 85 | ECHO_T = @ECHO_T@ 86 | EXEEXT = @EXEEXT@ 87 | INSTALL = @INSTALL@ 88 | INSTALL_DATA = @INSTALL_DATA@ 89 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 90 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ 91 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 92 | LDFLAGS = @LDFLAGS@ 93 | LIBOBJS = @LIBOBJS@ 94 | LIBS = @LIBS@ 95 | LTLIBOBJS = @LTLIBOBJS@ 96 | MAKEINFO = @MAKEINFO@ 97 | MKDIR_P = @MKDIR_P@ 98 | OBJC = @OBJC@ 99 | OBJCDEPMODE = @OBJCDEPMODE@ 100 | OBJCFLAGS = @OBJCFLAGS@ 101 | OBJEXT = @OBJEXT@ 102 | PACKAGE = @PACKAGE@ 103 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ 104 | PACKAGE_NAME = @PACKAGE_NAME@ 105 | PACKAGE_STRING = @PACKAGE_STRING@ 106 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ 107 | PACKAGE_VERSION = @PACKAGE_VERSION@ 108 | PATH_SEPARATOR = @PATH_SEPARATOR@ 109 | SET_MAKE = @SET_MAKE@ 110 | SHELL = @SHELL@ 111 | STRIP = $(PREFIX)strip 112 | VERSION = @VERSION@ 113 | abs_builddir = @abs_builddir@ 114 | abs_srcdir = @abs_srcdir@ 115 | abs_top_builddir = @abs_top_builddir@ 116 | abs_top_srcdir = @abs_top_srcdir@ 117 | ac_ct_CC = @ac_ct_CC@ 118 | ac_ct_OBJC = @ac_ct_OBJC@ 119 | am__include = @am__include@ 120 | am__leading_dot = @am__leading_dot@ 121 | am__quote = @am__quote@ 122 | am__tar = @am__tar@ 123 | am__untar = @am__untar@ 124 | bindir = @bindir@ 125 | build = @build@ 126 | build_alias = @build_alias@ 127 | build_cpu = @build_cpu@ 128 | build_os = @build_os@ 129 | build_vendor = @build_vendor@ 130 | builddir = @builddir@ 131 | datadir = @datadir@ 132 | datarootdir = @datarootdir@ 133 | docdir = @docdir@ 134 | dvidir = @dvidir@ 135 | exec_prefix = @exec_prefix@ 136 | host = @host@ 137 | host_alias = @host_alias@ 138 | host_cpu = @host_cpu@ 139 | host_os = @host_os@ 140 | host_vendor = @host_vendor@ 141 | htmldir = @htmldir@ 142 | includedir = @includedir@ 143 | infodir = @infodir@ 144 | install_sh = @install_sh@ 145 | libdir = @libdir@ 146 | libexecdir = @libexecdir@ 147 | localedir = @localedir@ 148 | localstatedir = @localstatedir@ 149 | mandir = @mandir@ 150 | mkdir_p = @mkdir_p@ 151 | oldincludedir = @oldincludedir@ 152 | pdfdir = @pdfdir@ 153 | prefix = @prefix@ 154 | program_transform_name = @program_transform_name@ 155 | psdir = @psdir@ 156 | sbindir = @sbindir@ 157 | sharedstatedir = @sharedstatedir@ 158 | srcdir = @srcdir@ 159 | sysconfdir = @sysconfdir@ 160 | target = @target@ 161 | target_alias = @target_alias@ 162 | target_cpu = @target_cpu@ 163 | target_os = @target_os@ 164 | target_vendor = @target_vendor@ 165 | top_builddir = @top_builddir@ 166 | top_srcdir = @top_srcdir@ 167 | SDKVER = 4.3 168 | IPHONESDK = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(SDKVER).sdk 169 | 170 | # /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/bin/arm-apple-darwin10- 171 | PREFIX = $(IPHONESDK)/usr/bin/arm-apple-darwin10- 172 | CXX = $(PREFIX)g++ 173 | LD = $(CC) 174 | AR = $(PREFIX)ar 175 | OBJCOPY = $(PREFIX)objcopy 176 | 177 | #################################################################################### 178 | INCPATH = -I"$(IPHONESDK)/usr/include" \ 179 | -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/gcc/arm-apple-darwin10/4.2/include/" \ 180 | -I"/Developer/Platforms/iPhoneOS.platform/Developer/usr/include/" \ 181 | -I"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(SDKVER).sdk/usr/include" 182 | #AM_LDFLAGS += -framework AddressBookUI 183 | #AM_LDFLAGS += -framework AddressBook 184 | #AM_LDFLAGS += -framework QuartzCore 185 | #AM_LDFLAGS += -framework GraphicsServices 186 | #AM_LDFLAGS += -framework CoreSurface 187 | #AM_LDFLAGS += -framework CoreAudio 188 | #AM_LDFLAGS += -framework Celestial 189 | #AM_LDFLAGS += -framework AudioToolbox 190 | #AM_LDFLAGS += -framework WebCore 191 | #AM_LDFLAGS += -framework WebKit 192 | #AM_LDFLAGS += -framework SystemConfiguration 193 | #AM_LDFLAGS += -framework CFNetwork 194 | #AM_LDFLAGS += -framework MediaPlayer 195 | #AM_LDFLAGS += -framework OpenGLES 196 | #AM_LDFLAGS += -framework OpenAL 197 | AM_LDFLAGS = -lobjc -bind_at_load -multiply_defined suppress -w \ 198 | -framework CoreFoundation -framework Foundation -framework \ 199 | UIKit -framework CoreGraphics \ 200 | -F"$(IPHONESDK)/System/Library/Frameworks" \ 201 | -F"$(IPHONESDK)/System/Library/PrivateFrameworks" 202 | # AM_CFLAGS += -O3 -DNDEBUG 203 | AM_CFLAGS = $(INCPATH) -std=c99 -W -Wall -funroll-loops \ 204 | -Diphoneos_version_min=2.0 -Wno-unused-parameter \ 205 | -Wno-sign-compare -O0 -g -DDEBUG_MUTEX \ 206 | -F"$(IPHONESDK)/System/Library/Frameworks" \ 207 | -F"$(IPHONESDK)/System/Library/PrivateFrameworks" 208 | ihello_SOURCES = SampleApp.m mainapp.m 209 | ihello_CFLAGS = $(AM_CFLAGS) 210 | ihello_LDFLAGS = $(AM_LDFLAGS) 211 | all: all-am 212 | 213 | .SUFFIXES: 214 | .SUFFIXES: .m .o .obj 215 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 216 | @for dep in $?; do \ 217 | case '$(am__configure_deps)' in \ 218 | *$$dep*) \ 219 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ 220 | && exit 0; \ 221 | exit 1;; \ 222 | esac; \ 223 | done; \ 224 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ 225 | cd $(top_srcdir) && \ 226 | $(AUTOMAKE) --gnu src/Makefile 227 | .PRECIOUS: Makefile 228 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 229 | @case '$?' in \ 230 | *config.status*) \ 231 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ 232 | *) \ 233 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ 234 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ 235 | esac; 236 | 237 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 238 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 239 | 240 | $(top_srcdir)/configure: $(am__configure_deps) 241 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 242 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 243 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 244 | install-binPROGRAMS: $(bin_PROGRAMS) 245 | @$(NORMAL_INSTALL) 246 | test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" 247 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ 248 | p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ 249 | if test -f $$p \ 250 | ; then \ 251 | f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ 252 | echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ 253 | $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ 254 | else :; fi; \ 255 | done 256 | 257 | uninstall-binPROGRAMS: 258 | @$(NORMAL_UNINSTALL) 259 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ 260 | f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ 261 | echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ 262 | rm -f "$(DESTDIR)$(bindir)/$$f"; \ 263 | done 264 | 265 | clean-binPROGRAMS: 266 | -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) 267 | ihello$(EXEEXT): $(ihello_OBJECTS) $(ihello_DEPENDENCIES) 268 | @rm -f ihello$(EXEEXT) 269 | $(ihello_LINK) $(ihello_OBJECTS) $(ihello_LDADD) $(LIBS) 270 | 271 | mostlyclean-compile: 272 | -rm -f *.$(OBJEXT) 273 | 274 | distclean-compile: 275 | -rm -f *.tab.c 276 | 277 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SampleApp.Po@am__quote@ 278 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mainapp.Po@am__quote@ 279 | 280 | .m.o: 281 | @am__fastdepOBJC_TRUE@ $(OBJCCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< 282 | @am__fastdepOBJC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 283 | @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ 284 | @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 285 | @am__fastdepOBJC_FALSE@ $(OBJCCOMPILE) -c -o $@ $< 286 | 287 | .m.obj: 288 | @am__fastdepOBJC_TRUE@ $(OBJCCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` 289 | @am__fastdepOBJC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 290 | @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ 291 | @AMDEP_TRUE@@am__fastdepOBJC_FALSE@ DEPDIR=$(DEPDIR) $(OBJCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 292 | @am__fastdepOBJC_FALSE@ $(OBJCCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` 293 | 294 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) 295 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 296 | unique=`for i in $$list; do \ 297 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 298 | done | \ 299 | $(AWK) ' { files[$$0] = 1; } \ 300 | END { for (i in files) print i; }'`; \ 301 | mkid -fID $$unique 302 | tags: TAGS 303 | 304 | TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 305 | $(TAGS_FILES) $(LISP) 306 | tags=; \ 307 | here=`pwd`; \ 308 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 309 | unique=`for i in $$list; do \ 310 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 311 | done | \ 312 | $(AWK) ' { files[$$0] = 1; } \ 313 | END { for (i in files) print i; }'`; \ 314 | if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ 315 | test -n "$$unique" || unique=$$empty_fix; \ 316 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 317 | $$tags $$unique; \ 318 | fi 319 | ctags: CTAGS 320 | CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 321 | $(TAGS_FILES) $(LISP) 322 | tags=; \ 323 | here=`pwd`; \ 324 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 325 | unique=`for i in $$list; do \ 326 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 327 | done | \ 328 | $(AWK) ' { files[$$0] = 1; } \ 329 | END { for (i in files) print i; }'`; \ 330 | test -z "$(CTAGS_ARGS)$$tags$$unique" \ 331 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 332 | $$tags $$unique 333 | 334 | GTAGS: 335 | here=`$(am__cd) $(top_builddir) && pwd` \ 336 | && cd $(top_srcdir) \ 337 | && gtags -i $(GTAGS_ARGS) $$here 338 | 339 | distclean-tags: 340 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 341 | 342 | distdir: $(DISTFILES) 343 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 344 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 345 | list='$(DISTFILES)'; \ 346 | dist_files=`for file in $$list; do echo $$file; done | \ 347 | sed -e "s|^$$srcdirstrip/||;t" \ 348 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 349 | case $$dist_files in \ 350 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 351 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 352 | sort -u` ;; \ 353 | esac; \ 354 | for file in $$dist_files; do \ 355 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 356 | if test -d $$d/$$file; then \ 357 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 358 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 359 | cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ 360 | fi; \ 361 | cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ 362 | else \ 363 | test -f $(distdir)/$$file \ 364 | || cp -p $$d/$$file $(distdir)/$$file \ 365 | || exit 1; \ 366 | fi; \ 367 | done 368 | check-am: all-am 369 | check: check-am 370 | all-am: Makefile $(PROGRAMS) 371 | installdirs: 372 | for dir in "$(DESTDIR)$(bindir)"; do \ 373 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ 374 | done 375 | install: install-am 376 | install-exec: install-exec-am 377 | install-data: install-data-am 378 | uninstall: uninstall-am 379 | 380 | install-am: all-am 381 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 382 | 383 | installcheck: installcheck-am 384 | install-strip: 385 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 386 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 387 | `test -z '$(STRIP)' || \ 388 | echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install 389 | mostlyclean-generic: 390 | 391 | clean-generic: 392 | 393 | distclean-generic: 394 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 395 | 396 | maintainer-clean-generic: 397 | @echo "This command is intended for maintainers to use" 398 | @echo "it deletes files that may require special tools to rebuild." 399 | clean: clean-am 400 | 401 | clean-am: clean-binPROGRAMS clean-generic mostlyclean-am 402 | 403 | distclean: distclean-am 404 | -rm -rf ./$(DEPDIR) 405 | -rm -f Makefile 406 | distclean-am: clean-am distclean-compile distclean-generic \ 407 | distclean-tags 408 | 409 | dvi: dvi-am 410 | 411 | dvi-am: 412 | 413 | html: html-am 414 | 415 | info: info-am 416 | 417 | info-am: 418 | 419 | install-data-am: 420 | 421 | install-dvi: install-dvi-am 422 | 423 | install-exec-am: install-binPROGRAMS 424 | 425 | install-html: install-html-am 426 | 427 | install-info: install-info-am 428 | 429 | install-man: 430 | 431 | install-pdf: install-pdf-am 432 | 433 | install-ps: install-ps-am 434 | 435 | installcheck-am: 436 | 437 | maintainer-clean: maintainer-clean-am 438 | -rm -rf ./$(DEPDIR) 439 | -rm -f Makefile 440 | maintainer-clean-am: distclean-am maintainer-clean-generic 441 | 442 | mostlyclean: mostlyclean-am 443 | 444 | mostlyclean-am: mostlyclean-compile mostlyclean-generic 445 | 446 | pdf: pdf-am 447 | 448 | pdf-am: 449 | 450 | ps: ps-am 451 | 452 | ps-am: 453 | 454 | uninstall-am: uninstall-binPROGRAMS 455 | 456 | .MAKE: install-am install-strip 457 | 458 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ 459 | clean-generic ctags distclean distclean-compile \ 460 | distclean-generic distclean-tags distdir dvi dvi-am html \ 461 | html-am info info-am install install-am install-binPROGRAMS \ 462 | install-data install-data-am install-dvi install-dvi-am \ 463 | install-exec install-exec-am install-html install-html-am \ 464 | install-info install-info-am install-man install-pdf \ 465 | install-pdf-am install-ps install-ps-am install-strip \ 466 | installcheck installcheck-am installdirs maintainer-clean \ 467 | maintainer-clean-generic mostlyclean mostlyclean-compile \ 468 | mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ 469 | uninstall-am uninstall-binPROGRAMS 470 | 471 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 472 | # Otherwise a system limit (for SysV at least) may be exceeded. 473 | .NOEXPORT: 474 | -------------------------------------------------------------------------------- /hellouikit/src/MyView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyView.h 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MyView : UIView { 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /hellouikit/src/MyView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyView.m 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import "MyView.h" 10 | 11 | @implementation MyView 12 | 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /hellouikit/src/bak/SampleApp.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import 5 | #import 6 | #import 7 | 8 | @interface SampleApp : UIApplication { 9 | UIView *mainView; 10 | UITextView *textView; 11 | } 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /hellouikit/src/bak/SampleApp.mm: -------------------------------------------------------------------------------- 1 | #import "SampleApp.h" 2 | 3 | @implementation SampleApp 4 | 5 | - (void) applicationDidFinishLaunching: (id) unused 6 | { 7 | UIWindow *window; 8 | // struct CGRect rect = [UIHardware fullScreenApplicationContentRect]; 9 | CGRect rect =CGRectMake(0,0,320,480); 10 | rect.origin.x = rect.origin.y = 0.0f; 11 | 12 | window = [[UIWindow alloc] initWithContentRect: rect]; 13 | mainView = [[UIView alloc] initWithFrame: rect]; 14 | textView = [[UITextView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)]; 15 | [textView setEditable:YES]; 16 | [textView setTextSize:14]; 17 | 18 | [window orderFront: self]; 19 | [window makeKey: self]; 20 | [window _setHidden: NO]; 21 | [window setContentView: mainView]; 22 | [mainView addSubview:textView]; 23 | 24 | [textView setText:@"Hello World"]; 25 | } 26 | 27 | @end 28 | 29 | -------------------------------------------------------------------------------- /hellouikit/src/bak/mainapp.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import "SampleApp.h" 3 | 4 | int main(int argc, char **argv) 5 | { 6 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 7 | int retVal = UIApplicationMain(argc, argv, nil, [SampleApp class]); 8 | [pool release]; 9 | return retVal; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /hellouikit/src/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, @"Hello_WorldAppDelegate"); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /ios_helloworld/Classes/Hello_WorldAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Hello_WorldAppDelegate.h 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class MyView; 12 | 13 | @interface Hello_WorldAppDelegate : NSObject { 14 | UIWindow *window; 15 | MyView *contentView; 16 | } 17 | 18 | @property (nonatomic, retain) UIWindow *window; 19 | @property (nonatomic, retain) MyView *contentView; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /ios_helloworld/Classes/Hello_WorldAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // Hello_WorldAppDelegate.m 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import "Hello_WorldAppDelegate.h" 10 | #import "MyView.h" 11 | 12 | @implementation Hello_WorldAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize contentView; 16 | 17 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 18 | // Create window 19 | self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 20 | 21 | // Set up content view 22 | self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; 23 | [window addSubview:contentView]; 24 | 25 | UIView *mainView; 26 | UITextView *textView; 27 | 28 | mainView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 29 | textView = [[UITextView alloc] 30 | initWithFrame: CGRectMake(10.0f, 10.0f, 320.0f, 480.0f)]; 31 | [textView setEditable:YES]; 32 | 33 | //[textView setTextSize:14]; 34 | 35 | //[window orderFront: self]; 36 | //[window makeKey: self]; 37 | //[window _setHidden: NO]; 38 | [window addSubview: mainView]; 39 | [mainView addSubview:textView]; 40 | 41 | [textView setText:@"Hello World"]; 42 | 43 | 44 | // Show window 45 | [window makeKeyAndVisible]; 46 | } 47 | 48 | - (void)dealloc { 49 | [contentView release]; 50 | [window release]; 51 | [super dealloc]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /ios_helloworld/Classes/MyView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyView.h 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MyView : UIView { 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ios_helloworld/Classes/MyView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyView.m 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import "MyView.h" 10 | 11 | @implementation MyView 12 | 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ios_helloworld/Hello World.xcodeproj/admin.pbxuser: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | 1D3623240D0F684500981E51 /* Hello_WorldAppDelegate.h */ = { 4 | uiCtxt = { 5 | sepNavIntBoundsRect = "{{0, 0}, {630, 668}}"; 6 | sepNavSelRange = "{172, 0}"; 7 | sepNavVisRange = "{0, 392}"; 8 | sepNavWindowFrame = "{{111, 35}, {689, 796}}"; 9 | }; 10 | }; 11 | 1D3623250D0F684500981E51 /* Hello_WorldAppDelegate.m */ = { 12 | uiCtxt = { 13 | sepNavIntBoundsRect = "{{0, 0}, {986, 686}}"; 14 | sepNavSelRange = "{647, 341}"; 15 | sepNavVisRange = "{0, 1126}"; 16 | sepNavWindowFrame = "{{174, 75}, {1045, 803}}"; 17 | }; 18 | }; 19 | 1D6058900D05DD3D006BFB54 /* Hello World */ = { 20 | activeExec = 0; 21 | executables = ( 22 | 84CE6A870D81EFDF00EA2B95 /* Hello World */, 23 | ); 24 | }; 25 | 289E37740D53116900ACCF19 /* MyView.h */ = { 26 | uiCtxt = { 27 | sepNavIntBoundsRect = "{{0, 0}, {470, 347}}"; 28 | sepNavSelRange = "{186, 0}"; 29 | sepNavVisRange = "{0, 195}"; 30 | sepNavWindowFrame = "{{88, 377}, {529, 475}}"; 31 | }; 32 | }; 33 | 289E37750D53116900ACCF19 /* MyView.m */ = { 34 | uiCtxt = { 35 | sepNavIntBoundsRect = "{{0, 0}, {630, 668}}"; 36 | sepNavSelRange = "{182, 0}"; 37 | sepNavVisRange = "{0, 183}"; 38 | sepNavWindowFrame = "{{65, 77}, {689, 796}}"; 39 | }; 40 | }; 41 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 42 | activeArchitecture = i386; 43 | activeBuildConfigurationName = Debug; 44 | activeExecutable = 84CE6A870D81EFDF00EA2B95 /* Hello World */; 45 | activeTarget = 1D6058900D05DD3D006BFB54 /* Hello World */; 46 | codeSenseManager = 84CE6A920D81EFE700EA2B95 /* Code sense */; 47 | executables = ( 48 | 84CE6A870D81EFDF00EA2B95 /* Hello World */, 49 | ); 50 | perUserDictionary = { 51 | PBXPerProjectTemplateStateSaveDate = 226619359; 52 | PBXWorkspaceStateSaveDate = 226619359; 53 | }; 54 | perUserProjectItems = { 55 | 84CE6A990D81F20600EA2B95 /* PBXBookmark */ = 84CE6A990D81F20600EA2B95 /* PBXBookmark */; 56 | 84CE6AAA0D81F46200EA2B95 /* PBXTextBookmark */ = 84CE6AAA0D81F46200EA2B95 /* PBXTextBookmark */; 57 | }; 58 | sourceControlManager = 84CE6A910D81EFE700EA2B95 /* Source Control */; 59 | userBuildSettings = { 60 | }; 61 | }; 62 | 84CE6A870D81EFDF00EA2B95 /* Hello World */ = { 63 | isa = PBXExecutable; 64 | activeArgIndices = ( 65 | ); 66 | argumentStrings = ( 67 | ); 68 | autoAttachOnCrash = 1; 69 | breakpointsEnabled = 1; 70 | configStateDict = { 71 | }; 72 | customDataFormattersEnabled = 1; 73 | debuggerPlugin = GDBDebugging; 74 | disassemblyDisplayState = 0; 75 | dylibVariantSuffix = ""; 76 | enableDebugStr = 1; 77 | environmentEntries = ( 78 | ); 79 | executableSystemSymbolLevel = 0; 80 | executableUserSymbolLevel = 0; 81 | libgmallocEnabled = 0; 82 | name = "Hello World"; 83 | savedGlobals = { 84 | }; 85 | sourceDirectories = ( 86 | ); 87 | }; 88 | 84CE6A910D81EFE700EA2B95 /* Source Control */ = { 89 | isa = PBXSourceControlManager; 90 | fallbackIsa = XCSourceControlManager; 91 | isSCMEnabled = 0; 92 | scmConfiguration = { 93 | }; 94 | }; 95 | 84CE6A920D81EFE700EA2B95 /* Code sense */ = { 96 | isa = PBXCodeSenseManager; 97 | indexTemplatePath = ""; 98 | }; 99 | 84CE6A990D81F20600EA2B95 /* PBXBookmark */ = { 100 | isa = PBXBookmark; 101 | fRef = 289E37750D53116900ACCF19 /* MyView.m */; 102 | }; 103 | 84CE6AAA0D81F46200EA2B95 /* PBXTextBookmark */ = { 104 | isa = PBXTextBookmark; 105 | fRef = 289E37750D53116900ACCF19 /* MyView.m */; 106 | name = "MyView.m: 14"; 107 | rLen = 0; 108 | rLoc = 182; 109 | rType = 0; 110 | vrLen = 183; 111 | vrLoc = 0; 112 | }; 113 | } 114 | -------------------------------------------------------------------------------- /ios_helloworld/Hello World.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 45; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1D3623260D0F684500981E51 /* Hello_WorldAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* Hello_WorldAppDelegate.m */; }; 11 | 1D3623EC0D0F72F000981E51 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; 12 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; 13 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 14 | 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; 15 | 289E37760D53116900ACCF19 /* MyView.m in Sources */ = {isa = PBXBuildFile; fileRef = 289E37750D53116900ACCF19 /* MyView.m */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 20 | 1D3623240D0F684500981E51 /* Hello_WorldAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Hello_WorldAppDelegate.h; sourceTree = ""; }; 21 | 1D3623250D0F684500981E51 /* Hello_WorldAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Hello_WorldAppDelegate.m; sourceTree = ""; }; 22 | 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 23 | 1D6058910D05DD3D006BFB54 /* Hello World.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Hello World.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 25 | 289E37740D53116900ACCF19 /* MyView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyView.h; sourceTree = ""; }; 26 | 289E37750D53116900ACCF19 /* MyView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyView.m; sourceTree = ""; }; 27 | 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 28 | 32CA4F630368D1EE00C91783 /* Hello World_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Hello World_Prefix.pch"; sourceTree = ""; }; 29 | 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | /* End PBXFileReference section */ 31 | 32 | /* Begin PBXFrameworksBuildPhase section */ 33 | 1D60588F0D05DD3D006BFB54 /* Frameworks */ = { 34 | isa = PBXFrameworksBuildPhase; 35 | buildActionMask = 2147483647; 36 | files = ( 37 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, 38 | 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */, 39 | 1D3623EC0D0F72F000981E51 /* CoreGraphics.framework in Frameworks */, 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 080E96DDFE201D6D7F000001 /* Classes */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 289E37740D53116900ACCF19 /* MyView.h */, 50 | 289E37750D53116900ACCF19 /* MyView.m */, 51 | 1D3623240D0F684500981E51 /* Hello_WorldAppDelegate.h */, 52 | 1D3623250D0F684500981E51 /* Hello_WorldAppDelegate.m */, 53 | ); 54 | path = Classes; 55 | sourceTree = ""; 56 | }; 57 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */, 61 | 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, 62 | 1D30AB110D05D00D00671497 /* Foundation.framework */, 63 | ); 64 | name = "Linked Frameworks"; 65 | sourceTree = ""; 66 | }; 67 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | ); 71 | name = "Other Frameworks"; 72 | sourceTree = ""; 73 | }; 74 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 1D6058910D05DD3D006BFB54 /* Hello World.app */, 78 | ); 79 | name = Products; 80 | sourceTree = ""; 81 | }; 82 | 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 080E96DDFE201D6D7F000001 /* Classes */, 86 | 29B97315FDCFA39411CA2CEA /* Other Sources */, 87 | 29B97317FDCFA39411CA2CEA /* Resources */, 88 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 89 | 19C28FACFE9D520D11CA2CBB /* Products */, 90 | ); 91 | name = CustomTemplate; 92 | sourceTree = ""; 93 | }; 94 | 29B97315FDCFA39411CA2CEA /* Other Sources */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 32CA4F630368D1EE00C91783 /* Hello World_Prefix.pch */, 98 | 29B97316FDCFA39411CA2CEA /* main.m */, 99 | ); 100 | name = "Other Sources"; 101 | sourceTree = ""; 102 | }; 103 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 8D1107310486CEB800E47090 /* Info.plist */, 107 | ); 108 | name = Resources; 109 | sourceTree = ""; 110 | }; 111 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 115 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, 116 | ); 117 | name = Frameworks; 118 | sourceTree = ""; 119 | }; 120 | /* End PBXGroup section */ 121 | 122 | /* Begin PBXNativeTarget section */ 123 | 1D6058900D05DD3D006BFB54 /* Hello World */ = { 124 | isa = PBXNativeTarget; 125 | buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "Hello World" */; 126 | buildPhases = ( 127 | 1D60588D0D05DD3D006BFB54 /* Resources */, 128 | 1D60588E0D05DD3D006BFB54 /* Sources */, 129 | 1D60588F0D05DD3D006BFB54 /* Frameworks */, 130 | ); 131 | buildRules = ( 132 | ); 133 | dependencies = ( 134 | ); 135 | name = "Hello World"; 136 | productName = "Hello World"; 137 | productReference = 1D6058910D05DD3D006BFB54 /* Hello World.app */; 138 | productType = "com.apple.product-type.application"; 139 | }; 140 | /* End PBXNativeTarget section */ 141 | 142 | /* Begin PBXProject section */ 143 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 144 | isa = PBXProject; 145 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Hello World" */; 146 | compatibilityVersion = "Xcode 3.1"; 147 | hasScannedForEncodings = 1; 148 | mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 1D6058900D05DD3D006BFB54 /* Hello World */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 1D60588D0D05DD3D006BFB54 /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXResourcesBuildPhase section */ 166 | 167 | /* Begin PBXSourcesBuildPhase section */ 168 | 1D60588E0D05DD3D006BFB54 /* Sources */ = { 169 | isa = PBXSourcesBuildPhase; 170 | buildActionMask = 2147483647; 171 | files = ( 172 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */, 173 | 1D3623260D0F684500981E51 /* Hello_WorldAppDelegate.m in Sources */, 174 | 289E37760D53116900ACCF19 /* MyView.m in Sources */, 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | }; 178 | /* End PBXSourcesBuildPhase section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 1D6058940D05DD3E006BFB54 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | COPY_PHASE_STRIP = NO; 185 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 186 | GCC_DYNAMIC_NO_PIC = NO; 187 | GCC_ENABLE_FIX_AND_CONTINUE = NO; 188 | GCC_OPTIMIZATION_LEVEL = 0; 189 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 190 | GCC_PREFIX_HEADER = "Hello World_Prefix.pch"; 191 | INFOPLIST_FILE = Info.plist; 192 | PREBINDING = NO; 193 | PRODUCT_NAME = "Hello World"; 194 | }; 195 | name = Debug; 196 | }; 197 | 1D6058950D05DD3E006BFB54 /* Release */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | COPY_PHASE_STRIP = YES; 201 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 202 | GCC_ENABLE_FIX_AND_CONTINUE = NO; 203 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 204 | GCC_PREFIX_HEADER = "Hello World_Prefix.pch"; 205 | INFOPLIST_FILE = Info.plist; 206 | PREBINDING = NO; 207 | PRODUCT_NAME = "Hello World"; 208 | WRAPPER_EXTENSION = app; 209 | }; 210 | name = Release; 211 | }; 212 | C01FCF4F08A954540054247B /* Debug */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | ALWAYS_SEARCH_USER_PATHS = NO; 216 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 217 | "CODE_SIGN_IDENTITY[sdk=aspen*]" = "iPhone Developer"; 218 | GCC_C_LANGUAGE_STANDARD = c99; 219 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 220 | GCC_WARN_UNUSED_VARIABLE = YES; 221 | ONLY_ACTIVE_ARCH = YES; 222 | PREBINDING = NO; 223 | SDKROOT = aspen1.2; 224 | }; 225 | name = Debug; 226 | }; 227 | C01FCF5008A954540054247B /* Release */ = { 228 | isa = XCBuildConfiguration; 229 | buildSettings = { 230 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 231 | PREBINDING = NO; 232 | SDKROOT = aspen1.2; 233 | }; 234 | name = Release; 235 | }; 236 | /* End XCBuildConfiguration section */ 237 | 238 | /* Begin XCConfigurationList section */ 239 | 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "Hello World" */ = { 240 | isa = XCConfigurationList; 241 | buildConfigurations = ( 242 | 1D6058940D05DD3E006BFB54 /* Debug */, 243 | 1D6058950D05DD3E006BFB54 /* Release */, 244 | ); 245 | defaultConfigurationIsVisible = 0; 246 | defaultConfigurationName = Release; 247 | }; 248 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Hello World" */ = { 249 | isa = XCConfigurationList; 250 | buildConfigurations = ( 251 | C01FCF4F08A954540054247B /* Debug */, 252 | C01FCF5008A954540054247B /* Release */, 253 | ); 254 | defaultConfigurationIsVisible = 0; 255 | defaultConfigurationName = Release; 256 | }; 257 | /* End XCConfigurationList section */ 258 | }; 259 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 260 | } 261 | -------------------------------------------------------------------------------- /ios_helloworld/Hello World_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Hello World' target in the 'Hello World' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /ios_helloworld/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | 26 | -------------------------------------------------------------------------------- /ios_helloworld/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | xcodebuild -sdk iphonesimulator4.3 -target Hello\ World 3 | /usr/local/bin/ios-sim launch build/Release-iphonesimulator/Hello\ World.app 4 | 5 | -------------------------------------------------------------------------------- /ios_helloworld/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Hello World 4 | // 5 | // Created by ktundwal on 3/7/08. 6 | // Copyright __MyCompanyName__ 2008. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, @"Hello_WorldAppDelegate"); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /offset1.3.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # This program will allow you to calculate the offset inside the binary for patching purposes 4 | # (c) 2011 Fractal Guru - reverse\@put.as - http://reverse.put.as 5 | # 6 | # Feel free to do whatever you want with this code (keep the credits!) 7 | # 8 | # * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" 9 | # * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 10 | # * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11 | # * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE 12 | # * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13 | # * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14 | # * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 15 | # * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 16 | # * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 17 | # * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | # * POSSIBILITY OF SUCH DAMAGE. 19 | # 20 | my $VERSION = "1.3"; 21 | # change me to 1 to have debug messages 22 | my $debug = 0; 23 | 24 | my %table; 25 | my $buffer = ""; 26 | 27 | my $info = < [offset] [x86/ppc/x64/arm/armv6/armv7] 33 | 34 | Where: 35 | = File to calculate offset from 36 | [offset] = Offset from otx/otool (in hexadecimal format!) 37 | [x84] = To calculate offset for x86 architecture 38 | [x64] = To calculate offset for x64 architecture 39 | [ppc] = To calculate offset for PPC architecture 40 | [arm] = To calculate offset for ARM_ALL architecture 41 | [armv6] = To calculate offset for ARM_V6 architecture 42 | [armv7] = To calculate offset for ARM_V7 architecture 43 | 44 | Default mode is interactive 45 | 46 | Example for interactive mode: 47 | $0 /bin/ls 48 | 49 | Example for x86: 50 | $0 /bin/ls 23f0 x86 51 | 52 | Example for PPC: 53 | $0 /bin/ls 16a4 ppc 54 | 55 | Example for x64: 56 | $0 /bin/ls 16a4 x64 57 | 58 | INFO 59 | 60 | my $header = <{'cputype'}, $fatinfo[$i]->{'cpusubtype'}, $fatinfo[$i]->{'offset'}, $fatinfo[$i]->{'size'}, $fatinfo[$i]->{'align'}) = unpack("NNNNN", $buffer); 137 | printf("Found architecture %d\n", $fatinfo[$i]->{'cputype'}) if $debug; 138 | # and now verify what is the structure 139 | # machine types defined @ /usr/include/mach/machine.h 140 | # x86 141 | if ($fatinfo[$i]->{'cputype'} == 7) { $baseaddresses{'x86'} = $fatinfo[$i]->{'offset'}; } 142 | # PPC 143 | elsif ($fatinfo[$i]->{'cputype'} == 18) { $baseaddresses{'ppc'} = $fatinfo[$i]->{'offset'}; } 144 | # x64 145 | elsif ($fatinfo[$i]->{'cputype'} == 16777223) { $baseaddresses{'x64'} = $fatinfo[$i]->{'offset'}; } 146 | # PPC_64 147 | elsif ($fatinfo[$i]->{'cputype'} == 16777234) { $baseaddresses{'ppc64'} = $fatinfo[$i]->{'offset'}; } 148 | # ARM_ALL 149 | elsif ($fatinfo[$i]->{'cputype'} == 12 && $fatinfo[$i]->{'cpusubtype'} == 0x0) { $baseaddresses{'arm'} = $fatinfo[$i]->{'offset'}; } 150 | # ARM_V6 151 | elsif ($fatinfo[$i]->{'cputype'} == 12 && $fatinfo[$i]->{'cpusubtype'} == 0x6) { $baseaddresses{'armv6'} = $fatinfo[$i]->{'offset'}; } 152 | # ARM_V7 153 | elsif ($fatinfo[$i]->{'cputype'} == 12 && $fatinfo[$i]->{'cpusubtype'} == 0x9) { $baseaddresses{'armv7'} = $fatinfo[$i]->{'offset'}; } 154 | } 155 | # if it's a i386 only binary then base address is 0 156 | } 157 | # x86 or ARM 158 | elsif ($magicheader == 0xcefaedfe) 159 | { 160 | print "Found a Mach-O i386 only binary!\n"; 161 | $baseaddresses{'x86'} = 0x0; 162 | $target = "x86"; 163 | } 164 | # ppc 165 | elsif ($magicheader == 0xfeedface) 166 | { 167 | print "Found a Mach-O PPC only binary!\n"; 168 | $baseaddresses{'ppc'} = 0x0; 169 | $target = "ppc"; 170 | } 171 | # x64 172 | elsif ($magicheader == 0xcffaedfe) 173 | { 174 | print "Found a Mach-O x86_64 only binary!\n"; 175 | $baseaddresses{'x64'} = 0x0; 176 | $target = "x64"; 177 | } 178 | 179 | # /usr/include/mach-o/loader.h 180 | #struct mach_header 181 | #{ 182 | # uint32_t magic; 183 | # cpu_type_t cputype; 184 | # cpu_subtype_t cpusubtype; 185 | # uint32_t filetype; 186 | # uint32_t ncmds; 187 | # uint32_t sizeofcmds; 188 | # uint32_t flags; 189 | #}; 190 | # Total Size: 28 bytes 191 | 192 | # interactive mode 193 | if ($mode == 0) 194 | { 195 | printf("Available architectures in this binary are: "); 196 | foreach $cpu (keys %baseaddresses) 197 | { 198 | printf("%s ", $cpu); 199 | } 200 | printf("\n"); 201 | printf("Please choose architecture to calculate offset for: "); 202 | $userarch = ; 203 | chomp($userarch); 204 | printf("Please input the desired offset: "); 205 | $useroffset = ; 206 | chomp($useroffset); 207 | $myoffset = hex($useroffset); 208 | $foundcpu = 1; 209 | $target = $userarch; 210 | $targetbaseaddress = $baseaddresses{$userarch}; 211 | } 212 | elsif ($mode == 1) 213 | { 214 | foreach $cpu (keys %baseaddresses) 215 | { 216 | printf("%s base address: 0x%x\n", $cpu, $baseaddresses{$cpu}) if $debug; 217 | if ($target eq $cpu) 218 | { 219 | $targetbaseaddress = $baseaddresses{$cpu}; 220 | $foundcpu = 1; 221 | } 222 | } 223 | } 224 | 225 | if ($foundcpu != 1) 226 | { 227 | printf("\nERROR! Requested architecture \"$target\" doesn't exist in this binary!\n"); 228 | printf("Available architectures are: "); 229 | foreach $cpu (keys %baseaddresses) 230 | { 231 | printf("%s ", $cpu); 232 | } 233 | printf("\n"); 234 | exit(1); 235 | } 236 | 237 | printf("Reading Mach Header with base address of %x\n", $targetbaseaddress) if $debug; 238 | sysseek(FILE, $targetbaseaddress, 0); 239 | if ($target eq "x86" || $target eq "ppc" || $target =~ /arm/) 240 | { 241 | sysread(FILE, $buffer, 28); 242 | # use L in unpack because it's exactly 32bits long (that's what we want!) 243 | # PPC is big-endian so unpack template must be different! very important ;) 244 | ($magic, $cputype, $cpusubtype, $filetype, $ncmds, $sizeofcmds, $flags) = unpack("LLLLLLL", $buffer) if ($target eq "x86" || $target =~ /arm/); 245 | ($magic, $cputype, $cpusubtype, $filetype, $ncmds, $sizeofcmds, $flags) = unpack("NNNNNNN", $buffer) if ($target eq "ppc"); 246 | } 247 | elsif ($target eq "x64") 248 | { 249 | sysread(FILE, $buffer, 32); 250 | ($magic, $cputype, $cpusubtype, $filetype, $ncmds, $sizeofcmds, $flags, $reserved) = unpack("LLLLLLLL", $buffer); 251 | } 252 | else 253 | { 254 | printf("\nERROR while reading mach header!\n"); 255 | exit(1); 256 | } 257 | 258 | print("\nDebug Information\n-----------------\n") if $debug; 259 | printf("Magic number: %x\n", $magic) if $debug; 260 | printf("Cpu type: %d, subtype is: %d\n", $cputype, $cpusubtype) if $debug; 261 | printf("Filetype: %x\n", $filetype) if $debug; 262 | printf("Number of commands: %d\n", $ncmds) if $debug; 263 | printf("Size of commands: 0x%x\n", $sizeofcmds) if $debug; 264 | printf("Flags: %x\n", $flags) if $debug; 265 | printf("Target architecture: %s\n", $target) if $debug; 266 | 267 | #struct load_command 268 | #{ 269 | # uint32_t cmd; 270 | # uint32_t cmdsize; 271 | #}; 272 | # Total size: 8 bytes 273 | # process all load commands 274 | for ($i=0; $i < $ncmds; $i++) 275 | { 276 | printf("Processing command nr# %d\n", $i) if $debug; 277 | # read each load_command where we get cmd number and total size for it 278 | $initialposition = sysseek(FILE, 0, 1); 279 | sysread(FILE, $buffer, 8); 280 | ($cmd, $cmdsize) = unpack("LL", $buffer) if ($target eq "x86" || $target eq "x64" || $target =~ /arm/); 281 | ($cmd, $cmdsize) = unpack("NN", $buffer) if ($target eq "ppc"); 282 | $table[$i]->{'position'} = $initialposition; 283 | $table[$i]->{'cmd'} = $cmd; 284 | $table[$i]->{'cmdsize'} = $cmdsize; 285 | # move to the next load command. we can find it by adding the previous load command size minus 8 (because we have read 8 bytes from the previous load command) 286 | $seekposition = sysseek(FILE, $initialposition+$cmdsize, 0); 287 | } 288 | 289 | # now let's find our __text,__TEXT section inside a load command 290 | foreach (@table) 291 | { 292 | printf("Looking at cmd %d\n", $_->{'cmd'}) if $debug ; 293 | if ($_->{'cmd'} == 1 || $_->{'cmd'} == 0x19) 294 | { 295 | print("Searching for __text,__TEXT section at position: $_->{'position'}\n") if $debug; 296 | # we know it's a LC_SEGMENT so we must read it and see if we can find out __TEXT segment and __text,__TEXT section 297 | # skip cmd and cmdsize since we already have them 298 | sysseek(FILE, $_->{'position'}+8, 0); 299 | #struct segment_command 300 | #{ 301 | # uint32_t cmd; 302 | # uint32_t cmdsize; 303 | # char segname[16]; 304 | # uint32_t vmaddr; 305 | # uint32_t vmsize; 306 | # uint32_t fileoff; 307 | # uint32_t filesize; 308 | # vm_prot_t maxprot; 309 | # vm_prot_t initprot; 310 | # uint32_t nsects; 311 | # uint32_t flags; 312 | #}; 313 | # Total Size: 48 bytes 314 | if ($target eq "x86" || $target eq "ppc" || $target =~ /arm/) 315 | { 316 | sysread(FILE, $buffer, 48); 317 | ($segname, $vmaddr, $vmsize, $fileoff, $filesize, $maxprot, $initprot, $nsects, $flags) = unpack("Z16NNNNNNLN", $buffer) if ($target eq "x86" || $target =~/arm/); 318 | ($segname, $vmaddr, $vmsize, $fileoff, $filesize, $maxprot, $initprot, $nsects, $flags) = unpack("Z16NNNNNNNN", $buffer) if ($target eq "ppc"); 319 | } 320 | elsif ($target eq "x64") 321 | { 322 | sysread(FILE, $buffer, 64); 323 | ($segname, $vmaddr, $vmsize, $fileoff, $filesize, $maxprot, $initprot, $nsects, $flags) = unpack("Z16QQQQLLLL", $buffer) if ($target eq "x64"); 324 | } 325 | else 326 | { 327 | printf("\nERROR!\n"); 328 | exit(1); 329 | } 330 | 331 | printf("Segment Name: %s Number of sections: %i \n", $segname, $nsects) if $debug; 332 | $currentposition = sysseek(FILE, 0,1); 333 | # we are interested in further reading if the number of sections is more than 1. 334 | if ($nsects > 0) 335 | { 336 | for ($x=0; $x < $nsects; $x++) 337 | { 338 | #struct section 339 | #{ 340 | # char sectname[16]; 341 | # char segname[16]; 342 | # uint32_t addr; 343 | # uint32_t size; 344 | # uint32_t offset; 345 | # uint32_t align; 346 | # uint32_t reloff; 347 | # uint32_t nreloc; 348 | # uint32_t flags; 349 | # uint32_t reserved1; 350 | # uint32_t reserved2; 351 | #}; 352 | # Total size: 16 + 16 + 9*4 = 68 bytes 353 | # read sectname, segname, addr, size, offset 354 | if ($target eq "x86" || $target eq "ppc" || $target =~ /arm/) 355 | { 356 | sysread(FILE, $buffer, 68); 357 | ($sectname, $segname, $addr, $size, $offset) = unpack("Z16Z16VVV", $buffer) if ($target eq "x86" || $target =~/arm/); 358 | ($sectname, $segname, $addr, $size, $offset) = unpack("Z16Z16NNN", $buffer) if ($target eq "ppc"); 359 | } 360 | elsif ($target eq "x64") 361 | { 362 | sysread(FILE, $buffer, 80); 363 | ($sectname, $segname, $addr, $size, $offset, $align, $reloff, $nreloc, $flags, $reserved1, $reserved2, $reserved3) = unpack("Z16Z16QQLLLLLLLL", $buffer) if ($target eq "x64"); 364 | } 365 | printf("Sectname: %s Segname: %s Offset: %x\n", $sectname, $segname, $offset) if $debug; 366 | # store the information we need to calculate the correct offset 367 | $goodoffset = $offset if ($sectname eq "__text" && $segname eq "__TEXT"); 368 | $goodvmaddr = $addr if ($sectname eq "__text" && $segname eq "__TEXT"); 369 | $goodsize = $size if ($sectname eq "__text" && $segname eq "__TEXT"); 370 | } 371 | } 372 | print "\n" if $debug; 373 | } 374 | } 375 | 376 | printf("CPU base address: 0x%x Goodoffset: 0x%x MyOffset: 0x%x Goodvmaddr: 0x%x\n", $baseaddresses->{'x86'}, $goodoffset, $myoffset, $goodvmaddr) if ($debug && $target eq "x86"); 377 | printf("CPU base address: 0x%x Goodoffset: 0x%x MyOffset: 0x%x Goodvmaddr: 0x%x\n", $baseaddresses->{'x86_64'}, $goodoffset, $myoffset, $goodvmaddr) if ($debug && $target eq "x64"); 378 | printf("CPU base address: 0x%x Goodoffset: 0x%x MyOffset: 0x%x Goodvmaddr: 0x%x\n", $baseaddresses->{'ppc'}, $goodoffset, $myoffset, $goodvmaddr) if ($debug && $target eq "ppc"); 379 | # check if input offset is valid - must be inside the __text segment 380 | if ($myoffset < $goodvmaddr || $myoffset > $goodvmaddr+$goodsize) 381 | { 382 | print "\nERROR: Your offset is outside code region\n"; 383 | printf("Valid code region is: 0x%x - 0x%x\n", $goodvmaddr, $goodvmaddr+$goodsize); 384 | exit(1); 385 | } 386 | # calculate the offset we want 387 | $patchedoffset = $targetbaseaddress + $goodoffset + $myoffset - $goodvmaddr; 388 | # and print it ! 389 | printf("\nReal offset to be patched: 0x%x\n\n", $patchedoffset); 390 | # end of story! 391 | close(FILE); 392 | -------------------------------------------------------------------------------- /osx.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/osx.pdf -------------------------------------------------------------------------------- /resetapp/build.sh: -------------------------------------------------------------------------------- 1 | ./configure --enable-cross-compile --cross-prefix=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 --prefix=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr --extra-cflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" --extra-ldflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" --arch=armv6 --enable-armv6 --enable-gpl --enable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook 2 | 3 | make 4 | 5 | make install 6 | 7 | -------------------------------------------------------------------------------- /resetapp/gas-preprocessor.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # by David Conrad 3 | # This code is licensed under GPLv2 or later; go to gnu.org to read it 4 | # (not that it much matters for an asm preprocessor) 5 | # usage: set your assembler to be something like "perl gas-preprocessor.pl gcc" 6 | use strict; 7 | 8 | # Apple's gas is ancient and doesn't support modern preprocessing features like 9 | # .rept and has ugly macro syntax, among other things. Thus, this script 10 | # implements the subset of the gas preprocessor used by x264 and ffmpeg 11 | # that isn't supported by Apple's gas. 12 | 13 | my @gcc_cmd = @ARGV; 14 | my @preprocess_c_cmd; 15 | 16 | if (grep /\.c$/, @gcc_cmd) { 17 | # C file (inline asm?) - compile 18 | @preprocess_c_cmd = (@gcc_cmd, "-S"); 19 | } elsif (grep /\.[sS]$/, @gcc_cmd) { 20 | # asm file, just do C preprocessor 21 | @preprocess_c_cmd = (@gcc_cmd, "-E"); 22 | } else { 23 | die "Unrecognized input filetype"; 24 | } 25 | @gcc_cmd = map { /\.[csS]$/ ? qw(-x assembler -) : $_ } @gcc_cmd; 26 | @preprocess_c_cmd = map { /\.o$/ ? "-" : $_ } @preprocess_c_cmd; 27 | 28 | my $comm; 29 | 30 | # detect architecture from gcc binary name 31 | if ($gcc_cmd[0] =~ /arm/) { 32 | $comm = '@'; 33 | } elsif ($gcc_cmd[0] =~ /powerpc|ppc/) { 34 | $comm = '#'; 35 | } 36 | 37 | # look for -arch flag 38 | foreach my $i (1 .. $#gcc_cmd-1) { 39 | if ($gcc_cmd[$i] eq "-arch") { 40 | if ($gcc_cmd[$i+1] =~ /arm/) { 41 | $comm = '@'; 42 | } elsif ($gcc_cmd[$i+1] =~ /powerpc|ppc/) { 43 | $comm = '#'; 44 | } 45 | } 46 | } 47 | 48 | # assume we're not cross-compiling if no -arch or the binary doesn't have the arch name 49 | if (!$comm) { 50 | my $native_arch = qx/arch/; 51 | if ($native_arch =~ /arm/) { 52 | $comm = '@'; 53 | } elsif ($native_arch =~ /powerpc|ppc/) { 54 | $comm = '#'; 55 | } 56 | } 57 | 58 | if (!$comm) { 59 | die "Unable to identify target architecture"; 60 | } 61 | 62 | my %ppc_spr = (ctr => 9, 63 | vrsave => 256); 64 | 65 | open(ASMFILE, "-|", @preprocess_c_cmd) || die "Error running preprocessor"; 66 | 67 | my $current_macro = ''; 68 | my $macro_level = 0; 69 | my %macro_lines; 70 | my %macro_args; 71 | my %macro_args_default; 72 | 73 | my @pass1_lines; 74 | my @ifstack; 75 | 76 | # pass 1: parse .macro 77 | # note that the handling of arguments is probably overly permissive vs. gas 78 | # but it should be the same for valid cases 79 | while () { 80 | # remove all comments (to avoid interfering with evaluating directives) 81 | s/$comm.*//x; 82 | 83 | # comment out unsupported directives 84 | s/\.type/$comm.type/x; 85 | s/\.func/$comm.func/x; 86 | s/\.endfunc/$comm.endfunc/x; 87 | s/\.ltorg/$comm.ltorg/x; 88 | s/\.size/$comm.size/x; 89 | s/\.fpu/$comm.fpu/x; 90 | 91 | # the syntax for these is a little different 92 | s/\.global/.globl/x; 93 | # also catch .section .rodata since the equivalent to .const_data is .section __DATA,__const 94 | s/(.*)\.rodata/.const_data/x; 95 | s/\.int/.long/x; 96 | s/\.float/.single/x; 97 | 98 | # catch unknown section names that aren't mach-o style (with a comma) 99 | if (/.section ([^,]*)$/) { 100 | die ".section $1 unsupported; figure out the mach-o section name and add it"; 101 | } 102 | 103 | parse_line($_); 104 | } 105 | 106 | sub parse_line { 107 | my $line = @_[0]; 108 | 109 | # evaluate .if blocks 110 | if (scalar(@ifstack)) { 111 | if (/\.endif/) { 112 | pop(@ifstack); 113 | return; 114 | } elsif ($line =~ /\.elseif\s+(.*)/) { 115 | if ($ifstack[-1] == 0) { 116 | $ifstack[-1] = !!eval($1); 117 | } elsif ($ifstack[-1] > 0) { 118 | $ifstack[-1] = -$ifstack[-1]; 119 | } 120 | return; 121 | } elsif (/\.else/) { 122 | $ifstack[-1] = !$ifstack[-1]; 123 | return; 124 | } 125 | 126 | # discard lines in false .if blocks 127 | if ($ifstack[-1] <= 0) { 128 | return; 129 | } 130 | } 131 | 132 | if (/\.macro/) { 133 | $macro_level++; 134 | if ($macro_level > 1 && !$current_macro) { 135 | die "nested macros but we don't have master macro"; 136 | } 137 | } elsif (/\.endm/) { 138 | $macro_level--; 139 | if ($macro_level < 0) { 140 | die "unmatched .endm"; 141 | } elsif ($macro_level == 0) { 142 | $current_macro = ''; 143 | return; 144 | } 145 | } 146 | 147 | if ($macro_level > 1) { 148 | push(@{$macro_lines{$current_macro}}, $line); 149 | } elsif ($macro_level == 0) { 150 | expand_macros($line); 151 | } else { 152 | if (/\.macro\s+([\d\w\.]+)\s*(.*)/) { 153 | $current_macro = $1; 154 | 155 | # commas in the argument list are optional, so only use whitespace as the separator 156 | my $arglist = $2; 157 | $arglist =~ s/,/ /g; 158 | 159 | my @args = split(/\s+/, $arglist); 160 | foreach my $i (0 .. $#args) { 161 | my @argpair = split(/=/, $args[$i]); 162 | $macro_args{$current_macro}[$i] = $argpair[0]; 163 | $argpair[0] =~ s/:vararg$//; 164 | $macro_args_default{$current_macro}{$argpair[0]} = $argpair[1]; 165 | } 166 | # ensure %macro_lines has the macro name added as a key 167 | $macro_lines{$current_macro} = []; 168 | 169 | } elsif ($current_macro) { 170 | push(@{$macro_lines{$current_macro}}, $line); 171 | } else { 172 | die "macro level without a macro name"; 173 | } 174 | } 175 | } 176 | 177 | sub expand_macros { 178 | my $line = @_[0]; 179 | 180 | # handle .if directives; apple's assembler doesn't support important non-basic ones 181 | # evaluating them is also needed to handle recursive macros 182 | if ($line =~ /\.if(n?)([a-z]*)\s+(.*)/) { 183 | my $result = $1 eq "n"; 184 | my $type = $2; 185 | my $expr = $3; 186 | 187 | if ($type eq "b") { 188 | $expr =~ s/\s//g; 189 | $result ^= $expr eq ""; 190 | } elsif ($type eq "c") { 191 | if ($expr =~ /(.*)\s*,\s*(.*)/) { 192 | $result ^= $1 eq $2; 193 | } else { 194 | die "argument to .ifc not recognized"; 195 | } 196 | } elsif ($type eq "") { 197 | $result ^= eval($expr) != 0; 198 | } else { 199 | die "unhandled .if varient"; 200 | } 201 | push (@ifstack, $result); 202 | return; 203 | } 204 | 205 | if (/\.purgem\s+([\d\w\.]+)/) { 206 | delete $macro_lines{$1}; 207 | delete $macro_args{$1}; 208 | delete $macro_args_default{$1}; 209 | return; 210 | } 211 | 212 | if ($line =~ /(\S+:|)\s*([\w\d\.]+)\s*(.*)/ && exists $macro_lines{$2}) { 213 | push(@pass1_lines, $1); 214 | my $macro = $2; 215 | 216 | # commas are optional here too, but are syntactically important because 217 | # parameters can be blank 218 | my @arglist = split(/,/, $3); 219 | my @args; 220 | foreach (@arglist) { 221 | my @whitespace_split = split(/\s+/, $_); 222 | if (!@whitespace_split) { 223 | push(@args, ''); 224 | } else { 225 | foreach (@whitespace_split) { 226 | if (length($_)) { 227 | push(@args, $_); 228 | } 229 | } 230 | } 231 | } 232 | 233 | my %replacements; 234 | if ($macro_args_default{$macro}){ 235 | %replacements = %{$macro_args_default{$macro}}; 236 | } 237 | 238 | # construct hashtable of text to replace 239 | foreach my $i (0 .. $#args) { 240 | my $argname = $macro_args{$macro}[$i]; 241 | 242 | if ($args[$i] =~ m/=/) { 243 | # arg=val references the argument name 244 | # XXX: I'm not sure what the expected behaviour if a lot of 245 | # these are mixed with unnamed args 246 | my @named_arg = split(/=/, $args[$i]); 247 | $replacements{$named_arg[0]} = $named_arg[1]; 248 | } elsif ($i > $#{$macro_args{$macro}}) { 249 | # more args given than the macro has named args 250 | # XXX: is vararg allowed on arguments before the last? 251 | $argname = $macro_args{$macro}[-1]; 252 | if ($argname =~ s/:vararg$//) { 253 | $replacements{$argname} .= ", $args[$i]"; 254 | } else { 255 | die "Too many arguments to macro $macro"; 256 | } 257 | } else { 258 | $argname =~ s/:vararg$//; 259 | $replacements{$argname} = $args[$i]; 260 | } 261 | } 262 | 263 | # apply replacements as regex 264 | foreach (@{$macro_lines{$macro}}) { 265 | my $macro_line = $_; 266 | # do replacements by longest first, this avoids wrong replacement 267 | # when argument names are subsets of each other 268 | foreach (reverse sort {length $a <=> length $b} keys %replacements) { 269 | $macro_line =~ s/\\$_/$replacements{$_}/g; 270 | } 271 | $macro_line =~ s/\\\(\)//g; # remove \() 272 | parse_line($macro_line); 273 | } 274 | } else { 275 | push(@pass1_lines, $line); 276 | } 277 | } 278 | 279 | close(ASMFILE) or exit 1; 280 | open(ASMFILE, "|-", @gcc_cmd) or die "Error running assembler"; 281 | 282 | my @sections; 283 | my $num_repts; 284 | my $rept_lines; 285 | 286 | my %literal_labels; # for ldr , = 287 | my $literal_num = 0; 288 | 289 | # pass 2: parse .rept and .if variants 290 | # NOTE: since we don't implement a proper parser, using .rept with a 291 | # variable assigned from .set is not supported 292 | foreach my $line (@pass1_lines) { 293 | # handle .previous (only with regard to .section not .subsection) 294 | if ($line =~ /\.(section|text|const_data)/) { 295 | push(@sections, $line); 296 | } elsif ($line =~ /\.previous/) { 297 | if (!$sections[-2]) { 298 | die ".previous without a previous section"; 299 | } 300 | $line = $sections[-2]; 301 | push(@sections, $line); 302 | } 303 | 304 | # handle ldr , = 305 | if ($line =~ /(.*)\s*ldr([\w\s\d]+)\s*,\s*=(.*)/) { 306 | my $label = $literal_labels{$3}; 307 | if (!$label) { 308 | $label = ".Literal_$literal_num"; 309 | $literal_num++; 310 | $literal_labels{$3} = $label; 311 | } 312 | $line = "$1 ldr$2, $label\n"; 313 | } elsif ($line =~ /\.ltorg/) { 314 | foreach my $literal (keys %literal_labels) { 315 | $line .= "$literal_labels{$literal}:\n .word $literal\n"; 316 | } 317 | %literal_labels = (); 318 | } 319 | 320 | # @l -> lo16() @ha -> ha16() 321 | $line =~ s/,\s+([^,]+)\@l\b/, lo16($1)/g; 322 | $line =~ s/,\s+([^,]+)\@ha\b/, ha16($1)/g; 323 | 324 | # move to/from SPR 325 | if ($line =~ /(\s+)(m[ft])([a-z]+)\s+(\w+)/ and exists $ppc_spr{$3}) { 326 | if ($2 eq 'mt') { 327 | $line = "$1${2}spr $ppc_spr{$3}, $4\n"; 328 | } else { 329 | $line = "$1${2}spr $4, $ppc_spr{$3}\n"; 330 | } 331 | } 332 | 333 | if ($line =~ /\.rept\s+(.*)/) { 334 | $num_repts = $1; 335 | $rept_lines = "\n"; 336 | 337 | # handle the possibility of repeating another directive on the same line 338 | # .endr on the same line is not valid, I don't know if a non-directive is 339 | if ($num_repts =~ s/(\.\w+.*)//) { 340 | $rept_lines .= "$1\n"; 341 | } 342 | $num_repts = eval($num_repts); 343 | } elsif ($line =~ /\.endr/) { 344 | for (1 .. $num_repts) { 345 | print ASMFILE $rept_lines; 346 | } 347 | $rept_lines = ''; 348 | } elsif ($rept_lines) { 349 | $rept_lines .= $line; 350 | } else { 351 | print ASMFILE $line; 352 | } 353 | } 354 | 355 | print ASMFILE ".text\n"; 356 | foreach my $literal (keys %literal_labels) { 357 | print ASMFILE "$literal_labels{$literal}:\n .word $literal\n"; 358 | } 359 | 360 | close(ASMFILE) or exit 1; 361 | 362 | -------------------------------------------------------------------------------- /resetapp/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #include 4 | #include 5 | 6 | // Framework Paths 7 | #define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices" 8 | #define UIKITPATH "/System/Library/Framework/UIKit.framework/UIKit" 9 | 10 | int main(int argc, char **argv) 11 | { 12 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 13 | 14 | // 15 | // For testing try issuing the following: 16 | // ap y; sleep 5; ./ap n 17 | // 18 | 19 | if (argc < 2) 20 | { 21 | printf("Usage: %s (y | n)\n", argv[0]); 22 | exit(-1); 23 | } 24 | 25 | // Fetch the SpringBoard server port 26 | mach_port_t *p; 27 | void *uikit = dlopen(UIKITPATH, RTLD_LAZY); 28 | int (*SBSSpringBoardServerPort)() = 29 | dlsym(uikit, "SBSSpringBoardServerPort"); 30 | p = SBSSpringBoardServerPort(); 31 | dlclose(uikit); 32 | 33 | // Link to SBSetAirplaneModeEnabled 34 | void *sbserv = dlopen(SBSERVPATH, RTLD_LAZY); 35 | // int (*setAPMode)(mach_port_t* port, BOOL yorn) = dlsym(sbserv, "SBSetAirplaneModeEnabled"); 36 | // // Argument used to switch airplane mode off or on 37 | // BOOL yorn = [[[NSString stringWithCString:argv[1]] uppercaseString] hasPrefix:@"Y"]; 38 | // setAPMode(p, yorn); 39 | int (*dataReset)(mach_port_t* port) = dlsym(sbserv, "SBDataReset"); 40 | dataReset(p); 41 | dlclose(sbserv); 42 | 43 | [pool release]; 44 | } -------------------------------------------------------------------------------- /tools/inject_bundle/Makefile: -------------------------------------------------------------------------------- 1 | BINS=inject-bundle run-bundle 2 | 3 | all: $(BINS) 4 | 5 | clean: 6 | rm $(BINS) 7 | -------------------------------------------------------------------------------- /tools/inject_bundle/inject-bundle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/tools/inject_bundle/inject-bundle -------------------------------------------------------------------------------- /tools/inject_bundle/inject-bundle.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | * NAME 3 | * inject_bundle -- Inject a dynamic library or bundle into a 4 | * running process 5 | * 6 | * SYNOPSIS 7 | * inject_bundle path_to_bundle [ pid ] 8 | * 9 | * DESCRIPTION 10 | * The inject_bundle utility injects a dynamic library or bundle 11 | * into another process. It does this by acquiring access to the 12 | * remote process' mach task port (via task_for_pid()) and 13 | * creating a new thread to call dlopen(). If the dylib or 14 | * bundle exports a function called "run", it will be called 15 | * separately. 16 | * 17 | * EXIT STATUS 18 | * Exits 0 on success, -1 on error. 19 | **********************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define __i386__ 1 34 | 35 | #if defined(__ppc__) || defined(__ppc64__) 36 | #include 37 | #endif 38 | 39 | /* 40 | * If this symbol is exported from the bundle, it will be called 41 | * separately after initialization. 42 | */ 43 | #define BUNDLE_MAIN "run" 44 | 45 | /*********************************************************************** 46 | * Mach Exceptions 47 | ***********************************************************************/ 48 | 49 | extern boolean_t exc_server(mach_msg_header_t *request, 50 | mach_msg_header_t *reply); 51 | 52 | /* 53 | * From: xnu/bsd/uxkern/ux_exception.c 54 | */ 55 | typedef struct { 56 | mach_msg_header_t header; 57 | mach_msg_body_t body; 58 | mach_msg_port_descriptor_t thread; 59 | mach_msg_port_descriptor_t task; 60 | NDR_record_t NDR; 61 | exception_type_t exception; 62 | mach_msg_type_number_t code_count; 63 | mach_exception_data_t code; 64 | char pad[512]; 65 | } exc_msg_t; 66 | 67 | /********************************************************************** 68 | * Remote task memory 69 | **********************************************************************/ 70 | kern_return_t 71 | remote_copyout(task_t task, void* src, vm_address_t dest, size_t n); 72 | 73 | kern_return_t 74 | remote_copyin(task_t task, vm_address_t src, void* dest, size_t n); 75 | 76 | extern vm_address_t 77 | remote_malloc(task_t task, size_t size); 78 | 79 | extern kern_return_t 80 | remote_free(task_t task, vm_address_t addr); 81 | 82 | kern_return_t 83 | remote_copyout(mach_port_t task, void* src, vm_address_t dest, size_t n) 84 | { 85 | kern_return_t kr = KERN_SUCCESS; 86 | void* buf; 87 | 88 | // vm_write needs to copy data from a page-aligned buffer 89 | buf = malloc((n + PAGE_SIZE) & ~PAGE_SIZE); 90 | memcpy(buf, src, n); 91 | 92 | if ((kr = vm_write(task, dest, (vm_offset_t)buf, n))) { 93 | return kr; 94 | } 95 | 96 | free(buf); 97 | 98 | return kr; 99 | } 100 | 101 | kern_return_t 102 | remote_copyin(mach_port_t task, vm_address_t src, void* dest, size_t n) 103 | { 104 | kern_return_t kr = KERN_SUCCESS; 105 | vm_size_t size = n; 106 | 107 | if ((kr = vm_read_overwrite(task, src, n, (vm_offset_t)dest, &size))) { 108 | return kr; 109 | } 110 | 111 | return kr; 112 | } 113 | 114 | vm_address_t 115 | remote_malloc(mach_port_t task, size_t size) 116 | { 117 | kern_return_t kr = KERN_SUCCESS; 118 | vm_address_t addr; 119 | 120 | if ((kr = vm_allocate(task, &addr, size + sizeof(size), TRUE))) 121 | return (vm_address_t)NULL; 122 | 123 | /* 124 | * Write allocation size into first bytes of remote page 125 | */ 126 | if (remote_copyout(task, &size, addr, sizeof(size))) { 127 | vm_deallocate(task, addr, size); 128 | return (vm_address_t)NULL; 129 | } 130 | 131 | return addr + sizeof(size); 132 | } 133 | 134 | kern_return_t 135 | remote_free(mach_port_t task, vm_address_t addr) 136 | { 137 | kern_return_t kr = KERN_SUCCESS; 138 | size_t size; 139 | 140 | /* 141 | * Read allocation size from remote memory 142 | */ 143 | if ((kr = remote_copyin(task, addr - sizeof(size), &size, sizeof(size)))) { 144 | return kr; 145 | } 146 | 147 | kr = vm_deallocate(task, addr - sizeof(size), size); 148 | return kr; 149 | } 150 | 151 | /********************************************************************** 152 | * Remote threads 153 | **********************************************************************/ 154 | 155 | typedef enum { 156 | UNINIT, // Remote thread not yet initialized (error returned) 157 | CREATED, // Thread and remote stack created and allocated 158 | RUNNING, // Thread is running 159 | SUSPENDED, // Thread suspended, but still allocated 160 | TERMINATED // Thread terminated and remote stack deallocated 161 | } remote_thread_state_t; 162 | 163 | typedef struct { 164 | remote_thread_state_t state; 165 | task_t task; 166 | thread_t thread; 167 | vm_address_t stack; 168 | size_t stack_size; 169 | } remote_thread_t; 170 | 171 | /* 172 | * This magic return address signals a return from the remote 173 | * function. The Mach VM manager cannot map a page at 0xfffff000, so 174 | * this is guaranteed to always generate an EXC_BAD_ACCESS. 175 | */ 176 | #define MAGIC_RETURN 0xfffffba0 177 | #define STACK_SIZE (512*1024) 178 | #define PTHREAD_SIZE (4096) // Size to reserve for pthread_t struct 179 | 180 | kern_return_t 181 | create_remote_thread(mach_port_t task, remote_thread_t* rt, 182 | vm_address_t start_address, int argc, ...); 183 | 184 | kern_return_t 185 | join_remote_thread(remote_thread_t* remote_thread, void** return_value); 186 | 187 | // Called by exc_server() 188 | kern_return_t catch_exception_raise_state_identity( 189 | mach_port_t exception_port, 190 | mach_port_t thread, 191 | mach_port_t task, 192 | exception_type_t exception, 193 | exception_data_t code, 194 | mach_msg_type_number_t code_count, 195 | int *flavor, 196 | thread_state_t old_state, 197 | mach_msg_type_number_t old_state_count, 198 | thread_state_t new_state, 199 | mach_msg_type_number_t *new_state_count) 200 | { 201 | switch (*flavor) { 202 | #if defined(__i386__) 203 | case x86_THREAD_STATE32: 204 | /* 205 | * A magic value of EIP signals that the thread is done 206 | * executing. We respond by suspending the thread so that 207 | * we can terminate the exception handling loop and 208 | * retrieve the return value. 209 | */ 210 | if (((x86_thread_state32_t*)old_state)->__eip == MAGIC_RETURN) { 211 | thread_suspend(thread); 212 | 213 | /* 214 | * Signal that exception was handled 215 | */ 216 | return MIG_NO_REPLY; 217 | } 218 | 219 | break; 220 | #elif defined(__ppc__) 221 | case PPC_THREAD_STATE: 222 | if (((ppc_thread_state_t*)old_state)->__srr0 == MAGIC_RETURN) { 223 | thread_suspend(thread); 224 | return MIG_NO_REPLY; 225 | } 226 | 227 | break; 228 | #endif 229 | } 230 | 231 | /* 232 | * Otherwise, keep searching for an exception handler 233 | */ 234 | return KERN_INVALID_ARGUMENT; 235 | } 236 | 237 | kern_return_t 238 | join_remote_thread(remote_thread_t* remote_thread, void** return_value) 239 | { 240 | kern_return_t kr; 241 | mach_port_t exception_port; 242 | thread_basic_info_data_t thread_basic_info; 243 | mach_msg_type_number_t thread_basic_info_count = THREAD_BASIC_INFO_COUNT; 244 | 245 | // Allocate exception port 246 | if ((kr = mach_port_allocate(mach_task_self(), 247 | MACH_PORT_RIGHT_RECEIVE, 248 | &exception_port))) { 249 | errx(EXIT_FAILURE, "mach_port_allocate: %s", mach_error_string(kr)); 250 | } 251 | 252 | if ((kr = mach_port_insert_right(mach_task_self(), 253 | exception_port, exception_port, 254 | MACH_MSG_TYPE_MAKE_SEND))) { 255 | errx(EXIT_FAILURE, "mach_port_insert_right: %s", 256 | mach_error_string(kr)); 257 | } 258 | 259 | // Set remote thread's exception port 260 | #if defined(__i386__) 261 | if ((kr = thread_set_exception_ports(remote_thread->thread, 262 | EXC_MASK_BAD_ACCESS, 263 | exception_port, 264 | EXCEPTION_STATE_IDENTITY, 265 | x86_THREAD_STATE32))) { 266 | errx(EXIT_FAILURE, "thread_set_exception_ports: %s", 267 | mach_error_string(kr)); 268 | } 269 | #elif defined(__ppc__) 270 | if ((kr = thread_set_exception_ports(remote_thread->thread, 271 | EXC_MASK_BAD_ACCESS, 272 | exception_port, 273 | EXCEPTION_STATE_IDENTITY, 274 | PPC_THREAD_STATE))) { 275 | errx(EXIT_FAILURE, "thread_set_exception_ports: %s", 276 | mach_error_string(kr)); 277 | } 278 | #endif 279 | 280 | // Run thread 281 | if ((kr = thread_resume(remote_thread->thread))) { 282 | errx(EXIT_FAILURE, "thread_resume: %s", mach_error_string(kr)); 283 | } 284 | 285 | remote_thread->state = RUNNING; 286 | 287 | /* 288 | * Run exception handling loop until thread terminates 289 | */ 290 | while (1) { 291 | if ((kr = mach_msg_server_once(exc_server, sizeof(exc_msg_t), 292 | exception_port, 293 | MACH_MSG_TIMEOUT_NONE))) { 294 | errx(EXIT_FAILURE, "mach_msg_server: %s", mach_error_string(kr)); 295 | } 296 | 297 | if ((kr = thread_info(remote_thread->thread, THREAD_BASIC_INFO, 298 | (thread_info_t)&thread_basic_info, 299 | &thread_basic_info_count))) { 300 | errx(EXIT_FAILURE, "thread_info: %s", mach_error_string(kr)); 301 | } 302 | 303 | if (thread_basic_info.suspend_count > 0) { 304 | /* 305 | * Retrieve return value from thread state 306 | */ 307 | remote_thread->state = SUSPENDED; 308 | 309 | #if defined(__i386__) 310 | x86_thread_state32_t remote_thread_state; 311 | mach_msg_type_number_t thread_state_count = 312 | x86_THREAD_STATE32_COUNT; 313 | 314 | if ((kr = thread_get_state(remote_thread->thread, 315 | x86_THREAD_STATE32, 316 | (thread_state_t)&remote_thread_state, 317 | &thread_state_count))) { 318 | errx(EXIT_FAILURE, "thread_get_state: %s", 319 | mach_error_string(kr)); 320 | } 321 | 322 | *return_value = (void*)remote_thread_state.__eax; 323 | #elif defined(__ppc__) 324 | ppc_thread_state_t remote_thread_state; 325 | mach_msg_type_number_t thread_state_count = 326 | PPC_THREAD_STATE_COUNT; 327 | 328 | if ((kr = thread_get_state(remote_thread->thread, 329 | PPC_THREAD_STATE, 330 | (thread_state_t)&remote_thread_state, 331 | &thread_state_count))) { 332 | errx(EXIT_FAILURE, "thread_get_state: %s", 333 | mach_error_string(kr)); 334 | } 335 | 336 | *return_value = (void*)remote_thread_state.__r3; 337 | #endif 338 | if ((kr = thread_terminate(remote_thread->thread))) { 339 | errx(EXIT_FAILURE, "thread_terminate: %s", 340 | mach_error_string(kr)); 341 | } 342 | 343 | if ((kr = vm_deallocate(remote_thread->task, 344 | remote_thread->stack, 345 | remote_thread->stack_size))) { 346 | errx(EXIT_FAILURE, "vm_deallocate: %s", 347 | mach_error_string(kr)); 348 | } 349 | 350 | remote_thread->state = TERMINATED; 351 | 352 | break; 353 | } 354 | } 355 | 356 | return kr; 357 | } 358 | 359 | /* 360 | * Raw assembly code for trampolines. If they are changed, 361 | * TRAMPOLINE_SIZE must be calculated manually and updated as well. 362 | * The asm keyword is an Apple GCC extension intended to resemble the 363 | * same feature in CodeWarrior and Visual Studio. 364 | */ 365 | #if defined(__i386__) 366 | #define MACH_THREAD_TRAMPOLINE_SIZE (16) 367 | asm void mach_thread_trampoline(void) 368 | { 369 | // Call _pthread_set_self with pthread_t arg already on stack 370 | pop eax 371 | call eax 372 | add esp, 4 373 | 374 | // Call cthread_set_self with pthread_t arg already on stack 375 | pop eax 376 | call eax 377 | add esp, 4 378 | 379 | // Call function with return address and arguments already on stack 380 | pop eax 381 | jmp eax 382 | } 383 | 384 | #define PTHREAD_TRAMPOLINE_SIZE (4) 385 | asm void pthread_trampoline(void) 386 | { 387 | nop 388 | nop 389 | nop 390 | nop 391 | } 392 | 393 | #elif defined(__ppc__) 394 | #define MACH_THREAD_TRAMPOLINE_SIZE (27*4) 395 | /* 396 | * Expects: 397 | * r3 - struct _pthread * 398 | * r26 - start_routine arg 399 | * r27 - &(pthread_join) 400 | * r28 - &(pthread_create) 401 | * r29 - &(_pthread_set_self) 402 | * r30 - &(cthread_set_self) 403 | * r31 - &(start_routine) 404 | * ... 405 | */ 406 | asm void mach_thread_trampoline(void) 407 | { 408 | mflr r0 409 | stw r0, 8(r1) 410 | stwu r1, -96(r1) 411 | stw r3, 56(r1) 412 | 413 | // Call _pthread_set_self(pthread) 414 | mtctr r29 415 | bctrl 416 | 417 | // Call cthread_set_self(pthread) 418 | lwz r3, 56(r1) 419 | mtctr r30 420 | bctrl 421 | 422 | // pthread_create(&pthread, NULL, start_routine, arg) 423 | addi r3, r1, 60 424 | xor r4, r4, r4 425 | mr r5, r31 426 | mr r6, r26 427 | mtctr r28 428 | bctrl 429 | 430 | // pthread_join(pthread, &return_value) 431 | lwz r3, 60(r1) 432 | addi r4, r1, 64 433 | mtctr r27 434 | bctrl 435 | 436 | lwz r3, 64(r1) 437 | lwz r0, 96 + 8(r1) 438 | mtlr r0 439 | addi r1, r1, 96 440 | blr 441 | } 442 | 443 | /* 444 | * Loads argument and function pointer from single argument and calls 445 | * the specified function with those arguments. 446 | */ 447 | #define PTHREAD_TRAMPOLINE_SIZE (12*4) 448 | asm void pthread_trampoline(void) 449 | { 450 | mr r2, r3 451 | 452 | lwz r3, 0(r2) 453 | lwz r4, 4(r2) 454 | lwz r5, 8(r2) 455 | lwz r6, 12(r2) 456 | lwz r7, 16(r2) 457 | lwz r8, 20(r2) 458 | lwz r9, 24(r2) 459 | lwz r10, 28(r2) 460 | 461 | lwz r2, 32(r2) 462 | mtctr r2 463 | bctr 464 | } 465 | #endif 466 | 467 | /* 468 | * create_remote_thread -- Create the remote thread, but do not run it yet. 469 | * 470 | * Actually creating the remote thread is tricky. A naked mach thread 471 | * will crash when a function that it calls tries to access 472 | * thread-specific data. Therefore, we must create a real pthread. 473 | * In order to do so, we create a remote mach thread to call 474 | * pthread_create with a small assembly trampoline as its start 475 | * routine. The parameter to the start routine is a parameter block 476 | * that contains the address of the function that the user really 477 | * wanted to call and any parameters to that function. 478 | * 479 | * pthread_create() will return into a second trampoline that calls 480 | * pthread_join() on the newly created thread. 481 | */ 482 | kern_return_t 483 | create_remote_thread(mach_port_t task, remote_thread_t* rt, 484 | vm_address_t start_address, int argc, ...) 485 | { 486 | va_list ap; 487 | int i; 488 | kern_return_t kr; 489 | thread_t remote_thread; 490 | vm_address_t remote_stack, pthread, 491 | mach_thread_trampoline_code, pthread_trampoline_code; 492 | size_t stack_size = STACK_SIZE; 493 | unsigned long* stack, *sp; 494 | static void (*pthread_set_self)(pthread_t) = NULL; 495 | static void (*cthread_set_self)(void*) = NULL; 496 | 497 | /* 498 | * Initialize remote_thread_t 499 | */ 500 | rt->state = UNINIT; 501 | rt->task = rt->thread = 0; 502 | rt->stack = rt->stack_size = 0; 503 | 504 | if (argc > 8) { 505 | // We don't handle that many arguments 506 | return KERN_FAILURE; 507 | } 508 | 509 | /* 510 | * Cheat and look up the private function _pthread_set_self(). We 511 | * need to call this in the created remote thread in order to 512 | * make it a real pthread. Many library functions fail if they 513 | * are called from a basic mach thread. 514 | */ 515 | if (pthread_set_self == NULL) { 516 | pthread_set_self = (void (*)(pthread_t)) 517 | dlsym(RTLD_DEFAULT, "__pthread_set_self"); 518 | } 519 | 520 | if (cthread_set_self == NULL) { 521 | cthread_set_self = (void (*)(void*)) 522 | dlsym(RTLD_DEFAULT, "cthread_set_self"); 523 | } 524 | 525 | /* 526 | * Allocate remote and local (temporary copy) stacks 527 | */ 528 | if ((kr = vm_allocate(task, &remote_stack, stack_size, TRUE))) 529 | return kr; 530 | 531 | stack = malloc(stack_size); 532 | sp = (unsigned long*)((char*)stack + stack_size); 533 | 534 | /* 535 | * Allocate space on the stack for a pthread structure 536 | */ 537 | sp = (unsigned long*) 538 | ((char*)sp - PTHREAD_SIZE); 539 | pthread = remote_stack + (vm_address_t)sp - (vm_address_t)stack; 540 | 541 | /* 542 | * Copy over trampoline code to call intended function 543 | */ 544 | sp = (unsigned long*)((char*)sp - MACH_THREAD_TRAMPOLINE_SIZE); 545 | memcpy(sp, &mach_thread_trampoline, MACH_THREAD_TRAMPOLINE_SIZE); 546 | mach_thread_trampoline_code = 547 | remote_stack + (vm_address_t)sp - (vm_address_t)stack; 548 | 549 | /* 550 | * Copy over trampoline code to call intended function 551 | */ 552 | sp = (unsigned long*)((char*)sp - PTHREAD_TRAMPOLINE_SIZE); 553 | memcpy(sp, &pthread_trampoline, PTHREAD_TRAMPOLINE_SIZE); 554 | pthread_trampoline_code = 555 | remote_stack + (vm_address_t)sp - (vm_address_t)stack; 556 | 557 | // Create remote thread suspended 558 | if ((kr = thread_create(task, &remote_thread))) { 559 | errx(EXIT_FAILURE, "thread_create: %s", mach_error_string(kr)); 560 | } 561 | 562 | #if defined(__i386__) 563 | { 564 | x86_thread_state32_t remote_thread_state; 565 | vm_address_t remote_sp; 566 | unsigned long* args; 567 | /* 568 | * Stack must be 16-byte aligned when we call the target 569 | * function. Otherwise, if we call dlopen(), we may get a 570 | * misaligned stack error. 571 | */ 572 | sp -= argc; 573 | sp -= ((unsigned int)sp % 16) / sizeof(*sp); 574 | 575 | args = sp; 576 | 577 | va_start(ap, argc); 578 | for (i = 0; i < argc; i++) { 579 | unsigned long arg = va_arg(ap, unsigned long); 580 | *(args + i) = arg; 581 | } 582 | va_end(ap); 583 | 584 | // Push magic return address and start address onto stack 585 | *(--sp) = MAGIC_RETURN; 586 | *(--sp) = (unsigned long)start_address; 587 | 588 | // Push pthread_t arg and address of cthread_set_self 589 | *(--sp) = pthread; 590 | *(--sp) = (unsigned long)cthread_set_self; 591 | 592 | // Push pthread_t arg and address of pthread_set_self 593 | *(--sp) = pthread; 594 | *(--sp) = (unsigned long)pthread_set_self; 595 | 596 | remote_sp = remote_stack + (vm_address_t)sp - (vm_address_t)stack; 597 | 598 | /* 599 | * Copy local stack to remote stack 600 | */ 601 | if ((kr = vm_write(task, remote_stack, 602 | (pointer_t)stack, stack_size))) { 603 | errx(EXIT_FAILURE, "vm_write: %s", mach_error_string(kr)); 604 | } 605 | 606 | // Initialize thread state 607 | bzero(&remote_thread_state, sizeof(remote_thread_state)); 608 | 609 | remote_thread_state.__eip = mach_thread_trampoline_code; 610 | remote_thread_state.__esp = remote_sp; 611 | 612 | if ((kr = thread_set_state(remote_thread, x86_THREAD_STATE32, 613 | (thread_state_t)&remote_thread_state, 614 | x86_THREAD_STATE32_COUNT))) { 615 | errx(EXIT_FAILURE, "thread_set_state: %s", mach_error_string(kr)); 616 | } 617 | } 618 | #elif defined(__ppc__) 619 | { 620 | ppc_thread_state_t remote_thread_state; 621 | vm_address_t remote_sp; 622 | unsigned long* start_arg; 623 | 624 | /* 625 | * Build parameter block for pthread_trampoline 626 | */ 627 | *(--sp) = start_address; 628 | sp -= 8; 629 | start_arg = sp; 630 | 631 | va_start(ap, argc); 632 | for (i = 0; i < argc; i++) { 633 | unsigned long arg = va_arg(ap, unsigned long); 634 | *(sp + i) = arg; 635 | } 636 | va_end(ap); 637 | 638 | sp -= ((unsigned int)sp % 16) / sizeof(*sp); 639 | 640 | /* 641 | * Copy local stack to remote stack 642 | */ 643 | if ((kr = vm_write(task, remote_stack, 644 | (pointer_t)stack, stack_size))) { 645 | errx(EXIT_FAILURE, "vm_write: %s", mach_error_string(kr)); 646 | } 647 | 648 | /* 649 | * Set registers 650 | */ 651 | // XXX: C_ARGSAVE_LEN and C_RED_ZONE are probably unnecessary 652 | remote_sp = remote_stack + (vm_address_t)sp - (vm_address_t)stack - 653 | C_ARGSAVE_LEN - C_RED_ZONE; 654 | 655 | bzero(&remote_thread_state, sizeof(remote_thread_state)); 656 | 657 | remote_thread_state.__srr0 = mach_thread_trampoline_code; 658 | remote_thread_state.__r1 = remote_sp; 659 | remote_thread_state.__r3 = pthread; 660 | 661 | remote_thread_state.__r26 = 662 | remote_stack + (vm_address_t)start_arg - (vm_address_t)stack; 663 | 664 | remote_thread_state.__r27 = (unsigned int)pthread_join; 665 | remote_thread_state.__r28 = (unsigned int)pthread_create; 666 | remote_thread_state.__r29 = (unsigned int)pthread_set_self; 667 | remote_thread_state.__r30 = (unsigned int)cthread_set_self; 668 | remote_thread_state.__r31 = (unsigned int)pthread_trampoline_code; 669 | 670 | remote_thread_state.__lr = MAGIC_RETURN; 671 | 672 | // Initialize thread 673 | if ((kr = thread_set_state(remote_thread, PPC_THREAD_STATE, 674 | (thread_state_t)&remote_thread_state, 675 | PPC_THREAD_STATE_COUNT))) { 676 | errx(EXIT_FAILURE, "thread_set_state: %s", mach_error_string(kr)); 677 | } 678 | } 679 | #endif 680 | 681 | rt->state = CREATED; 682 | rt->task = task; 683 | rt->thread = remote_thread; 684 | rt->stack = remote_stack; 685 | rt->stack_size = stack_size; 686 | 687 | return kr; 688 | } 689 | 690 | /********************************************************************** 691 | * Bundle injection 692 | **********************************************************************/ 693 | 694 | kern_return_t 695 | remote_getpid(task_t task, pid_t* pid) 696 | { 697 | kern_return_t kr; 698 | remote_thread_t thread; 699 | 700 | if ((kr = create_remote_thread(task, &thread, 701 | (vm_address_t)&getpid, 0))) { 702 | warnx("create_remote_thread() failed: %s", mach_error_string(kr)); 703 | return kr; 704 | } 705 | 706 | if ((kr = join_remote_thread(&thread, (void**)pid))) { 707 | warnx("join_remote_thread() failed: %s", mach_error_string(kr)); 708 | return kr; 709 | } 710 | 711 | return kr; 712 | } 713 | 714 | kern_return_t 715 | inject_bundle(task_t task, const char* bundle_path, void** return_value) 716 | { 717 | kern_return_t kr; 718 | char path[PATH_MAX]; 719 | vm_address_t path_rptr, sub_rptr; 720 | remote_thread_t thread; 721 | void* dl_handle = 0, *sub_addr = 0; 722 | 723 | /* 724 | * Since the remote process may have a different working directory 725 | * and library path environment variables, we must load the bundle 726 | * via a canonical absolute path. 727 | */ 728 | if (!realpath(bundle_path, path)) { 729 | warn("realpath"); 730 | return KERN_FAILURE; 731 | } 732 | 733 | /* 734 | * dl_handle = dlopen(path, RTLD_NOW | RTLD_LOCAL) 735 | */ 736 | path_rptr = remote_malloc(task, sizeof(path)); 737 | remote_copyout(task, path, path_rptr, sizeof(path)); 738 | 739 | if ((kr = create_remote_thread(task, &thread, 740 | (vm_address_t)&dlopen, 2, 741 | path_rptr, RTLD_NOW | RTLD_LOCAL))) { 742 | warnx("create_remote_thread dlopen() failed: %s", 743 | mach_error_string(kr)); 744 | return kr; 745 | } 746 | 747 | if ((kr = join_remote_thread(&thread, &dl_handle))) { 748 | warnx("join_remote_thread dlopen() failed: %s", 749 | mach_error_string(kr)); 750 | return kr; 751 | } 752 | 753 | remote_free(task, path_rptr); 754 | 755 | if (dl_handle == NULL) { 756 | warnx("dlopen() failed"); 757 | return KERN_FAILURE; 758 | } 759 | 760 | /* 761 | * sub_addr = dlsym(dl_handle, "run") 762 | */ 763 | sub_rptr = remote_malloc(task, strlen(BUNDLE_MAIN) + 1); 764 | remote_copyout(task, BUNDLE_MAIN, sub_rptr, strlen(BUNDLE_MAIN) + 1); 765 | 766 | if ((kr = create_remote_thread(task, &thread, 767 | (vm_address_t)&dlsym, 2, 768 | dl_handle, sub_rptr))) { 769 | warnx("create_remote_thread dlsym() failed: %s", 770 | mach_error_string(kr)); 771 | return kr; 772 | } 773 | 774 | if ((kr = join_remote_thread(&thread, &sub_addr))) { 775 | warnx("join_remote_thread dlsym() failed: %s", 776 | mach_error_string(kr)); 777 | return kr; 778 | } 779 | 780 | remote_free(task, sub_rptr); 781 | 782 | if (sub_addr) { 783 | /* 784 | * return_value = run() 785 | */ 786 | if ((kr = create_remote_thread(task, &thread, 787 | (vm_address_t)sub_addr, 0))) { 788 | warnx("create_remote_thread run() failed: %s", 789 | mach_error_string(kr)); 790 | return kr; 791 | } 792 | 793 | if ((kr = join_remote_thread(&thread, return_value))) { 794 | warnx("join_remote_thread run() failed: %s", 795 | mach_error_string(kr)); 796 | return kr; 797 | } 798 | 799 | return (int)return_value; 800 | } 801 | 802 | return kr; 803 | } 804 | 805 | int main(int argc, char* argv[]) 806 | { 807 | pid_t pid; 808 | kern_return_t kr; 809 | task_t task; 810 | void* return_value; 811 | 812 | if (argc < 2) { 813 | fprintf(stderr, "usage: %s []\n", argv[0]); 814 | exit(EXIT_FAILURE); 815 | } 816 | 817 | if (argc == 3) { 818 | pid = atoi(argv[2]); 819 | if ((kr = task_for_pid(mach_task_self(), pid, &task))) { 820 | errx(EXIT_FAILURE, "task_for_pid: %s", mach_error_string(kr)); 821 | } 822 | } 823 | else { 824 | task = mach_task_self(); 825 | } 826 | 827 | inject_bundle(task, argv[1], &return_value); 828 | return (int)return_value; 829 | } 830 | -------------------------------------------------------------------------------- /tools/inject_bundle/run-bundle.c: -------------------------------------------------------------------------------- 1 | // 2 | // Simple bundle driver 3 | // 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | void* dl_handle; 12 | 13 | if (argc < 2) { 14 | fprintf(stderr, "usage: %s \n", argv[0]); 15 | exit(EXIT_FAILURE); 16 | } 17 | 18 | dl_handle = dlopen(argv[1], RTLD_NOW | RTLD_LOCAL); 19 | if (dl_handle) { 20 | int (*run)(int); 21 | run = dlsym(dl_handle, "run"); 22 | if (run != NULL) { 23 | return run(0); 24 | } 25 | } 26 | else { 27 | errx(EXIT_FAILURE, "dlopen: %s", dlerror()); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tools/macho_module/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-g -m32 2 | LDFLAGS=-bundle 3 | wow: wow.c mach_override.h mach_override.c 4 | 5 | clean: 6 | rm -rf wow *.dSYM 7 | -------------------------------------------------------------------------------- /tools/macho_module/mach_override.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | mach_override.c 3 | Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: 4 | Some rights reserved: 5 | 6 | ***************************************************************************/ 7 | 8 | #include "mach_override.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | /************************** 19 | * 20 | * Constants 21 | * 22 | **************************/ 23 | #pragma mark - 24 | #pragma mark (Constants) 25 | 26 | #if defined(__ppc__) || defined(__POWERPC__) 27 | 28 | long kIslandTemplate[] = { 29 | 0x9001FFFC, // stw r0,-4(SP) 30 | 0x3C00DEAD, // lis r0,0xDEAD 31 | 0x6000BEEF, // ori r0,r0,0xBEEF 32 | 0x7C0903A6, // mtctr r0 33 | 0x8001FFFC, // lwz r0,-4(SP) 34 | 0x60000000, // nop ; optionally replaced 35 | 0x4E800420 // bctr 36 | }; 37 | 38 | #define kAddressHi 3 39 | #define kAddressLo 5 40 | #define kInstructionHi 10 41 | #define kInstructionLo 11 42 | 43 | #elif defined(__i386__) 44 | 45 | #define kOriginalInstructionsSize 16 46 | 47 | char kIslandTemplate[] = { 48 | // kOriginalInstructionsSize nop instructions so that we 49 | // should have enough space to host original instructions 50 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 51 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 52 | // Now the real jump instruction 53 | 0xE9, 0xEF, 0xBE, 0xAD, 0xDE 54 | }; 55 | 56 | #define kInstructions 0 57 | #define kJumpAddress kInstructions + kOriginalInstructionsSize + 1 58 | #elif defined(__x86_64__) 59 | 60 | #define kOriginalInstructionsSize 32 61 | 62 | #define kJumpAddress kOriginalInstructionsSize + 6 63 | 64 | char kIslandTemplate[] = { 65 | // kOriginalInstructionsSize nop instructions so that we 66 | // should have enough space to host original instructions 67 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 68 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 69 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 70 | 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 71 | // Now the real jump instruction 72 | 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, 73 | 0x00, 0x00, 0x00, 0x00, 74 | 0x00, 0x00, 0x00, 0x00 75 | }; 76 | 77 | #endif 78 | 79 | #define kAllocateHigh 1 80 | #define kAllocateNormal 0 81 | 82 | /************************** 83 | * 84 | * Data Types 85 | * 86 | **************************/ 87 | #pragma mark - 88 | #pragma mark (Data Types) 89 | 90 | typedef struct { 91 | char instructions[sizeof(kIslandTemplate)]; 92 | int allocatedHigh; 93 | } BranchIsland; 94 | 95 | /************************** 96 | * 97 | * Funky Protos 98 | * 99 | **************************/ 100 | #pragma mark - 101 | #pragma mark (Funky Protos) 102 | 103 | mach_error_t 104 | allocateBranchIsland( 105 | BranchIsland **island, 106 | int allocateHigh, 107 | void *originalFunctionAddress); 108 | 109 | mach_error_t 110 | freeBranchIsland( 111 | BranchIsland *island ); 112 | 113 | #if defined(__ppc__) || defined(__POWERPC__) 114 | mach_error_t 115 | setBranchIslandTarget( 116 | BranchIsland *island, 117 | const void *branchTo, 118 | long instruction ); 119 | #endif 120 | 121 | #if defined(__i386__) || defined(__x86_64__) 122 | mach_error_t 123 | setBranchIslandTarget_i386( 124 | BranchIsland *island, 125 | const void *branchTo, 126 | char* instructions ); 127 | void 128 | atomic_mov64( 129 | uint64_t *targetAddress, 130 | uint64_t value ); 131 | 132 | static Boolean 133 | eatKnownInstructions( 134 | unsigned char *code, 135 | uint64_t *newInstruction, 136 | int *howManyEaten, 137 | char *originalInstructions ); 138 | #endif 139 | 140 | /******************************************************************************* 141 | * 142 | * Interface 143 | * 144 | *******************************************************************************/ 145 | #pragma mark - 146 | #pragma mark (Interface) 147 | 148 | mach_error_t 149 | mach_override( 150 | char *originalFunctionSymbolName, 151 | const char *originalFunctionLibraryNameHint, 152 | const void *overrideFunctionAddress, 153 | void **originalFunctionReentryIsland ) 154 | { 155 | assert( originalFunctionSymbolName ); 156 | assert( strlen( originalFunctionSymbolName ) ); 157 | assert( overrideFunctionAddress ); 158 | 159 | // Lookup the original function's code pointer. 160 | long *originalFunctionPtr; 161 | if( originalFunctionLibraryNameHint ) 162 | _dyld_lookup_and_bind_with_hint( 163 | originalFunctionSymbolName, 164 | originalFunctionLibraryNameHint, 165 | (void*) &originalFunctionPtr, 166 | NULL ); 167 | else{ 168 | _dyld_lookup_and_bind( 169 | originalFunctionSymbolName, 170 | (void*) &originalFunctionPtr, 171 | NULL ); 172 | } 173 | 174 | //printf ("In mach_override\n"); 175 | return mach_override_ptr( originalFunctionPtr, overrideFunctionAddress, 176 | originalFunctionReentryIsland ); 177 | } 178 | 179 | #if defined(__x86_64__) 180 | mach_error_t makeIslandExecutable(void *address) { 181 | mach_error_t err = err_none; 182 | vm_size_t pageSize; 183 | host_page_size( mach_host_self(), &pageSize ); 184 | uint64_t page = (uint64_t)address & ~(uint64_t)(pageSize-1); 185 | int e = err_none; 186 | e |= mprotect((void *)page, pageSize, PROT_EXEC | PROT_READ | PROT_WRITE); 187 | e |= msync((void *)page, pageSize, MS_INVALIDATE ); 188 | if (e) { 189 | err = err_cannot_override; 190 | } 191 | return err; 192 | } 193 | #endif 194 | 195 | mach_error_t 196 | mach_override_ptr( 197 | void *originalFunctionAddress, 198 | const void *overrideFunctionAddress, 199 | void **originalFunctionReentryIsland ) 200 | { 201 | assert( originalFunctionAddress ); 202 | assert( overrideFunctionAddress ); 203 | 204 | long *originalFunctionPtr = (long*) originalFunctionAddress; 205 | mach_error_t err = err_none; 206 | 207 | #if defined(__ppc__) || defined(__POWERPC__) 208 | // Ensure first instruction isn't 'mfctr'. 209 | #define kMFCTRMask 0xfc1fffff 210 | #define kMFCTRInstruction 0x7c0903a6 211 | 212 | long originalInstruction = *originalFunctionPtr; 213 | if( !err && ((originalInstruction & kMFCTRMask) == kMFCTRInstruction) ) 214 | err = err_cannot_override; 215 | #elif defined(__i386__) || defined(__x86_64__) 216 | int eatenCount = 0; 217 | char originalInstructions[kOriginalInstructionsSize]; 218 | uint64_t jumpRelativeInstruction = 0; // JMP 219 | 220 | Boolean overridePossible = eatKnownInstructions ((unsigned char *)originalFunctionPtr, 221 | &jumpRelativeInstruction, &eatenCount, originalInstructions); 222 | if (eatenCount > kOriginalInstructionsSize) { 223 | //printf ("Too many instructions eaten\n"); 224 | overridePossible = false; 225 | } 226 | if (!overridePossible) err = err_cannot_override; 227 | if (err) printf("err = %x %d\n", err, __LINE__); 228 | #endif 229 | 230 | // Make the original function implementation writable. 231 | if( !err ) { 232 | err = vm_protect( mach_task_self(), 233 | (vm_address_t) originalFunctionPtr, 234 | sizeof(long), false, (VM_PROT_ALL | VM_PROT_COPY) ); 235 | if( err ) 236 | err = vm_protect( mach_task_self(), 237 | (vm_address_t) originalFunctionPtr, sizeof(long), false, 238 | (VM_PROT_DEFAULT | VM_PROT_COPY) ); 239 | } 240 | if (err) printf("err = %x %d\n", err, __LINE__); 241 | 242 | // Allocate and target the escape island to the overriding function. 243 | BranchIsland *escapeIsland = NULL; 244 | if( !err ) 245 | err = allocateBranchIsland( &escapeIsland, kAllocateHigh, originalFunctionAddress ); 246 | if (err) printf("err = %x %d\n", err, __LINE__); 247 | 248 | 249 | #if defined(__ppc__) || defined(__POWERPC__) 250 | if( !err ) 251 | err = setBranchIslandTarget( escapeIsland, overrideFunctionAddress, 0 ); 252 | 253 | // Build the branch absolute instruction to the escape island. 254 | long branchAbsoluteInstruction = 0; // Set to 0 just to silence warning. 255 | if( !err ) { 256 | long escapeIslandAddress = ((long) escapeIsland) & 0x3FFFFFF; 257 | branchAbsoluteInstruction = 0x48000002 | escapeIslandAddress; 258 | } 259 | #elif defined(__i386__) || defined(__x86_64__) 260 | if (err) printf("err = %x %d\n", err, __LINE__); 261 | 262 | if( !err ) 263 | err = setBranchIslandTarget_i386( escapeIsland, overrideFunctionAddress, 0 ); 264 | 265 | if (err) printf("err = %x %d\n", err, __LINE__); 266 | // Build the jump relative instruction to the escape island 267 | #endif 268 | 269 | 270 | #if defined(__i386__) || defined(__x86_64__) 271 | if (!err) { 272 | uint32_t addressOffset = ((void*)escapeIsland - (void*)originalFunctionPtr - 5); 273 | addressOffset = OSSwapInt32(addressOffset); 274 | 275 | jumpRelativeInstruction |= 0xE900000000000000LL; 276 | jumpRelativeInstruction |= ((uint64_t)addressOffset & 0xffffffff) << 24; 277 | jumpRelativeInstruction = OSSwapInt64(jumpRelativeInstruction); 278 | } 279 | #endif 280 | 281 | // Optionally allocate & return the reentry island. 282 | BranchIsland *reentryIsland = NULL; 283 | if( !err && originalFunctionReentryIsland ) { 284 | err = allocateBranchIsland( &reentryIsland, kAllocateNormal, NULL); 285 | if( !err ) 286 | *originalFunctionReentryIsland = reentryIsland; 287 | } 288 | 289 | #if defined(__ppc__) || defined(__POWERPC__) 290 | // Atomically: 291 | // o If the reentry island was allocated: 292 | // o Insert the original instruction into the reentry island. 293 | // o Target the reentry island at the 2nd instruction of the 294 | // original function. 295 | // o Replace the original instruction with the branch absolute. 296 | if( !err ) { 297 | int escapeIslandEngaged = false; 298 | do { 299 | if( reentryIsland ) 300 | err = setBranchIslandTarget( reentryIsland, 301 | (void*) (originalFunctionPtr+1), originalInstruction ); 302 | if( !err ) { 303 | escapeIslandEngaged = CompareAndSwap( originalInstruction, 304 | branchAbsoluteInstruction, 305 | (UInt32*)originalFunctionPtr ); 306 | if( !escapeIslandEngaged ) { 307 | // Someone replaced the instruction out from under us, 308 | // re-read the instruction, make sure it's still not 309 | // 'mfctr' and try again. 310 | originalInstruction = *originalFunctionPtr; 311 | if( (originalInstruction & kMFCTRMask) == kMFCTRInstruction) 312 | err = err_cannot_override; 313 | } 314 | } 315 | } while( !err && !escapeIslandEngaged ); 316 | } 317 | #elif defined(__i386__) || defined(__x86_64__) 318 | // Atomically: 319 | // o If the reentry island was allocated: 320 | // o Insert the original instructions into the reentry island. 321 | // o Target the reentry island at the first non-replaced 322 | // instruction of the original function. 323 | // o Replace the original first instructions with the jump relative. 324 | // 325 | // Note that on i386, we do not support someone else changing the code under our feet 326 | if ( !err ) { 327 | if( reentryIsland ) 328 | err = setBranchIslandTarget_i386( reentryIsland, 329 | (void*) ((char *)originalFunctionPtr+eatenCount), originalInstructions ); 330 | if ( !err ) 331 | atomic_mov64((uint64_t *)originalFunctionPtr, jumpRelativeInstruction); 332 | } 333 | #endif 334 | 335 | // Clean up on error. 336 | if( err ) { 337 | if( reentryIsland ) 338 | freeBranchIsland( reentryIsland ); 339 | if( escapeIsland ) 340 | freeBranchIsland( escapeIsland ); 341 | } 342 | 343 | #if defined(__x86_64__) 344 | err = makeIslandExecutable(escapeIsland); 345 | err = makeIslandExecutable(reentryIsland); 346 | #endif 347 | 348 | return err; 349 | } 350 | 351 | /******************************************************************************* 352 | * 353 | * Implementation 354 | * 355 | *******************************************************************************/ 356 | #pragma mark - 357 | #pragma mark (Implementation) 358 | 359 | /***************************************************************************//** 360 | Implementation: Allocates memory for a branch island. 361 | 362 | @param island <- The allocated island. 363 | @param allocateHigh -> Whether to allocate the island at the end of the 364 | address space (for use with the branch absolute 365 | instruction). 366 | @result <- mach_error_t 367 | 368 | ***************************************************************************/ 369 | 370 | mach_error_t 371 | allocateBranchIsland( 372 | BranchIsland **island, 373 | int allocateHigh, 374 | void *originalFunctionAddress) 375 | { 376 | assert( island ); 377 | 378 | mach_error_t err = err_none; 379 | 380 | if( allocateHigh ) { 381 | vm_size_t pageSize; 382 | err = host_page_size( mach_host_self(), &pageSize ); 383 | if( !err ) { 384 | assert( sizeof( BranchIsland ) <= pageSize ); 385 | #if defined(__x86_64__) 386 | vm_address_t first = (uint64_t)originalFunctionAddress & ~(uint64_t)(((uint64_t)1 << 31) - 1) | ((uint64_t)1 << 31); // start in the middle of the page? 387 | vm_address_t last = 0x0; 388 | #else 389 | vm_address_t first = 0xfeffffff; 390 | vm_address_t last = 0xfe000000 + pageSize; 391 | #endif 392 | 393 | vm_address_t page = first; 394 | int allocated = 0; 395 | vm_map_t task_self = mach_task_self(); 396 | 397 | while( !err && !allocated && page != last ) { 398 | 399 | err = vm_allocate( task_self, &page, pageSize, 0 ); 400 | if( err == err_none ) 401 | allocated = 1; 402 | else if( err == KERN_NO_SPACE ) { 403 | #if defined(__x86_64__) 404 | page -= pageSize; 405 | #else 406 | page += pageSize; 407 | #endif 408 | err = err_none; 409 | } 410 | } 411 | if( allocated ) 412 | *island = (void*) page; 413 | else if( !allocated && !err ) 414 | err = KERN_NO_SPACE; 415 | } 416 | } else { 417 | void *block = malloc( sizeof( BranchIsland ) ); 418 | if( block ) 419 | *island = block; 420 | else 421 | err = KERN_NO_SPACE; 422 | } 423 | if( !err ) 424 | (**island).allocatedHigh = allocateHigh; 425 | 426 | return err; 427 | } 428 | 429 | /***************************************************************************//** 430 | Implementation: Deallocates memory for a branch island. 431 | 432 | @param island -> The island to deallocate. 433 | @result <- mach_error_t 434 | 435 | ***************************************************************************/ 436 | 437 | mach_error_t 438 | freeBranchIsland( 439 | BranchIsland *island ) 440 | { 441 | assert( island ); 442 | assert( (*(long*)&island->instructions[0]) == kIslandTemplate[0] ); 443 | assert( island->allocatedHigh ); 444 | 445 | mach_error_t err = err_none; 446 | 447 | if( island->allocatedHigh ) { 448 | vm_size_t pageSize; 449 | err = host_page_size( mach_host_self(), &pageSize ); 450 | if( !err ) { 451 | assert( sizeof( BranchIsland ) <= pageSize ); 452 | err = vm_deallocate( 453 | mach_task_self(), 454 | (vm_address_t) island, pageSize ); 455 | } 456 | } else { 457 | free( island ); 458 | } 459 | 460 | return err; 461 | } 462 | 463 | /***************************************************************************//** 464 | Implementation: Sets the branch island's target, with an optional 465 | instruction. 466 | 467 | @param island -> The branch island to insert target into. 468 | @param branchTo -> The address of the target. 469 | @param instruction -> Optional instruction to execute prior to branch. Set 470 | to zero for nop. 471 | @result <- mach_error_t 472 | 473 | ***************************************************************************/ 474 | #if defined(__ppc__) || defined(__POWERPC__) 475 | mach_error_t 476 | setBranchIslandTarget( 477 | BranchIsland *island, 478 | const void *branchTo, 479 | long instruction ) 480 | { 481 | // Copy over the template code. 482 | bcopy( kIslandTemplate, island->instructions, sizeof( kIslandTemplate ) ); 483 | 484 | // Fill in the address. 485 | ((short*)island->instructions)[kAddressLo] = ((long) branchTo) & 0x0000FFFF; 486 | ((short*)island->instructions)[kAddressHi] 487 | = (((long) branchTo) >> 16) & 0x0000FFFF; 488 | 489 | // Fill in the (optional) instuction. 490 | if( instruction != 0 ) { 491 | ((short*)island->instructions)[kInstructionLo] 492 | = instruction & 0x0000FFFF; 493 | ((short*)island->instructions)[kInstructionHi] 494 | = (instruction >> 16) & 0x0000FFFF; 495 | } 496 | 497 | //MakeDataExecutable( island->instructions, sizeof( kIslandTemplate ) ); 498 | msync( island->instructions, sizeof( kIslandTemplate ), MS_INVALIDATE ); 499 | 500 | return err_none; 501 | } 502 | #endif 503 | 504 | #if defined(__i386__) 505 | mach_error_t 506 | setBranchIslandTarget_i386( 507 | BranchIsland *island, 508 | const void *branchTo, 509 | char* instructions ) 510 | { 511 | 512 | // Copy over the template code. 513 | bcopy( kIslandTemplate, island->instructions, sizeof( kIslandTemplate ) ); 514 | 515 | // copy original instructions 516 | if (instructions) { 517 | bcopy (instructions, island->instructions + kInstructions, kOriginalInstructionsSize); 518 | } 519 | 520 | // Fill in the address. 521 | int32_t addressOffset = (char *)branchTo - (island->instructions + kJumpAddress + 4); 522 | *((int32_t *)(island->instructions + kJumpAddress)) = addressOffset; 523 | 524 | msync( island->instructions, sizeof( kIslandTemplate ), MS_INVALIDATE ); 525 | return err_none; 526 | } 527 | 528 | #elif defined(__x86_64__) 529 | mach_error_t 530 | setBranchIslandTarget_i386( 531 | BranchIsland *island, 532 | const void *branchTo, 533 | char* instructions ) 534 | { 535 | // Copy over the template code. 536 | bcopy( kIslandTemplate, island->instructions, sizeof( kIslandTemplate ) ); 537 | 538 | // Copy original instructions. 539 | if (instructions) { 540 | bcopy (instructions, island->instructions, kOriginalInstructionsSize); 541 | } 542 | 543 | // Fill in the address. 544 | *((uint64_t *)(island->instructions + kJumpAddress)) = (uint64_t)branchTo; 545 | msync( island->instructions, sizeof( kIslandTemplate ), MS_INVALIDATE ); 546 | 547 | return err_none; 548 | } 549 | #endif 550 | 551 | 552 | #if defined(__i386__) || defined(__x86_64__) 553 | // simplistic instruction matching 554 | typedef struct { 555 | unsigned int length; // max 15 556 | unsigned char mask[15]; // sequence of bytes in memory order 557 | unsigned char constraint[15]; // sequence of bytes in memory order 558 | } AsmInstructionMatch; 559 | 560 | #if defined(__i386__) 561 | static AsmInstructionMatch possibleInstructions[] = { 562 | { 0x1, {0xFF}, {0x90} }, // nop 563 | { 0x1, {0xFF}, {0x55} }, // push %esp 564 | { 0x2, {0xFF, 0xFF}, {0x89, 0xE5} }, // mov %esp,%ebp 565 | { 0x1, {0xFF}, {0x53} }, // push %ebx 566 | { 0x3, {0xFF, 0xFF, 0x00}, {0x83, 0xEC, 0x00} }, // sub 0x??, %esp 567 | { 0x1, {0xFF}, {0x57} }, // push %edi 568 | { 0x1, {0xFF}, {0x56} }, // push %esi 569 | 570 | // added by Tanaris4! 571 | { 0x3, {0xFF, 0x00, 0x00}, {0x8B, 0x00, 0x00} }, // mov eax, [ebp+arg_0] 572 | { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xA1, 0x00, 0x00, 0x00, 0x00} }, // mov %eax, dword_ 573 | { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xB9, 0x00, 0x00, 0x00, 0x00} }, // call $+5 574 | { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xA1, 0x00, 0x00, 0x00, 0x00} }, // mov ecx, offset byte_B33150 575 | 576 | { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0x83, 0x00, 0x00, 0x00, 0x00} }, // add [esp+arg_0], 0FFFFFFF8h 577 | 578 | 579 | { 0x6, {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}, {0x81, 0xEC, 0x00, 0x00, 0x00, 0x00} }, //sub esp, 0C8h 580 | { 0x2, {0xFF, 0x00}, {0x31, 0x00} }, // xor edi edi 581 | { 0x2, {0xFF, 0xFF}, {0x89, 0xC7} }, // mov edi, eax 582 | { 0x5, {0xFF, 0x00, 0x00, 0x00, 0x00}, {0xBA, 0x00, 0x00, 0x00, 0x00} }, // mov edx, 1 583 | { 0x0 } 584 | }; 585 | #elif defined(__x86_64__) 586 | static AsmInstructionMatch possibleInstructions[] = { 587 | { 0x1, {0xFF}, {0x90} }, // nop 588 | { 0x1, {0xF8}, {0x50} }, // push %rX 589 | { 0x3, {0xFF, 0xFF, 0xFF}, {0x48, 0x89, 0xE5} }, // mov %rsp,%rbp 590 | { 0x4, {0xFF, 0xFF, 0xFF, 0x00}, {0x48, 0x83, 0xEC, 0x00} }, // sub 0x??, %rsp 591 | { 0x4, {0xFB, 0xFF, 0x00, 0x00}, {0x48, 0x89, 0x00, 0x00} }, // move onto rbp 592 | { 0x2, {0xFF, 0x00}, {0x41, 0x00} }, // push %rXX 593 | { 0x2, {0xFF, 0x00}, {0x85, 0x00} }, // test %rX,%rX 594 | { 0x0 } 595 | }; 596 | #endif 597 | 598 | static Boolean codeMatchesInstruction(unsigned char *code, AsmInstructionMatch* instruction) 599 | { 600 | Boolean match = true; 601 | 602 | int i; 603 | for (i=0; ilength; i++) { 604 | unsigned char mask = instruction->mask[i]; 605 | unsigned char constraint = instruction->constraint[i]; 606 | unsigned char codeValue = code[i]; 607 | 608 | match = ((codeValue & mask) == constraint); 609 | if (!match) break; 610 | } 611 | 612 | return match; 613 | } 614 | 615 | #if defined(__i386__) || defined(__x86_64__) 616 | static Boolean 617 | eatKnownInstructions( 618 | unsigned char *code, 619 | uint64_t* newInstruction, 620 | int* howManyEaten, 621 | char* originalInstructions ) 622 | { 623 | Boolean allInstructionsKnown = true; 624 | int totalEaten = 0; 625 | unsigned char* ptr = code; 626 | int remainsToEat = 5; // a JMP instruction takes 5 bytes 627 | 628 | if (howManyEaten) *howManyEaten = 0; 629 | while (remainsToEat > 0) { 630 | Boolean curInstructionKnown = false; 631 | 632 | // See if instruction matches one we know 633 | AsmInstructionMatch* curInstr = possibleInstructions; 634 | do { 635 | if (curInstructionKnown = codeMatchesInstruction(ptr, curInstr)) break; 636 | curInstr++; 637 | } while (curInstr->length > 0); 638 | 639 | // if all instruction matches failed, we don't know current instruction then, stop here 640 | if (!curInstructionKnown) { 641 | allInstructionsKnown = false; 642 | break; 643 | } 644 | 645 | // At this point, we've matched curInstr 646 | int eaten = curInstr->length; 647 | ptr += eaten; 648 | remainsToEat -= eaten; 649 | totalEaten += eaten; 650 | } 651 | 652 | 653 | if (howManyEaten) *howManyEaten = totalEaten; 654 | 655 | if (originalInstructions) { 656 | Boolean enoughSpaceForOriginalInstructions = (totalEaten < kOriginalInstructionsSize); 657 | 658 | if (enoughSpaceForOriginalInstructions) { 659 | memset(originalInstructions, 0x90 /* NOP */, kOriginalInstructionsSize); // fill instructions with NOP 660 | bcopy(code, originalInstructions, totalEaten); 661 | } else { 662 | // printf ("Not enough space in island to store original instructions. Adapt the island definition and kOriginalInstructionsSize\n"); 663 | return false; 664 | } 665 | } 666 | 667 | if (allInstructionsKnown) { 668 | // save last 3 bytes of first 64bits of codre we'll replace 669 | uint64_t currentFirst64BitsOfCode = *((uint64_t *)code); 670 | currentFirst64BitsOfCode = OSSwapInt64(currentFirst64BitsOfCode); // back to memory representation 671 | currentFirst64BitsOfCode &= 0x0000000000FFFFFFLL; 672 | 673 | // keep only last 3 instructions bytes, first 5 will be replaced by JMP instr 674 | *newInstruction &= 0xFFFFFFFFFF000000LL; // clear last 3 bytes 675 | *newInstruction |= (currentFirst64BitsOfCode & 0x0000000000FFFFFFLL); // set last 3 bytes 676 | } 677 | 678 | return allInstructionsKnown; 679 | } 680 | #endif 681 | 682 | #if defined(__i386__) 683 | asm( 684 | ".text;" 685 | ".align 2, 0x90;" 686 | ".globl _atomic_mov64;" 687 | "_atomic_mov64:;" 688 | " pushl %ebp;" 689 | " movl %esp, %ebp;" 690 | " pushl %esi;" 691 | " pushl %ebx;" 692 | " pushl %ecx;" 693 | " pushl %eax;" 694 | " pushl %edx;" 695 | 696 | // atomic push of value to an address 697 | // we use cmpxchg8b, which compares content of an address with 698 | // edx:eax. If they are equal, it atomically puts 64bit value 699 | // ecx:ebx in address. 700 | // We thus put contents of address in edx:eax to force ecx:ebx 701 | // in address 702 | " mov 8(%ebp), %esi;" // esi contains target address 703 | " mov 12(%ebp), %ebx;" 704 | " mov 16(%ebp), %ecx;" // ecx:ebx now contains value to put in target address 705 | " mov (%esi), %eax;" 706 | " mov 4(%esi), %edx;" // edx:eax now contains value currently contained in target address 707 | " lock; cmpxchg8b (%esi);" // atomic move. 708 | 709 | // restore registers 710 | " popl %edx;" 711 | " popl %eax;" 712 | " popl %ecx;" 713 | " popl %ebx;" 714 | " popl %esi;" 715 | " popl %ebp;" 716 | " ret" 717 | ); 718 | #elif defined(__x86_64__) 719 | void atomic_mov64( 720 | uint64_t *targetAddress, 721 | uint64_t value ) 722 | { 723 | *targetAddress = value; 724 | } 725 | #endif 726 | #endif -------------------------------------------------------------------------------- /tools/macho_module/mach_override.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | mach_override.h 3 | Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: 4 | Some rights reserved: 5 | 6 | ***************************************************************************/ 7 | 8 | /***************************************************************************//** 9 | @mainpage mach_override 10 | @author Jonathan 'Wolf' Rentzsch: 11 | 12 | This package, coded in C to the Mach API, allows you to override ("patch") 13 | program- and system-supplied functions at runtime. You can fully replace 14 | functions with your implementations, or merely head- or tail-patch the 15 | original implementations. 16 | 17 | Use it by #include'ing mach_override.h from your .c, .m or .mm file(s). 18 | 19 | @todo Discontinue use of Carbon's MakeDataExecutable() and 20 | CompareAndSwap() calls and start using the Mach equivalents, if they 21 | exist. If they don't, write them and roll them in. That way, this 22 | code will be pure Mach, which will make it easier to use everywhere. 23 | Update: MakeDataExecutable() has been replaced by 24 | msync(MS_INVALIDATE). There is an OSCompareAndSwap in libkern, but 25 | I'm currently unsure if I can link against it. May have to roll in 26 | my own version... 27 | @todo Stop using an entire 4K high-allocated VM page per 28-byte escape 28 | branch island. Done right, this will dramatically speed up escape 29 | island allocations when they number over 250. Then again, if you're 30 | overriding more than 250 functions, maybe speed isn't your main 31 | concern... 32 | @todo Add detection of: b, bl, bla, bc, bcl, bcla, bcctrl, bclrl 33 | first-instructions. Initially, we should refuse to override 34 | functions beginning with these instructions. Eventually, we should 35 | dynamically rewrite them to make them position-independent. 36 | @todo Write mach_unoverride(), which would remove an override placed on a 37 | function. Must be multiple-override aware, which means an almost 38 | complete rewrite under the covers, because the target address can't 39 | be spread across two load instructions like it is now since it will 40 | need to be atomically updatable. 41 | @todo Add non-rentry variants of overrides to test_mach_override. 42 | 43 | ***************************************************************************/ 44 | 45 | #ifndef _mach_override_ 46 | #define _mach_override_ 47 | 48 | #include 49 | #include 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | /** 56 | Returned if the function to be overrided begins with a 'mfctr' instruction. 57 | */ 58 | #define err_cannot_override (err_local|1) 59 | 60 | /***************************************************************************//** 61 | Dynamically overrides the function implementation referenced by 62 | originalFunctionSymbolName with the implentation pointed to by 63 | overrideFunctionAddress. Optionally returns a pointer to a "reentry island" 64 | which, if jumped to, will resume the original implementation. 65 | 66 | @param originalFunctionSymbolName -> Required symbol name of the 67 | function to override (with 68 | overrideFunctionAddress). 69 | Remember, C function name 70 | symbols are prepended with an 71 | underscore. 72 | @param originalFunctionLibraryNameHint -> Optional name of the library 73 | which contains 74 | originalFunctionSymbolName. Can 75 | be NULL, but this may result in 76 | the wrong function being 77 | overridden and/or a crash. 78 | @param overrideFunctionAddress -> Required address to the 79 | overriding function. 80 | @param originalFunctionReentryIsland <- Optional pointer to pointer to 81 | the reentry island. Can be NULL. 82 | @result <- err_cannot_override if the 83 | original function's 84 | implementation begins with the 85 | 'mfctr' instruction. 86 | 87 | ***************************************************************************/ 88 | 89 | mach_error_t 90 | mach_override( 91 | char *originalFunctionSymbolName, 92 | const char *originalFunctionLibraryNameHint, 93 | const void *overrideFunctionAddress, 94 | void **originalFunctionReentryIsland ); 95 | 96 | /************************************************************************************//** 97 | Dynamically overrides the function implementation referenced by 98 | originalFunctionAddress with the implentation pointed to by overrideFunctionAddress. 99 | Optionally returns a pointer to a "reentry island" which, if jumped to, will resume 100 | the original implementation. 101 | 102 | @param originalFunctionAddress -> Required address of the function to 103 | override (with overrideFunctionAddress). 104 | @param overrideFunctionAddress -> Required address to the overriding 105 | function. 106 | @param originalFunctionReentryIsland <- Optional pointer to pointer to the 107 | reentry island. Can be NULL. 108 | @result <- err_cannot_override if the original 109 | function's implementation begins with 110 | the 'mfctr' instruction. 111 | 112 | ************************************************************************************/ 113 | 114 | mach_error_t 115 | mach_override_ptr( 116 | void *originalFunctionAddress, 117 | const void *overrideFunctionAddress, 118 | void **originalFunctionReentryIsland ); 119 | 120 | /************************************************************************************//** 121 | 122 | 123 | ************************************************************************************/ 124 | 125 | #ifdef __cplusplus 126 | 127 | #define MACH_OVERRIDE( ORIGINAL_FUNCTION_RETURN_TYPE, ORIGINAL_FUNCTION_NAME, ORIGINAL_FUNCTION_ARGS, ERR ) \ 128 | { \ 129 | static ORIGINAL_FUNCTION_RETURN_TYPE (*ORIGINAL_FUNCTION_NAME##_reenter)ORIGINAL_FUNCTION_ARGS; \ 130 | static bool ORIGINAL_FUNCTION_NAME##_overriden = false; \ 131 | class mach_override_class__##ORIGINAL_FUNCTION_NAME { \ 132 | public: \ 133 | static kern_return_t override(void *originalFunctionPtr) { \ 134 | kern_return_t result = err_none; \ 135 | if (!ORIGINAL_FUNCTION_NAME##_overriden) { \ 136 | ORIGINAL_FUNCTION_NAME##_overriden = true; \ 137 | result = mach_override_ptr( (void*)originalFunctionPtr, \ 138 | (void*)mach_override_class__##ORIGINAL_FUNCTION_NAME::replacement, \ 139 | (void**)&ORIGINAL_FUNCTION_NAME##_reenter ); \ 140 | } \ 141 | return result; \ 142 | } \ 143 | static ORIGINAL_FUNCTION_RETURN_TYPE replacement ORIGINAL_FUNCTION_ARGS { 144 | 145 | #define END_MACH_OVERRIDE( ORIGINAL_FUNCTION_NAME ) \ 146 | } \ 147 | }; \ 148 | \ 149 | err = mach_override_class__##ORIGINAL_FUNCTION_NAME::override((void*)ORIGINAL_FUNCTION_NAME); \ 150 | } 151 | 152 | #endif 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | #endif // _mach_override_ -------------------------------------------------------------------------------- /tools/macho_module/wow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lite/osxrce/a818b832552001bfc16a3c046cefcad097b0d897/tools/macho_module/wow -------------------------------------------------------------------------------- /tools/macho_module/wow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "mach_override.h" 9 | 10 | /********************************************************************** 11 | * Hooks * 12 | **********************************************************************/ 13 | int (*_real_NSCreateObjectFileImageFromMemory)(const void* address, size_t size, NSObjectFileImage* objectFileImage); 14 | int _hook_NSCreateObjectFileImageFromMemory(const void* address, size_t size, NSObjectFileImage* objectFileImage){ 15 | 16 | // call the original function! 17 | int res = (*_real_NSCreateObjectFileImageFromMemory)(address, size, objectFileImage); 18 | 19 | // save the module to a file :-) 20 | char name[100]; 21 | snprintf(name, sizeof(name), "/0x%X_0x%X.bin", (unsigned int)address, (unsigned int)size); 22 | printf("WRITING module to %s\n", name); 23 | int fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0600); 24 | if (fd > 0) { 25 | // pretty straightforward, we know the start address of where the module is stored within wow's memory 26 | // and we know the size! 27 | write(fd, address, size); 28 | } 29 | close(fd); 30 | 31 | return res; 32 | } 33 | 34 | 35 | /********************************************************************** 36 | * Bundle Interface * 37 | **********************************************************************/ 38 | static void init(void) __attribute__ ((constructor)); 39 | void init(void) 40 | { 41 | mach_error_t me; 42 | 43 | me = mach_override( "_NSCreateObjectFileImageFromMemory", NULL, 44 | (void*)&_hook_NSCreateObjectFileImageFromMemory, 45 | (void**)&_real_NSCreateObjectFileImageFromMemory); 46 | 47 | warnx("Was the hook successful? %x %s", me, mach_error_string(me)); 48 | } 49 | --------------------------------------------------------------------------------