From nobody Sun May 5 17:48:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1669774061; cv=none; d=zohomail.com; s=zohoarc; b=fmSM2cKGP6VPfB6xyIXUosDePEr18SWcaKv3SOdzXR2BznE+eMNyHTWFQkTuNE77KDw+ZpQS6kkzlVxfFQ6t1T5+iFXg+ezMKRt3tAWTYnowgFZIOMG+hBI1UcTTvBcaiMWjQGo2MOVv87U9+65IUGWG0KXMNl9736YxXm4YRqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669774061; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pVi/U26AhZf/rbBLtYfoyTLQ+an6palKbfw2UihlUPo=; b=B2z9SrFAFP4tQ53TMTazt+6XhuSCAMgnfdOQb/122qBc7enRsl1huLLYdgjspqdwfk3I4Mzej+HmU1IwYWF1NMN4tlIIaB35B3guJ4tNChsECIIuXBTGOzmRIL4paVuigyl+GnvFVoexJ8rWQkW7DyH8kkMyzRdKOyyM5hsDMuY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166977406164766.04347070321023; Tue, 29 Nov 2022 18:07:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0CUx-00027G-Mi; Tue, 29 Nov 2022 21:06:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0AZc-0007z9-AI for qemu-devel@nongnu.org; Tue, 29 Nov 2022 19:03:36 -0500 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0AZZ-0004tk-78 for qemu-devel@nongnu.org; Tue, 29 Nov 2022 19:03:36 -0500 Received: by mail-lf1-x12c.google.com with SMTP id p8so24487704lfu.11 for ; Tue, 29 Nov 2022 16:03:32 -0800 (PST) Received: from vp-pc.. (46-138-224-213.dynamic.spd-mgts.ru. [46.138.224.213]) by smtp.gmail.com with ESMTPSA id x17-20020a056512079100b004b4f4360407sm2399377lfr.105.2022.11.29.16.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 16:03:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pVi/U26AhZf/rbBLtYfoyTLQ+an6palKbfw2UihlUPo=; b=J4SRGL0g94ieDKiNuaxfiz9V9cCKQvS1Rag/VUbpXq9TGlQCzYF0m2SCJf1wf9fOxK Rb25m9ZFQsltyBuZh7qQj99cAsGRzMKDY91zmdwogZn8pIwj7haJ6MCf0Gb5a4ul2lKt Vcf2Cmu6qmRj2UMiwN943xz1Di0QL2IXKuc/toiv6DyELPpWVdGAlqX878pWBQ6MRilk TxohHZG9Gajtf1hHlOSE2QZEc1MjyCZO5ORfP059YA0+XwbSsbNSgAKULa0ioyyTpGYK EN3NrXzMFTbMuyoJg7QPEoBTeKSfpfhCYNbaerBUt7ksiN3psfEOTqY/0AO55MXykKeT Kj5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pVi/U26AhZf/rbBLtYfoyTLQ+an6palKbfw2UihlUPo=; b=3cVhyEYTUqUKXSaWtYrbnHt8wM4N96y49cHS6d6ygHXaNJ/mi/IQwUazHX2YNlO9tj MyD53FdGFv5WOg5zn3mNLVPS684K1Hxewhs543ihVZgvzxaa9hv28NLf7DMfe4QfvKJL JN8lOYNnrC2cxBpilJ/IrkVwYG7+zLC7Cx/c/VxliWcnnvsZpC6bZWME7ZCWUUJ3N5Ah jPNf5gfAzoxn4808hEe+BJrLTiuD+jpBuVQQ0I2FR2hQBY5P6bFqLDRNobp1b47wudE7 DdVtQHDYwDknolIs3APC8ATp2yeqfksI50FrHdBVzbjgyTzE1kFjJ6Sq4fLj1NNQRxb6 +5xw== X-Gm-Message-State: ANoB5pkc5T9GwZSs8IDq0MiB0rrYPVDEvwZwUJy52M3HunVqOXJSG+IO bYxgg+V5r9J0Z9VQoufQvDaG6A== X-Google-Smtp-Source: AA0mqf7MSLsUmPtfakOHTto+bk3KZ8gE3f86J9i857f1ETnvp1aJok23A9+TiW9dIQ7mmCIhUQBlXg== X-Received: by 2002:a05:6512:32ce:b0:4a2:676e:cf60 with SMTP id f14-20020a05651232ce00b004a2676ecf60mr12506707lfg.624.1669766610542; Tue, 29 Nov 2022 16:03:30 -0800 (PST) From: Viktor Prutyanov To: pbonzini@redhat.com Cc: viktor.prutyanov@phystech.edu, yuri.benditovich@daynix.com, yan@daynix.com, qemu-devel@nongnu.org, viktor@daynix.com Subject: [PATCH v1 1/3] contrib/elf2dmp: fix code style Date: Wed, 30 Nov 2022 03:03:18 +0300 Message-Id: <20221130000320.287976-2-viktor@daynix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221130000320.287976-1-viktor@daynix.com> References: <20221130000320.287976-1-viktor@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::12c; envelope-from=viktor@daynix.com; helo=mail-lf1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 29 Nov 2022 21:06:53 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1669774063770100003 Content-Type: text/plain; charset="utf-8" Originally elf2dmp were added with some code style issues, especially in pe.h header, and some were introduced by 2d0fc797faaa73fbc1d30f5f9e90407bf3dd93f0. Fix them now. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/addrspace.c | 1 + contrib/elf2dmp/main.c | 9 ++-- contrib/elf2dmp/pe.h | 100 ++++++++++++++++++------------------ 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 53ded17061..0b04cba00e 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -11,6 +11,7 @@ static struct pa_block *pa_space_find_block(struct pa_space *ps, uint64_t = pa) { size_t i; + for (i =3D 0; i < ps->block_nr; i++) { if (ps->block[i].paddr <=3D pa && pa <=3D ps->block[i].paddr + ps->block[i].size) { diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index d77b8f98f7..9224764239 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -282,14 +282,16 @@ static int fill_header(WinDumpHeader64 *hdr, struct p= a_space *ps, }; =20 for (i =3D 0; i < ps->block_nr; i++) { - h.PhysicalMemoryBlock.NumberOfPages +=3D ps->block[i].size / ELF2D= MP_PAGE_SIZE; + h.PhysicalMemoryBlock.NumberOfPages +=3D + ps->block[i].size / ELF2DMP_PAGE_SIZE; h.PhysicalMemoryBlock.Run[i] =3D (WinDumpPhyMemRun64) { .BasePage =3D ps->block[i].paddr / ELF2DMP_PAGE_SIZE, .PageCount =3D ps->block[i].size / ELF2DMP_PAGE_SIZE, }; } =20 - h.RequiredDumpSpace +=3D h.PhysicalMemoryBlock.NumberOfPages << ELF2DM= P_PAGE_BITS; + h.RequiredDumpSpace +=3D + h.PhysicalMemoryBlock.NumberOfPages << ELF2DMP_PAGE_BITS; =20 *hdr =3D h; =20 @@ -299,7 +301,8 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_= space *ps, static int fill_context(KDDEBUGGER_DATA64 *kdbg, struct va_space *vs, QEMU_Elf *qe) { - int i; + int i; + for (i =3D 0; i < qe->state_nr; i++) { uint64_t Prcb; uint64_t Context; diff --git a/contrib/elf2dmp/pe.h b/contrib/elf2dmp/pe.h index c2a4a6ba7c..807d006364 100644 --- a/contrib/elf2dmp/pe.h +++ b/contrib/elf2dmp/pe.h @@ -33,70 +33,70 @@ typedef struct IMAGE_DOS_HEADER { } __attribute__ ((packed)) IMAGE_DOS_HEADER; =20 typedef struct IMAGE_FILE_HEADER { - uint16_t Machine; - uint16_t NumberOfSections; - uint32_t TimeDateStamp; - uint32_t PointerToSymbolTable; - uint32_t NumberOfSymbols; - uint16_t SizeOfOptionalHeader; - uint16_t Characteristics; + uint16_t Machine; + uint16_t NumberOfSections; + uint32_t TimeDateStamp; + uint32_t PointerToSymbolTable; + uint32_t NumberOfSymbols; + uint16_t SizeOfOptionalHeader; + uint16_t Characteristics; } __attribute__ ((packed)) IMAGE_FILE_HEADER; =20 typedef struct IMAGE_DATA_DIRECTORY { - uint32_t VirtualAddress; - uint32_t Size; + uint32_t VirtualAddress; + uint32_t Size; } __attribute__ ((packed)) IMAGE_DATA_DIRECTORY; =20 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 =20 typedef struct IMAGE_OPTIONAL_HEADER64 { - uint16_t Magic; /* 0x20b */ - uint8_t MajorLinkerVersion; - uint8_t MinorLinkerVersion; - uint32_t SizeOfCode; - uint32_t SizeOfInitializedData; - uint32_t SizeOfUninitializedData; - uint32_t AddressOfEntryPoint; - uint32_t BaseOfCode; - uint64_t ImageBase; - uint32_t SectionAlignment; - uint32_t FileAlignment; - uint16_t MajorOperatingSystemVersion; - uint16_t MinorOperatingSystemVersion; - uint16_t MajorImageVersion; - uint16_t MinorImageVersion; - uint16_t MajorSubsystemVersion; - uint16_t MinorSubsystemVersion; - uint32_t Win32VersionValue; - uint32_t SizeOfImage; - uint32_t SizeOfHeaders; - uint32_t CheckSum; - uint16_t Subsystem; - uint16_t DllCharacteristics; - uint64_t SizeOfStackReserve; - uint64_t SizeOfStackCommit; - uint64_t SizeOfHeapReserve; - uint64_t SizeOfHeapCommit; - uint32_t LoaderFlags; - uint32_t NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; + uint16_t Magic; /* 0x20b */ + uint8_t MajorLinkerVersion; + uint8_t MinorLinkerVersion; + uint32_t SizeOfCode; + uint32_t SizeOfInitializedData; + uint32_t SizeOfUninitializedData; + uint32_t AddressOfEntryPoint; + uint32_t BaseOfCode; + uint64_t ImageBase; + uint32_t SectionAlignment; + uint32_t FileAlignment; + uint16_t MajorOperatingSystemVersion; + uint16_t MinorOperatingSystemVersion; + uint16_t MajorImageVersion; + uint16_t MinorImageVersion; + uint16_t MajorSubsystemVersion; + uint16_t MinorSubsystemVersion; + uint32_t Win32VersionValue; + uint32_t SizeOfImage; + uint32_t SizeOfHeaders; + uint32_t CheckSum; + uint16_t Subsystem; + uint16_t DllCharacteristics; + uint64_t SizeOfStackReserve; + uint64_t SizeOfStackCommit; + uint64_t SizeOfHeapReserve; + uint64_t SizeOfHeapCommit; + uint32_t LoaderFlags; + uint32_t NumberOfRvaAndSizes; + IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; } __attribute__ ((packed)) IMAGE_OPTIONAL_HEADER64; =20 typedef struct IMAGE_NT_HEADERS64 { - uint32_t Signature; - IMAGE_FILE_HEADER FileHeader; - IMAGE_OPTIONAL_HEADER64 OptionalHeader; + uint32_t Signature; + IMAGE_FILE_HEADER FileHeader; + IMAGE_OPTIONAL_HEADER64 OptionalHeader; } __attribute__ ((packed)) IMAGE_NT_HEADERS64; =20 typedef struct IMAGE_DEBUG_DIRECTORY { - uint32_t Characteristics; - uint32_t TimeDateStamp; - uint16_t MajorVersion; - uint16_t MinorVersion; - uint32_t Type; - uint32_t SizeOfData; - uint32_t AddressOfRawData; - uint32_t PointerToRawData; + uint32_t Characteristics; + uint32_t TimeDateStamp; + uint16_t MajorVersion; + uint16_t MinorVersion; + uint32_t Type; + uint32_t SizeOfData; + uint32_t AddressOfRawData; + uint32_t PointerToRawData; } __attribute__ ((packed)) IMAGE_DEBUG_DIRECTORY; =20 #define IMAGE_DEBUG_TYPE_CODEVIEW 2 --=20 2.35.1 From nobody Sun May 5 17:48:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1669774079; cv=none; d=zohomail.com; s=zohoarc; b=fppKB8ddGsEpTp4rmLTiN1WkxoCN/PAa06ELasmhyRFce7n3wNwx0Z6xBhn0CLjoVmwdeL70Hg0I/7NzjFukRPDlBVoVhOHHht5T7RDYCpLZ4R0TND/CIhJ2nAQrOKTlll5oVCxL0bSP9xNR12Q0BkyS54dGIzBXn5Ijyq9nb2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669774079; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vXXvbMaw4dlxbhxJdfBIIOU5Lz9vDqR3CybYqjdPI5Q=; b=P90Wbdc9eVwDYI8Gojspm6+hjke7Y7YdUdkobVdYuHs4P1taaigQcJ0IWXtJk2X2IBfi1n/lyMg5/OZUfNC9bui4OinFihO7oB0KeuruXBD7a2z5qCQem1Fk8Jdr1OshOI0arN2Uo65wZXXW1GKdfJjJhdWt7TneucA5rRMSszo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669774079371782.2480547780484; Tue, 29 Nov 2022 18:07:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0CUz-0002BP-N5; Tue, 29 Nov 2022 21:06:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0AZg-00080t-4N for qemu-devel@nongnu.org; Tue, 29 Nov 2022 19:03:40 -0500 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0AZa-0004tn-LB for qemu-devel@nongnu.org; Tue, 29 Nov 2022 19:03:39 -0500 Received: by mail-lf1-x133.google.com with SMTP id r12so24549301lfp.1 for ; Tue, 29 Nov 2022 16:03:32 -0800 (PST) Received: from vp-pc.. (46-138-224-213.dynamic.spd-mgts.ru. [46.138.224.213]) by smtp.gmail.com with ESMTPSA id x17-20020a056512079100b004b4f4360407sm2399377lfr.105.2022.11.29.16.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 16:03:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vXXvbMaw4dlxbhxJdfBIIOU5Lz9vDqR3CybYqjdPI5Q=; b=MEpbTn1Fl42mSn7oBxuk8IrovZ5adchv3GF+Zq3s5GOuZ+C0W7rd9gGxh+frfmf0+l jfuFi15rYTE+92nloS2+iKiAZdIuOoeN6OVoUhAT7vBxQ7brfAnDpvljEv6WN0YrGdE0 H7xLzH1zTNQ68Hl1TxCH482rMz25cJLS8x1KPgx03MOw+Vk68bSdE7gLsN6e61HaSIDH 6H0useRu8obIUTo5Uctv2zQYdFp3K7KfJOa5SGROCJIAWu04EzgNF0xSiYG4DDctlyr7 QVp/MJ+w2lp0Z3/3bJzqbltUBUSj04iQGO2kJIdzSjxSL/z4ZKTaKFTZ07EtBLZ5+Kvs 7UBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vXXvbMaw4dlxbhxJdfBIIOU5Lz9vDqR3CybYqjdPI5Q=; b=KnxGyX3Nlfqgz0gydUERTf1ZRImI/2lvSdoc/jiXNppPP2H59mzFmc+XmTA2fJIuJS SpFJi9n0A2lvNbAgERuWD8G9OioBSw2IT2thEn+m3ugDFT2TvBeqUfEUI1IAGFXAKIVG nOBE8dvLT/e5YkOoZ77sOyfcrvy1yFb17FrUYyMilYIzx/z63u69Y0u09k+32cbXZpvu tqSloZE4dBcjpAc58T1bwuym4mCKCv5JQTSB/kbI/ygF+2ext4jFcosnhscodHc9YR6N /rLd5U2VeG9Ut8F7sLKM2l1yBp1I8LSPk3QRfCr2DQ+GLutxcciOVbaW4UErYA+TrAUa Ao+A== X-Gm-Message-State: ANoB5pnS2+T/hX1FUdE47qRD7Pr6QpCpIJUvxOgyDtTDT3PKzvXulie1 0Ujr9KLl9o7c3TOY8cZhUHXlmw== X-Google-Smtp-Source: AA0mqf4gI7+WEVoeKnbYVO4dc8MGqbdHwdSyz5lG1fOux7Cl/doBxrQHbEHr7A0+Yz5s92oUsjqIgg== X-Received: by 2002:a05:6512:151e:b0:4af:1cbe:1ad8 with SMTP id bq30-20020a056512151e00b004af1cbe1ad8mr13668924lfb.16.1669766611498; Tue, 29 Nov 2022 16:03:31 -0800 (PST) From: Viktor Prutyanov To: pbonzini@redhat.com Cc: viktor.prutyanov@phystech.edu, yuri.benditovich@daynix.com, yan@daynix.com, qemu-devel@nongnu.org, viktor@daynix.com Subject: [PATCH v1 2/3] contrib/elf2dmp: move PE dir search to pe_get_data_dir_entry Date: Wed, 30 Nov 2022 03:03:19 +0300 Message-Id: <20221130000320.287976-3-viktor@daynix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221130000320.287976-1-viktor@daynix.com> References: <20221130000320.287976-1-viktor@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::133; envelope-from=viktor@daynix.com; helo=mail-lf1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 29 Nov 2022 21:06:53 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1669774081698100005 Content-Type: text/plain; charset="utf-8" Move out PE directory search functionality to be reused not only for Debug Directory processing but for arbitrary PE directory. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/main.c | 66 +++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 9224764239..f3052b3c64 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -333,6 +333,40 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, return 0; } =20 +static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, + void *entry, size_t size, struct va_space *vs) +{ + const char e_magic[2] =3D "MZ"; + const char Signature[4] =3D "PE\0\0"; + IMAGE_DOS_HEADER *dos_hdr =3D start_addr; + IMAGE_NT_HEADERS64 nt_hdrs; + IMAGE_FILE_HEADER *file_hdr =3D &nt_hdrs.FileHeader; + IMAGE_OPTIONAL_HEADER64 *opt_hdr =3D &nt_hdrs.OptionalHeader; + IMAGE_DATA_DIRECTORY *data_dir =3D nt_hdrs.OptionalHeader.DataDirector= y; + + if (memcmp(&dos_hdr->e_magic, e_magic, sizeof(e_magic))) { + return 1; + } + + if (va_space_rw(vs, base + dos_hdr->e_lfanew, + &nt_hdrs, sizeof(nt_hdrs), 0)) { + return 1; + } + + if (memcmp(&nt_hdrs.Signature, Signature, sizeof(Signature)) || + file_hdr->Machine !=3D 0x8664 || opt_hdr->Magic !=3D 0x020b) { + return 1; + } + + if (va_space_rw(vs, + base + data_dir[idx].VirtualAddress, + entry, size, 0)) { + return 1; + } + + return 0; +} + static int write_dump(struct pa_space *ps, WinDumpHeader64 *hdr, const char *name) { @@ -369,42 +403,16 @@ static int write_dump(struct pa_space *ps, static int pe_get_pdb_symstore_hash(uint64_t base, void *start_addr, char *hash, struct va_space *vs) { - const char e_magic[2] =3D "MZ"; - const char Signature[4] =3D "PE\0\0"; const char sign_rsds[4] =3D "RSDS"; - IMAGE_DOS_HEADER *dos_hdr =3D start_addr; - IMAGE_NT_HEADERS64 nt_hdrs; - IMAGE_FILE_HEADER *file_hdr =3D &nt_hdrs.FileHeader; - IMAGE_OPTIONAL_HEADER64 *opt_hdr =3D &nt_hdrs.OptionalHeader; - IMAGE_DATA_DIRECTORY *data_dir =3D nt_hdrs.OptionalHeader.DataDirector= y; IMAGE_DEBUG_DIRECTORY debug_dir; OMFSignatureRSDS rsds; char *pdb_name; size_t pdb_name_sz; size_t i; =20 - QEMU_BUILD_BUG_ON(sizeof(*dos_hdr) >=3D ELF2DMP_PAGE_SIZE); - - if (memcmp(&dos_hdr->e_magic, e_magic, sizeof(e_magic))) { - return 1; - } - - if (va_space_rw(vs, base + dos_hdr->e_lfanew, - &nt_hdrs, sizeof(nt_hdrs), 0)) { - return 1; - } - - if (memcmp(&nt_hdrs.Signature, Signature, sizeof(Signature)) || - file_hdr->Machine !=3D 0x8664 || opt_hdr->Magic !=3D 0x020b) { - return 1; - } - - printf("Debug Directory RVA =3D 0x%08"PRIx32"\n", - (uint32_t)data_dir[IMAGE_FILE_DEBUG_DIRECTORY].VirtualAddress); - - if (va_space_rw(vs, - base + data_dir[IMAGE_FILE_DEBUG_DIRECTORY].VirtualAddress, - &debug_dir, sizeof(debug_dir), 0)) { + if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_DEBUG_DIRECTORY, + &debug_dir, sizeof(debug_dir), vs)) { + eprintf("Failed to get Debug Directory\n"); return 1; } =20 --=20 2.35.1 From nobody Sun May 5 17:48:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1669774109; cv=none; d=zohomail.com; s=zohoarc; b=TFzoRLNj3fpxrl5UE+llfNOI2IcRYGaQKz794Whf9RIRsoDQHhBtiQL7ARhFiWiPO1TXkfXHbO/fHDesYxYIXo3DtiiXDE7u3TLsneGorEOKmQxNTlxsocownjRKUjoD6AARZOKfxVdMWLCOJ0pE845l8RjXgocIpdCTAOb7hwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669774109; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9LnWPuKtqHKtpKk06xgRc3yHBStzUkLPUQ6Q4gHALNk=; b=ElYhjXWz3KgvRFzHJcTg2L/0xlYLOvfzDYDvM/RBnzhNewHKCrTgqRAJeY01ED1sScsfR1bhgASvj8zWh38nqcUghtmGfvs/2G42emkGFc+DZDUZU2UH9hEOzfBW/WoIEY0OVQOzc6QX2z4ysr1w0OfJVooltaEMm3oHlLGsp1s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166977410969828.195390281236087; Tue, 29 Nov 2022 18:08:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0CUy-0002Ax-Oh; Tue, 29 Nov 2022 21:06:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0AZi-00083I-Fr for qemu-devel@nongnu.org; Tue, 29 Nov 2022 19:03:42 -0500 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0AZa-0004tx-Ll for qemu-devel@nongnu.org; Tue, 29 Nov 2022 19:03:41 -0500 Received: by mail-lf1-x133.google.com with SMTP id d6so24496024lfs.10 for ; Tue, 29 Nov 2022 16:03:33 -0800 (PST) Received: from vp-pc.. (46-138-224-213.dynamic.spd-mgts.ru. [46.138.224.213]) by smtp.gmail.com with ESMTPSA id x17-20020a056512079100b004b4f4360407sm2399377lfr.105.2022.11.29.16.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 16:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9LnWPuKtqHKtpKk06xgRc3yHBStzUkLPUQ6Q4gHALNk=; b=2g4/zJ7cxTfDlE/n4DOedlCyWUB8EONd1+VCLNH4oABl0NKGcAj6oTvkWpLUkj/WoI /sN+e42tIV4jCtbDN+vPv52Zl6f4JTQWbdnJVT2x4zzQB49h0yiwn6QlF8p92gW42rHi sMoxw02JgH0sF2M1mFipjKBjHSPjpwxxb0d+tH6Gbl2mfSN41Yk/1Gk/d9e6KJrbZlk7 TWBxxXiS0hRbZbcTLbBu1GJnykHbMTlorDWq6KtRNbvY8HooMsMBgtqFXu2K7yYOWuKk oQt41+Z277fYqlVkESTHEK9QBRZM9hA58HYclW68ydP9UW6GrgauObxOfhydmRUiIZeG 1Hug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9LnWPuKtqHKtpKk06xgRc3yHBStzUkLPUQ6Q4gHALNk=; b=CuMeWI7SSZXtWczSyWeLX10NGJe8XoL1lHQg/sHd1nCQoJTgs/m5GzjAainFG5Yy3k 3zoCqMSo5J0l54D5g7hSyQcZjp7G2BuI8EYBeIwcrr8A3wv5cupvIgogj16OPq2HHQhi H8uo+DX4FgBmGoRetQNbiBffh57pAyb2K3n3G1mjGEKMwMw7dBU6NvjjFIa6zdhHkAjT OLEZ4IWWw+uS4smdddvBTYXacMfiJyKEHTd6punD1q/s96PdUurAsDi+kUJHJbfiCBDC YcGLGfstteYNZytTuxi5my0sNYfn6rYfPPmequ/4A45X/dFmqQPLsMVBJlXGREf56uuo 3xMQ== X-Gm-Message-State: ANoB5plUuMcmah7FBjSENwByywC5M1cBq0NxDh0arWrKl7RORCBB/z0D AyhgMx/2b4KqOB9mnMngJCwJFgMb8/ZZvXUE X-Google-Smtp-Source: AA0mqf6Dy/epY2hZvm2SkRrCBQo5LAUBqXdRnx4CIaOZAxMUsq2/JefnzbqKXK8fE7ZFb5dHAjDiGA== X-Received: by 2002:a05:6512:118b:b0:4a4:77a8:45a4 with SMTP id g11-20020a056512118b00b004a477a845a4mr19108742lfr.654.1669766612479; Tue, 29 Nov 2022 16:03:32 -0800 (PST) From: Viktor Prutyanov To: pbonzini@redhat.com Cc: viktor.prutyanov@phystech.edu, yuri.benditovich@daynix.com, yan@daynix.com, qemu-devel@nongnu.org, viktor@daynix.com Subject: [PATCH v1 3/3] contrib/elf2dmp: add PE name check and Windows Server 2022 support Date: Wed, 30 Nov 2022 03:03:20 +0300 Message-Id: <20221130000320.287976-4-viktor@daynix.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221130000320.287976-1-viktor@daynix.com> References: <20221130000320.287976-1-viktor@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::133; envelope-from=viktor@daynix.com; helo=mail-lf1-x133.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 29 Nov 2022 21:06:53 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1669774111732100003 Content-Type: text/plain; charset="utf-8" Since its inception elf2dmp has checked MZ signatures within an address space above IDT[0] interrupt vector and took first PE image found as Windows Kernel. But in Windows Server 2022 memory dump this address space range is full of invalid PE fragments and the tool must check that PE image is 'ntoskrnl.exe' actually. So, introduce additional validation by checking image name from Export Directory against 'ntoskrnl.exe'. Signed-off-by: Viktor Prutyanov Tested-by: Yuri Benditovich --- contrib/elf2dmp/main.c | 28 ++++++++++++++++++++++++++-- contrib/elf2dmp/pe.h | 15 +++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index f3052b3c64..f7de82a03e 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -17,6 +17,7 @@ =20 #define SYM_URL_BASE "https://msdl.microsoft.com/download/symbols/" #define PDB_NAME "ntkrnlmp.pdb" +#define PE_NAME "ntoskrnl.exe" =20 #define INITIAL_MXCSR 0x1f80 =20 @@ -400,6 +401,25 @@ static int write_dump(struct pa_space *ps, return fclose(dmp_file); } =20 +static bool pe_check_export_name(uint64_t base, void *start_addr, + struct va_space *vs) +{ + IMAGE_EXPORT_DIRECTORY export_dir; + const char *pe_name; + + if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_EXPORT_DIRECTOR= Y, + &export_dir, sizeof(export_dir), vs)) { + return false; + } + + pe_name =3D va_space_resolve(vs, base + export_dir.Name); + if (!pe_name) { + return false; + } + + return !strcmp(pe_name, PE_NAME); +} + static int pe_get_pdb_symstore_hash(uint64_t base, void *start_addr, char *hash, struct va_space *vs) { @@ -484,6 +504,7 @@ int main(int argc, char *argv[]) uint64_t KdDebuggerDataBlock; KDDEBUGGER_DATA64 *kdbg; uint64_t KdVersionBlock; + bool kernel_found =3D false; =20 if (argc !=3D 3) { eprintf("usage:\n\t%s elf_file dmp_file\n", argv[0]); @@ -531,11 +552,14 @@ int main(int argc, char *argv[]) } =20 if (*(uint16_t *)nt_start_addr =3D=3D 0x5a4d) { /* MZ */ - break; + if (pe_check_export_name(KernBase, nt_start_addr, &vs)) { + kernel_found =3D true; + break; + } } } =20 - if (!nt_start_addr) { + if (!kernel_found) { eprintf("Failed to find NT kernel image\n"); err =3D 1; goto out_ps; diff --git a/contrib/elf2dmp/pe.h b/contrib/elf2dmp/pe.h index 807d006364..71126af1ac 100644 --- a/contrib/elf2dmp/pe.h +++ b/contrib/elf2dmp/pe.h @@ -88,6 +88,20 @@ typedef struct IMAGE_NT_HEADERS64 { IMAGE_OPTIONAL_HEADER64 OptionalHeader; } __attribute__ ((packed)) IMAGE_NT_HEADERS64; =20 +typedef struct IMAGE_EXPORT_DIRECTORY { + uint32_t Characteristics; + uint32_t TimeDateStamp; + uint16_t MajorVersion; + uint16_t MinorVersion; + uint32_t Name; + uint32_t Base; + uint32_t NumberOfFunctions; + uint32_t NumberOfNames; + uint32_t AddressOfFunctions; + uint32_t AddressOfNames; + uint32_t AddressOfNameOrdinals; +} __attribute__ ((packed)) IMAGE_EXPORT_DIRECTORY; + typedef struct IMAGE_DEBUG_DIRECTORY { uint32_t Characteristics; uint32_t TimeDateStamp; @@ -102,6 +116,7 @@ typedef struct IMAGE_DEBUG_DIRECTORY { #define IMAGE_DEBUG_TYPE_CODEVIEW 2 #endif =20 +#define IMAGE_FILE_EXPORT_DIRECTORY 0 #define IMAGE_FILE_DEBUG_DIRECTORY 6 =20 typedef struct guid_t { --=20 2.35.1