Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
b49cc566
Commit
b49cc566
authored
Dec 04, 2009
by
Owen Rudge
Committed by
Alexandre Julliard
Dec 07, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imagehlp: Recalculate PE checksum after file modification.
parent
ba5a86e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
integrity.c
dlls/imagehlp/integrity.c
+88
-0
No files found.
dlls/imagehlp/integrity.c
View file @
b49cc566
...
...
@@ -285,6 +285,88 @@ static BOOL IMAGEHLP_GetCertificateOffset( HANDLE handle, DWORD num,
return
TRUE
;
}
/***********************************************************************
* IMAGEHLP_RecalculateChecksum (INTERNAL)
*
* Update the NT header checksum for the specified file.
*/
static
BOOL
IMAGEHLP_RecalculateChecksum
(
HANDLE
handle
)
{
DWORD
FileLength
,
count
,
HeaderSum
,
pe_offset
,
nt_hdr_size
;
IMAGE_NT_HEADERS32
nt_hdr32
;
IMAGE_NT_HEADERS64
nt_hdr64
;
LPVOID
BaseAddress
;
HANDLE
hMapping
;
DWORD
*
CheckSum
;
void
*
nt_hdr
;
int
ret
;
BOOL
r
;
TRACE
(
"handle %p
\n
"
,
handle
);
ret
=
IMAGEHLP_GetNTHeaders
(
handle
,
&
pe_offset
,
&
nt_hdr32
,
&
nt_hdr64
);
if
(
ret
==
HDR_NT32
)
{
CheckSum
=
&
nt_hdr32
.
OptionalHeader
.
CheckSum
;
nt_hdr
=
&
nt_hdr32
;
nt_hdr_size
=
sizeof
(
IMAGE_NT_HEADERS32
);
}
else
if
(
ret
==
HDR_NT64
)
{
CheckSum
=
&
nt_hdr64
.
OptionalHeader
.
CheckSum
;
nt_hdr
=
&
nt_hdr64
;
nt_hdr_size
=
sizeof
(
IMAGE_NT_HEADERS64
);
}
else
return
FALSE
;
hMapping
=
CreateFileMappingW
(
handle
,
NULL
,
PAGE_READONLY
,
0
,
0
,
NULL
);
if
(
!
hMapping
)
return
FALSE
;
BaseAddress
=
MapViewOfFile
(
hMapping
,
FILE_MAP_READ
,
0
,
0
,
0
);
if
(
!
BaseAddress
)
{
CloseHandle
(
hMapping
);
return
FALSE
;
}
FileLength
=
GetFileSize
(
handle
,
NULL
);
*
CheckSum
=
0
;
CheckSumMappedFile
(
BaseAddress
,
FileLength
,
&
HeaderSum
,
CheckSum
);
UnmapViewOfFile
(
BaseAddress
);
CloseHandle
(
hMapping
);
if
(
*
CheckSum
)
{
/* write the header back again */
count
=
SetFilePointer
(
handle
,
pe_offset
,
NULL
,
FILE_BEGIN
);
if
(
count
==
INVALID_SET_FILE_POINTER
)
return
FALSE
;
count
=
0
;
r
=
WriteFile
(
handle
,
nt_hdr
,
nt_hdr_size
,
&
count
,
NULL
);
if
(
!
r
)
return
FALSE
;
if
(
count
!=
nt_hdr_size
)
return
FALSE
;
return
TRUE
;
}
return
FALSE
;
}
/***********************************************************************
* ImageAddCertificate (IMAGEHLP.@)
...
...
@@ -392,6 +474,9 @@ BOOL WINAPI ImageAddCertificate(
if
(
!
IMAGEHLP_SetSecurityDirOffset
(
FileHandle
,
sd_VirtualAddr
,
size
))
return
FALSE
;
if
(
!
IMAGEHLP_RecalculateChecksum
(
FileHandle
))
return
FALSE
;
return
TRUE
;
}
...
...
@@ -636,6 +721,9 @@ BOOL WINAPI ImageRemoveCertificate(HANDLE FileHandle, DWORD Index)
if
(
!
r
)
return
FALSE
;
if
(
!
IMAGEHLP_RecalculateChecksum
(
FileHandle
))
return
FALSE
;
return
TRUE
;
error:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment