|
| 1 | +/* |
| 2 | + * Copyright 2021-present by Nedim Sabic Sabic |
| 3 | + * https://www.fibratus.io |
| 4 | + * All Rights Reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package symbolize |
| 20 | + |
| 21 | +import ( |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/rabbitstack/fibratus/pkg/util/va" |
| 25 | + "github.com/stretchr/testify/assert" |
| 26 | +) |
| 27 | + |
| 28 | +func TestSymbolFromRVA(t *testing.T) { |
| 29 | + var tests = []struct { |
| 30 | + rva va.Address |
| 31 | + exports map[uint32]string |
| 32 | + expectedSymbol string |
| 33 | + }{ |
| 34 | + {va.Address(317949), map[uint32]string{ |
| 35 | + 9824: "SHCreateScopeItemFromShellItem", |
| 36 | + 23248: "SHCreateScopeItemFromIDList", |
| 37 | + 165392: "DllGetClassObject", |
| 38 | + 186368: "SHCreateSearchIDListFromAutoList", |
| 39 | + 238048: "DllCanUnloadNow", |
| 40 | + 240112: "IsShellItemInSearchIndex", |
| 41 | + 240304: "IsMSSearchEnabled", |
| 42 | + 272336: "SHSaveBinaryAutoListToStream", |
| 43 | + 310672: "DllMain", |
| 44 | + 317920: "", |
| 45 | + 320864: "", |
| 46 | + 434000: "SHCreateAutoList", |
| 47 | + 434016: "SHCreateAutoListWithID", |
| 48 | + 555040: "CreateDefaultProviderResolver", |
| 49 | + 571136: "GetGatherAdmin", |
| 50 | + 572592: "SEARCH_RemoteLocationsCscStateCache_IsRemoteLocationInCsc"}, |
| 51 | + "?", |
| 52 | + }, |
| 53 | + {va.Address(434011), map[uint32]string{ |
| 54 | + 9824: "SHCreateScopeItemFromShellItem", |
| 55 | + 23248: "SHCreateScopeItemFromIDList", |
| 56 | + 165392: "DllGetClassObject", |
| 57 | + 186368: "SHCreateSearchIDListFromAutoList", |
| 58 | + 238048: "DllCanUnloadNow", |
| 59 | + 240112: "IsShellItemInSearchIndex", |
| 60 | + 240304: "IsMSSearchEnabled", |
| 61 | + 272336: "SHSaveBinaryAutoListToStream", |
| 62 | + 310672: "DllMain", |
| 63 | + 317920: "", |
| 64 | + 320864: "", |
| 65 | + 434000: "SHCreateAutoList", |
| 66 | + 434016: "SHCreateAutoListWithID", |
| 67 | + 555040: "CreateDefaultProviderResolver", |
| 68 | + 571136: "GetGatherAdmin", |
| 69 | + 572592: "SEARCH_RemoteLocationsCscStateCache_IsRemoteLocationInCsc"}, |
| 70 | + "SHCreateAutoList", |
| 71 | + }, |
| 72 | + {va.Address(4532), map[uint32]string{ |
| 73 | + 9824: "SHCreateScopeItemFromShellItem", |
| 74 | + 23248: "SHCreateScopeItemFromIDList", |
| 75 | + 165392: "DllGetClassObject", |
| 76 | + 186368: "SHCreateSearchIDListFromAutoList", |
| 77 | + 238048: "DllCanUnloadNow", |
| 78 | + 240112: "IsShellItemInSearchIndex", |
| 79 | + 240304: "IsMSSearchEnabled", |
| 80 | + 572592: "SEARCH_RemoteLocationsCscStateCache_IsRemoteLocationInCsc"}, |
| 81 | + "", |
| 82 | + }, |
| 83 | + } |
| 84 | + |
| 85 | + for _, tt := range tests { |
| 86 | + t.Run(tt.expectedSymbol, func(t *testing.T) { |
| 87 | + exps := &ModuleExports{exps: tt.exports} |
| 88 | + assert.Equal(t, tt.expectedSymbol, exps.SymbolFromRVA(tt.rva)) |
| 89 | + }) |
| 90 | + } |
| 91 | +} |
0 commit comments