|
| 1 | +/* |
| 2 | + * Copyright (c) FFRI Security, Inc., 2023 / Author: FFRI Security, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef _INCLUDE_XTAC_H_ |
| 18 | +#define _INCLUDE_XTAC_H_ |
| 19 | + |
| 20 | +#include <r_types.h> |
| 21 | + |
| 22 | +#define XTAC_MAGIC "XTAC" |
| 23 | + |
| 24 | +typedef struct x86_arm_addr_pair_t { |
| 25 | + ut32 x86_rva; |
| 26 | + ut32 arm64_rva; |
| 27 | +} X86ArmAddrPair; |
| 28 | + |
| 29 | +// NOTE: Here "pointer" means RVA from the image base of the cache file |
| 30 | +typedef struct r_bin_xtac_header_t { |
| 31 | + ut32 magic; // signature (always "XTAC") |
| 32 | + ut32 version; // version of XTAC |
| 33 | + ut32 is_updated; // cache file is updated (1) or not (0) |
| 34 | + ut32 ptr_to_addr_pairs; // pointer to x86 to arm address pairs |
| 35 | + ut32 num_of_addr_pairs; // number of address pairs |
| 36 | + ut32 ptr_to_mod_name; // pointer to module name |
| 37 | + ut32 size_of_mod_name; // size of module name (in bytes) |
| 38 | + ut32 ptr_to_nt_pname; // pointer to NT path name |
| 39 | + ut32 size_of_nt_pname; // size of NT path name (in bytes) |
| 40 | + ut32 ptr_to_head_blck_stub; // pointer to head BLCK stub |
| 41 | + ut32 ptr_to_tail_blck_stub; // pointer to tail BLCK stub |
| 42 | + ut32 size_of_blck_stub_code; // size of BLCK stub code (not including BLCK stub header) |
| 43 | + ut32 ptr_to_xtac_linked_list_head; // pointer to the head of linked list for updating |
| 44 | + // xtac.exe uses this for accessing the location to be corrected |
| 45 | + ut32 ptr_to_xtac_linked_list_tail; // pointer to the tail of linked list for updating |
| 46 | +} RBinXtacHeader; |
| 47 | + |
| 48 | +typedef struct r_bin_blck_stub_header_t { |
| 49 | + ut32 magic; // signature (always "BLCK") |
| 50 | + ut32 offset_to_next_entry; // offset to the next entry from the current BLCK stub code |
| 51 | + ut32 ptr_to_next_entry; // pointer to the next BLCK stub |
| 52 | + ut32 padding; // padding (always 0) |
| 53 | + |
| 54 | + ut32 ptr_to_entry; // pointer to this entry |
| 55 | +} RBinBlckStubHeader; |
| 56 | + |
| 57 | +typedef struct r_bin_xtac_linked_list_entry_t { |
| 58 | + ut32 meta_and_offset; // metadata (upper 8bits) and quarter of offset to next entry (lower 24bits) |
| 59 | + ut32 forward_edge_addr; // x86 RVA of forward edge address |
| 60 | + ut32 backward_edge_addr; // x86 RVA of backward edge address |
| 61 | + |
| 62 | + ut32 ptr_to_entry; // pointer to this entry |
| 63 | +} RBinXtacLinkedListEntry; |
| 64 | + |
| 65 | +typedef struct r_bin_xtac_obj_t { |
| 66 | + RBinXtacHeader *header; |
| 67 | + X86ArmAddrPair *address_pairs; |
| 68 | + ut16 *mod_name_u16; |
| 69 | + char *mod_name_u8; |
| 70 | + ut16 *nt_path_name_u16; |
| 71 | + char *nt_path_name_u8; |
| 72 | + |
| 73 | + RBuffer *b; |
| 74 | + RList *blck_stubs; // RList of r_bin_bock_stub_header_t |
| 75 | + RList *xtac_linked_list; // RList of r_bin_xtac_linked_list_entry_t |
| 76 | + Sdb *kv; |
| 77 | + bool verbose; |
| 78 | + int size; |
| 79 | +} RBinXtacObj; |
| 80 | + |
| 81 | +#endif |
0 commit comments