| 1 | // |
| 2 | // Copyright (c) SAS Institute 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 | package authenticode |
| 18 | |
| 19 | // MSI table names are packed in pairs into a Chinese codepoint which then |
| 20 | // becomes 2 bytes of UTF-16. This seems to be an attempt to support longer |
| 21 | // table names than CDF would otherwise allow but it's incredibly silly. |
| 22 | func msiDecodeName(msiName string) string { |
| 23 | out := "" |
| 24 | for _, x := range msiName { |
| 25 | if x >= 0x3800 && x < 0x4800 { |
| 26 | x -= 0x3800 |
| 27 | out += string(msiDecodeRune(x&0x3f)) + string(msiDecodeRune(x>>6)) |
| 28 | } else if x >= 0x4800 && x < 0x4840 { |
| 29 | x -= 0x4800 |
| 30 | out += string(msiDecodeRune(x)) |
| 31 | } else if x == 0x4840 { |
| 32 | out += "Table." |
| 33 | } else { |
| 34 | out += string(x) |
| 35 | } |
| 36 | } |
| 37 | return out |
| 38 | } |
| 39 | |
| 40 | func msiDecodeRune(x rune) rune { |
| 41 | if x < 10 { |
| 42 | return x + '0' |
| 43 | } else if x < 10+26 { |
| 44 | return x - 10 + 'A' |
| 45 | } else if x < 10+26+26 { |
| 46 | return x - 10 - 26 + 'a' |
| 47 | } else if x == 10+26+26 { |
| 48 | return '.' |
| 49 | } else { |
| 50 | return '_' |
| 51 | } |
| 52 | } |