diff --git a/research/custom_loader/b.cc b/research/custom_loader/b.cc index 0127465..fd80703 100644 --- a/research/custom_loader/b.cc +++ b/research/custom_loader/b.cc @@ -642,7 +642,7 @@ void build_cache(struct libcache& cache, void* main) { char *name = dyld_get_image_name_func(i); bootstrap_libcache_item(&cache.libs[i], header, name); cache.libs[i].hash = calculate_libname_hash(&cache, name); - printf("%p %s\n", header, name); + // printf("%p %s\n", header, name); } } @@ -709,6 +709,7 @@ void fix(struct libcache& cache) { // think of a way to get what binary to fix // so we can iterate through them struct libcache_item* libfixing = get_libcache_with_name(&cache, "./out/a"); + // print_macho_summary(libfixing->header); for (int i = 0; i < nimports; i++) { struct imported_symbol symbol = imported_table[i]; uint64_t fix_at = symbol.offset + libfixing->segment[symbol.segment_i]; @@ -716,13 +717,13 @@ void fix(struct libcache& cache) { int need_rw_fix = true; for (int j = 0; j < npage_rw_fixed; j++) { if (page_rw_fixed[j] <= fix_at && - page_rw_fixed[j] + 0x4000 > fix_at) { + page_rw_fixed[j] + 0x1000 > fix_at) { need_rw_fix = false; } } if (need_rw_fix) { - uint64_t start_page = fix_at - (fix_at % 0x4000); - vm_protect_func(mach_task_self_func(), start_page, 0x4000, 0, + uint64_t start_page = fix_at - (fix_at % 0x1000); + vm_protect_func(mach_task_self_func(), start_page, 0x1000, 0, VM_PROT_READ | VM_PROT_WRITE); page_rw_fixed[npage_rw_fixed++] = start_page; printf("modify page starts at 0x%llx to RW\n", start_page); diff --git a/research/custom_loader/build.sh b/research/custom_loader/build.sh index 249ff37..442bf99 100755 --- a/research/custom_loader/build.sh +++ b/research/custom_loader/build.sh @@ -1,11 +1,19 @@ -set -ex +# set -ex -VERSION=11 +VERSION=${1:-14} OUT=./out LOGIC=2 mkdir -p $OUT +echo "using mach-o version $VERSION" +if [[ $VERSION -ge 14 ]] +then + echo "Resulting binary uses MODERN symbol resolver" +else + echo "Resulting binary uses LEGACY symbol resolver" +fi + if [[ $LOGIC -eq 0 ]] then @@ -38,6 +46,8 @@ clang++ -mmacosx-version-min=$VERSION -o $OUT/a -L"./out" -lb a.cc # build libb with symbols extracted from a clang++ -mmacosx-version-min=$VERSION -o $OUT/libb.dylib -shared -Wl,-reexport_library out/libc.dylib b.cc +out/a + else # dummy test build