// Copyright (c) 2013, Facebook, Inc.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name Facebook nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific
// prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "fishhook.h"
#import <dlfcn.h>
#import <stdlib.h>
#import <string.h>
#import <sys/types.h>
#import <mach-o/dyld.h>
#import <mach-o/loader.h>
#import <mach-o/nlist.h>
#ifdef __LP64__
typedef struct mach_header_64 mach_header_t;
typedef struct segment_command_64 segment_command_t;
typedef struct section_64 section_t;
typedef struct nlist_64 nlist_t;
#define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT_64
#else
typedef struct mach_header mach_header_t;
typedef struct segment_command segment_command_t;
typedef struct section section_t;
typedef struct nlist nlist_t;
#define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT
#endif
#ifndef SEG_DATA_CONST
#define SEG_DATA_CONST "__DATA_CONST"
#endif
struct rebindings_entry {
struct rebinding *rebindings;
size_t rebindings_nel;
struct rebindings_entry *next;
};
static struct rebindings_entry *_rebindings_head;
static int prepend_rebindings(struct rebindings_entry **rebindings_head,
struct rebinding rebindings[],
size_t nel) {
struct rebindings_entry *new_entry = (struct rebindings_entry *) malloc(sizeof(struct rebindings_entry));
if (!new_entry) {
return -1;
}
new_entry->rebindings = (struct rebinding *) malloc(sizeof(struct rebinding) * nel);
if (!new_entry->rebindings) {
free(new_entry);
return -1;
}
memcpy(new_entry->rebindings, rebindings, sizeof(struct rebinding) * nel);
new_entry->rebindings_nel = nel;
new_entry->next = *rebindings_head;
*rebindings_head = new_entry;
return 0;
}
static void perform_rebinding_with_section(struct rebindings_entry *rebindings,
section_t *section,
intptr_t slide,
nlist_t *symtab,
char *strtab,
uint32_t *indirect_symtab) {
uint32_t *indirect_symbol_indices = indirect_symtab + section->reserved1;
void **indirect_symbol_bindings = (void **)((uintptr_t)slide + section->addr);
for (uint i = 0; i < section->size / sizeof(void *); i++) {
uint32_t symtab_index = indirect_symbol_indices[i];
if (symtab_index == INDIRECT_SYMBOL_ABS || symtab_index == INDIRECT_SYMBOL_LOCAL ||
symtab_index == (INDIRECT_SYMBOL_LOCAL | INDIRECT_SYMBOL_ABS)) {
continue;
}
uint32_t strtab_offset = symtab[symtab_index].n_un.n_strx;
char *symbol_name = strtab + strtab_offset;
if (strnlen(symbol_name, 2) < 2) {
continue;
}
struct rebindings_entry *cur = rebindings;
while (cur) {
for (uint j = 0; j < cur->rebindings_nel; j++) {
if (strcmp(&symbol_name[1], cur->rebindings[j].name) == 0) {
if (cur->rebindings[j].replaced != NULL &&
indirect_symbol_bindings[i] != cur->rebindings[j].replacement) {
*(cur->rebindings[j].replaced) = indirect_symbol_bindings[i];
}
indirect_symbol_bindings[i] = cur->rebindings[j].replacement;
goto symbol_loop;
}
}
cur = cur->next;
}
symbol_loop:;
}
}
static void rebind_symbols_for_image(struct rebindings_entry *rebindings,
const struct mach_header *header,
intptr_t slide) {
Dl_info info;
if (dladdr(header, &info) == 0) {
return;
}
segment_command_t *cur_seg_cmd;
segment_command_t *linkedit_segment = NULL;
struct symtab_command* symtab_cmd = NULL;
struct dysymtab_command* dysymtab_cmd = NULL;
uintptr_t cur = (uintptr_t)header + sizeof(mach_header_t);
for (uint i = 0; i < header->ncmds; i++, cur += cur_seg_cmd->cmdsize) {
cur_seg_cmd = (segment_command_t *)cur;
if (cur_seg_cmd->cmd == LC_SEGMENT_ARCH_DEPENDENT) {
if (strcmp(cur_seg_cmd->segname, SEG_LINKEDIT) == 0) {
linkedit_segment = cur_seg_cmd;
}
} else if (cur_seg_cmd->cmd == LC_SYMTAB) {
symtab_cmd = (struct symtab_command*)cur_seg_cmd;
} else if (cur_seg_cmd->cmd == LC_DYSYMTAB) {
dysymtab_cmd = (struct dysymtab_command*)cur_seg_cmd;
}
}
if (!symtab_cmd || !dysymtab_cmd || !linkedit_segment ||
!dysymtab_cmd->nindirectsyms) {
return;
}
// Find base symbol/string table addresses
uintptr_t linkedit_base = (uintptr_t)slide + linkedit_segment->vmaddr - linkedit_segment->fileoff;
nlist_t *symtab = (nlist_t *)(linkedit_base + symtab_cmd->symoff);
char *strtab = (char *)(linkedit_base + symtab_cmd->stroff);
// Get indirect symbol table (array of uint32_t indices into symbol table)
uint32_t *indirect_symtab = (uint32_t *)(linkedit_base + dysymtab_cmd->indirectsymoff);
cur = (uintptr_t)header + sizeof(mach_header_t);
for (uint i = 0; i < header->ncmds; i++, cur += cur_seg_cmd->cmdsize) {
cur_seg_cmd = (segment_command_t *)cur;
if (cur_seg_cmd->cmd == LC_SEGMENT_ARCH_DEPENDENT) {
if (strcmp(cur_seg_cmd->segname, SEG_DATA) != 0 &&
strcmp(cur_seg_cmd->segname, SEG_DATA_CONST) != 0) {
continue;
}
for (uint j = 0; j < cur_seg_cmd->nsects; j++) {
section_t *sect =
(section_t *)(cur + sizeof(segment_command_t)) + j;
if ((sect->flags & SECTION_TYPE) == S_LAZY_SYMBOL_POINTERS) {
perform_rebinding_with_section(rebindings, sect, slide, symtab, strtab, indirect_symtab);
}
if ((sect->flags & SECTION_TYPE) == S_NON_LAZY_SYMBOL_POINTERS) {
perform_rebinding_with_section(rebindings, sect, slide, symtab, strtab, indirect_symtab);
}
}
}
}
}
static void _rebind_symbols_for_image(const struct mach_header *header,
intptr_t slide) {
rebind_symbols_for_image(_rebindings_head, header, slide);
}
int rebind_symbols_image(void *header,
intptr_t slide,
struct rebinding rebindings[],
size_t rebindings_nel) {
struct rebindings_entry *rebindings_head = NULL;
int retval = prepend_rebindings(&rebindings_head, rebindings, rebindings_nel);
rebind_symbols_for_image(rebindings_head, (const struct mach_header *) header, slide);
free(rebindings_head);
return retval;
}
int rebind_symbols(struct rebinding rebindings[], size_t rebindings_nel) {
int retval = prepend_rebindings(&_rebindings_head, rebindings, rebindings_nel);
if (retval <
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
hookKwai670.zip (2004个子文件)
fishhook.c 8KB
.DS_Store 10KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
Header.h 58KB
KSStartupResponse.h 46KB
KSFeedViewController.h 30KB
KSLiveViewController.h 18KB
KS_feed.h 16KB
KSMediaEditTimeLineViewController.h 15KB
KWDaenerysCaptureSession.h 15KB
KSNewShareViewController.h 15KB
UIView+Toast.h 14KB
KSLiveAudienceViewModel.h 13KB
KSGoggleImportVideoViewController.h 12KB
KSBusinessProfileComponent.h 9KB
KSPostViewController.h 9KB
KSMomentDistributeViewController.h 8KB
KSMomentViewController.h 7KB
KSWesterosAdapter.h 7KB
KSFeedAd.h 7KB
KSLocalDetailViewController.h 7KB
KSMediaEditAudioPickerViewModel.h 7KB
KSBeautificationViewModel.h 7KB
KSBasePlayerView.h 7KB
FCFileManager.h 7KB
KSVideoJoinViewController.h 7KB
KSMagicFaceDataController.h 7KB
KSFollowLiveSingleComponent.h 6KB
KSPOIFeedsListViewController.h 6KB
KGGameFeedsViewController.h 6KB
KSLiveKTVViewModel.h 6KB
KSChildrenLockManager.h 6KB
KSPlayscriptCentreCell.h 6KB
BabyBluetooth.h 6KB
KSUAnchorStatEvent.h 6KB
KSFeedCommentViewModel.h 6KB
KSNearbyUserCollectionViewController.h 6KB
KSMediaEditFragmentAdjustController.h 6KB
KSCustomSearchBar.h 6KB
KSVideoRecorPluginPictureInPictureAndFollowShootBase.h 6KB
KSIMService.h 5KB
KSAtlasEditViewController.h 5KB
KSFeedNavigationBar.h 5KB
KSWesterosEffectDescription.h 5KB
KSAlertViewController.h 5KB
KSPlayscriptCentreCellAdapter.h 5KB
KSSlideFeedNewUserGuide.h 5KB
KSYQosInfo.h 5KB
KSLiveUserProfileViewModel.h 5KB
KSOnlineResource.h 5KB
KSStoryPopComponent.h 5KB
KSAtlasEditSingleAtlasPreviewViewController.h 5KB
KSEditMultipleVideosController.h 5KB
KSHomePageDataModel.h 5KB
KVESmartEditTaskBuilder.h 5KB
KSLetterImageBrowerViewController.h 5KB
KSTextChartletView.h 5KB
NSMutableAttributedString-KSRL.h 5KB
KGGameFeedViewController.h 5KB
KVESmartGalleryTask.h 5KB
KSSocialActivityViewController.h 4KB
KSAdFeedViewModel.h 4KB
KSGlassesPeripheral.h 4KB
KSAssetPickDelegateDefaultHandler.h 4KB
KSLiveEndRecommendController.h 4KB
KSMediaMusicPickViewController.h 4KB
KSGlassesDetailSettingViewController.h 4KB
_KSForgetPWDTabStyleViewController.h 4KB
KSMomentFollowedViewController.h 4KB
KSProfileStoryComponent.h 4KB
KSStoryProductionHomeViewController.h 4KB
KSMagicFaceListViewController.h 4KB
KSPhoneCodeViewController.h 4KB
KSNewUserInterestTagViewController.h 4KB
KSFeedDetailVideoPlayerView.h 4KB
KSMessageForwardViewController.h 4KB
KSHomeHotSpotCell.h 4KB
KWAryaQosInfo.h 4KB
KSLiveAnchorBottomBarComponent.h 4KB
KSSharePreviewViewController.h 4KB
KSLivePKMatchView.h 4KB
KSFlexibleTitleView.h 4KB
KSThanosEmbedFeedViewController.h 4KB
KSRedPacket.h 4KB
KSTubeSearchSuggestionComponent.h 4KB
KSTubeTagFeedsComponent.h 4KB
KSShareTokenTag.h 4KB
KSBeautificationMakeupViewModel.h 4KB
KSIMLikeListViewController.h 4KB
KSHomePageDataService.h 4KB
KSTagNavigationComponent.h 4KB
VDLogSender.h 4KB
KSRecommendUserFeedViewModel.h 4KB
KSMediaEditComponent.h 4KB
KSPhotoMovieProKeyFrameEditView.h 4KB
KSKaraPickViewController.h 4KB
MDConfigManager.h 4KB
KSTubeTagFeedsHeaderComponent.h 4KB
共 2004 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
白兔糖五花肉
- 粉丝: 1
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功